forked from Shinonome/dots-hyprland
config loader: write back on load to include new options in user config
This commit is contained in:
@@ -20,23 +20,30 @@ Singleton {
|
|||||||
id: root
|
id: root
|
||||||
property string filePath: Directories.shellConfigPath
|
property string filePath: Directories.shellConfigPath
|
||||||
property bool firstLoad: true
|
property bool firstLoad: true
|
||||||
|
property bool preventNextLoad: false
|
||||||
|
|
||||||
function loadConfig() {
|
function loadConfig() {
|
||||||
configFileView.reload()
|
configFileView.reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyConfig(fileContent) {
|
function applyConfig(fileContent) {
|
||||||
|
console.log("[ConfigLoader] Applying config from file:", root.filePath);
|
||||||
try {
|
try {
|
||||||
|
if (fileContent.trim() === "") {
|
||||||
|
console.warn("[ConfigLoader] Config file is empty, skipping load.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const json = JSON.parse(fileContent);
|
const json = JSON.parse(fileContent);
|
||||||
|
|
||||||
ObjectUtils.applyToQtObject(ConfigOptions, json);
|
ObjectUtils.applyToQtObject(ConfigOptions, json);
|
||||||
if (root.firstLoad) {
|
if (root.firstLoad) {
|
||||||
root.firstLoad = false;
|
root.firstLoad = false;
|
||||||
} else {
|
root.preventNextLoad = true;
|
||||||
Hyprland.dispatch(`exec notify-send "${qsTr("Shell configuration reloaded")}" "${root.filePath}"`)
|
root.saveConfig(); // Make sure new properties are added to the user's config file
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[ConfigLoader] Error reading file:", e);
|
console.error("[ConfigLoader] Error reading file:", e);
|
||||||
|
console.log("[ConfigLoader] File content was:", fileContent);
|
||||||
Hyprland.dispatch(`exec notify-send "${qsTr("Shell configuration failed to load")}" "${root.filePath}"`)
|
Hyprland.dispatch(`exec notify-send "${qsTr("Shell configuration failed to load")}" "${root.filePath}"`)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -85,7 +92,16 @@ Singleton {
|
|||||||
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
|
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
|
||||||
running: false
|
running: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.applyConfig(configFileView.text())
|
if (root.preventNextLoad) {
|
||||||
|
root.preventNextLoad = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (root.firstLoad) {
|
||||||
|
root.applyConfig(configFileView.text())
|
||||||
|
} else {
|
||||||
|
root.applyConfig(configFileView.text())
|
||||||
|
Hyprland.dispatch(`exec notify-send "${qsTr("Shell configuration reloaded")}" "${root.filePath}"`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,13 +110,12 @@ Singleton {
|
|||||||
path: Qt.resolvedUrl(root.filePath)
|
path: Qt.resolvedUrl(root.filePath)
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
onFileChanged: {
|
onFileChanged: {
|
||||||
console.log("[ConfigLoader] File changed, reloading...")
|
|
||||||
this.reload()
|
this.reload()
|
||||||
delayedFileRead.start()
|
delayedFileRead.start()
|
||||||
}
|
}
|
||||||
onLoadedChanged: {
|
onLoadedChanged: {
|
||||||
const fileContent = configFileView.text()
|
const fileContent = configFileView.text()
|
||||||
root.applyConfig(fileContent)
|
delayedFileRead.start()
|
||||||
}
|
}
|
||||||
onLoadFailed: (error) => {
|
onLoadFailed: (error) => {
|
||||||
if(error == FileViewError.FileNotFound) {
|
if(error == FileViewError.FileNotFound) {
|
||||||
|
|||||||
Reference in New Issue
Block a user