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
feat: let a runtime app turn its site tweaks off for an extension that restyles the site
Tw93025016d721c0
diff --git a/.claude/rules/tauri-runtime.md b/.claude/rules/tauri-runtime.mdindex ed7fd227..2691ecd6 100644--- a/.claude/rules/tauri-runtime.md+++ b/.claude/rules/tauri-runtime.md@@ -12,6 +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.- `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.+- `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.- `--incognito` intentionally trades persistence for clean private sessions; be careful around login, cookies, local storage, and WeChat-style WebView detection.- Web apps restore the main window's last URL by default. `--no-restore-last-url` / config `restoreLastUrl: false` disables both reading and saving that URL without changing cookie or local-storage persistence. Legacy native configs missing `restore_last_url` default to true. Startup and close/exit persistence share `WindowConfig::remembers_last_url`, which excludes incognito sessions and local pages. Verify with `cargo test --lib` and `node tests/integration/last-url.mjs` (real macOS WebView).diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rsindex a1a9f3c8..37080f7a 100644--- a/src-tauri/src/app/config.rs+++ b/src-tauri/src/app/config.rs@@ -45,6 +45,12 @@ pub struct WindowConfig {/// traffic lights. Off unless the app asks for them.#[serde(default)]pub navigation_buttons: bool,+ /// The per-site tweaks `style.js` puts on a few sites, such as X's+ /// centred column. Set by the runtime builder, not a CLI flag: an app+ /// whose extension restyles its site turns them off so the two do not+ /// fight, which takes effect only where the extensions run.+ #[serde(default = "default_site_styles")]+ pub site_styles: bool,#[serde(default = "default_zoom")]pub zoom: u32,#[serde(default)]@@ -63,6 +69,10 @@ fn default_restore_last_url() -> bool {true}+fn default_site_styles() -> bool {+ true+}+#[cfg(any(windows, test))]impl WindowConfig {pub fn password_autosave_enabled(&self) -> bool {@@ -285,6 +295,19 @@ mod tests {assert!(asked.navigation_buttons);}+ #[test]+ fn site_styles_stay_on_unless_the_builder_turns_them_off() {+ let window = config_for("https://example.com").windows.remove(0);+ let mut window = serde_json::to_value(window).unwrap();+ window.as_object_mut().unwrap().remove("site_styles");+ let legacy: WindowConfig = serde_json::from_value(window.clone()).unwrap();+ assert!(legacy.site_styles);++ window["site_styles"] = false.into();+ let off: WindowConfig = serde_json::from_value(window).unwrap();+ assert!(!off.site_styles);+ }+#[test]fn transparent_title_bar_is_opt_in_and_yields_to_the_overlay() {let mut window = config_for("https://example.com").windows.remove(0);diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rsindex 4bd921fb..6d40caf4 100644--- a/src-tauri/src/app/window.rs+++ b/src-tauri/src/app/window.rs@@ -1,4 +1,4 @@-use crate::app::config::PakeConfig;+use crate::app::config::{PakeConfig, WindowConfig};#[cfg(target_os = "windows")]use crate::app::navigation::set_password_autosave;#[cfg(not(target_os = "windows"))]@@ -807,7 +807,7 @@ fn build_window(let config_script = format!("window.pakeConfig = {}",- serde_json::to_string(&window_config).unwrap_or_else(|_| "{}".to_string())+ page_config(window_config, extensions_run(config)));// A host-provided marker avoids relying on a site's overridden user agent.#[cfg(target_os = "windows")]@@ -1595,3 +1595,47 @@ mod proxy_arg_tests {#[cfg(feature = "native-download-probe")]#[path = "native_download_smoke.rs"]mod native_download_smoke;++/// Whether the app's extensions load in this webview: on Windows whenever the+/// app carries one, on macOS only from 15.4, where WebKit runs them.+fn extensions_run(config: &PakeConfig) -> bool {+ if config.runtime_extensions.is_none() {+ return false;+ }+ #[cfg(target_os = "macos")]+ return crate::app::extensions::supported();+ #[cfg(target_os = "windows")]+ return true;+ #[cfg(not(any(target_os = "macos", target_os = "windows")))]+ return false;+}++/// `window.pakeConfig` for the page. An extension that restyles the site turns+/// the runtime's own tweaks off (`site_styles`), but where it does not run they+/// stay, so the site never ends up with neither.+fn page_config(window_config: &WindowConfig, extensions_run: bool) -> String {+ let mut value = serde_json::to_value(window_config).unwrap_or_default();+ if !extensions_run {+ if let Some(object) = value.as_object_mut() {+ object.insert("site_styles".into(), true.into());+ }+ }+ serde_json::to_string(&value).unwrap_or_else(|_| "{}".to_string())+}++#[cfg(test)]+mod site_style_tests {+ use super::page_config;+ use crate::app::config::PakeConfig;++ #[test]+ fn site_styles_turn_off_only_where_extensions_run() {+ let config: PakeConfig = serde_json::from_str(include_str!("../../pake.json")).unwrap();+ let mut window = config.windows[0].clone();+ window.site_styles = false;+ let page =+ |run| serde_json::from_str::<serde_json::Value>(&page_config(&window, run)).unwrap();+ assert_eq!(page(true)["site_styles"], false);+ assert_eq!(page(false)["site_styles"], true);+ }+}diff --git a/src-tauri/src/inject/style.js b/src-tauri/src/inject/style.jsindex c6b4e087..9782b2ce 100644--- a/src-tauri/src/inject/style.js+++ b/src-tauri/src/inject/style.js@@ -349,6 +349,10 @@ window.addEventListener("DOMContentLoaded", (_event) => {const matchedSites = siteStyles.filter(({ hosts }) =>hosts.some((host) => hostname === host || hostname.endsWith(`.${host}`)),);+ // An app whose extension restyles the site (`site_styles: false`, set by+ // the runtime builder) keeps only the window rules: the content tweaks+ // would fight the extension's own layout.+ const siteStylesOn = window["pakeConfig"]?.site_styles !== false;const siteCSS = (key) =>matchedSites.map((site) => site[key] || "").join("\n");@@ -363,7 +367,10 @@ window.addEventListener("DOMContentLoaded", (_event) => {}};- injectStyle(globalContentCSS + siteCSS("content"), "pake-content-style");+ injectStyle(+ globalContentCSS + (siteStylesOn ? siteCSS("content") : ""),+ "pake-content-style",+ );// Top spacing adapts to head-hiding scenariosconst isMac = /Mac/i.test(navigator.userAgent);diff --git a/tests/unit/site-styles.test.js b/tests/unit/site-styles.test.jsindex df90fb6c..0dfa5c24 100644--- a/tests/unit/site-styles.test.js+++ b/tests/unit/site-styles.test.js@@ -10,7 +10,10 @@ const source = fs.readFileSync("utf-8",);-function injectedStyles(hostname, { mac = true, immersive = true } = {}) {+function injectedStyles(+ hostname,+ { mac = true, immersive = true, pakeConfig = {} } = {},+) {const styles = {};let onReady;runInNewContext(source, {@@ -18,7 +21,7 @@ function injectedStyles(hostname, { mac = true, immersive = true } = {}) {hasImmersiveHeader: () => immersive,window: {location: { hostname },- pakeConfig: {},+ pakeConfig,__PAKE_INJECT_STYLE__: (css, id) => {styles[id] = css;},@@ -73,4 +76,20 @@ describe("site styles", () => {injectedStyles("chat.deepseek.com", { immersive: false }).immersive,).toBe("");});++ it("leaves a site's content rules to an extension that restyles it", () => {+ const off = injectedStyles("x.com", { pakeConfig: { site_styles: false } });+ expect(off.content).toContain("html::-webkit-scrollbar");+ expect(off.content).not.toContain("#react-root");+ // The window's own rules stay: the drag strip and the traffic-light room.+ expect(off.immersive).toContain("#pake-top-dom");+ expect(+ injectedStyles("chat.deepseek.com", {+ pakeConfig: { site_styles: false },+ }).immersive,+ ).toContain("._5a20a69");+ expect(+ injectedStyles("x.com", { pakeConfig: { site_styles: true } }).content,+ ).toContain("#react-root");+ });});