working carousel
This commit is contained in:
1 parent
7d58533539
commit
eb0dc429da
7 files changed
+109
-66
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import QtQuick
|
||||
import Quickshell.Io
|
||||
import Quickshell
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
readonly property string appConfigPath: Quickshell.env("SKYG_APP_CAROUSEL")
|
||||
property list<var> appConfig: []
|
||||
|
||||
FileView {
|
||||
id: configFile
|
||||
path: root.appConfigPath
|
||||
watchChanges: true
|
||||
onFileChanged: configFile.reload()
|
||||
onLoaded: {
|
||||
let parsed = JSON.parse(configFile.text());
|
||||
if (!Array.isArray(parsed)) {
|
||||
throw new Error(`Invalid app config: expected a JSON array, got ${typeof parsed}`);
|
||||
}
|
||||
for (const elm of parsed) {
|
||||
if (!(typeof elm.name == 'string')) {
|
||||
throw new Error(`Invalid app config: expected name to be a string, got ${typeof elm.name}`);
|
||||
}
|
||||
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}`);
|
||||
}
|
||||
if (elm.dims !== undefined) {
|
||||
if (!elm.isIcon) {
|
||||
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))) {
|
||||
throw new Error(`Invalid app config: expected dims to be a tuple of 2 ints`);
|
||||
}
|
||||
} else {
|
||||
elm.dims = [100, 100];
|
||||
}
|
||||
if (!Array.isArray(elm.exec) || elm.exec.length === 0) {
|
||||
throw new Error(`Invalid app config: expected exec to be a non-empty array, got ${typeof elm.exec}`);
|
||||
}
|
||||
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);
|
||||
root.appConfig = parsed;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user