Shell 32: ui-daemon-window-lifecycle (#824) #881

Closed
charles wants to merge 0 commits from shell-32-ui-daemon-window-lifecycle into shell
Owner

What

fluxer-ui now runs as an iced::daemon (Task 1's findings; the spike succeeded, so no fallback).

  • crates/fluxer-ui/src/shell.rs: WindowSystem (Windows / X11 / Wayland, guessed then corrected from the window's raw handle), WindowRef (raw window + display handles; Debug names the system only), the WindowHost trait { opened(WindowRef), closed() } and announce, and Lifecycle: the one window's id and a pure state machine that answers window events and the store's WindowCommands with WindowOps (data), which the shell performs in order.
  • First window: start_placement / opens_at_start of fluxer_core::shell::window (Task 9); started hidden → no window, WindowRequest::Hidden reported (the store's 3 s tray grace then applies). exit_on_close_request: false on every window; maximised re-asked after Opened (X11).
  • Close request → UserAction::Shell(Window(CloseRequested)) only; the store's answer is carried out: Hide = set_mode(Hidden) on Windows/X11, window::close on Wayland; Show reverses (or reopens at the kept placement after Closed; a show while closing reopens once Closed comes, a hide meanwhile cancels it); Raise/Activate also un-minimise; Close closes, daemon keeps running; Attention/StopAttention = request_user_attention; Quit → host told closed, iced::exit() (the existing shutdown in apps/fluxer/src/main.rs follows). Runtime gone → same.
  • Reported: Moved (X11 frame offset subtracted so positions do not creep), Resized, Maximized, Minimized (asked with is_maximized/is_minimized after resize and focus loss), Shown/Hidden, Fullscreen. Focus was already reported (WindowFocus).
  • window::oldest()/latest() are gone; view/title/theme take the window id.
  • Animation clock (window::frames()) only while a window is shown (closed or hidden X11 included). A reopened window gets the focus where typing starts; App/Local survive.
  • run(snapshot, events, Services): Services is now a public struct (Services::new(files, frames) + public optional fields incl. window_host and launch).
  • CLAUDE.md: the WindowHost boundary added to the sanctioned I/O paths. READMEs updated.

Tests

crates/fluxer-ui/tests/window_lifecycle.rs (the shell's update driven through a #[doc(hidden)] app::TestDaemon with synthetic events and a fake host, every windowing system): first_window_uses_restored_placement, start_hidden_opens_none, close_request_follows_store, hide_and_show_per_platform, reopen_after_close_keeps_app_and_local, quit_command_exits, window_events_reported, host_told_on_open_and_close, no_frames_without_window, plus x11_frame_offset_is_not_saved. Mutation-checked (hide per platform, clock gating) that they fail when the behaviour is broken. Headless and screenshot suites unchanged and green: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci passed locally. No real-display (FLUXER_DESKTOP_TESTS) run was made.

Deviations / notes for the reviewer

  • apps/fluxer/src/main.rs (outside the Files list) only adapts to the new run signature; it passes Launch::default() and no WindowHost until Task 33 injects them.
  • WindowRef has unsafe impl Send + Sync (with SAFETY comments) so the runtime's host can keep it for the badge / activation; it never dereferences the handles.
  • Activate(token) shows/raises the window; using the token with xdg_activation_v1 is Task 30's (runtime + platform).
  • Until Task 33 reports tray availability, a close request quits (as before: the store's rules say Quit without a tray).
  • UiMessage gains WindowLifecycle(LifecycleEvent) and WindowSystem(Id, Option<WindowSystem>) (appended).

Charles to check by hand (Windows, Task 44)

Close button quits (no tray yet); minimise/maximise/restore and moving the window save the state; a notification click raises the window.

Stacked on: origin/shell-1-spike-iced-daemon-hide, origin/shell-9-core-window-rules-close (both already contained in shell)

Closes #824

🤖 Generated with Claude Code

https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K

## What `fluxer-ui` now runs as an `iced::daemon` (Task 1's findings; the spike succeeded, so no fallback). - `crates/fluxer-ui/src/shell.rs`: `WindowSystem` (Windows / X11 / Wayland, guessed then corrected from the window's raw handle), `WindowRef` (raw window + display handles; `Debug` names the system only), the `WindowHost` trait `{ opened(WindowRef), closed() }` and `announce`, and `Lifecycle`: the one window's id and a pure state machine that answers window events and the store's `WindowCommand`s with `WindowOp`s (data), which the shell performs in order. - First window: `start_placement` / `opens_at_start` of `fluxer_core::shell::window` (Task 9); started hidden → no window, `WindowRequest::Hidden` reported (the store's 3 s tray grace then applies). `exit_on_close_request: false` on every window; maximised re-asked after `Opened` (X11). - Close request → `UserAction::Shell(Window(CloseRequested))` only; the store's answer is carried out: `Hide` = `set_mode(Hidden)` on Windows/X11, `window::close` on Wayland; `Show` reverses (or reopens at the kept placement after `Closed`; a show while closing reopens once `Closed` comes, a hide meanwhile cancels it); `Raise`/`Activate` also un-minimise; `Close` closes, daemon keeps running; `Attention`/`StopAttention` = `request_user_attention`; `Quit` → host told closed, `iced::exit()` (the existing shutdown in `apps/fluxer/src/main.rs` follows). Runtime gone → same. - Reported: `Moved` (X11 frame offset subtracted so positions do not creep), `Resized`, `Maximized`, `Minimized` (asked with `is_maximized`/`is_minimized` after resize and focus loss), `Shown`/`Hidden`, `Fullscreen`. Focus was already reported (`WindowFocus`). - `window::oldest()`/`latest()` are gone; `view`/`title`/`theme` take the window id. - Animation clock (`window::frames()`) only while a window is shown (closed or hidden X11 included). A reopened window gets the focus where typing starts; `App`/`Local` survive. - `run(snapshot, events, Services)`: `Services` is now a public struct (`Services::new(files, frames)` + public optional fields incl. `window_host` and `launch`). - `CLAUDE.md`: the `WindowHost` boundary added to the sanctioned I/O paths. READMEs updated. ## Tests `crates/fluxer-ui/tests/window_lifecycle.rs` (the shell's `update` driven through a `#[doc(hidden)] app::TestDaemon` with synthetic events and a fake host, every windowing system): `first_window_uses_restored_placement`, `start_hidden_opens_none`, `close_request_follows_store`, `hide_and_show_per_platform`, `reopen_after_close_keeps_app_and_local`, `quit_command_exits`, `window_events_reported`, `host_told_on_open_and_close`, `no_frames_without_window`, plus `x11_frame_offset_is_not_saved`. Mutation-checked (hide per platform, clock gating) that they fail when the behaviour is broken. Headless and screenshot suites unchanged and green: `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` passed locally. No real-display (`FLUXER_DESKTOP_TESTS`) run was made. ## Deviations / notes for the reviewer - `apps/fluxer/src/main.rs` (outside the Files list) only adapts to the new `run` signature; it passes `Launch::default()` and no `WindowHost` until Task 33 injects them. - `WindowRef` has `unsafe impl Send + Sync` (with SAFETY comments) so the runtime's host can keep it for the badge / activation; it never dereferences the handles. - `Activate(token)` shows/raises the window; using the token with `xdg_activation_v1` is Task 30's (runtime + platform). - Until Task 33 reports tray availability, a close request quits (as before: the store's rules say `Quit` without a tray). - `UiMessage` gains `WindowLifecycle(LifecycleEvent)` and `WindowSystem(Id, Option<WindowSystem>)` (appended). ## Charles to check by hand (Windows, Task 44) Close button quits (no tray yet); minimise/maximise/restore and moving the window save the state; a notification click raises the window. Stacked on: origin/shell-1-spike-iced-daemon-hide, origin/shell-9-core-window-rules-close (both already contained in shell) Closes #824 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Refs #824

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
fluxer-ui runs as an iced::daemon; shell::Lifecycle keeps the one window,
reports close requests and window changes to the store and carries out its
WindowCommands per windowing system; WindowHost / WindowRef hand the raw
handles to the platform. apps/fluxer/src/main.rs only adapts to the new
run(snapshot, events, Services) signature.

Refs #824

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Author
Owner

Independent review: Shell 32 (ui-daemon-window-lifecycle)

Reviewed a68e4701..a6b107ff (the two commits of this task) against the plan's Task 32, spec §5.3 and §7.1, and the fork's fluxer_desktop/src/main/Window.ts and NotificationsIpc.ts.

Gate: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci run by the reviewer in a fresh worktree: all steps passed. tests/window_lifecycle.rs ran 10 of 10 green.

Checked

  1. Tests: all nine tests the plan names exist (plus x11_frame_offset_is_not_saved) and assert what the plan says. They cover the restored placement from restore(saved, displays) and --reset-window-state giving the default 1280x800, starting hidden only with autostart + Start minimized + tray, the close request reported and nothing else, Hide/Show per system (set_mode on Windows/X11, close and reopen on Wayland), App/Local kept across a reopen, Quit giving HostClosed, Exit, Moved/Resized/Maximized/Minimized reports, the host told on open and close, and the clock off when hidden or closed. The headless and screenshot suites are unchanged.
  2. Interfaces: run(snapshot, events, Services) (a struct, not more positional arguments), fluxer_ui::shell::{WindowHost { opened(WindowRef), closed() }, WindowRef} wrapping the raw window and display handles, announced through window::run. exit_on_close_request: false. No window::oldest() or latest() is left. view, title and theme take the id. The whole WindowCommand set is handled. UiMessage variants are appended.
  3. Invariants: fluxer-core is untouched. The only new I/O path in fluxer-ui is the injected WindowHost, which is added to CLAUDE.md. No logging was added, and WindowRef's Debug prints only the system, never the handles. There are no unwraps outside tests. The unsafe impl Send/Sync carry SAFETY comments and nothing in this crate dereferences the handles. Nothing is windows-gated beyond cfg!(windows), and the test file is cfg(not(windows)) like the other shell suites (#93).
  4. Parity (spot checks): (a) The close handler: Window.ts:853-866 saves the bounds at once and hides when shouldHideMainWindowOnClose, otherwise closes. The UI only reports the request, and Task 9's reducer saves and answers Hide or Quit. This matches. (b) showWindow/focusWindow (Window.ts:377-389, 1105-1152) restore when minimised, then show and focus. Show on a hidden window gives Windowed, focus and Shown, and Show on a known-minimised window gives Restore and Focus. This matches. (c) A notification click (NotificationsIpc.ts:175-183) restores, shows and focuses. Raise/Activate give Restore and Focus. This matches. hideWindowLeavingFullScreen only acts differently on darwin, so a Linux or Windows hide is a plain hide, as here.
  5. Review Focus 5: without a tray the window is never left unreachable. The close becomes Quit, and a window the system closed or one started hidden is reported Hidden, so the store's grace or Show reopens it. This matches the spec.

Findings

  • minor: Host ordering inside one batch. WindowOp::HostClosed calls host.closed() synchronously in perform, but WindowOp::Announce is a deferred window::run task. If Opened arrives with hide_when_opened set on Wayland, opened() returns Announce, …, HostClosed, Close in that order. The host is then told closed() before opened() runs, so it keeps a WindowRef to a destroyed surface. This needs a Hide or Close that arrives while the window is still opening, and nothing emits one today. Task 33's badge holds that ref, though. A fix: on Wayland, skip Announce when the window is closed straight away, or run HostClosed as a task queued after the Announce.
  • minor: close() while the window is opening sets hide_when_opened, so on Windows and X11 a WindowCommand::Close that arrives during opening ends as a hidden window, not a closed one. Nothing emits Close yet.
  • minor (note for Task 33): WindowRef is Send + Sync and handed out on the UI thread. The Wayland and X11 display pointers must only be used under the platform's thread rules. Task 33's SetBadge should say on which thread it uses them.

No blocking findings.

Verdict: approved. No blocking findings, and the local gate is green. The PR body lists what Charles must check by hand on Windows: hide/show via set_mode(Hidden), is_minimized after a minimise, and the badge handle once Task 33 lands.

🤖 Generated with Claude Code

## Independent review: Shell 32 (ui-daemon-window-lifecycle) Reviewed `a68e4701..a6b107ff` (the two commits of this task) against the plan's Task 32, spec §5.3 and §7.1, and the fork's `fluxer_desktop/src/main/Window.ts` and `NotificationsIpc.ts`. **Gate:** `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` run by the reviewer in a fresh worktree: **all steps passed**. `tests/window_lifecycle.rs` ran 10 of 10 green. ### Checked 1. **Tests:** all nine tests the plan names exist (plus `x11_frame_offset_is_not_saved`) and assert what the plan says. They cover the restored placement from `restore(saved, displays)` and `--reset-window-state` giving the default 1280x800, starting hidden only with autostart + Start minimized + tray, the close request reported and nothing else, Hide/Show per system (set_mode on Windows/X11, close and reopen on Wayland), App/Local kept across a reopen, Quit giving `HostClosed, Exit`, Moved/Resized/Maximized/Minimized reports, the host told on open and close, and the clock off when hidden or closed. The headless and screenshot suites are unchanged. 2. **Interfaces:** `run(snapshot, events, Services)` (a struct, not more positional arguments), `fluxer_ui::shell::{WindowHost { opened(WindowRef), closed() }, WindowRef}` wrapping the raw window and display handles, announced through `window::run`. `exit_on_close_request: false`. No `window::oldest()` or `latest()` is left. `view`, `title` and `theme` take the id. The whole `WindowCommand` set is handled. `UiMessage` variants are appended. 3. **Invariants:** fluxer-core is untouched. The only new I/O path in fluxer-ui is the injected `WindowHost`, which is added to `CLAUDE.md`. No logging was added, and `WindowRef`'s `Debug` prints only the system, never the handles. There are no unwraps outside tests. The `unsafe impl Send/Sync` carry SAFETY comments and nothing in this crate dereferences the handles. Nothing is windows-gated beyond `cfg!(windows)`, and the test file is `cfg(not(windows))` like the other shell suites (#93). 4. **Parity (spot checks):** (a) The close handler: `Window.ts:853-866` saves the bounds at once and hides when `shouldHideMainWindowOnClose`, otherwise closes. The UI only reports the request, and Task 9's reducer saves and answers Hide or Quit. This matches. (b) `showWindow`/`focusWindow` (`Window.ts:377-389`, `1105-1152`) restore when minimised, then show and focus. Show on a hidden window gives `Windowed`, focus and `Shown`, and Show on a known-minimised window gives Restore and Focus. This matches. (c) A notification click (`NotificationsIpc.ts:175-183`) restores, shows and focuses. `Raise`/`Activate` give Restore and Focus. This matches. `hideWindowLeavingFullScreen` only acts differently on darwin, so a Linux or Windows hide is a plain hide, as here. 5. **Review Focus 5:** without a tray the window is never left unreachable. The close becomes Quit, and a window the system closed or one started hidden is reported `Hidden`, so the store's grace or Show reopens it. This matches the spec. ### Findings - **minor:** Host ordering inside one batch. `WindowOp::HostClosed` calls `host.closed()` synchronously in `perform`, but `WindowOp::Announce` is a deferred `window::run` task. If `Opened` arrives with `hide_when_opened` set on Wayland, `opened()` returns `Announce, …, HostClosed, Close` in that order. The host is then told `closed()` before `opened()` runs, so it keeps a `WindowRef` to a destroyed surface. This needs a Hide or Close that arrives while the window is still opening, and nothing emits one today. Task 33's badge holds that ref, though. A fix: on Wayland, skip `Announce` when the window is closed straight away, or run `HostClosed` as a task queued after the `Announce`. - **minor:** `close()` while the window is opening sets `hide_when_opened`, so on Windows and X11 a `WindowCommand::Close` that arrives during opening ends as a hidden window, not a closed one. Nothing emits `Close` yet. - **minor (note for Task 33):** `WindowRef` is `Send + Sync` and handed out on the UI thread. The Wayland and X11 display pointers must only be used under the platform's thread rules. Task 33's `SetBadge` should say on which thread it uses them. No blocking findings. **Verdict: approved.** No blocking findings, and the local gate is green. The PR body lists what Charles must check by hand on Windows: hide/show via `set_mode(Hidden)`, `is_minimized` after a minimise, and the badge handle once Task 33 lands. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Author
Owner

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

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

Pull request closed

Sign in to join this conversation.
No description provided.