Skip to content

fix(app): keep an open request until the window is connected - #151

Merged
bketelsen merged 2 commits into
mainfrom
irulan/open-message-after-reconnect
Oct 30, 2026
Merged

bketelsen merged 2 commits into
mainfrom
irulan/open-message-after-reconnect

Conversation

@frostyard-machines

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

Copy link
Copy Markdown
Contributor

Fixes #149.

Cause

After a flatpak update, a click on a notification of the old maild runs the new launcher (frostmail-open, then frostmail --open-message <id> from the latest deployment). The launcher stops the old maild (mailctl shutdown), starts the new one, waits until it answers (about 0.2 s; maild.log in the gate: rpc.shutdown: stopping at 15:13:16.036, maild started at 16.235), and runs frostmail-app --open-message <id>. The single-instance plugin hands it to the running window as the open-message event.

But when the old maild stopped, the window's connection closed: Session (app/src/data/session.tsx) drops its client, unmounts MainWindow, and retries after RETRY_MS (1 s). The open-message listener lived in MainWindow (watchOpenRequests), so the event arrived with no listener and was lost. startup_message holds only the first launch's request, so the remount did not get it either. A later click, with no maild change, worked: the window stayed connected.

A second race had the same result: an event that arrives before the window sees the close fails in message.summaries and was dropped.

Fix

app/src/app/openMessage.ts: the listener and the startup_message call now start once per webview and stay. The latest request (a new object for each request) waits in the module until a client is watched, and is cleared after it opens or after maild refuses it. A lookup applies only while its request is still the pending one, so a late answer for an older request changes nothing. A failure with a lost connection (RPCError with CodeNotConnected from JsonRpcSession, or a plain error from a failed send) keeps it for the next client. docs/design/desktop.md (One app instance) says so.

Tests

app/src/app/openMessage.test.ts, 9 tests (the listen mock removes its handler on unlisten; deferred lookups settle by hand). On the old openMessage.ts, 7 fail: the #149 case (an event with no listener), the lost connection, one startup_message across clients, a newer request replacing an older one, reversed completion, A → B → A, and a client change during a delivery.

  • make ui-check (nsl): passes, 1405 tests.
  • make check: passes.

Coder: github-copilot/claude-sonnet-5.5.

Cross-review: openai/gpt-6.1-sol. The initial review at 02a31fd found 1 blocker (an older request's late lookup could replace a newer selection) and 1 test gap; both fixed in 0837252. Re-review 1 at 083725250ea5ec05292df3112eb7a001107419c0 (base 71b37f4): Ready, Blocking: none.

Not checked on a real desktop: the update-then-click sequence of the clean-install gate (plan 0013, item 5) was not run again.

A click on a notification of the old maild after a Flatpak update runs
the new launcher, which replaces maild and then hands --open-message to
the running window. The window had dropped its client when the old maild
stopped, and with it MainWindow and the open-message listener, so the
event was lost and the message never opened.

The listener and the startup request now live as long as the webview.
The latest request waits until a client is connected, and a request
that fails because the connection broke is kept for the next client.

Fixes #149
A late answer for an older request could select its message after a
newer one opened. Each request is now an object, and a lookup applies
only while its request is still the pending one. The tests remove a
listener on unlisten and settle lookups by hand.

Refs #149
@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Oct 30, 2026
@bketelsen
bketelsen merged commit 94b9230 into main Oct 30, 2026
11 checks passed
@bketelsen
bketelsen deleted the irulan/open-message-after-reconnect branch October 30, 2026 16:13
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.

Flatpak: after an update, a click on the old build's notification replaces maild but does not open the message

2 participants