Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
fix(macos): keep sampling the title bar color while the page is hidden
Tw93ed2a2d4952a9
diff --git a/.claude/rules/tauri-runtime.md b/.claude/rules/tauri-runtime.mdindex b6158f76..49409338 100644--- a/.claude/rules/tauri-runtime.md+++ b/.claude/rules/tauri-runtime.md@@ -12,7 +12,7 @@ paths:- A page's `alert()`, `confirm()` and `prompt()` show nothing in a WKWebView unless its UI delegate implements the three `runJavaScript…Panel` methods, and Wry's does not (through 0.57.2): `alert` returned at once, `confirm` returned false and `prompt` null in a millisecond, so a site that confirms before logging out did nothing (a user's report, 2026-11-17; WebView2 and WebKitGTK show their own). `src-tauri/src/app/script_dialogs.rs` adds the three methods to the delegate's class where it lacks them, for every webview from `build_window`, and then sets the same delegate on the webview again: WebKit records which methods a delegate answers when it is set, and without the reset the added methods are never called. Each panel is an NSAlert sheet on the page's window whose completion calls WebKit's handler exactly once (WebKit raises on zero or two calls), which keeps the script waiting as a browser does. The sheet goes on the window even when it is hidden, as a closed window is with hide-on-close: AppKit then shows the window with its sheet (measured: a window hidden with Cmd+W came back on screen when its page called `confirm()`), where an app-modal panel would float over whatever else the user is doing; only a webview with no window falls back to `runModal`. Cancel carries an explicit Escape key equivalent, because AppKit gives Escape only to a button titled Cancel and the Chinese title is 取消. Verify on a real bundle with a page that calls all three and writes what it got back: OK gives `true`, Cancel `false`, a prompt its field's text or `null`, and each wait is seconds, not a millisecond. Send the keys with a CGEvent tool of your own: Escape must give `false` and `null`, Return `true`. Cover it with `tests/unit/macos-script-dialogs.test.ts` and the `script_panel_encodings_match_their_selectors` Rust test, which keeps each selector's colons and its type encoding in step.- Passkeys on macOS (2026-11-19): WKWebView refuses WebAuthn in an app that neither lists the site under `webcredentials` nor holds Apple's browser entitlement, which an ad hoc signed app never can, so `create` and `get` failed in 30 ms with `NotAllowedError`. `src-tauri/src/inject/passkey.js` (main frame; not incognito, nor with `ignore_certificate_errors`, where a stand-in on the network would get a signature for the real origin; `passkey::enabled`) hands a `publicKey` request to the `pakePasskey` `WKScriptMessageHandlerWithReply` in `src-tauri/src/app/passkey/macos.rs`, which takes the origin from WebKit's `WKFrameInfo` (main frames only, never from the page), checks the rpId against the public suffix list (`resolve_rp_id`), makes a non-permanent Secure Enclave P-256 key gated by `userPresence` (Touch ID, or the login password), keeps its token (`toid`) in `<app data>/passkeys.json`, and writes `none` attestation itself; no keychain entitlement is needed. The passkeys stay in that app on that Mac, outside iCloud Keychain; a sign-in with none shows a sheet saying so. Any process of the same user can read the store and sign after a prompt that names that process, as with Chrome's profile authenticator. Only the key window of the active app may start a ceremony, and a Mac without an enclave refuses without a sheet. One ceremony runs at a time under a token (`OWNER`); leaving the page (`pagehide`) cancels it like an abort; the page's abort or timeout (5 minutes when the site gives none) sends `cancel`, which counts only from the webview that started it, frees it at once, invalidates the LAContext and ends the sheet; a key made after that is not saved; a sheet left on a closed or close-hidden window (not a minimized one, nor while the app is hidden) gives way to the next request, since the sheet keeps its `Reply` alive. The credential object must read as a browser's: its fields are enumerable getters with no setter and its methods writable, one prototype step up (`shaped`), so `Object.keys` is empty, `for...in` lists the fields (FIDO's webauthn-demo serialises that way) and a page may replace a method, because GitHub's webauthn-json assigns `credential.toJSON = ...` in strict mode and a read-only property made every registration fail after the key was saved (found on github.com with a probe that reported `unhandledrejection`; GitHub's error said only "Passkey registration failed"). Verify on a real bundle: a localhost page backed by py_webauthn for register, sign-in with and without `allowCredentials`, the account picker, cancel then retry; then add and use a passkey on github.com. Cover it with the `app::passkey` Rust tests and `tests/unit/passkey-bridge.test.js`.- `navigation_buttons` is a runtime-only macOS window field (no CLI flag; the paid apps set it, off by default): `src-tauri/src/app/nav_buttons.rs` adds Back and Forward to the title bar in a leading accessory beside the traffic lights, for people with a plain mouse who have neither the swipe nor Cmd-[. The buttons call `history_step`, the native step the Navigation menu uses, so they work on a blank error page; their action lives on the window's class as `tab_bar.rs`'s does. Enabled state follows the WKWebView's `canGoBack` and `canGoForward` by key-value observing; do not poll. The webview owns the observer through an associated object, which means the observer drops only while the webview is deallocating, when a weak reference to it already reads nil: removal in `Drop` never runs, so the observer unregisters on `NSWindowWillCloseNotification`, behind one flag because removing an unregistered observer raises (`auth.rs`'s delegate still has only the `Drop` removal). Alignment is to ink, checked on a 2x capture: each chevron's middle goes on the close button's centre line, read from `standardWindowButton:` (the lights sit 16 points down a 32 point bar on macOS 26) and from the cell's `imageRectForBounds:` (NSButton sets a 16 point image half a point above a 22 point button's middle), and redone on resize and around full screen. The chevrons are drawn, not `chevron.left`, because that symbol sits on a text baseline 1.5 points high. Labels are the system's own, 返回 and 前进, 上一頁 and 下一頁, through `UiLanguage`. A real-bundle check measures the rows of the red light and of each chevron in a `screencapture -l` PNG, whose centres must be equal, and opens then closes a Cmd+N window with the app still running. Under `hide_title_bar` the buttons sit over the page beside the lights, and the per-site `immersive` paddings in `style.js` clear only the lights' width. Cover it with `tests/unit/macos-navigation-buttons.test.ts` and the `navigation_buttons_are_opt_in` Rust test.-- `transparent_title_bar` is a runtime-only macOS window field (no CLI flag; the paid apps set it): Tauri's `Transparent` title bar keeps the page below the bar, and `src-tauri/src/inject/title_bar.js` paints the window background with the page's top-edge color through `set_title_bar_color`. `hide_title_bar` keeps precedence and its overlay behavior. The color is the majority of three top-edge samples, resolved through a canvas so `oklch()`/`color()` values work; do not skip sampling for `document.hidden`, or windows revealed after load stay uncolored. Cover it with `tests/unit/title-bar-color.test.js`; when checking a real bundle, window captures carry the display profile, so convert the sRGB page color before comparing pixels.+- `transparent_title_bar` is a runtime-only macOS window field (no CLI flag; the paid apps set it): Tauri's `Transparent` title bar keeps the page below the bar, and `src-tauri/src/inject/title_bar.js` paints the window background with the page's top-edge color through `set_title_bar_color`. `hide_title_bar` keeps precedence and its overlay behavior. The color is the majority of three top-edge samples, resolved through a canvas so `oklch()`/`color()` values work; do not skip sampling for `document.hidden`, or windows revealed after load stay uncolored: only the 1.5 s poll rests while the page is hidden, page events still sample, and the poll picks up again once the page shows, with or without a `visibilitychange` event. Cover it with `tests/unit/title-bar-color.test.js`; when checking a real bundle, window captures carry the display profile, so convert the sRGB page color before comparing pixels.- A runtime app can carry its own pages (2026-11-25): with `url_type: "local"` the window's `url` names a file inside `pake-runtime/site/` (`tool.html`, `index.html`), and `apply_runtime_override` sets `PakeConfig::runtime_site` only when that file exists, refusing an empty, absolute or `..` path. `run_app` then swaps the context's assets for `src-tauri/src/app/local_site.rs`, which reads files from that folder on each request and refuses any path, `..` or symbolic link, that resolves outside it, so the pages keep the origin and local-page behaviour of a CLI local app (`tauri://localhost`, `http://tauri.localhost` on Windows) without a compiler. Covered by `runtime_override_serves_a_local_window_from_its_site_folder` and the `local_site` tests; measured on the test Mac with a page, a script in a subfolder, a `fetch` of a JSON file and localStorage across a relaunch.- `site_styles` is a runtime-only window field (no CLI flag; default true): the paid apps write false when the app carries a browser extension that restyles its site (Minimal Theme for Twitter on X), and `style.js` then leaves out that site's `content` rules, keeping the global and `immersive` ones. On X the runtime's 700 px column, `!important` under `#react-root`, overrode the extension's own width setting. `page_config` in `window.rs` forces it back to true wherever the app's extensions do not run (no `pake-runtime/extensions`, macOS before 15.4, Linux), so a site never loses both. Covered by `site_styles_stay_on_unless_the_builder_turns_them_off`, `site_styles_turn_off_only_where_extensions_run` and `tests/unit/site-styles.test.js`.- Window/runtime options with platform-sensitive behavior include `--incognito`, `--new-window`, `--min-width`, `--min-height`, `--maximize`, multi-window behavior, notification click handling, and Linux/Wayland WebKit compositing defaults.diff --git a/src-tauri/src/inject/title_bar.js b/src-tauri/src/inject/title_bar.jsindex 7d42b7d9..85804d5e 100644--- a/src-tauri/src/inject/title_bar.js+++ b/src-tauri/src/inject/title_bar.js@@ -8,7 +8,6 @@let lastSent = "";let pending = 0;let warned = false;- let hasSampled = false;// A 1x1 canvas resolves any CSS color the engine supports (rgb, oklch,// color(), named) into sRGB bytes, so modern color syntax is not missed.@@ -72,9 +71,7 @@function update() {pending = 0;- if (hasSampled && document.hidden) return;const color = pageTopColor() || themeColor();- hasSampled = true;if (!color) return;const key = `${color.red},${color.green},${color.blue}`;if (key === lastSent) return;@@ -91,7 +88,6 @@}function schedule() {- if (hasSampled && document.hidden) return;if (!pending) pending = setTimeout(update, 150);}@@ -115,8 +111,10 @@.matchMedia?.("(prefers-color-scheme: dark)")?.addEventListener?.("change", schedule);// Single-page apps repaint their header without touching html or body.+ // Only this poll rests while the page is hidden; events still sample, so a+ // window revealed after load is colored.setInterval(() => {- if (hasSampled && document.hidden) return;+ if (document.hidden) return;schedule();}, 1500);}diff --git a/tests/unit/title-bar-color.test.js b/tests/unit/title-bar-color.test.jsindex 270cf5e2..aa00503d 100644--- a/tests/unit/title-bar-color.test.js+++ b/tests/unit/title-bar-color.test.js@@ -129,6 +129,9 @@ function loadTitleBar({for (const fn of docListeners.visibilitychange || []) fn();flushTimer();},+ setHiddenQuietly(nextHidden) {+ context.document.hidden = nextHidden;+ },fireWindowEvent(type, next) {if (next) current = next;for (const fn of winListeners[type] || []) fn();@@ -231,4 +234,26 @@ describe("macOS transparent title bar color", () => {expect(calls).toHaveLength(3);expect(calls[2].args).toEqual({ red: 12, green: 24, blue: 48 });});++ it("keeps sampling on page events while hidden, so a window revealed after load is colored", () => {+ const white = element("255,255,255,255");+ const dark = element("24,24,28,255");+ const navy = element("12,24,48,255");+ const { calls, repaint, fireWindowEvent, tickInterval, setHiddenQuietly } =+ loadTitleBar({ columns: [white, white, white], hidden: true });+ expect(calls).toHaveLength(1);++ // The page finishes loading and repaints while its window is still hidden.+ fireWindowEvent("load", [dark, dark, dark]);+ expect(calls).toHaveLength(2);+ expect(calls[1].args).toEqual({ red: 24, green: 24, blue: 28 });+ repaint([navy, navy, navy]);+ expect(calls).toHaveLength(3);++ // Revealed without a visibilitychange event: the poll resumes on its own.+ setHiddenQuietly(false);+ tickInterval([white, white, white]);+ expect(calls).toHaveLength(4);+ expect(calls[3].args).toEqual({ red: 255, green: 255, blue: 255 });+ });});