forked from Shinonome/dots-hyprland
persistent state manager: prevent writing default config before first load
This commit is contained in:
@@ -14,6 +14,7 @@ Singleton {
|
|||||||
property string fileDir: `${StandardPaths.standardLocations(StandardPaths.StateLocation)[0]}`
|
property string fileDir: `${StandardPaths.standardLocations(StandardPaths.StateLocation)[0]}`
|
||||||
property string fileName: "states.json"
|
property string fileName: "states.json"
|
||||||
property string filePath: `${root.fileDir}/${root.fileName}`
|
property string filePath: `${root.fileDir}/${root.fileName}`
|
||||||
|
property bool allowWriteback: false
|
||||||
|
|
||||||
function getState(nestedKey) {
|
function getState(nestedKey) {
|
||||||
let keys = nestedKey.split(".");
|
let keys = nestedKey.split(".");
|
||||||
@@ -29,7 +30,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setState(nestedKey, value) {
|
function setState(nestedKey, value) {
|
||||||
// console.log(`[PersistentStateManager] Setting state: ${nestedKey} = ${value}`);
|
if (!root.allowWriteback) return;
|
||||||
let keys = nestedKey.split(".");
|
let keys = nestedKey.split(".");
|
||||||
let obj = PersistentStates;
|
let obj = PersistentStates;
|
||||||
let parents = [obj];
|
let parents = [obj];
|
||||||
@@ -61,8 +62,8 @@ Singleton {
|
|||||||
function applyStates(fileContent) {
|
function applyStates(fileContent) {
|
||||||
try {
|
try {
|
||||||
const json = JSON.parse(fileContent);
|
const json = JSON.parse(fileContent);
|
||||||
|
|
||||||
ObjectUtils.applyToQtObject(PersistentStates, json);
|
ObjectUtils.applyToQtObject(PersistentStates, json);
|
||||||
|
root.allowWriteback = true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[PersistentStateManager] Error reading file:", e);
|
console.error("[PersistentStateManager] Error reading file:", e);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user