Skip to content

Offer updates in a window, and install without cutting anyone off - #28

Merged
fylorn merged 2 commits into
mainfrom
feat/update-prompt
Sep 16, 2026
Merged

fylorn merged 2 commits into
mainfrom
feat/update-prompt

Conversation

@fylorn

@fylorn fylorn commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What this changes

  • Update checking is on by default (two minutes after launch, then every six hours).
  • A newer version opens a small update window, instead of a notification that disappears. What it offers depends on how the app was installed:
    • Downloaded from the web: one press, then no more questions. The app downloads the update, verifies it, waits for the gateway's in-flight requests to finish, installs, and restarts. After the restart a notice says which version it came from.
    • Installed with Homebrew: the full command, and a button that copies it. The app never replaces itself.
  • Settings › 更新 keeps the switch and 立即检查; a manual check that finds something opens the same window.
  • Pins tw-api v0.1.1 for Status.in_flight; the bundled core follows automatically.

Why

Waiting for in-flight requests is the point of the one-press install. A restart cuts every stream still producing output: a Claude Code task mid-response loses that output and has to send the request again. The app polls core's new in_flight count and restarts in the gap between requests. The wait is capped at three minutes, so an update still happens under continuous load. The update is downloaded first and installed last, so while it waits, the files on disk never belong to a different version than the one running.

Homebrew installs ask the tap, not the release page. latest.json knows about a release the moment it is published, while the cask only follows once the tap's bump job runs (now hourly). Prompting as soon as the release page changes would hand users a brew upgrade with nothing to install. The command starts with brew update because brew upgrade refreshes taps on its own at most once a day (HOMEBREW_AUTO_UPDATE_SECS, default 86400 — read from Homebrew's source).

The copy happens in Rust (tauri-plugin-clipboard-manager, behind a command that can only copy that one string). The web clipboard API depends on the webview granting permission, and when it is refused the button silently does nothing. Tested in the preview: writeText was refused, and nothing happened. If the native write ever fails, the window selects the command and says to press ⌘C.

Prompt pacing. A new version is offered immediately. A version dismissed with 稍后 is offered again after a day, not at the next six-hour check. Development builds don't check on their own.

Two bugs fixed along the way:

  • Closing the update window made the app an accessory (no Dock icon) even with the main window still open. It now does that only when the last window closes.
  • The restart raced the old core for its lock (found end to end; details below). Supervisor::stop_and_wait stops the core and waits for it to exit first. run_once now returns Next::{Again, SafeMode, Stop} — with a bool, a deliberate stop would have been read as "go to safe mode".

How it was checked

End to end on a real bundle (built at 2026.9.1 with this code, updating to the published 2026.9.2). Temporary, uncommitted patches shortened the first check to five seconds and pressed the window's real button from its own page.

  • Standalone, with a stream in flight. A fake upstream sent one SSE event and then held the connection for 30 seconds. The app downloaded the update, logged 「网关手上还有 1 个请求,等它们结束再重启」, and the client received message_stop at +33s — not cut. The restart came 23 seconds after the wait began; the bundle became 2026.9.2.
  • The restart race. On the first run the new core failed twice with 「已经有一个 twcore 在跑」: the old core only noticed its parent was gone a second later. After the fix: SIGTERM, the old core exited 0 within 8 ms, and the new gateway was listening under a second later with no failures.
  • Homebrew. The same build was forced to identify as a Homebrew install. It read 2026.9.2 from the tap, opened the window, and the copy button put exactly brew update && brew upgrade --cask thinkwatch-lite on the system clipboard. The bundle stayed at 2026.9.1. (The clipboard was empty before and was emptied again after.)
  • Post-update notice. A marker from an older version is consumed at startup; a same-version marker is dropped silently.
  • The copied command, run for real: brew update && brew upgrade --cask thinkwatch-lite upgraded this machine's Homebrew install from 2026.9.1 (zip) to 2026.9.2 (disk image) — no quarantine attribute, and codesign --verify passes.

The window, visually. Rendered in a browser with Tauri's IPC mocked, at the real 480px width, in light and dark: idle, downloading, waiting, failed, Homebrew, copied, and copy-failed. That pass found that the command was truncated inside an input with an embedded button (…--cask thinkwatc), so copying moved to the action row and the window widened from 460 to 480px. Measured: no overflow.

Tests:

  • update.rs: prefs default on, and an explicit false still reads back as false; the cask version parser against the real cask format; numeric version comparison (2026.9.10 > 2026.9.9); prompt pacing; the command starts with brew update.
  • supervisor: a core stopped for exit is not restarted, including a SIGTERM round trip against a real child process; a requested restart still comes back. Removing the stop check fails with Restarting { attempt: 1 }.
  • updateFlow.test.ts: no install button for Homebrew or dev builds; step text never invents a total size.

Gates: cargo fmt --check, cargo clippy --all-targets -D warnings, cargo test (77), pnpm typecheck, pnpm test (68), pnpm build.

Related

🤖 Generated with Claude Code

fylorn and others added 2 commits September 16, 2026 19:01
Checking for updates is now on by default. When there is a newer version,
a small window says so instead of a notification that disappears; what
it offers depends on how the app was installed.

Downloaded from the web: one press installs. The app downloads, verifies
the signature, waits for the gateway's in-flight requests to finish,
replaces itself, and restarts, then says which version it came from.
Waiting is the point: a restart cuts every stream still producing
output, so a Claude Code task mid-response would lose that output and
have to send the request again. The count comes from core 0.1.1's
`in_flight`, is polled until it reaches zero, and is capped at three
minutes so an update still happens under continuous load. The download
comes first and the bundle is replaced last, so the files on disk never
belong to a different version than the one running while it waits.

Installed with Homebrew: the window gives the command and copies it,
and the app never replaces itself. It asks the tap rather than the
release page whether there is something newer, because the release page
knows first — prompting then would give a `brew upgrade` with nothing
to install. The command starts with `brew update`, since `brew upgrade`
refreshes taps at most once a day on its own. The copy happens in Rust:
the web clipboard API is refused in some webviews, and refused means a
copy button that silently does nothing.

A dismissed version is offered again after a day, not at the next
six-hour check. A newer version is offered immediately. Development
builds do not check on their own.

Closing the update window no longer turns the app back into a menu-bar
accessory while the main window is still open.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Running the update end to end on a real bundle showed the restart race:
the app exited, the new app started and spawned a core, and the old core
was still holding the lock — it only notices its parent is gone about a
second later. The new core failed twice ("已经有一个 twcore 在跑") before a
third attempt stuck. The gateway was down a second longer than it needed
to be, and every update left two error blocks in the log.

`Supervisor::stop_and_wait` sends SIGTERM and waits for the child to
actually exit, with a SIGKILL fallback, before the app restarts.

That needed a way to say "stopped on purpose, do not start another".
`run_once` returned a bool, and `false` meant "go to safe mode" to the
supervise loop — a deliberate stop would have started a safe-mode core
to fight over the lock and brought the main window up over a restarting
app. It now returns `Next::{Again, SafeMode, Stop}`, and the stop check
comes before any crash accounting.

Same scenario after the fix: SIGTERM, core exits 0 within 8 ms, the new
app's first core binds the port under a second later, nothing fails.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for the PR. One thing before review: this targets main, and it should target dev.

main is a release-only line — branch-protected, linear history, and every commit on it is a tagged release snapshot. Routine work lands on dev and reaches main with the next release. GitHub pre-filled main here because it is the default branch, so this is our defaults being unhelpful rather than anything you did wrong.

No need to close and reopen: click Edit next to the PR title and change the base branch to dev. The commits and the discussion carry over.

See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract.

@fylorn
fylorn merged commit fbba8b8 into main Sep 16, 2026
3 checks passed
@fylorn
fylorn deleted the feat/update-prompt branch September 16, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant