make persistent states persistent

This commit is contained in:
end-4
2025-05-10 23:05:32 +02:00
parent 9d51815661
commit f13912a027
5 changed files with 126 additions and 32 deletions
@@ -1,7 +1,3 @@
function trimFileProtocol(str) {
return str.startsWith("file://") ? str.slice(7) : str;
}
function toPlainObject(qtObj) {
if (qtObj === null || typeof qtObj !== "object") return qtObj;
@@ -26,4 +22,24 @@ function toPlainObject(qtObj) {
}
}
return result;
}
}
function applyToQtObject(qtObj, jsonObj) {
if (!qtObj || typeof jsonObj !== "object" || jsonObj === null) return;
for (let key in jsonObj) {
if (!qtObj.hasOwnProperty(key)) continue;
// Check if the property is a QtObject (not a value)
const value = qtObj[key];
const jsonValue = jsonObj[key];
// If it's an object and not an array, recurse
if (value && typeof value === "object" && !Array.isArray(value)) {
applyToQtObject(value, jsonValue);
} else {
// Otherwise, assign the value
qtObj[key] = jsonValue;
}
}
}
@@ -29,13 +29,8 @@ Rectangle {
}
}
Component.onCompleted: {
bottomWidgetGroupRow.opacity = !collapsed
collapsedBottomWidgetGroupRow.opacity = collapsed
}
function setCollapsed(state) {
PersistentStates.sidebar.bottomGroup.collapsed = state
PersistentStateManager.setState("sidebar.bottomGroup.collapsed", state)
if (collapsed) {
bottomWidgetGroupRow.opacity = 0
}
@@ -70,6 +65,7 @@ Rectangle {
// The thing when collapsed
RowLayout {
id: collapsedBottomWidgetGroupRow
opacity: collapsed ? 1 : 0
visible: opacity > 0
Behavior on opacity {
NumberAnimation {
@@ -111,6 +107,7 @@ Rectangle {
RowLayout {
id: bottomWidgetGroupRow
opacity: collapsed ? 0 : 1
visible: opacity > 0
Behavior on opacity {
NumberAnimation {