forked from Shinonome/dots-hyprland
persistent states: also use jsonadapter
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
pragma Singleton
|
||||
pragma ComponentBehavior: Bound
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
property alias states: persistentStatesJsonAdapter
|
||||
property string fileDir: Directories.state
|
||||
property string fileName: "states.json"
|
||||
property string filePath: `${root.fileDir}/${root.fileName}`
|
||||
|
||||
FileView {
|
||||
path: root.filePath
|
||||
|
||||
watchChanges: true
|
||||
onFileChanged: reload()
|
||||
onAdapterUpdated: {
|
||||
writeAdapter()
|
||||
}
|
||||
onLoadFailed: error => {
|
||||
console.log("Failed to load persistent states file:", error);
|
||||
if (error == FileViewError.FileNotFound) {
|
||||
writeAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
adapter: JsonAdapter {
|
||||
id: persistentStatesJsonAdapter
|
||||
property JsonObject ai: JsonObject {
|
||||
property string model
|
||||
property real temperature: 0.5
|
||||
}
|
||||
|
||||
property JsonObject sidebar: JsonObject {
|
||||
property JsonObject bottomGroup: JsonObject {
|
||||
property bool collapsed: false
|
||||
}
|
||||
}
|
||||
|
||||
property JsonObject booru: JsonObject {
|
||||
property bool allowNsfw: false
|
||||
property string provider: "yandere"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,14 +65,14 @@ Item {
|
||||
name: "safe",
|
||||
description: qsTr("Disable NSFW content"),
|
||||
execute: () => {
|
||||
PersistentStateManager.setState("booru.allowNsfw", false);
|
||||
Persistent.states.booru.allowNsfw = false;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "lewd",
|
||||
description: qsTr("Allow NSFW content"),
|
||||
execute: () => {
|
||||
PersistentStateManager.setState("booru.allowNsfw", true);
|
||||
Persistent.states.booru.allowNsfw = true;
|
||||
}
|
||||
},
|
||||
]
|
||||
@@ -106,7 +106,7 @@ Item {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Booru.makeRequest(tagList, PersistentStates.booru.allowNsfw, Config.options.sidebar.booru.limit, pageIndex);
|
||||
Booru.makeRequest(tagList, Persistent.states.booru.allowNsfw, Config.options.sidebar.booru.limit, pageIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,10 +593,10 @@ Item {
|
||||
enabled: Booru.currentProvider !== "zerochan"
|
||||
scale: 0.6
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
checked: (PersistentStates.booru.allowNsfw && Booru.currentProvider !== "zerochan")
|
||||
checked: (Persistent.states.booru.allowNsfw && Booru.currentProvider !== "zerochan")
|
||||
onCheckedChanged: {
|
||||
if (!nsfwSwitch.enabled) return;
|
||||
PersistentStateManager.setState("booru.allowNsfw", checked)
|
||||
Persistent.states.booru.allowNsfw = checked;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -610,7 +610,6 @@ Item {
|
||||
id: commandRepeater
|
||||
model: commandButtonsRow.commandsShown
|
||||
delegate: ApiCommandButton {
|
||||
id: tagButton
|
||||
property string commandRepresentation: `${root.commandPrefix}${modelData.name}`
|
||||
buttonText: commandRepresentation
|
||||
colBackground: Appearance.colors.colLayer2
|
||||
|
||||
@@ -15,7 +15,7 @@ Rectangle {
|
||||
clip: true
|
||||
implicitHeight: collapsed ? collapsedBottomWidgetGroupRow.implicitHeight : bottomWidgetGroupRow.implicitHeight
|
||||
property int selectedTab: 0
|
||||
property bool collapsed: PersistentStates.sidebar.bottomGroup.collapsed
|
||||
property bool collapsed: Persistent.states.sidebar.bottomGroup.collapsed
|
||||
property var tabs: [
|
||||
{"type": "calendar", "name": "Calendar", "icon": "calendar_month", "widget": calendarWidget},
|
||||
{"type": "todo", "name": "To Do", "icon": "done_outline", "widget": todoWidget}
|
||||
@@ -30,7 +30,7 @@ Rectangle {
|
||||
}
|
||||
|
||||
function setCollapsed(state) {
|
||||
PersistentStateManager.setState("sidebar.bottomGroup.collapsed", state)
|
||||
Persistent.states.sidebar.bottomGroup.collapsed = state
|
||||
if (collapsed) {
|
||||
bottomWidgetGroupRow.opacity = 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user