Skip to content

feat(flatpak): a setting keeps notesd running without a window, or not (G2) - #110

Merged
bketelsen merged 6 commits into
mainfrom
irulan/g2-background-setting
Oct 28, 2026
Merged

bketelsen merged 6 commits into
mainfrom
irulan/g2-background-setting

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Plan 0008, gap G2 (Brian's day line 7, T377a).

What. In the Flatpak, Settings gains a Background section:

  • Keep syncing when no window is open (toggle, On by default = today's behaviour). Its description says what Off does: notesd stops when the last window closes and does not start at login; notes sync only while a window is open.
  • Desktop permission: what the Background portal last answered. Refused: "The desktop stops notesd about 45 seconds after the last window closes, and at login. Allow it in GNOME Settings, Apps, Frostnotes, Run in Background, then open Frostnotes again." (the GNOME 48 finding of 2026-10-27). No answer: "Not known: the desktop did not answer (…)". After a change: "Asking the desktop…" until the answer to that change is in.

How (ADR-0033, Proposed):

  • Off is the file $XDG_CONFIG_HOME/frostnotes/background-off. The shell (app/src-tauri/src/background.rs, commands background_get, background_set) writes it.
  • The helper (frostnotes-request-background) reads the file itself, under an exclusive lock on background.lock, and asks the portal for autostart only while it is absent; it asks again (at most 3 requests) if the setting changed meanwhile. It writes the answer atomically to $XDG_STATE_HOME/frostnotes/background.json.
  • frostnotes --background (the autostart command line, also of older entries) starts no notesd while the off file exists. A window's launcher starts notesd with the new frostnotes --notesd.
  • With Off, the primary app instance runs notesctl shutdown (bounded at 35 s) on RunEvent::Exit. A second launch exits in tauri-plugin-single-instance's setup before the app's setup marks the primary, so it never stops notesd.
  • The shell bumps a counter (background-gen) after each change; each helper reads it under the lock before it reads the setting, and every answer, failures included, carries it. Settings polls every 2 s while open and ends "Asking the desktop…" on an answer with a generation at or above its change's.
  • serde_json becomes a direct dependency (already locked at 1.0.151; cargo-sources.json unchanged).

Tests. Rust unit tests (paths, the off file, the counter, the answer's parse); Vitest (the section, each portal state, the polling and generations); the Flatpak smoke test (the helper is started with no arguments; window spawns use --notesd; --background with the off file starts no notesd).

Known limit (accepted by Brian, T394c): when a helper cannot take background.lock (for example, a read-only state directory), it writes its failure without the lock and can replace a newer answer, so "Desktop permission" can stay on "Asking the desktop…" until Settings closes. Off itself is not affected. Tracked in #112.

Not done here. Plan 0008 Phase 3, item 4 in each state, on a real desktop (the build sandbox has no portal).

Review. Cross-review by openai/gpt-6.1-sol: 1 review, 3 re-reviews and 1 extra re-review authorized by Brian (T394a); every blocking point fixed except the known limit above.

Coder: deepseek/deepseek-flash (subagent); parent: Irulan.

…t (G2)

Settings gains a Background section in the Flatpak: "Keep syncing when no
window is open" (On by default), and what the desktop's Background portal
last allowed. Off is the file $XDG_CONFIG_HOME/frostnotes/background-off:
the launcher then asks the portal with --no-autostart, so the portal drops
the autostart entry, and the app shell stops notesd (notesctl shutdown)
when the primary instance exits. The helper writes the portal's answer to
$XDG_STATE_HOME/frostnotes/background.json for the window to show.

ADR-0033 (Proposed) records the decision. Plan 0008: G2 built; Phase 3's
item 4 in each state is still to run on a real desktop.
…ows the new answer (cross-review)

- request-background.py reads the off file itself, under an exclusive lock
  held until its answer is written, and asks again (at most 3 requests)
  when the setting changed meanwhile; no --no-autostart argument.
- frostnotes --notesd starts notesd for a window; --background, the
  autostart's command line (also of older entries), starts none while the
  off file exists.
- Settings shows "Asking the desktop…" and reads background.json every
  second, at most 30 s, until a new answer is in.
…hile open (cross-review)

background_set names each change (FROSTNOTES_BACKGROUND_REQUEST), the
helper writes that name into background.json, and Settings says "Asking
the desktop…" until the answer to its own change is in. While the dialog
is open it reads the answer every 2 s with no limit, so a late answer, the
launcher's included, shows; no old answer returns after a timeout.
…s-review)

The shell writes the setting, then notes the time (since); each helper
notes askedMs under the lock just before it reads the setting. An answer
with askedMs > since read the new setting, whichever helper wrote it, so
a later helper's answer no longer leaves Settings asking forever.
…s included (cross-review)

The shell bumps background-gen after it writes the setting; each helper
reads it under the lock just before it reads the setting, and every
outcome, a failure's included, carries it. Settings waits for an answer
with generation >= its change's, so neither a clock that moves backward
nor a helper that fails early leaves the row asking forever.
@bketelsen
bketelsen merged commit 7c9eedb into main Oct 28, 2026
9 checks passed
@bketelsen
bketelsen deleted the irulan/g2-background-setting branch October 28, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants