forked from Shinonome/dots-hyprland
config options: notify on reload
This commit is contained in:
@@ -13,6 +13,8 @@ function findSuitableMaterialSymbol(summary = "") {
|
|||||||
'welcome': 'waving_hand',
|
'welcome': 'waving_hand',
|
||||||
'time': 'scheduleb',
|
'time': 'scheduleb',
|
||||||
'installed': 'download',
|
'installed': 'download',
|
||||||
|
'configuration reloaded': 'reset_wrench',
|
||||||
|
'config': 'reset_wrench',
|
||||||
'update': 'update',
|
'update': 'update',
|
||||||
'ai response': 'neurology',
|
'ai response': 'neurology',
|
||||||
'startswith:file': 'folder_copy', // Declarative startsWith check
|
'startswith:file': 'folder_copy', // Declarative startsWith check
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ Singleton {
|
|||||||
property string fileDir: `${StandardPaths.standardLocations(StandardPaths.ConfigLocation)[0]}/illogical-impulse`
|
property string fileDir: `${StandardPaths.standardLocations(StandardPaths.ConfigLocation)[0]}/illogical-impulse`
|
||||||
property string fileName: "config.json"
|
property string fileName: "config.json"
|
||||||
property string filePath: `${root.fileDir}/${root.fileName}`
|
property string filePath: `${root.fileDir}/${root.fileName}`
|
||||||
|
property bool firstLoad: true
|
||||||
|
|
||||||
function toPlainObject(qtObj) {
|
function toPlainObject(qtObj) {
|
||||||
if (qtObj === null || typeof qtObj !== "object") return qtObj;
|
if (qtObj === null || typeof qtObj !== "object") return qtObj;
|
||||||
@@ -45,29 +46,40 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function applyConfig(fileContent) {
|
function applyConfig(fileContent) {
|
||||||
const json = JSON.parse(fileContent);
|
try {
|
||||||
|
const json = JSON.parse(fileContent);
|
||||||
|
|
||||||
function applyToQtObject(qtObj, jsonObj) {
|
function applyToQtObject(qtObj, jsonObj) {
|
||||||
if (!qtObj || typeof jsonObj !== "object" || jsonObj === null) return;
|
if (!qtObj || typeof jsonObj !== "object" || jsonObj === null) return;
|
||||||
|
|
||||||
for (let key in jsonObj) {
|
for (let key in jsonObj) {
|
||||||
if (!qtObj.hasOwnProperty(key)) continue;
|
if (!qtObj.hasOwnProperty(key)) continue;
|
||||||
|
|
||||||
// Check if the property is a QtObject (not a value)
|
// Check if the property is a QtObject (not a value)
|
||||||
const value = qtObj[key];
|
const value = qtObj[key];
|
||||||
const jsonValue = jsonObj[key];
|
const jsonValue = jsonObj[key];
|
||||||
|
|
||||||
// If it's an object and not an array, recurse
|
// If it's an object and not an array, recurse
|
||||||
if (value && typeof value === "object" && !Array.isArray(value)) {
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
||||||
applyToQtObject(value, jsonValue);
|
applyToQtObject(value, jsonValue);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, assign the value
|
// Otherwise, assign the value
|
||||||
qtObj[key] = jsonValue;
|
qtObj[key] = jsonValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
applyToQtObject(ConfigOptions, json);
|
applyToQtObject(ConfigOptions, json);
|
||||||
|
if (root.firstLoad) {
|
||||||
|
root.firstLoad = false;
|
||||||
|
} else {
|
||||||
|
Hyprland.dispatch(`exec notify-send "Shell configuration reloaded" "${root.filePath}"`)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[ConfigLoader] Error reading file:", e);
|
||||||
|
Hyprland.dispatch(`exec notify-send "Shell configuration failed to load" "${root.filePath}"`)
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
@@ -85,6 +97,7 @@ Singleton {
|
|||||||
path: root.filePath
|
path: root.filePath
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
onFileChanged: {
|
onFileChanged: {
|
||||||
|
console.log("[ConfigLoader] File changed, reloading...")
|
||||||
this.reload()
|
this.reload()
|
||||||
delayedFileRead.start()
|
delayedFileRead.start()
|
||||||
}
|
}
|
||||||
@@ -98,8 +111,9 @@ Singleton {
|
|||||||
// Apply ConfigOptions json to file
|
// Apply ConfigOptions json to file
|
||||||
const plainConfig = toPlainObject(ConfigOptions)
|
const plainConfig = toPlainObject(ConfigOptions)
|
||||||
configFileView.setText(JSON.stringify(plainConfig, null, 2))
|
configFileView.setText(JSON.stringify(plainConfig, null, 2))
|
||||||
|
Hyprland.dispatch(`exec notify-send "Shell configuration created" "${root.filePath}"`)
|
||||||
} else {
|
} else {
|
||||||
Hyprland.dispatch(`exec notify-send "Failed to load config file at ${root.filePath}"`)
|
Hyprland.dispatch(`exec notify-send "Shell configuration failed to load" "${root.filePath}"`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user