validation/

This commit is contained in:
ari committed 2026-09-11 15:01:11 -04:00
1 parent eb0dc429da
commit 6c7713cda4
4 files changed
+52 -90

No files matched your search

+26 -23
View File
@@ -14,39 +14,42 @@ Item {
watchChanges: true watchChanges: true
onFileChanged: configFile.reload() onFileChanged: configFile.reload()
onLoaded: { onLoaded: {
let parsed = JSON.parse(configFile.text()); const logPrefix = 'Invalid app config: ';
if (!Array.isArray(parsed)) { const testIt = (cond, error) => {
throw new Error(`Invalid app config: expected a JSON array, got ${typeof parsed}`); if (!cond) {
throw new Error(`${logPrefix} ${error}`)
}
} }
for (const elm of parsed) { const isOf = (typeName) => (name, elm, iffDefined = false) => {
if (!(typeof elm.name == 'string')) { if (!iffDefined || (iffDefined && elm !== undefined)) {
throw new Error(`Invalid app config: expected name to be a string, got ${typeof elm.name}`); testIt(typeof elm === typeName, `expected ${name} to be a ${typeName}, got ${typeof elm}`)
}
if (!(typeof elm.image == 'string')) {
throw new Error(`Invalid app config: expected image to be a string, got ${typeof elm.image}`);
}
if (elm.isIcon !== undefined && typeof elm.isIcon !== 'boolean') {
throw new Error(`Invalid app config: expected isIcon to be a boolean, got ${typeof elm.isIcon}`);
} }
}
const isBoolean = isOf('boolean')
const isString = isOf('string')
let parsed = JSON.parse(configFile.text());
let apps = parsed.apps;
if (!Array.isArray(apps)) {
throw new Error(`Invalid app config: expected a JSON array, got ${typeof apps}`);
}
isBoolean('autoStart', parsed.autoStart, true)
for (const elm of apps) {
isString('name', elm.name)
isString('image', elm.image)
isBoolean('isIcon', elm.isIcon, true)
if (elm.dims !== undefined) { if (elm.dims !== undefined) {
if (!elm.isIcon) { testIt(elm.isIcon, 'dims is only allowed when isIcon is true')
throw new Error(`Invalid app config: dims is only allowed when isIcon is true`);
}
if (!Array.isArray(elm.dims) || elm.dims.length !== 2 || !elm.dims.every(n => Number.isInteger(n))) { if (!Array.isArray(elm.dims) || elm.dims.length !== 2 || !elm.dims.every(n => Number.isInteger(n))) {
throw new Error(`Invalid app config: expected dims to be a tuple of 2 ints`); throw new Error(`${logPrefix} expected dims to be a tuple of 2 ints`);
} }
} else { } else {
elm.dims = [100, 100]; elm.dims = [100, 100];
} }
if (!Array.isArray(elm.exec) || elm.exec.length === 0) { testIt(Array.isArray(elm.exec) && elm.exec.length > 0, `expected exec to be a non-empty array, got ${elm.exec}`)
throw new Error(`Invalid app config: expected exec to be a non-empty array, got ${typeof elm.exec}`); testIt(elm.exec.every(arg => typeof arg === 'string'), 'expected all exec entries to be strings')
}
if (!elm.exec.every(arg => typeof arg === 'string')) {
throw new Error(`Invalid app config: expected all exec entries to be strings`);
}
} }
console.log("Loaded Config", configFile.__data); console.log("Loaded Config", configFile.__data);
root.appConfig = parsed; root.appConfig = apps;
} }
} }
} }
+4 -4
View File
@@ -6,10 +6,10 @@ QtObject {
readonly property color selectedBorder: "#7aa2f7" readonly property color selectedBorder: "#7aa2f7"
readonly property color textColor: "#ffffff" readonly property color textColor: "#ffffff"
readonly property color labelBg: "#99000000" readonly property color labelBg: "#99000000"
readonly property real cornerRadius: 10 readonly property real cornerRadius: 20
readonly property real cardWidth: 240 readonly property real cardWidth: 480
readonly property real cardHeight: 240 readonly property real cardHeight: 480
readonly property real cardPadding: 10 readonly property real cardPadding: 50
readonly property real cardSpacing: 40 readonly property real cardSpacing: 40
readonly property real fontSize: 24 readonly property real fontSize: 24
+22 -30
View File
@@ -1,30 +1,22 @@
[ {
{ "autoStart": true,
"name": "Chromium", "apps": [
"image": "chromium", {
"isIcon": true, "name": "Chromium",
"exec": [ "image": "chromium",
"chromium" "isIcon": true,
] "exec": ["chromium"]
}, },
{ {
"name": "Netflix", "name": "Netflix",
"image": "https://assets.nflxext.com/us/ffe/siteui/common/icons/nficon2023.ico", "image": "https://assets.nflxext.com/us/ffe/siteui/common/icons/nficon2023.ico",
"exec": [ "exec": ["chromium", "--app=https://www.netflix.com"]
"chromium", },
"--app=https://www.netflix.com" {
] "name": "Settings",
}, "image": "system-settings",
{ "isIcon": true,
"name": "Settings", "exec": ["dms", "ipc", "call", "settings", "toggle"]
"image": "system-settings", }
"isIcon": true, ]
"exec": [ }
"dms",
"ipc",
"call",
"settings",
"toggle"
]
}
]
-33
View File
@@ -1,33 +0,0 @@
import QtQuick
import QtWebEngine
import Quickshell
ShellRoot {
// Ensure the WebEngine is initialized
Component.onCompleted: WebEngine.initialize()
PanelWindow {
id: webWindow
width: 800
height: 600
// Background container
Rectangle {
anchors.fill: parent
color: "#1e1e2e" // Match your desktop theme
// The embedded Web Page Component
WebEngineView {
anchors.fill: parent
url: "https://quickshell.org" // The URL you want to embed
// Optional: Handle loading status
onLoadingChanged: (loadingInfo) => {
if (loadingInfo.status === WebEngineView.LoadFailedStatus) {
console.log("Failed to load page: " + loadingInfo.errorString);
}
}
}
}
}
}