forked from Shinonome/dots-hyprland
77 lines
2.3 KiB
QML
77 lines
2.3 KiB
QML
pragma Singleton
|
|
pragma ComponentBehavior: Bound
|
|
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Io
|
|
|
|
Singleton {
|
|
id: root
|
|
property string configFilePath: Directories.shellConfigPath
|
|
property alias options: configOptionsJsonAdapter
|
|
|
|
function setNestedValue(nestedKey, value) {
|
|
let keys = nestedKey.split(".");
|
|
let obj = root.options;
|
|
let parents = [obj];
|
|
|
|
// Traverse and collect parent objects
|
|
for (let i = 0; i < keys.length - 1; ++i) {
|
|
if (!obj[keys[i]] || typeof obj[keys[i]] !== "object") {
|
|
obj[keys[i]] = {};
|
|
}
|
|
obj = obj[keys[i]];
|
|
parents.push(obj);
|
|
}
|
|
|
|
// Convert value to correct type using JSON.parse when safe
|
|
let convertedValue = value;
|
|
if (typeof value === "string") {
|
|
let trimmed = value.trim();
|
|
if (trimmed === "true" || trimmed === "false" || !isNaN(Number(trimmed))) {
|
|
try {
|
|
convertedValue = JSON.parse(trimmed);
|
|
} catch (e) {
|
|
convertedValue = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
obj[keys[keys.length - 1]] = convertedValue;
|
|
}
|
|
|
|
FileView {
|
|
path: root.configFilePath
|
|
|
|
watchChanges: true
|
|
onFileChanged: reload()
|
|
onAdapterUpdated: writeAdapter()
|
|
onLoadFailed: error => {
|
|
if (error == FileViewError.FileNotFound) {
|
|
writeAdapter();
|
|
}
|
|
}
|
|
|
|
JsonAdapter {
|
|
id: configOptionsJsonAdapter
|
|
|
|
property JsonObject background: JsonObject {
|
|
property bool fixedClockPosition: false
|
|
property real clockX: -500
|
|
property real clockY: -500
|
|
property string wallpaperPath: ""
|
|
property JsonObject parallax: JsonObject {
|
|
property bool enableWorkspace: true
|
|
property real workspaceZoom: 1.07 // Relative to your screen, not wallpaper size
|
|
property bool enableSidebar: true
|
|
}
|
|
}
|
|
|
|
property JsonObject time: JsonObject {
|
|
// https://doc.qt.io/qt-6/qtime.html#toString
|
|
property string format: "hh:mm"
|
|
property string dateFormat: "ddd, dd/MM"
|
|
}
|
|
}
|
|
}
|
|
}
|