1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-04-17 19:22:04 -04:00

notifications: add configurable durations for do not disturb

fixes #1481
This commit is contained in:
bbedward
2026-04-16 16:51:05 -04:00
parent c6e8067a22
commit 7ced91ede1
18 changed files with 868 additions and 40 deletions

View File

@@ -29,9 +29,33 @@ Singleton {
property bool isLightMode: false
property bool doNotDisturb: false
property real doNotDisturbUntil: 0
property bool isSwitchingMode: false
property bool suppressOSD: true
Timer {
id: dndExpireTimer
repeat: false
running: false
onTriggered: root.setDoNotDisturb(false)
}
function _armDndExpireTimer() {
dndExpireTimer.stop();
if (!doNotDisturb || doNotDisturbUntil <= 0)
return;
const remaining = doNotDisturbUntil - Date.now();
if (remaining <= 0) {
setDoNotDisturb(false);
return;
}
dndExpireTimer.interval = remaining;
dndExpireTimer.start();
}
onDoNotDisturbChanged: _armDndExpireTimer()
onDoNotDisturbUntilChanged: _armDndExpireTimer()
Timer {
id: osdSuppressTimer
interval: 2000
@@ -49,6 +73,7 @@ Singleton {
function onSessionResumed() {
root.suppressOSD = true;
osdSuppressTimer.restart();
root._applyDndExpirySanity();
}
}
@@ -190,6 +215,7 @@ Singleton {
}
Store.parse(root, obj);
_applyDndExpirySanity();
_loadedSessionSnapshot = getCurrentSessionJson();
_hasLoaded = true;
@@ -271,6 +297,7 @@ Singleton {
}
Store.parse(root, obj);
_applyDndExpirySanity();
_loadedSessionSnapshot = getCurrentSessionJson();
_hasLoaded = true;
@@ -288,6 +315,16 @@ Singleton {
}
}
function _applyDndExpirySanity() {
if (doNotDisturb && doNotDisturbUntil > 0 && Date.now() >= doNotDisturbUntil) {
doNotDisturb = false;
doNotDisturbUntil = 0;
} else if (!doNotDisturb && doNotDisturbUntil !== 0) {
doNotDisturbUntil = 0;
}
_armDndExpireTimer();
}
function saveSettings() {
if (isGreeterMode || _parseError || !_hasLoaded)
return;
@@ -357,8 +394,21 @@ Singleton {
});
}
function setDoNotDisturb(enabled) {
function setDoNotDisturb(enabled, durationMinutes) {
const minutes = Number(durationMinutes) || 0;
doNotDisturb = enabled;
doNotDisturbUntil = (enabled && minutes > 0) ? Date.now() + minutes * 60 * 1000 : 0;
saveSettings();
}
function setDoNotDisturbUntilTimestamp(timestampMs) {
const target = Number(timestampMs) || 0;
if (target <= Date.now()) {
setDoNotDisturb(false);
return;
}
doNotDisturb = true;
doNotDisturbUntil = target;
saveSettings();
}