Keep the display awake while sharing, watching or showing a camera (#913) #915

Closed
charles wants to merge 0 commits from fix-913-keep-screen-awake into textchat
Owner

Closes #913

Cause

Flaxative has no display-sleep inhibitor at all (only the idle-time query in fluxer-platform/src/idle.rs), so the screen dims, locks and sleeps during a share and while watching a stream.

When the original keeps the display awake

Two sources. (1) The desktop app, from fluxer-soundboard (main): fluxer_desktop/src/main/StreamingPriority.ts starts powerSaveBlocker.start('prevent-display-sleep') when the ref count of acquireStreamingPriority goes 0 → 1, stops it at 1 → 0, and resets it when the renderer dies or navigates (Window.ts). The only renderer caller is VoiceEngineV2AppScreenShareExecutionAdapter.setStreamingPriorityInternal (driven by VoiceEngineV2AppScreenShareLiveKitFlows.ts, ...Rituals.ts). Nothing in fluxer_app/src uses navigator.wakeLock. (2) Chromium itself holds a display wake lock while a visible <video> plays: a watched stream's tile and camera tiles. The fork never asks for it, but users of the original experience it (design decision on this PR: Flaxative matches what users experience).

Condition Original source What users of the original experience Flaxative (selectors::keep_display_awake)
Voice-only call nothing sleeps not held
In-app source picker open, before a share the picker comes before setEnabled(true) sleeps not held (Picking { switch: false })
Own share starting (capture, system/portal picker) setEnabled(true) acquires streaming priority awake held (Starting)
Own share live (screen, window or device) streaming priority held awake held (Live)
Source switch / codec republish kept (acquireStreamingPriority: false, no release) awake kept (Picking { switch: true }, Live)
LiveKit room reconnecting while sharing kept; restore re-acquires awake kept (share stays Live)
Own share stopped / failed / cancelled / timed out released (preparePreflightForSetEnabled, finalizeSetEnabledFailure) sleeps (unless another row holds) released (Stopping, Idle)
Watching a remote stream (subscribed, waiting, buffering, playing) Chromium video wake lock awake held (key in Streams::watching)
Watched stream ended, still watched (republish grace) the tile still shows a (stalled) video element awake held (Ended, still watched)
Watch dropped (stopped, streamer gone, grace over) video element removed sleeps released
Watching failed no video plays sleeps not held (Failed)
Own camera on Chromium (own preview tile) awake held (own voice state self_video; Flaxative cannot turn the camera on yet)
Remote camera shown Chromium (camera tile) awake not reachable: cameras are not received on this branch (voice::live); add when sub-project 5 receives them
Several of the above at once, or one handing over to another — awake one inhibition, not released in between
Room lost, call left, moved, logout resetStreamTracking, terminal unload; tiles go sleeps released (share and watches end with the connection)
Window hidden / closed to tray Chromium releases its video lock for an invisible video (the share's blocker stays) sleeps unless sharing not modelled yet: no window visibility in the core on textchat. Follow-up #916, once the desktop shell lands (shell.window.visible, close to tray): a hidden window releases it for watching and cameras
Renderer crash / app quit resetStreamingPriority; the process ends sleeps released when the runtime task ends or is aborted; the OS ends it with the process

Fix

  • fluxer-core selectors::keep_awake::{keep_display_awake, keep_awake_reasons, AwakeReason, share_keeps_display_awake, watching_keeps_display_awake, camera_keeps_display_awake}: a pure selector, true while any reason holds (table above).
  • fluxer-platform keep_awake (new module): KeepAwake::acquire() -> Box<dyn Inhibition> (dropping releases), Unsupported, fake::FakeKeepAwake, system(), on_bus(address) (tests).
    • Linux/BSD: org.freedesktop.portal.Inhibit.Inhibit("", 8 /*idle*/, {reason, handle_token}) → released with org.freedesktop.portal.Request.Close on the handle; else org.freedesktop.ScreenSaver.Inhibit / UnInhibit; else org.gnome.SessionManager.Inhibit(app, 0, reason, 8) / Uninhibit. Each call bounded by 2 s. The inhibition owns its own bus connection, and all three services drop an inhibition when the caller's connection goes, so it cannot outlive the process. Expected method: KDE Plasma Wayland → portal (xdg-desktop-portal-kde), GNOME → portal (xdg-desktop-portal-gnome/-gtk, which forwards to gnome-session); the other two are fallbacks for sessions without a portal Inhibit backend.
    • Windows: PowerCreateRequest with the reason "Showing or sharing video" (shows in powercfg /requests), PowerSetRequest for DisplayRequired and SystemRequired, cleared and closed on release. Adds the Win32_System_Power feature to the workspace windows dependency (no new crate). Type-checked only (cargo clippy -p fluxer-platform --target x86_64-pc-windows-gnu --all-targets -D warnings clean); not run on Windows.
  • apps/fluxer keep_awake_rt (new file): follows the published snapshots and holds at most one inhibition on a dedicated thread (acquire/release block on D-Bus). Released when the selector turns false, when the task is aborted at shutdown, and when the snapshot sender drops (runtime ended or panicked). Runtime::with_keep_awake; the runtime keeps nothing awake by default (like the silent notifier), main passes keep_awake::system(), so tests never inhibit the desktop. Edits to shared files (runtime.rs, main.rs, lib.rss, Cargo.toml) are small, for the shell branch.

Verification

  • Core: selectors::keep_awake::tests::the_table (every GoLive state), the_watching_table (nothing watched, watched before publication, waiting, buffering, playing, ended while watched, ended tile after the watch was dropped, a playback entry without a watch, failed) and stream_golive::display_kept_awake_while_sharing_watching_or_showing_a_camera (through App::apply: voice-only call, remote camera not received, watching, watching + own camera = two reasons, streamer stops → watch dropped → released, in-app picker, starting, live, switch, stop, system-picker cancel, room lost, leave, logout).
  • Runtime with the fake (apps/fluxer/tests/keep_awake_runtime.rs, devserver + FakeRoom): acquired once and released once per share; a source switch and a LiveKit reconnect keep the one inhibition; a lost room releases it and the next share acquires anew, never two held at once; watching acquires and the stream ending (republish grace over) releases; watching + sharing hold one inhibition, and handing over between them in either direction neither releases nor re-acquires; quitting while sharing releases; a refused inhibitor does not affect the share. Checked that the switch test fails when the selector drops Picking { switch: true }, and that the two watching tests fail when the watching reason is disabled.
  • Linux bus (crates/fluxer-platform/tests/keep_awake_bus.rs): fake portal / ScreenSaver / gnome-session on a private dbus-daemon with no service activation (explicit address, never the session bus; run locally under dbus-run-session with FLUXER_NO_DESKTOP_NOTIFICATIONS=1): portal preferred and Closed on release; ScreenSaver without the portal; gnome-session last; nothing available → error, no hang; a child process that exits holding the inhibition leaves no connection on the bus.
  • Gate: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci → ==> xtask ci: all steps passed. No goldens changed.

Follow-up

  • #916: release the inhibitor for watching and cameras while the window is hidden, once the desktop shell gives the core window visibility. Also noted in the fluxer-core and apps/fluxer READMEs.

Not verified

  • Behaviour on a real KDE/GNOME desktop and on Windows (deliberately: a test must not keep the owner's screen awake).
  • Chromium's video wake lock is taken from how Chromium behaves, not from the fork's source; not measured against the Electron app here.
  • The camera row is reachable only through the own voice state's self_video, which this client cannot set yet; remote cameras are not received on this branch.

🤖 Generated with Claude Code

Closes #913 ## Cause Flaxative has no display-sleep inhibitor at all (only the idle-time query in `fluxer-platform/src/idle.rs`), so the screen dims, locks and sleeps during a share and while watching a stream. ## When the original keeps the display awake Two sources. **(1) The desktop app**, from `fluxer-soundboard` (main): `fluxer_desktop/src/main/StreamingPriority.ts` starts `powerSaveBlocker.start('prevent-display-sleep')` when the ref count of `acquireStreamingPriority` goes 0 → 1, stops it at 1 → 0, and resets it when the renderer dies or navigates (`Window.ts`). The only renderer caller is `VoiceEngineV2AppScreenShareExecutionAdapter.setStreamingPriorityInternal` (driven by `VoiceEngineV2AppScreenShareLiveKitFlows.ts`, `...Rituals.ts`). Nothing in `fluxer_app/src` uses `navigator.wakeLock`. **(2) Chromium itself** holds a display wake lock while a visible `<video>` plays: a watched stream's tile and camera tiles. The fork never asks for it, but users of the original experience it (design decision on this PR: Flaxative matches what users experience). | Condition | Original source | What users of the original experience | Flaxative (`selectors::keep_display_awake`) | |---|---|---|---| | Voice-only call | nothing | sleeps | not held | | In-app source picker open, before a share | the picker comes before `setEnabled(true)` | sleeps | not held (`Picking { switch: false }`) | | Own share starting (capture, system/portal picker) | `setEnabled(true)` acquires streaming priority | awake | held (`Starting`) | | Own share live (screen, window or device) | streaming priority held | awake | held (`Live`) | | Source switch / codec republish | kept (`acquireStreamingPriority: false`, no release) | awake | kept (`Picking { switch: true }`, `Live`) | | LiveKit room reconnecting while sharing | kept; restore re-acquires | awake | kept (share stays `Live`) | | Own share stopped / failed / cancelled / timed out | released (`preparePreflightForSetEnabled`, `finalizeSetEnabledFailure`) | sleeps (unless another row holds) | released (`Stopping`, `Idle`) | | Watching a remote stream (subscribed, waiting, buffering, playing) | Chromium video wake lock | awake | held (key in `Streams::watching`) | | Watched stream ended, still watched (republish grace) | the tile still shows a (stalled) video element | awake | held (`Ended`, still watched) | | Watch dropped (stopped, streamer gone, grace over) | video element removed | sleeps | released | | Watching failed | no video plays | sleeps | not held (`Failed`) | | Own camera on | Chromium (own preview tile) | awake | held (own voice state `self_video`; Flaxative cannot turn the camera on yet) | | Remote camera shown | Chromium (camera tile) | awake | not reachable: cameras are not received on this branch (`voice::live`); add when sub-project 5 receives them | | Several of the above at once, or one handing over to another | — | awake | one inhibition, not released in between | | Room lost, call left, moved, logout | `resetStreamTracking`, terminal unload; tiles go | sleeps | released (share and watches end with the connection) | | Window hidden / closed to tray | Chromium releases its video lock for an invisible video (the share's blocker stays) | sleeps unless sharing | **not modelled yet**: no window visibility in the core on `textchat`. Follow-up #916, once the desktop shell lands (`shell.window.visible`, close to tray): a hidden window releases it for watching and cameras | | Renderer crash / app quit | `resetStreamingPriority`; the process ends | sleeps | released when the runtime task ends or is aborted; the OS ends it with the process | ## Fix - **fluxer-core** `selectors::keep_awake::{keep_display_awake, keep_awake_reasons, AwakeReason, share_keeps_display_awake, watching_keeps_display_awake, camera_keeps_display_awake}`: a pure selector, true while any reason holds (table above). - **fluxer-platform** `keep_awake` (new module): `KeepAwake::acquire() -> Box<dyn Inhibition>` (dropping releases), `Unsupported`, `fake::FakeKeepAwake`, `system()`, `on_bus(address)` (tests). - Linux/BSD: `org.freedesktop.portal.Inhibit.Inhibit("", 8 /*idle*/, {reason, handle_token})` → released with `org.freedesktop.portal.Request.Close` on the handle; else `org.freedesktop.ScreenSaver.Inhibit` / `UnInhibit`; else `org.gnome.SessionManager.Inhibit(app, 0, reason, 8)` / `Uninhibit`. Each call bounded by 2 s. The inhibition owns its own bus connection, and all three services drop an inhibition when the caller's connection goes, so it cannot outlive the process. Expected method: **KDE Plasma Wayland → portal** (`xdg-desktop-portal-kde`), **GNOME → portal** (`xdg-desktop-portal-gnome`/`-gtk`, which forwards to gnome-session); the other two are fallbacks for sessions without a portal Inhibit backend. - Windows: `PowerCreateRequest` with the reason "Showing or sharing video" (shows in `powercfg /requests`), `PowerSetRequest` for `DisplayRequired` and `SystemRequired`, cleared and closed on release. Adds the `Win32_System_Power` feature to the workspace `windows` dependency (no new crate). **Type-checked only** (`cargo clippy -p fluxer-platform --target x86_64-pc-windows-gnu --all-targets -D warnings` clean); not run on Windows. - **apps/fluxer** `keep_awake_rt` (new file): follows the published snapshots and holds at most one inhibition on a dedicated thread (acquire/release block on D-Bus). Released when the selector turns false, when the task is aborted at shutdown, and when the snapshot sender drops (runtime ended or panicked). `Runtime::with_keep_awake`; the runtime keeps nothing awake by default (like the silent notifier), `main` passes `keep_awake::system()`, so tests never inhibit the desktop. Edits to shared files (`runtime.rs`, `main.rs`, `lib.rs`s, `Cargo.toml`) are small, for the `shell` branch. ## Verification - Core: `selectors::keep_awake::tests::the_table` (every `GoLive` state), `the_watching_table` (nothing watched, watched before publication, waiting, buffering, playing, ended while watched, ended tile after the watch was dropped, a playback entry without a watch, failed) and `stream_golive::display_kept_awake_while_sharing_watching_or_showing_a_camera` (through `App::apply`: voice-only call, remote camera not received, watching, watching + own camera = two reasons, streamer stops → watch dropped → released, in-app picker, starting, live, switch, stop, system-picker cancel, room lost, leave, logout). - Runtime with the fake (`apps/fluxer/tests/keep_awake_runtime.rs`, devserver + FakeRoom): acquired once and released once per share; a source switch and a LiveKit reconnect keep the one inhibition; a lost room releases it and the next share acquires anew, never two held at once; watching acquires and the stream ending (republish grace over) releases; watching + sharing hold one inhibition, and handing over between them in either direction neither releases nor re-acquires; quitting while sharing releases; a refused inhibitor does not affect the share. Checked that the switch test fails when the selector drops `Picking { switch: true }`, and that the two watching tests fail when the watching reason is disabled. - Linux bus (`crates/fluxer-platform/tests/keep_awake_bus.rs`): fake portal / ScreenSaver / gnome-session on a private `dbus-daemon` with no service activation (explicit address, never the session bus; run locally under `dbus-run-session` with `FLUXER_NO_DESKTOP_NOTIFICATIONS=1`): portal preferred and `Close`d on release; ScreenSaver without the portal; gnome-session last; nothing available → error, no hang; a child process that exits holding the inhibition leaves no connection on the bus. - Gate: `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` → `==> xtask ci: all steps passed`. No goldens changed. ## Follow-up - #916: release the inhibitor for watching and cameras while the window is hidden, once the desktop shell gives the core window visibility. Also noted in the `fluxer-core` and `apps/fluxer` READMEs. ## Not verified - Behaviour on a real KDE/GNOME desktop and on Windows (deliberately: a test must not keep the owner's screen awake). - Chromium's video wake lock is taken from how Chromium behaves, not from the fork's source; not measured against the Electron app here. - The camera row is reachable only through the own voice state's `self_video`, which this client cannot set yet; remote cameras are not received on this branch. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The original desktop app holds Electron's prevent-display-sleep blocker
while "streaming priority" is acquired, which only the own screen share
does: from setEnabled(true) (the capture and its system picker) until the
share stops, fails, is cancelled or the room disconnects; kept across a
source switch. Watching a stream, a camera or a call never acquire it, and
the web client does not use the Screen Wake Lock API. Flaxative had no
inhibitor at all.

- fluxer-core: selectors::keep_display_awake, true while the own share
  is Starting, Live or switching its source.
- fluxer-platform: keep_awake::{KeepAwake, Inhibition}; on Linux the
  portal's Inhibit (idle), then org.freedesktop.ScreenSaver, then
  org.gnome.SessionManager, the inhibition owning its bus connection; on
  Windows a power request (display and system required); a fake.
- apps/fluxer: keep_awake_rt follows the snapshots and holds at most one
  inhibition on a thread of its own, released when the selector turns
  false, at shutdown and when the runtime task ends. main passes the
  system's; the runtime keeps nothing awake by default, so tests never
  reach the desktop.

Refs #913

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
charles changed title from Keep the display awake while sharing the screen (#913) to Keep the display awake while sharing, watching or showing a camera (#913) 2026-11-18 21:19:55 +00:00
In the original, Chromium holds its own display wake lock while a visible
video plays, so users see the display stay awake while watching a stream
or with a camera tile in the call, even though the fork never asks for it.
The selector now holds while any of: the own share runs (as before), a
watched stream's video arrives or is expected (in `watching`, not Failed;
an Ended tile counts only while the watch lasts), or a camera is shown
(the own `self_video`; remote cameras are not received on this branch).
A voice-only call keeps nothing awake. The reason string no longer names
only sharing.

No window-visibility condition yet: the core has none on this branch; a
hidden window should release it once the desktop shell lands.

Refs #913

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #913

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Merged into textchat by hand (the merge API returns 405); the commits are in the branch.

Merged into `textchat` by hand (the merge API returns 405); the commits are in the branch.
charles closed this pull request 2026-11-18 21:58:23 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.