Settings/State: Moved state IPC logic to ShellState.qml.

This commit is contained in:
ItsLemmy
2025-11-29 11:04:44 -05:00
parent 9d4ac03d21
commit 993b6bc422
3 changed files with 57 additions and 55 deletions
+4 -34
View File
@@ -6,8 +6,6 @@ import Quickshell.Io
import "../Helpers/QtObj2JS.js" as QtObj2JS
import qs.Commons
import qs.Modules.OSD
import qs.Services.Power
import qs.Services.System
import qs.Services.UI
Singleton {
@@ -148,7 +146,7 @@ Singleton {
property JsonObject bar: JsonObject {
property string position: "top" // "top", "bottom", "left", or "right"
property real backgroundOpacity: 1.0
property list<string> monitors: []
property list<string> monitors: [] // holds bar visibility per monitor
property string density: "default" // "compact", "default", "comfortable"
property bool showCapsule: true
property real capsuleOpacity: 1.0
@@ -322,9 +320,6 @@ Singleton {
property string wallhavenResolutionMode: "atleast" // "atleast" or "exact"
property string wallhavenResolutionWidth: ""
property string wallhavenResolutionHeight: ""
property string defaultWallpaper: "" // TODO REMOVE
property list<var> monitors: [] // TODO REMOVE
}
// applauncher
@@ -431,7 +426,7 @@ Singleton {
property real floatingRatio: 1.0
property real size: 1
property bool onlySameOutput: true
property list<string> monitors: []
property list<string> monitors: [] // holds dock visibility per monitor
// Desktop entry IDs pinned to the dock (e.g., "org.kde.konsole", "firefox.desktop")
property list<string> pinnedApps: []
property bool colorizeIcons: false
@@ -479,7 +474,7 @@ Singleton {
// notifications
property JsonObject notifications: JsonObject {
property bool enabled: true
property list<string> monitors: []
property list<string> monitors: [] // holds notifications visibility per monitor
property string location: "top_right"
property bool overlayLayer: true
property real backgroundOpacity: 1.0
@@ -498,7 +493,7 @@ Singleton {
property bool overlayLayer: true
property real backgroundOpacity: 1.0
property list<var> enabledTypes: [OSD.Type.Volume, OSD.Type.InputVolume, OSD.Type.Brightness]
property list<string> monitors: []
property list<string> monitors: [] // holds osd visibility per monitor
}
// audio
@@ -760,29 +755,4 @@ Singleton {
}
}
}
// -----------------------------------------------------
function buildStateSnapshot() {
try {
const settingsData = QtObj2JS.qtObjectToPlainObject(adapter);
const shellStateData = ShellState?.data ? QtObj2JS.qtObjectToPlainObject(ShellState.data) || {} : {};
return {
settings: settingsData,
state: {
doNotDisturb: NotificationService.doNotDisturb,
noctaliaPerformanceMode: PowerProfileService.noctaliaPerformanceMode,
barVisible: BarService.isVisible,
display: shellStateData.display || {},
wallpapers: shellStateData.wallpapers || {},
notificationsState: shellStateData.notificationsState || {},
changelogState: shellStateData.changelogState || {},
colorSchemesList: shellStateData.colorSchemesList || {}
}
};
} catch (error) {
Logger.e("Settings", "Failed to build state snapshot:", error);
return null;
}
}
}
+29
View File
@@ -3,6 +3,10 @@ pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import "../Helpers/QtObj2JS.js" as QtObj2JS
import qs.Services.Power
import qs.Services.System
import qs.Services.UI
// Centralized shell state management for small cache files
Singleton {
@@ -179,4 +183,29 @@ Singleton {
function getWallpapers() {
return adapter.wallpapers || {};
}
// -----------------------------------------------------
function buildStateSnapshot() {
try {
const settingsData = QtObj2JS.qtObjectToPlainObject(Settings.data);
const shellStateData = ShellState?.data ? QtObj2JS.qtObjectToPlainObject(ShellState.data) || {} : {};
return {
settings: settingsData,
state: {
doNotDisturb: NotificationService.doNotDisturb,
noctaliaPerformanceMode: PowerProfileService.noctaliaPerformanceMode,
barVisible: BarService.isVisible,
display: shellStateData.display || {},
wallpapers: shellStateData.wallpapers || {},
notificationsState: shellStateData.notificationsState || {},
changelogState: shellStateData.changelogState || {},
colorSchemesList: shellStateData.colorSchemesList || {}
}
};
} catch (error) {
Logger.e("Settings", "Failed to build state snapshot:", error);
return null;
}
}
}
+24 -21
View File
@@ -366,7 +366,29 @@ Item {
}
}
IpcHandler {
target: "state"
// Returns all settings and shell state as JSON
function all(): string {
try {
var snapshot = ShellState.buildStateSnapshot();
if (!snapshot) {
throw new Error("State snapshot unavailable");
}
return JSON.stringify(snapshot, null, 2);
} catch (error) {
Logger.e("IPC", "Failed to serialize state:", error);
return JSON.stringify({
"error": "Failed to serialize state: " + error
}, null, 2);
}
}
}
// -------------------------------------------------------------------
// Queue an IPC panel operation - will execute when screen is detected
// -------------------------------------------------------------------
function withTargetScreen(callback) {
if (pendingCallback) {
Logger.w("IPC", "Another IPC call is pending, ignoring new call");
@@ -383,27 +405,6 @@ Item {
screenDetectorLoader.active = true;
}
}
IpcHandler {
target: "state"
// Returns all settings and shell state as JSON
function all(): string {
try {
var snapshot = Settings.buildStateSnapshot();
if (!snapshot) {
throw new Error("State snapshot unavailable");
}
return JSON.stringify(snapshot, null, 2);
} catch (error) {
Logger.e("IPC", "Failed to serialize state:", error);
return JSON.stringify({
"error": "Failed to serialize state: " + error
}, null, 2);
}
}
}
/**
* For IPC calls on multi-monitors setup that will open panels on screen,
* we need to open a QS PanelWindow and wait for it's "screen" property to stabilize.
@@ -458,4 +459,6 @@ Item {
}
}
}
// -------------------------------------------------------------------
// -------------------------------------------------------------------
}