mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-23 19:45:21 -04:00
portal: add bidirectional syncing with freedesktop color-scheme, read in
addition to the existing write
This commit is contained in:
@@ -58,6 +58,7 @@ Singleton {
|
||||
signal openUrlRequested(string url)
|
||||
signal appPickerRequested(var data)
|
||||
signal screensaverStateUpdate(var data)
|
||||
signal freedesktopStateUpdate(var data)
|
||||
signal clipboardStateUpdate(var data)
|
||||
signal locationStateUpdate(var data)
|
||||
signal sysupdateStateUpdate(var data)
|
||||
@@ -384,6 +385,8 @@ Singleton {
|
||||
screensaverInhibited = data.inhibited || false;
|
||||
screensaverInhibitors = data.inhibitors || [];
|
||||
screensaverStateUpdate(data);
|
||||
} else if (service === "freedesktop") {
|
||||
freedesktopStateUpdate(data);
|
||||
} else if (service === "dbus") {
|
||||
dbusSignalReceived(data.subscriptionId || "", data);
|
||||
} else if (service === "clipboard") {
|
||||
|
||||
@@ -87,17 +87,22 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
function getSystemColorScheme() {
|
||||
if (typeof SettingsData !== "undefined" && SettingsData.syncModeWithPortal === false) {
|
||||
function evaluateColorScheme() {
|
||||
if (typeof SettingsData === "undefined" || !SettingsData.syncModeWithPortal)
|
||||
return;
|
||||
}
|
||||
if (!freedeskAvailable)
|
||||
if (!settingsPortalAvailable)
|
||||
return;
|
||||
DMSService.sendRequest("freedesktop.settings.getColorScheme", null, response => {
|
||||
if (response.result) {
|
||||
systemColorScheme = response.result.value || 0;
|
||||
}
|
||||
});
|
||||
if (typeof SessionData !== "undefined" && SessionData.themeModeAutoEnabled)
|
||||
return;
|
||||
if (typeof Theme === "undefined")
|
||||
return;
|
||||
// Defer mid-generation: setLightMode's regen would be dropped, and DMS's own transient color-scheme toggle would be misread. Re-run on worker completion.
|
||||
if (Theme.workerRunning)
|
||||
return;
|
||||
const shouldBeLight = systemColorScheme !== 1;
|
||||
if (Theme.isLightMode === shouldBeLight)
|
||||
return;
|
||||
Theme.setLightMode(shouldBeLight, true, false);
|
||||
}
|
||||
|
||||
function setLightMode(isLightMode) {
|
||||
@@ -176,6 +181,36 @@ Singleton {
|
||||
colorSchemeDetector.running = true;
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: typeof SettingsData !== "undefined" ? SettingsData : null
|
||||
|
||||
function onSyncModeWithPortalChanged() {
|
||||
if (SettingsData.syncModeWithPortal)
|
||||
root.evaluateColorScheme();
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: DMSService
|
||||
|
||||
function onFreedesktopStateUpdate(data) {
|
||||
if (!data || !data.settings)
|
||||
return;
|
||||
root.settingsPortalAvailable = data.settings.available === true;
|
||||
root.systemColorScheme = data.settings.colorScheme || 0;
|
||||
root.evaluateColorScheme();
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: typeof Theme !== "undefined" ? Theme : null
|
||||
|
||||
function onWorkerRunningChanged() {
|
||||
if (!Theme.workerRunning)
|
||||
root.evaluateColorScheme();
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: DMSService
|
||||
|
||||
@@ -232,9 +267,8 @@ Singleton {
|
||||
DMSService.sendRequest("freedesktop.getState", null, response => {
|
||||
if (response.result && response.result.settings) {
|
||||
settingsPortalAvailable = response.result.settings.available || false;
|
||||
if (settingsPortalAvailable && SettingsData.syncModeWithPortal) {
|
||||
getSystemColorScheme();
|
||||
}
|
||||
systemColorScheme = response.result.settings.colorScheme || 0;
|
||||
evaluateColorScheme();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user