Shell 19: platform-autostart (#811) #894

Closed
charles wants to merge 0 commits from shell-19-platform-autostart into shell
Owner

What

fluxer-platform::autostart (spec §7.3, plan Task 19):

  • Autostart trait { state() -> AutostartState, enable(&Launch) -> io::Result<()>, disable() -> io::Result<()> } (Send + Sync), system_autostart() -> Box<dyn Autostart>, unavailable_reason(&Launch, development_build), AUTOSTART_ARG, FakeAutostart (records FakeCalls, set_state, fail_next).
  • Linux LinuxAutostart::new(XdgDirs, Option<AutostartUnavailable>): $XDG_CONFIG_HOME/autostart/flaxative.desktop with the original's keys (D/Autostart.ts:362-381): Exec="<AppImage or exe>" --autostart, TryExec, StartupWMClass=flaxative, X-GNOME-Autostart-enabled=true, marker; atomic write, 0644, folder 0700, idempotent. State as :472-483: missing / Hidden=true → Off; command (TryExec, else first word of Exec, parsed as :307-352) gone → Stale; else On.
  • Windows WindowsAutostart::new(Arc<dyn Registry>, …): HKCU\Software\Microsoft\Windows\CurrentVersion\Run, value Forked.Flaxative = "<Velopack stub or exe>" --autostart (D/Autostart.ts:117-143); Explorer\StartupApproved\Run read only (first byte 3 → DisabledBySystem); program gone → Stale; disable deletes only our value.
  • Not offered for a non-installed build: Unavailable(DevelopmentBuild) for a debug build, Unavailable(NotInstalled) otherwise; enable refuses (Unsupported). Paths with a quote, %, a control character (or relative on Linux) are refused (InvalidInput).

Tests

crates/fluxer-platform/tests/autostart.rs (temp XDG_CONFIG_HOME, MemoryRegistry): the plan's enable_writes_file_and_state_is_on, hidden_or_missing_command_is_off_or_stale, disable_removes, exec_uses_appimage_path, development_build_unavailable, run_value_written_with_stub_path, startup_approved_disabled_reported, disable_deletes_only_our_value, plus disable_leaves_an_entry_it_did_not_write, odd_paths_refused, fake_records_calls_and_follows_them, trait_is_object_safe_and_shared; unit tests for the Exec / Run command parsing. FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally. No real-desktop test was added (it would write the user's own autostart folder); none run with FLUXER_DESKTOP_TESTS.

Deviations / for the reviewer

  • crates/fluxer-platform/src/desktop_entry/{mod.rs,linux.rs} (Task 18's, outside this task's Files list): mod linux and six helpers (GENERATED_MARKER, escape_value, quote_exec_arg, main_group_value, is_executable_file, write_atomically) made pub(crate) so the autostart entry shares the same quoting and atomic write instead of copying them. No behaviour change.
  • disable on Linux removes only an entry the client wrote (marker + Exec … --autostart). The original removes any flaxative.desktop there; with autostart off by default (§18 Q5) that would delete, at every start, an entry the user added through KDE's autostart settings (which copy the application's desktop file, marker included). Such an entry is reported On and left alone.
  • Run command is always quoted ("<exe>" --autostart, as spec §7.3), where the original quotes only paths with spaces.
  • Flatpak (Background portal) not done: no Flatpak build (spec §3 row 34, NP).

Windows: to check by hand (Task 44)

Turning the switch on writes Forked.Flaxative under HKCU\…\Run pointing at the stub in %LocalAppData%\Flaxative; turning it off in Settings → Apps → Startup reports "Turned off in Windows settings." and the client does not overwrite it; switching off in Flaxative deletes only that value.

Strings: none new in this task (the notes are Task 16's).

Stacked on: origin/shell-16-core-autostart, origin/shell-18-platform-desktop-entry-and (both already on shell at branch time)

Closes #811

🤖 Generated with Claude Code

https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K

## What `fluxer-platform::autostart` (spec §7.3, plan Task 19): - `Autostart` trait `{ state() -> AutostartState, enable(&Launch) -> io::Result<()>, disable() -> io::Result<()> }` (`Send + Sync`), `system_autostart() -> Box<dyn Autostart>`, `unavailable_reason(&Launch, development_build)`, `AUTOSTART_ARG`, `FakeAutostart` (records `FakeCall`s, `set_state`, `fail_next`). - Linux `LinuxAutostart::new(XdgDirs, Option<AutostartUnavailable>)`: `$XDG_CONFIG_HOME/autostart/flaxative.desktop` with the original's keys (`D/Autostart.ts:362-381`): `Exec="<AppImage or exe>" --autostart`, `TryExec`, `StartupWMClass=flaxative`, `X-GNOME-Autostart-enabled=true`, marker; atomic write, 0644, folder 0700, idempotent. State as `:472-483`: missing / `Hidden=true` → `Off`; command (`TryExec`, else first word of `Exec`, parsed as `:307-352`) gone → `Stale`; else `On`. - Windows `WindowsAutostart::new(Arc<dyn Registry>, …)`: `HKCU\Software\Microsoft\Windows\CurrentVersion\Run`, value `Forked.Flaxative` = `"<Velopack stub or exe>" --autostart` (`D/Autostart.ts:117-143`); `Explorer\StartupApproved\Run` read only (first byte 3 → `DisabledBySystem`); program gone → `Stale`; `disable` deletes only our value. - Not offered for a non-installed build: `Unavailable(DevelopmentBuild)` for a debug build, `Unavailable(NotInstalled)` otherwise; `enable` refuses (`Unsupported`). Paths with a quote, `%`, a control character (or relative on Linux) are refused (`InvalidInput`). ## Tests `crates/fluxer-platform/tests/autostart.rs` (temp `XDG_CONFIG_HOME`, `MemoryRegistry`): the plan's `enable_writes_file_and_state_is_on`, `hidden_or_missing_command_is_off_or_stale`, `disable_removes`, `exec_uses_appimage_path`, `development_build_unavailable`, `run_value_written_with_stub_path`, `startup_approved_disabled_reported`, `disable_deletes_only_our_value`, plus `disable_leaves_an_entry_it_did_not_write`, `odd_paths_refused`, `fake_records_calls_and_follows_them`, `trait_is_object_safe_and_shared`; unit tests for the `Exec` / `Run` command parsing. `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally. No real-desktop test was added (it would write the user's own autostart folder); none run with `FLUXER_DESKTOP_TESTS`. ## Deviations / for the reviewer - `crates/fluxer-platform/src/desktop_entry/{mod.rs,linux.rs}` (Task 18's, outside this task's Files list): `mod linux` and six helpers (`GENERATED_MARKER`, `escape_value`, `quote_exec_arg`, `main_group_value`, `is_executable_file`, `write_atomically`) made `pub(crate)` so the autostart entry shares the same quoting and atomic write instead of copying them. No behaviour change. - `disable` on Linux removes only an entry the client wrote (marker + `Exec … --autostart`). The original removes any `flaxative.desktop` there; with autostart off by default (§18 Q5) that would delete, at every start, an entry the user added through KDE's autostart settings (which copy the application's desktop file, marker included). Such an entry is reported `On` and left alone. - `Run` command is always quoted (`"<exe>" --autostart`, as spec §7.3), where the original quotes only paths with spaces. - Flatpak (Background portal) not done: no Flatpak build (spec §3 row 34, NP). ## Windows: to check by hand (Task 44) Turning the switch on writes `Forked.Flaxative` under `HKCU\…\Run` pointing at the stub in `%LocalAppData%\Flaxative`; turning it off in Settings → Apps → Startup reports "Turned off in Windows settings." and the client does not overwrite it; switching off in Flaxative deletes only that value. Strings: none new in this task (the notes are Task 16's). Stacked on: origin/shell-16-core-autostart, origin/shell-18-platform-desktop-entry-and (both already on shell at branch time) Closes #811 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
The login entry behind "Launch Flaxative at login" (spec §7.3): the
Autostart trait (state, enable, disable), system_autostart, the XDG
autostart entry (D/Autostart.ts:362-381, state as :472-483, Stale when
its command is gone), the Windows Run value Forked.Flaxative with the
StartupApproved read (first byte 3 -> DisabledBySystem, never written),
unavailable_reason and FakeAutostart. desktop_entry's quoting, escaping
and atomic-write helpers become pub(crate) to be shared.

Refs #811

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

Independent review: Shell 19 (platform-autostart)

Reviewed baf0a929..73bcf24d cold. Local gate: FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci at 73bcf24d: all steps passed (12/12 in tests/autostart.rs, plus the unit tests in autostart/{linux,windows}.rs).

Plan tests (1): all eight named tests exist and assert what the plan asks: enable_writes_file_and_state_is_on (keys, Exec="<exe>" --autostart, TryExec, 0644, idempotent without rewrite), hidden_or_missing_command_is_off_or_stale, disable_removes, exec_uses_appimage_path ($APPIMAGE, not the .mount_ path), development_build_unavailable, run_value_written_with_stub_path (Velopack stub one folder above current), startup_approved_disabled_reported (first byte 3, never written), disable_deletes_only_our_value. Extra: disable_leaves_an_entry_it_did_not_write, odd_paths_refused, fake and object-safety tests.

Interfaces (2): Autostart { state() -> AutostartState, enable(&Launch), disable() } (both return io::Result<()>), system_autostart() -> Box<dyn Autostart>, FakeAutostart are present; they use fluxer_core::shell::{AutostartState, AutostartUnavailable} from Task 16 and Launch / Registry from Task 18 unchanged. The trait is Send + Sync, so Task 33 can hold it behind an Arc.

Invariants (3): only fluxer-platform is changed. No core or UI I/O. No secrets. Log lines carry no paths (io::Errors from read_to_string / registry, static messages). Paths are computed and quoted, and a quote, %, a control character or a relative path is refused. The desktop_entry helpers widened to pub(crate) are unchanged in behaviour.

Parity (4), checked against fluxer_desktop/src/main/Autostart.ts:

  • The file body matches buildLinuxDesktopFileContents (:362-381) key for key, in order. Name and Comment use the client's name.
  • parseDesktopExecCommand (:307-332) and commandExists (:334-352) are ported faithfully: first word or quoted argument with backslash escapes, absolute path vs PATH, empty entries skipped. Hidden → off, as at :472-483.
  • getWindowsLoginItemPath (:117-128), the stub at ..\<exe>, matches the test. The value name is WINDOWS_APP_USER_MODEL_ID (Forked.Flaxative), as at :130-143.

Review Focus 8: met. The entry and value are quoted and computed, writing them again changes nothing, and the switch that created them removes them. StartupApproved is never written.

Windows code (read as a compiler would): system_autostart's cfg(windows) arm coerces Arc::new(SystemRegistry) (a unit struct, Registry: Send + Sync) to Arc<dyn Registry> at the argument site, which is valid. The cfg'd tail blocks are the usual pattern. Nothing in mod.rs / linux.rs / windows.rs becomes unused on Windows. create_private_dir's mut is needed by recursive(true). I expect no Windows clippy issue, but the Windows runner is the proof.

Findings

  • minor: crates/fluxer-platform/src/autostart/linux.rs. Hidden=true, which GNOME and KDE set when the user turns the entry off in the desktop's own settings, is reported as Off. With the setting on, Task 16's reconcile (on + Off → SetAutostart(true)) then rewrites the entry at the next start and undoes the user's choice there. Windows treats the same case as DisabledBySystem and leaves it. This matches the spec's wording ("not Hidden" → not On) and the original's state function, so it does not block. Consider reporting a client-written entry with Hidden=true as DisabledBySystem, or open a follow-up for Task 33 / 38 to decide.
  • minor: crates/fluxer-platform/src/autostart/linux.rs disable. An entry the user added (no marker) is reported On and kept, so with the setting off, reconcile emits SetAutostart(false) on every reconcile and it does nothing. This is harmless and documented as a deliberate deviation. Task 33 / 38 should show it as on, set from outside the client, rather than spin on it.
  • minor (note): Flatpak (Background portal, Autostart.ts:440-470) is not implemented. It is out of scope here (NP) and listed in the PR.

Hand checks for Charles on Windows (from the PR): the Run value appears in Task Manager → Startup apps. After it is turned off there, the client shows "disabled in Windows settings" and does not re-enable it.

Verdict: APPROVED. There are no blocking findings, and the local gate is green at 73bcf24d.

## Independent review: Shell 19 (platform-autostart) Reviewed `baf0a929..73bcf24d` cold. Local gate: `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` at 73bcf24d: **all steps passed** (12/12 in `tests/autostart.rs`, plus the unit tests in `autostart/{linux,windows}.rs`). **Plan tests (1):** all eight named tests exist and assert what the plan asks: `enable_writes_file_and_state_is_on` (keys, `Exec="<exe>" --autostart`, `TryExec`, 0644, idempotent without rewrite), `hidden_or_missing_command_is_off_or_stale`, `disable_removes`, `exec_uses_appimage_path` (`$APPIMAGE`, not the `.mount_` path), `development_build_unavailable`, `run_value_written_with_stub_path` (Velopack stub one folder above `current`), `startup_approved_disabled_reported` (first byte 3, never written), `disable_deletes_only_our_value`. Extra: `disable_leaves_an_entry_it_did_not_write`, `odd_paths_refused`, fake and object-safety tests. **Interfaces (2):** `Autostart { state() -> AutostartState, enable(&Launch), disable() }` (both return `io::Result<()>`), `system_autostart() -> Box<dyn Autostart>`, `FakeAutostart` are present; they use `fluxer_core::shell::{AutostartState, AutostartUnavailable}` from Task 16 and `Launch` / `Registry` from Task 18 unchanged. The trait is `Send + Sync`, so Task 33 can hold it behind an `Arc`. **Invariants (3):** only `fluxer-platform` is changed. No core or UI I/O. No secrets. Log lines carry no paths (`io::Error`s from `read_to_string` / registry, static messages). Paths are computed and quoted, and a quote, `%`, a control character or a relative path is refused. The desktop_entry helpers widened to `pub(crate)` are unchanged in behaviour. **Parity (4), checked against `fluxer_desktop/src/main/Autostart.ts`:** - The file body matches `buildLinuxDesktopFileContents` (:362-381) key for key, in order. Name and Comment use the client's name. - `parseDesktopExecCommand` (:307-332) and `commandExists` (:334-352) are ported faithfully: first word or quoted argument with backslash escapes, absolute path vs `PATH`, empty entries skipped. Hidden → off, as at :472-483. - `getWindowsLoginItemPath` (:117-128), the stub at `..\<exe>`, matches the test. The value name is `WINDOWS_APP_USER_MODEL_ID` (`Forked.Flaxative`), as at :130-143. **Review Focus 8:** met. The entry and value are quoted and computed, writing them again changes nothing, and the switch that created them removes them. StartupApproved is never written. **Windows code (read as a compiler would):** `system_autostart`'s `cfg(windows)` arm coerces `Arc::new(SystemRegistry)` (a unit struct, `Registry: Send + Sync`) to `Arc<dyn Registry>` at the argument site, which is valid. The cfg'd tail blocks are the usual pattern. Nothing in `mod.rs` / `linux.rs` / `windows.rs` becomes unused on Windows. `create_private_dir`'s `mut` is needed by `recursive(true)`. I expect no Windows clippy issue, but the Windows runner is the proof. ### Findings - **minor**: `crates/fluxer-platform/src/autostart/linux.rs`. `Hidden=true`, which GNOME and KDE set when the user turns the entry off in the desktop's own settings, is reported as `Off`. With the setting on, Task 16's `reconcile` (on + `Off` → `SetAutostart(true)`) then rewrites the entry at the next start and undoes the user's choice there. Windows treats the same case as `DisabledBySystem` and leaves it. This matches the spec's wording ("not Hidden" → not On) and the original's state function, so it does not block. Consider reporting a client-written entry with `Hidden=true` as `DisabledBySystem`, or open a follow-up for Task 33 / 38 to decide. - **minor**: `crates/fluxer-platform/src/autostart/linux.rs` `disable`. An entry the user added (no marker) is reported `On` and kept, so with the setting off, `reconcile` emits `SetAutostart(false)` on every reconcile and it does nothing. This is harmless and documented as a deliberate deviation. Task 33 / 38 should show it as on, set from outside the client, rather than spin on it. - **minor** (note): Flatpak (Background portal, `Autostart.ts:440-470`) is not implemented. It is out of scope here (NP) and listed in the PR. Hand checks for Charles on Windows (from the PR): the Run value appears in Task Manager → Startup apps. After it is turned off there, the client shows "disabled in Windows settings" and does not re-enable it. **Verdict: APPROVED.** There are no blocking findings, and the local gate is green at 73bcf24d.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 15:44:38 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.