From 64461c534fb9faef30ac1c7aaabe64ce48ebc2fe Mon Sep 17 00:00:00 2001 From: bbedward Date: Mon, 27 Jul 2026 13:40:34 -0400 Subject: [PATCH] qs/socket: improve resilience of socket detection and connection related #2369 port 1.5 --- quickshell/Services/DMSService.qml | 83 +++++++++++------------------- 1 file changed, 30 insertions(+), 53 deletions(-) diff --git a/quickshell/Services/DMSService.qml b/quickshell/Services/DMSService.qml index 3e936f4ad..42d2716d2 100644 --- a/quickshell/Services/DMSService.qml +++ b/quickshell/Services/DMSService.qml @@ -11,7 +11,7 @@ Singleton { id: root readonly property var log: Log.scoped("DMSService") - property bool dmsAvailable: false + readonly property bool dmsAvailable: isConnected property var capabilities: [] property int apiVersion: 0 property string cliVersion: "" @@ -21,7 +21,7 @@ Singleton { property var availableThemes: [] property var installedThemes: [] property bool isConnected: false - property bool isConnecting: false + readonly property bool isConnecting: requestSocket.connected && !requestSocket.linkUp property bool subscribeConnected: false readonly property string socketPath: Quickshell.env("DMS_SOCKET") @@ -72,9 +72,10 @@ Singleton { property var activeSubscriptions: ["network", "network.credentials", "loginctl", "freedesktop", "freedesktop.screensaver", "gamma", "theme.auto", "wallpaper", "bluetooth", "bluetooth.pairing", "brightness", "wlroutput", "evdev", "browser", "dbus", "clipboard", "sysupdate"] Component.onCompleted: { - if (socketPath && socketPath.length > 0) { - detectUpdateCommand(); - } + if (!socketPath || socketPath.length === 0) + return; + detectUpdateCommand(); + requestSocket.connected = true; } function detectUpdateCommand() { @@ -82,12 +83,6 @@ Singleton { checkAurHelper.running = true; } - function startSocketConnection() { - if (socketPath && socketPath.length > 0) { - testProcess.running = true; - } - } - Process { id: checkAurHelper command: ["sh", "-c", "command -v paru || command -v yay"] @@ -105,7 +100,6 @@ Singleton { } else { updateCommand = "dms update"; checkingUpdateCommand = false; - startSocketConnection(); } } } @@ -114,7 +108,6 @@ Singleton { if (exitCode !== 0) { updateCommand = "dms update"; checkingUpdateCommand = false; - startSocketConnection(); } } } @@ -135,7 +128,6 @@ Singleton { updateCommand = "dms update"; } checkingUpdateCommand = false; - startSocketConnection(); } } @@ -143,52 +135,27 @@ Singleton { if (exitCode !== 0) { updateCommand = "dms update"; checkingUpdateCommand = false; - startSocketConnection(); } } } - Process { - id: testProcess - command: ["test", "-S", root.socketPath] - - onExited: exitCode => { - if (exitCode === 0) { - root.dmsAvailable = true; - connectSocket(); - } else { - root.dmsAvailable = false; - } - } - } - - function connectSocket() { - if (!dmsAvailable || isConnected || isConnecting) { - return; - } - - isConnecting = true; - requestSocket.connected = true; - } - DankSocket { id: requestSocket path: root.socketPath connected: false onConnectionStateChanged: { - if (connected) { + if (linkUp) { root.isConnected = true; - root.isConnecting = false; root.connectionStateChanged(); subscribeSocket.connected = true; - } else { - root.isConnected = false; - root.isConnecting = false; - root.apiVersion = 0; - root.capabilities = []; - root.connectionStateChanged(); + return; } + root.isConnected = false; + root.apiVersion = 0; + root.capabilities = []; + root.failPendingRequests(); + root.connectionStateChanged(); } parser: SplitParser { @@ -219,10 +186,10 @@ Singleton { connected: false onConnectionStateChanged: { - root.subscribeConnected = connected; - if (connected) { - sendSubscribeRequest(); - } + root.subscribeConnected = linkUp; + if (!linkUp) + return; + sendSubscribeRequest(); } parser: SplitParser { @@ -432,10 +399,20 @@ Singleton { function handleResponse(response) { const callback = pendingRequests[response.id]; + if (!callback) + return; + delete pendingRequests[response.id]; + callback(response); + } - if (callback) { - delete pendingRequests[response.id]; - callback(response); + function failPendingRequests() { + const pending = pendingRequests; + pendingRequests = {}; + clipboardRequestIds = {}; + for (const id in pending) { + pending[id]({ + "error": "not connected to DMS socket" + }); } }