persistent state manager: prevent writing default config before first load

This commit is contained in:
end-4
2025-05-11 08:08:01 +02:00
parent d90067a11d
commit b827edf2ef
@@ -14,6 +14,7 @@ Singleton {
property string fileDir: `${StandardPaths.standardLocations(StandardPaths.StateLocation)[0]}`
property string fileName: "states.json"
property string filePath: `${root.fileDir}/${root.fileName}`
property bool allowWriteback: false
function getState(nestedKey) {
let keys = nestedKey.split(".");
@@ -29,7 +30,7 @@ Singleton {
}
function setState(nestedKey, value) {
// console.log(`[PersistentStateManager] Setting state: ${nestedKey} = ${value}`);
if (!root.allowWriteback) return;
let keys = nestedKey.split(".");
let obj = PersistentStates;
let parents = [obj];
@@ -61,8 +62,8 @@ Singleton {
function applyStates(fileContent) {
try {
const json = JSON.parse(fileContent);
ObjectUtils.applyToQtObject(PersistentStates, json);
root.allowWriteback = true
} catch (e) {
console.error("[PersistentStateManager] Error reading file:", e);
return;