mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-30 17:42:06 -04:00
fix(quickshell): restore night mode and OSD surfaces after resume (#2254)
This commit is contained in:
committed by
GitHub
parent
c6ed64b24e
commit
b87c36d29e
@@ -40,6 +40,7 @@ Singleton {
|
||||
property bool nightModeEnabled: false
|
||||
property bool automationAvailable: false
|
||||
property bool gammaControlAvailable: false
|
||||
property int resumeRecoveryAttempt: 0
|
||||
|
||||
property var gammaState: ({})
|
||||
property int gammaCurrentTemp: gammaState?.currentTemp ?? 0
|
||||
@@ -672,6 +673,15 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
function runResumeRecoveryPass() {
|
||||
checkGammaControlAvailability();
|
||||
rescanDevices();
|
||||
|
||||
if (nightModeEnabled) {
|
||||
evaluateNightMode();
|
||||
}
|
||||
}
|
||||
|
||||
function checkGammaControlAvailability() {
|
||||
if (!DMSService.isConnected) {
|
||||
return;
|
||||
@@ -730,6 +740,26 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: resumeRecoveryTimer
|
||||
interval: 400
|
||||
repeat: false
|
||||
|
||||
onTriggered: {
|
||||
runResumeRecoveryPass();
|
||||
resumeRecoveryAttempt++;
|
||||
|
||||
if (resumeRecoveryAttempt < 3) {
|
||||
interval = resumeRecoveryAttempt === 1 ? 1400 : 2600;
|
||||
restart();
|
||||
return;
|
||||
}
|
||||
|
||||
resumeRecoveryAttempt = 0;
|
||||
interval = 400;
|
||||
}
|
||||
}
|
||||
|
||||
function rescanDevices() {
|
||||
if (!DMSService.isConnected) {
|
||||
return;
|
||||
@@ -815,19 +845,23 @@ Singleton {
|
||||
updateSingleDevice(device);
|
||||
}
|
||||
|
||||
function onLoginctlEvent(event) {
|
||||
if (event.event === "unlock" || event.event === "resume") {
|
||||
suppressOsd = true;
|
||||
osdSuppressTimer.restart();
|
||||
evaluateNightMode();
|
||||
}
|
||||
}
|
||||
|
||||
function onGammaStateUpdate(data) {
|
||||
root.gammaState = data;
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: SessionService
|
||||
|
||||
function onSessionResumed() {
|
||||
suppressOsd = true;
|
||||
osdSuppressTimer.restart();
|
||||
resumeRecoveryAttempt = 0;
|
||||
resumeRecoveryTimer.interval = 400;
|
||||
resumeRecoveryTimer.restart();
|
||||
}
|
||||
}
|
||||
|
||||
// Session Data Connections
|
||||
Connections {
|
||||
target: SessionData
|
||||
|
||||
@@ -48,6 +48,9 @@ Singleton {
|
||||
signal loginctlStateChanged
|
||||
|
||||
property bool stateInitialized: false
|
||||
property string prepareForSleepSubscriptionId: ""
|
||||
property bool prepareForSleepSubscriptionPending: false
|
||||
property double lastResumeSignalTimestamp: 0
|
||||
|
||||
readonly property string socketPath: Quickshell.env("DMS_SOCKET")
|
||||
|
||||
@@ -463,10 +466,13 @@ Singleton {
|
||||
function onConnectionStateChanged() {
|
||||
if (DMSService.isConnected) {
|
||||
checkDMSCapabilities();
|
||||
} else {
|
||||
clearPrepareForSleepSubscriptionState();
|
||||
}
|
||||
}
|
||||
|
||||
function onCapabilitiesReceived() {
|
||||
checkDMSCapabilities();
|
||||
syncSleepInhibitor();
|
||||
}
|
||||
}
|
||||
@@ -478,6 +484,13 @@ Singleton {
|
||||
function onCapabilitiesChanged() {
|
||||
checkDMSCapabilities();
|
||||
}
|
||||
|
||||
function onDbusSignalReceived(subscriptionId, data) {
|
||||
if (subscriptionId !== prepareForSleepSubscriptionId) {
|
||||
return;
|
||||
}
|
||||
handlePrepareForSleepSignal(data);
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
@@ -539,6 +552,61 @@ Singleton {
|
||||
loginctlAvailable = false;
|
||||
console.log("SessionService: loginctl capability not available in DMS");
|
||||
}
|
||||
|
||||
if (DMSService.capabilities.includes("dbus")) {
|
||||
ensurePrepareForSleepSubscription();
|
||||
} else {
|
||||
clearPrepareForSleepSubscriptionState();
|
||||
}
|
||||
}
|
||||
|
||||
function clearPrepareForSleepSubscriptionState() {
|
||||
prepareForSleepSubscriptionId = "";
|
||||
prepareForSleepSubscriptionPending = false;
|
||||
}
|
||||
|
||||
function ensurePrepareForSleepSubscription() {
|
||||
if (!DMSService.isConnected || !DMSService.capabilities.includes("dbus")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (prepareForSleepSubscriptionId || prepareForSleepSubscriptionPending) {
|
||||
return;
|
||||
}
|
||||
|
||||
prepareForSleepSubscriptionPending = true;
|
||||
DMSService.dbusSubscribe("system", "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PrepareForSleep", response => {
|
||||
prepareForSleepSubscriptionPending = false;
|
||||
|
||||
if (response.error) {
|
||||
console.warn("SessionService: Failed to subscribe to PrepareForSleep:", response.error);
|
||||
return;
|
||||
}
|
||||
|
||||
prepareForSleepSubscriptionId = response.result?.subscriptionId || "";
|
||||
});
|
||||
}
|
||||
|
||||
function emitSessionResumedOnce() {
|
||||
const now = Date.now();
|
||||
if ((now - lastResumeSignalTimestamp) < 1000) {
|
||||
return;
|
||||
}
|
||||
lastResumeSignalTimestamp = now;
|
||||
sessionResumed();
|
||||
}
|
||||
|
||||
function handlePrepareForSleepSignal(data) {
|
||||
if (!data?.body || data.body.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const wasSleeping = preparingForSleep;
|
||||
preparingForSleep = data.body[0] === true;
|
||||
|
||||
if (wasSleeping && !preparingForSleep) {
|
||||
emitSessionResumedOnce();
|
||||
}
|
||||
}
|
||||
|
||||
function getLoginctlState() {
|
||||
@@ -604,7 +672,7 @@ Singleton {
|
||||
}
|
||||
|
||||
if (wasSleeping && !preparingForSleep) {
|
||||
sessionResumed();
|
||||
emitSessionResumedOnce();
|
||||
}
|
||||
|
||||
loginctlStateChanged();
|
||||
|
||||
Reference in New Issue
Block a user