import QtQuick import Quickshell.Io import Quickshell Item { id: root readonly property string appConfigPath: Quickshell.env("SKYG_APP_CAROUSEL") property list appConfig: [] property bool enableCacheFolder: false property bool backgroundMode: false FileView { id: configFile path: root.appConfigPath watchChanges: true onFileChanged: configFile.reload() onLoaded: { const logPrefix = 'Invalid app config: '; const testIt = (cond, error) => { if (!cond) { throw new Error(`${logPrefix} ${error}`) } } const isOf = (typeName) => (name, elm, iffDefined = false) => { if (!iffDefined || (iffDefined && elm !== undefined)) { testIt(typeof elm === typeName, `expected ${name} to be a ${typeName}, got ${typeof elm}`) } } const isBoolean = isOf('boolean') const isString = isOf('string') const resolveImagePath = (image) => { if (image.startsWith('http://') || image.startsWith('https://') || image.startsWith('file://')) return image let path = image if (path.startsWith('~/')) path = Quickshell.env('HOME') + path.slice(1) if (!path.startsWith('/')) { const cfg = root.appConfigPath const i = cfg.lastIndexOf('/') path = (i >= 0 ? cfg.substring(0, i) : '.') + '/' + path } return 'file://' + path } 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) isBoolean('enableCacheFolder', parsed.enableCacheFolder, true) isBoolean('backgroundMode', parsed.backgroundMode, true) root.enableCacheFolder = !!parsed.enableCacheFolder root.backgroundMode = !!parsed.backgroundMode for (const elm of apps) { isString('name', elm.name) isString('image', elm.image) isBoolean('isIcon', elm.isIcon, true) if (elm.dims !== undefined) { testIt(elm.isIcon, '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(`${logPrefix} expected dims to be a tuple of 2 ints`); } } else { elm.dims = [100, 100]; } const hasExec = elm.exec !== undefined const hasDispatch = elm.hyprlandDispatch !== undefined testIt(hasExec !== hasDispatch, 'specify exactly one of exec or hyprlandDispatch') if (hasExec) { testIt(Array.isArray(elm.exec) && elm.exec.length > 0, `expected exec to be a non-empty array, got ${elm.exec}`) testIt(elm.exec.every(arg => typeof arg === 'string'), 'expected all exec entries to be strings') } else { isString('hyprlandDispatch', elm.hyprlandDispatch) testIt(elm.hyprlandDispatch.length > 0, 'expected hyprlandDispatch to be a non-empty string') } if (!elm.isIcon) elm.image = resolveImagePath(elm.image) } console.log("Loaded Config", configFile.__data); root.appConfig = apps; } } }