From 993b6bc4228164bdd8345449b172bc68a6c39593 Mon Sep 17 00:00:00 2001 From: ItsLemmy Date: Sat, 29 Nov 2025 11:04:44 -0500 Subject: [PATCH] Settings/State: Moved state IPC logic to ShellState.qml. --- Commons/Settings.qml | 38 +++------------------------- Commons/ShellState.qml | 29 +++++++++++++++++++++ Services/Control/IPCService.qml | 45 ++++++++++++++++++--------------- 3 files changed, 57 insertions(+), 55 deletions(-) diff --git a/Commons/Settings.qml b/Commons/Settings.qml index 62b12a86..489eedf4 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -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 monitors: [] + property list 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 monitors: [] // TODO REMOVE } // applauncher @@ -431,7 +426,7 @@ Singleton { property real floatingRatio: 1.0 property real size: 1 property bool onlySameOutput: true - property list monitors: [] + property list monitors: [] // holds dock visibility per monitor // Desktop entry IDs pinned to the dock (e.g., "org.kde.konsole", "firefox.desktop") property list pinnedApps: [] property bool colorizeIcons: false @@ -479,7 +474,7 @@ Singleton { // notifications property JsonObject notifications: JsonObject { property bool enabled: true - property list monitors: [] + property list 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 enabledTypes: [OSD.Type.Volume, OSD.Type.InputVolume, OSD.Type.Brightness] - property list monitors: [] + property list 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; - } - } } diff --git a/Commons/ShellState.qml b/Commons/ShellState.qml index 3019e143..0b72f817 100644 --- a/Commons/ShellState.qml +++ b/Commons/ShellState.qml @@ -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; + } + } } diff --git a/Services/Control/IPCService.qml b/Services/Control/IPCService.qml index 67570701..5c676ed8 100644 --- a/Services/Control/IPCService.qml +++ b/Services/Control/IPCService.qml @@ -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 { } } } + // ------------------------------------------------------------------- + // ------------------------------------------------------------------- }