Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion shell/plugins/services/idle/Service.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ Item {
readonly property bool idleEnabled: stayAwakeStateLoaded && !stayAwake
readonly property string screensaverClass: "org.omarchy.screensaver"

// A retimed IdleMonitor can reuse its notification's address and never rebind
// isIdle to the replacement; pulsing it off sends the pointer through null.
onFirstIdleTimeoutSecondsChanged: if (root.idleEnabled) {
root.logEvent("idle-monitor-rearm", "timeout=" + root.firstIdleTimeoutSeconds)
idleMonitorRearmTimer.restart()
}

property bool stayAwake: false
property bool stayAwakeStateLoaded: false
property bool hasPendingStayAwakePersist: false
Expand Down Expand Up @@ -192,6 +199,7 @@ Item {
lockDelay: root.lockDelaySeconds,
screensaverWindows: root.screensaverWindowCount,
timers: {
idleMonitorRearm: idleMonitorRearmTimer.running,
screensaver: screensaverTimer.running,
lock: lockTimer.running,
screensaverLaunchGrace: screensaverLaunchGraceTimer.running
Expand Down Expand Up @@ -249,12 +257,18 @@ Item {

IdleMonitor {
id: idleMonitor
enabled: root.idleEnabled
enabled: root.idleEnabled && !idleMonitorRearmTimer.running
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
timeout: root.firstIdleTimeoutSeconds
respectInhibitors: true
onIsIdleChanged: root.handleIdleChanged()
}

Timer {
id: idleMonitorRearmTimer
interval: 150
repeat: false
}

Timer {
id: screensaverTimer
interval: root.screensaverDelaySeconds * 1000
Expand Down
19 changes: 19 additions & 0 deletions test/shell.d/idle-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

run_node_test <<'JS'
const fs = require('fs')
const idle = requireFromRoot('shell/plugins/services/idle/IdleModel.js')
const serviceSource = fs.readFileSync(root + '/shell/plugins/services/idle/Service.qml', 'utf8')

assertEqual(idle.secondsFromConfig('42.9', 10), 42, 'idle floors configured seconds')
assertEqual(idle.secondsFromConfig('-1', 10), 10, 'idle rejects negative seconds')
Expand Down Expand Up @@ -33,6 +35,23 @@ assertDeepEqual(
{ windows: { a: true }, count: 1 },
'idle leaves screensaver windows unchanged without an address'
)

assert(
/onFirstIdleTimeoutSecondsChanged:[\s\S]*?idleMonitorRearmTimer\.restart\(\)/.test(serviceSource),
'idle re-arms its monitor when the configured first timeout changes'
)

const idleMonitor = serviceSource.slice(serviceSource.indexOf(' IdleMonitor {'))
.split('\n }', 1)[0]
assert(
/enabled: root\.idleEnabled && !idleMonitorRearmTimer\.running/.test(idleMonitor),
'idle monitor stays disabled for the re-arm timer turn'
)

const rearmTimer = serviceSource.slice(serviceSource.indexOf(' id: idleMonitorRearmTimer'))
.split('\n }', 1)[0]
assert(/interval: 150/.test(rearmTimer), 'idle re-arm spans a tested event-loop delay')
assert(/repeat: false/.test(rearmTimer), 'idle re-arm only pulses the monitor once per timeout change')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Re-arm lacks runtime coverage

These assertions match QML source text but never change a timeout in a running IdleMonitor. They can pass even if idle notifications fail to resume, so the reported regression has no behavioral test coverage.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

JS

test_tmp=$(mktemp -d)
Expand Down