1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-07 14:08:29 -04:00

Compare commits

..

1 Commits

Author SHA1 Message Date
bbedward c128793239 qs/socket: improve resilience of socket detection and connection
related #2369
port 1.5

(cherry picked from commit 64461c534f)
2026-07-27 17:41:17 +00:00
+24 -47
View File
@@ -11,7 +11,7 @@ Singleton {
id: root id: root
readonly property var log: Log.scoped("DMSService") readonly property var log: Log.scoped("DMSService")
property bool dmsAvailable: false readonly property bool dmsAvailable: isConnected
property var capabilities: [] property var capabilities: []
property int apiVersion: 0 property int apiVersion: 0
property string cliVersion: "" property string cliVersion: ""
@@ -21,7 +21,7 @@ Singleton {
property var availableThemes: [] property var availableThemes: []
property var installedThemes: [] property var installedThemes: []
property bool isConnected: false property bool isConnected: false
property bool isConnecting: false readonly property bool isConnecting: requestSocket.connected && !requestSocket.linkUp
property bool subscribeConnected: false property bool subscribeConnected: false
readonly property string socketPath: Quickshell.env("DMS_SOCKET") 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"] 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: { Component.onCompleted: {
if (socketPath && socketPath.length > 0) { if (!socketPath || socketPath.length === 0)
return;
detectUpdateCommand(); detectUpdateCommand();
} requestSocket.connected = true;
} }
function detectUpdateCommand() { function detectUpdateCommand() {
@@ -82,12 +83,6 @@ Singleton {
checkAurHelper.running = true; checkAurHelper.running = true;
} }
function startSocketConnection() {
if (socketPath && socketPath.length > 0) {
testProcess.running = true;
}
}
Process { Process {
id: checkAurHelper id: checkAurHelper
command: ["sh", "-c", "command -v paru || command -v yay"] command: ["sh", "-c", "command -v paru || command -v yay"]
@@ -105,7 +100,6 @@ Singleton {
} else { } else {
updateCommand = "dms update"; updateCommand = "dms update";
checkingUpdateCommand = false; checkingUpdateCommand = false;
startSocketConnection();
} }
} }
} }
@@ -114,7 +108,6 @@ Singleton {
if (exitCode !== 0) { if (exitCode !== 0) {
updateCommand = "dms update"; updateCommand = "dms update";
checkingUpdateCommand = false; checkingUpdateCommand = false;
startSocketConnection();
} }
} }
} }
@@ -135,7 +128,6 @@ Singleton {
updateCommand = "dms update"; updateCommand = "dms update";
} }
checkingUpdateCommand = false; checkingUpdateCommand = false;
startSocketConnection();
} }
} }
@@ -143,53 +135,28 @@ Singleton {
if (exitCode !== 0) { if (exitCode !== 0) {
updateCommand = "dms update"; updateCommand = "dms update";
checkingUpdateCommand = false; 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 { DankSocket {
id: requestSocket id: requestSocket
path: root.socketPath path: root.socketPath
connected: false connected: false
onConnectionStateChanged: { onConnectionStateChanged: {
if (connected) { if (linkUp) {
root.isConnected = true; root.isConnected = true;
root.isConnecting = false;
root.connectionStateChanged(); root.connectionStateChanged();
subscribeSocket.connected = true; subscribeSocket.connected = true;
} else { return;
}
root.isConnected = false; root.isConnected = false;
root.isConnecting = false;
root.apiVersion = 0; root.apiVersion = 0;
root.capabilities = []; root.capabilities = [];
root.failPendingRequests();
root.connectionStateChanged(); root.connectionStateChanged();
} }
}
parser: SplitParser { parser: SplitParser {
onRead: line => { onRead: line => {
@@ -219,11 +186,11 @@ Singleton {
connected: false connected: false
onConnectionStateChanged: { onConnectionStateChanged: {
root.subscribeConnected = connected; root.subscribeConnected = linkUp;
if (connected) { if (!linkUp)
return;
sendSubscribeRequest(); sendSubscribeRequest();
} }
}
parser: SplitParser { parser: SplitParser {
onRead: line => { onRead: line => {
@@ -446,11 +413,21 @@ Singleton {
function handleResponse(response) { function handleResponse(response) {
const callback = pendingRequests[response.id]; const callback = pendingRequests[response.id];
if (!callback)
if (callback) { return;
delete pendingRequests[response.id]; delete pendingRequests[response.id];
callback(response); callback(response);
} }
function failPendingRequests() {
const pending = pendingRequests;
pendingRequests = {};
clipboardRequestIds = {};
for (const id in pending) {
pending[id]({
"error": "not connected to DMS socket"
});
}
} }
function ping(callback) { function ping(callback) {