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: multi-window tray visibility and native webview navigation
Tw93476a0a62a805
diff --git a/AGENTS.md b/AGENTS.mdindex 26268134..5339a1bd 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -106,7 +106,8 @@ Proactive latent-bug sweeps use `.agents/skills/bugs/SKILL.md`. Pick one row and- Local app builds and test runs mutate tracked files as build state: `src-tauri/pake.json`, `src-tauri/tauri.conf.json`, `src-tauri/tauri.macos.conf.json`, and regenerated icons under `src-tauri/png/` and `src-tauri/icons/`. Before committing, `git restore` whatever you did not intentionally change; never let a feature or release commit absorb this churn.- Per-app optional fields in `default_app_list.json` currently take their defaults in Actions expressions in `release.yml` (`matrix.config.x || false` and the numeric ones), which works because every field so far is default-false or numeric. The first default-true field cannot use that path and must move its default into the jq read step: GitHub expressions cast both `null` and `false` to `0`, so `matrix.config.x != false` cannot express "default true" and would silently flip every app missing the field.- Windows taskbar icons can register blank when an autostarted app launches before Explorer's icon cache is ready (#1323). Every hidden-to-visible `window.show()` path (main or secondary: tray show/click, activation shortcut, single-instance activation, startup/page-load reveal, multi-window Cmd+N reveal) must call `reapply_window_icon` from `src-tauri/src/app/window.rs` (or go through `reveal_built_window` / `reveal_startup_window`, which already do). The helper reasserts both the small window icon and the large taskbar icon; a new show path without it regresses the bug.-- Multi-window home clones (`open_additional_window_safe`, labels `pake-N`) are built hidden and revealed via `reveal_built_window` on the first real page load (or a 3s fallback), matching the main-window blank-shell guard. OAuth/pop-up windows from `--new-window` stay immediately visible by design.+- Multi-window home clones (`open_additional_window_safe`, labels `pake-N`) are built hidden and revealed via `reveal_built_window` on the first real page load (or a 3s fallback), matching the main-window blank-shell guard. OAuth/pop-up windows from `--new-window` stay immediately visible by design. Tray Hide/Show, tray left-click, and the activation shortcut must act on **every** webview via `hide_all_app_windows` / `show_all_app_windows` / `toggle_all_app_windows` (not only label `"pake"`).+- Injected Linux/Windows shortcuts (Ctrl+R / [ / ]) call the `webview_navigate` IPC so reload and history use the platform webview API on blank error pages; do not route those shortcuts only through page `history` / `location`.- Download and toast paths must not hardcode `get_webview_window("pake")` when the action originates from a secondary window: IPC commands take the calling `WebviewWindow`, and `on_download` resolves toast by the event webview's label. Authenticated downloads should attach webview session cookies when available. Link-download heuristics prefer real file extensions, the `download` attribute, and `?download` / `?attachment` query hints; Cmd/Ctrl+click is navigation, not "save as"; do not re-add broad SPA roots such as `/assets/`, `/dist/`, `/files/`, or `/releases/` (see #1337, #1339).- macOS menu navigation must keep working on blank error pages: Reload uses native `WebviewWindow::reload`, Go Home uses `navigate` + `resolve_home_url`, Back/Forward use the platform WKWebView history API rather than page `eval`. Copy URL reads `window.url()` so it does not depend on a live JS document.- `.github/workflows/pake-cli.yaml` and `single-app.yaml` are public build surfaces that external users trigger from their own forks (see `docs/github-actions-usage*.md`). Changes there ship to outside users on push to `main`, independent of `V*` releases; treat them like public API, not internal CI.diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lockindex 75ba4aab..264a3766 100644--- a/src-tauri/Cargo.lock+++ b/src-tauri/Cargo.lock@@ -2584,6 +2584,7 @@ dependencies = ["tauri-plugin-single-instance","tauri-plugin-window-state","tokio",+ "webview2-com","windows-sys 0.61.2",]diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex 0c3d1e39..e5c82c72 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -48,6 +48,8 @@ windows-sys = { version = "0.61.2", features = ["Win32_UI_Shell","Win32_UI_WindowsAndMessaging",] }+# Used for native WebView2 GoBack/GoForward on error pages (no page JS).+webview2-com = "0.38"[features]# this feature is used for development builds from development clidiff --git a/src-tauri/src/app/invoke.rs b/src-tauri/src/app/invoke.rsindex 501e5f0a..20528508 100644--- a/src-tauri/src/app/invoke.rs+++ b/src-tauri/src/app/invoke.rs@@ -1,3 +1,4 @@+use crate::app::navigation::{history_step, reload_window};use crate::util::{check_file_or_append, get_download_message_with_lang, sanitize_download_filename, show_toast,MessageType,@@ -240,3 +241,27 @@ pub fn set_zoom(window: WebviewWindow, percent: f64) -> Result<(), String> {.set_zoom(factor).map_err(|e| format!("Failed to set zoom: {}", e))}++/// Native navigation for injected shortcuts (Linux/Windows Ctrl+R / [ / ]).+/// Blank error pages have no JS context, so page `history` / `location` calls+/// are no-ops; these use the platform webview API instead.+#[command]+pub fn webview_navigate(window: WebviewWindow, action: String) -> Result<(), String> {+ match action.as_str() {+ "reload" => {+ reload_window(&window);+ Ok(())+ }+ "back" => {+ history_step(&window, true);+ Ok(())+ }+ "forward" => {+ history_step(&window, false);+ Ok(())+ }+ other => Err(format!(+ "Unknown webview_navigate action '{other}' (expected reload|back|forward)"+ )),+ }+}diff --git a/src-tauri/src/app/menu.rs b/src-tauri/src/app/menu.rsindex 8287dff9..c9d63915 100644--- a/src-tauri/src/app/menu.rs+++ b/src-tauri/src/app/menu.rs@@ -1,7 +1,6 @@// Menu functionality is only used on macOS; the module is gated in app/mod.rs.+use crate::app::navigation::{history_step, reload_window};use crate::app::window::{open_additional_window_safe, MultiWindowState};-use objc2::msg_send;-use objc2::runtime::AnyObject;use std::io::Write;use std::process::{Command, Stdio};use tauri::menu::{AboutMetadata, Menu, MenuItem, PredefinedMenuItem, Submenu};@@ -258,33 +257,6 @@ fn focused_webview_window(app_handle: &AppHandle) -> Option<WebviewWindow> {.or_else(|| windows.get("pake").cloned())}-/// Drive WKWebView history without page JS. Blank error shells have no JS-/// context, so `window.history.back()` via eval is a no-op exactly when the-/// user is stuck (#1328 class).-fn webview_history_step(window: &WebviewWindow, selector: SelName) {- let _ = window.with_webview(move |webview| {- let ptr = webview.inner() as *mut AnyObject;- if ptr.is_null() {- return;- }- unsafe {- match selector {- SelName::Back => {- let _: *mut AnyObject = msg_send![ptr, goBack];- }- SelName::Forward => {- let _: *mut AnyObject = msg_send![ptr, goForward];- }- }- }- });-}--enum SelName {- Back,- Forward,-}-/// Copy text via pbcopy so it works when the page has no JS context (error/// shells) and when the Clipboard API is blocked by the site CSP.fn copy_text_to_pasteboard(text: &str) {@@ -310,7 +282,7 @@ pub fn handle_menu_click(app_handle: &AppHandle, id: &str) {"reload" => {if let Some(window) = focused_webview_window(app_handle) {// Native reload works on blank error pages where eval cannot.- let _ = window.reload();+ reload_window(&window);}}"toggle_devtools" => {@@ -340,12 +312,12 @@ pub fn handle_menu_click(app_handle: &AppHandle, id: &str) {}"go_back" => {if let Some(window) = focused_webview_window(app_handle) {- webview_history_step(&window, SelName::Back);+ history_step(&window, true);}}"go_forward" => {if let Some(window) = focused_webview_window(app_handle) {- webview_history_step(&window, SelName::Forward);+ history_step(&window, false);}}"go_home" => {diff --git a/src-tauri/src/app/mod.rs b/src-tauri/src/app/mod.rsindex 815f9629..0b28fc68 100644--- a/src-tauri/src/app/mod.rs+++ b/src-tauri/src/app/mod.rs@@ -4,5 +4,6 @@ pub mod config;pub mod invoke;#[cfg(target_os = "macos")]pub mod menu;+pub mod navigation;pub mod setup;pub mod window;diff --git a/src-tauri/src/app/navigation.rs b/src-tauri/src/app/navigation.rsnew file mode 100644index 00000000..43168984--- /dev/null+++ b/src-tauri/src/app/navigation.rs@@ -0,0 +1,81 @@+//! Cross-platform webview navigation that does not depend on page JS.+//! Blank error shells have no JS context, so `eval("history.back()")` and+//! `location.reload()` are dead exactly when the user is stuck.++use tauri::WebviewWindow;++/// Reload the current document via the native webview API.+pub fn reload_window(window: &WebviewWindow) {+ if let Err(error) = window.reload() {+ eprintln!("[Pake] Failed to reload webview: {error}");+ }+}++/// Step the webview history without requiring a live page JS context.+pub fn history_step(window: &WebviewWindow, back: bool) {+ let stepped = window.with_webview(move |webview| {+ history_step_platform(&webview, back);+ });++ if stepped.is_err() {+ // Last resort when with_webview is unavailable (rare). Still fails on+ // blank error shells, but preserves SPA history when the page is live.+ let script = if back {+ "window.history.back()"+ } else {+ "window.history.forward()"+ };+ if let Err(error) = window.eval(script) {+ eprintln!("[Pake] Failed to step webview history: {error}");+ }+ }+}++#[cfg(target_os = "macos")]+fn history_step_platform(webview: &tauri::webview::PlatformWebview, back: bool) {+ use objc2::msg_send;+ use objc2::runtime::AnyObject;++ let ptr = webview.inner() as *mut AnyObject;+ if ptr.is_null() {+ return;+ }+ unsafe {+ if back {+ let _: *mut AnyObject = msg_send![ptr, goBack];+ } else {+ let _: *mut AnyObject = msg_send![ptr, goForward];+ }+ }+}++#[cfg(target_os = "linux")]+fn history_step_platform(webview: &tauri::webview::PlatformWebview, back: bool) {+ let gtk_webview = webview.inner();+ if back {+ gtk_webview.go_back();+ } else {+ gtk_webview.go_forward();+ }+}++#[cfg(windows)]+fn history_step_platform(webview: &tauri::webview::PlatformWebview, back: bool) {+ use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Controller;++ let controller = webview.controller();+ unsafe {+ // ICoreWebView2Controller::CoreWebView2 returns the underlying browser.+ let Ok(core) = controller.CoreWebView2() else {+ return;+ };+ if back {+ let _ = core.GoBack();+ } else {+ let _ = core.GoForward();+ }+ }+}++#[cfg(not(any(target_os = "macos", target_os = "linux", windows)))]+fn history_step_platform(_webview: &tauri::webview::PlatformWebview, _back: bool) {}diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rsindex 8d6e14df..8ddcf8a0 100644--- a/src-tauri/src/app/setup.rs+++ b/src-tauri/src/app/setup.rs@@ -1,4 +1,6 @@-use crate::app::window::{open_additional_window_safe, reapply_window_icon};+use crate::app::window::{+ hide_all_app_windows, open_additional_window_safe, show_all_app_windows, toggle_all_app_windows,+};use crate::cancel_startup_reveal;use std::str::FromStr;use std::sync::{atomic::AtomicBool, Arc, Mutex};@@ -53,22 +55,13 @@ pub fn set_system_tray(open_additional_window_safe(app);}"hide_app" => {- if let Some(window) = app.get_webview_window("pake") {- cancel_startup_reveal(&menu_revealed);- let _ = window.minimize();- }+ // Hide every webview (main + multi-window clones), not only "pake".+ cancel_startup_reveal(&menu_revealed);+ hide_all_app_windows(app);}"show_app" => {- if let Some(window) = app.get_webview_window("pake") {- cancel_startup_reveal(&menu_revealed);- let _ = window.show();- reapply_window_icon(&window);- #[cfg(target_os = "linux")]- if _init_fullscreen && !window.is_fullscreen().unwrap_or(false) {- let _ = window.set_fullscreen(true);- let _ = window.set_focus();- }- }+ cancel_startup_reveal(&menu_revealed);+ show_all_app_windows(app, _init_fullscreen);}"quit" => {let flags = if _init_fullscreen {@@ -84,22 +77,9 @@ pub fn set_system_tray(.on_tray_icon_event(move |tray, event| {if let TrayIconEvent::Click { button, .. } = event {if button == tauri::tray::MouseButton::Left {- if let Some(window) = tray.app_handle().get_webview_window("pake") {- // Any tray toggle claims visibility control from startup reveal.- cancel_startup_reveal(&click_revealed);- let is_visible = window.is_visible().unwrap_or(false);- if is_visible {- let _ = window.hide();- } else {- let _ = window.show();- reapply_window_icon(&window);- let _ = window.set_focus();- #[cfg(target_os = "linux")]- if _init_fullscreen && !window.is_fullscreen().unwrap_or(false) {- let _ = window.set_fullscreen(true);- }- }- }+ // Any tray toggle claims visibility control from startup reveal.+ cancel_startup_reveal(&click_revealed);+ toggle_all_app_windows(tray.app_handle(), _init_fullscreen);}}});@@ -159,21 +139,8 @@ pub fn set_global_shortcut(*last_triggered = Instant::now();if shortcut_hotkey.eq(event) {- if let Some(window) = app.get_webview_window("pake") {- cancel_startup_reveal(&startup_revealed);- let is_visible = window.is_visible().unwrap_or(false);- if is_visible {- let _ = window.hide();- } else {- let _ = window.show();- reapply_window_icon(&window);- let _ = window.set_focus();- #[cfg(target_os = "linux")]- if _init_fullscreen && !window.is_fullscreen().unwrap_or(false) {- let _ = window.set_fullscreen(true);- }- }- }+ cancel_startup_reveal(&startup_revealed);+ toggle_all_app_windows(app, _init_fullscreen);}}})diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rsindex df239d97..00d4b379 100644--- a/src-tauri/src/app/window.rs+++ b/src-tauri/src/app/window.rs@@ -228,6 +228,54 @@ pub fn reveal_built_window(window: &WebviewWindow) {let _ = window.set_focus();}+/// True when any Pake webview window is currently visible.+pub fn any_app_window_visible(app: &AppHandle) -> bool {+ app.webview_windows()+ .values()+ .any(|window| window.is_visible().unwrap_or(false))+}++/// Hide every webview window (main + multi-window clones). Used by tray Hide+/// and the activation shortcut so secondary windows are not left on screen.+pub fn hide_all_app_windows(app: &AppHandle) {+ for window in app.webview_windows().values() {+ let _ = window.hide();+ }+}++/// Show every webview window, reassert icons, and focus the main window.+pub fn show_all_app_windows(app: &AppHandle, init_fullscreen: bool) {+ let windows = app.webview_windows();+ for window in windows.values() {+ let _ = window.unminimize();+ let _ = window.show();+ reapply_window_icon(window);+ #[cfg(target_os = "linux")]+ if init_fullscreen && !window.is_fullscreen().unwrap_or(false) {+ let _ = window.set_fullscreen(true);+ }+ }+ #[cfg(not(target_os = "linux"))]+ let _ = init_fullscreen;++ if let Some(main) = windows.get("pake") {+ let _ = main.set_focus();+ } else if let Some(any) = windows.values().next() {+ let _ = any.set_focus();+ }+}++/// Tray-click / activation-shortcut toggle: hide all if anything is visible,+/// otherwise show all. Cancels startup reveal when the caller has already done+/// so; this helper only touches visibility.+pub fn toggle_all_app_windows(app: &AppHandle, init_fullscreen: bool) {+ if any_app_window_visible(app) {+ hide_all_app_windows(app);+ } else {+ show_all_app_windows(app, init_fullscreen);+ }+}+fn build_window_with_label(app: &AppHandle,config: &PakeConfig,diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.jsindex cc1f2282..03342f5f 100644--- a/src-tauri/src/inject/event.js+++ b/src-tauri/src/inject/event.js@@ -1,11 +1,35 @@+// Prefer native webview navigation over page JS so Ctrl+R / [ / ] still work+// on blank error shells (no JS context). Falls back to history/location when+// the IPC bridge is unavailable.+function nativeNavigate(action) {+ const invoke = window.__TAURI__?.core?.invoke;+ if (invoke) {+ invoke("webview_navigate", { action }).catch(() => {+ fallbackNavigate(action);+ });+ return;+ }+ fallbackNavigate(action);+}++function fallbackNavigate(action) {+ if (action === "reload") {+ window.location.reload();+ } else if (action === "back") {+ window.history.back();+ } else if (action === "forward") {+ window.history.forward();+ }+}+const shortcuts = {- "[": () => window.history.back(),- "]": () => window.history.forward(),+ "[": () => nativeNavigate("back"),+ "]": () => nativeNavigate("forward"),"-": () => zoomOut(),"=": () => zoomIn(),"+": () => zoomIn(),0: () => setZoom("100%"),- r: () => window.location.reload(),+ r: () => nativeNavigate("reload"),ArrowUp: () => scrollTo(0, 0),ArrowDown: () => scrollTo(0, document.body.scrollHeight),};diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rsindex daa637dd..28dbee15 100644--- a/src-tauri/src/lib.rs+++ b/src-tauri/src/lib.rs@@ -28,7 +28,7 @@ const GDK_BACKEND: &str = "GDK_BACKEND";use app::{invoke::{clear_dock_badge, download_file, increment_dock_badge, send_notification, set_dock_badge,- set_dock_badge_label, set_zoom, update_theme_mode,+ set_dock_badge_label, set_zoom, update_theme_mode, webview_navigate,},setup::{set_global_shortcut, set_system_tray},window::{@@ -300,6 +300,7 @@ pub fn run_app() {clear_dock_badge,update_theme_mode,set_zoom,+ webview_navigate,]).setup(move |app| {app.manage(MultiWindowState::new(diff --git a/tests/unit/event-fullscreen-shortcuts.test.js b/tests/unit/event-fullscreen-shortcuts.test.jsindex c857685b..5b68cb40 100644--- a/tests/unit/event-fullscreen-shortcuts.test.js+++ b/tests/unit/event-fullscreen-shortcuts.test.js@@ -43,6 +43,7 @@ function loadEventHelpers({const elementsById = new Map();const fullscreenCalls = [];const reloadCalls = [];+ const navigateCalls = [];const body = createElement("body");body.appendChild = (child) => {body.children.push(child);@@ -105,7 +106,12 @@ function loadEventHelpers({},__TAURI__: {core: {- invoke: () => Promise.resolve(),+ invoke: (command, payload) => {+ if (command === "webview_navigate") {+ navigateCalls.push(payload?.action);+ }+ return Promise.resolve();+ },},window: {getCurrentWindow: () => ({@@ -147,6 +153,7 @@ function loadEventHelpers({eventListeners,fullscreenCalls,reloadCalls,+ navigateCalls,get isFullscreen() {return isFullscreen;},@@ -201,7 +208,8 @@ describe("event fullscreen shortcuts", () => {getWebShortcutHandler(context)(event);- expect(context.reloadCalls).toEqual([true]);+ // Native webview_navigate so blank error pages still reload.+ expect(context.navigateCalls).toEqual(["reload"]);expect(event.preventDefault).toHaveBeenCalled();});diff --git a/tests/unit/menu-focused-window.test.ts b/tests/unit/menu-focused-window.test.tsindex b6d2f1f7..f9661068 100644--- a/tests/unit/menu-focused-window.test.ts+++ b/tests/unit/menu-focused-window.test.ts@@ -19,9 +19,10 @@ describe('macOS menu window targeting', () => {it('uses native reload and history so error pages stay operable', () => {// Blank WebView error shells have no JS context; eval-based navigation// is a no-op exactly when the user is stuck (#1328 class).- expect(handler).toContain('window.reload()');+ expect(handler).toContain('reload_window(&window)');expect(handler).not.toContain('window.location.reload()');- expect(handler).toContain('webview_history_step');+ expect(handler).toContain('history_step(&window, true)');+ expect(handler).toContain('history_step(&window, false)');expect(handler).not.toContain('window.history.back()');expect(handler).not.toContain('window.history.forward()');});diff --git a/tests/unit/multi-window-visibility.test.ts b/tests/unit/multi-window-visibility.test.tsnew file mode 100644index 00000000..0c2b2025--- /dev/null+++ b/tests/unit/multi-window-visibility.test.ts@@ -0,0 +1,75 @@+import fs from 'node:fs';+import path from 'node:path';+import { describe, expect, it } from 'vitest';++const windowSource = fs.readFileSync(+ path.join(process.cwd(), 'src-tauri/src/app/window.rs'),+ 'utf8',+);+const setupSource = fs.readFileSync(+ path.join(process.cwd(), 'src-tauri/src/app/setup.rs'),+ 'utf8',+);+const invokeSource = fs.readFileSync(+ path.join(process.cwd(), 'src-tauri/src/app/invoke.rs'),+ 'utf8',+);+const libSource = fs.readFileSync(+ path.join(process.cwd(), 'src-tauri/src/lib.rs'),+ 'utf8',+);+const eventSource = fs.readFileSync(+ path.join(process.cwd(), 'src-tauri/src/inject/event.js'),+ 'utf8',+);++describe('multi-window visibility control', () => {+ it('exposes hide/show/toggle helpers over every webview window', () => {+ expect(windowSource).toContain('pub fn hide_all_app_windows');+ expect(windowSource).toContain('pub fn show_all_app_windows');+ expect(windowSource).toContain('pub fn toggle_all_app_windows');+ expect(windowSource).toContain('app.webview_windows()');+ });++ it('routes tray hide/show/click and activation shortcut through multi-window helpers', () => {+ expect(setupSource).toContain('hide_all_app_windows(app)');+ expect(setupSource).toContain('show_all_app_windows(app, _init_fullscreen)');+ expect(setupSource).toContain(+ 'toggle_all_app_windows(tray.app_handle(), _init_fullscreen)',+ );+ expect(setupSource).toContain(+ 'toggle_all_app_windows(app, _init_fullscreen)',+ );+ // Must not only touch the main label for hide/show menu items.+ const hideBranch = setupSource.slice(+ setupSource.indexOf('"hide_app"'),+ setupSource.indexOf('"show_app"'),+ );+ expect(hideBranch).not.toContain('get_webview_window("pake")');+ });+});++describe('native webview navigation IPC', () => {+ it('registers webview_navigate for reload/back/forward', () => {+ expect(invokeSource).toContain('pub fn webview_navigate');+ expect(invokeSource).toContain('reload_window(&window)');+ expect(invokeSource).toContain('history_step(&window, true)');+ expect(invokeSource).toContain('history_step(&window, false)');+ expect(libSource).toContain('webview_navigate');+ });++ it('routes Ctrl shortcut reload/back/forward through native navigate', () => {+ expect(eventSource).toContain('function nativeNavigate(action)');+ expect(eventSource).toContain('invoke("webview_navigate", { action })');+ expect(eventSource).toContain('nativeNavigate("reload")');+ expect(eventSource).toContain('nativeNavigate("back")');+ expect(eventSource).toContain('nativeNavigate("forward")');+ // Top-level shortcuts must not call page APIs directly.+ expect(eventSource).not.toMatch(+ /const shortcuts = \{[\s\S]*?window\.location\.reload\(\)/,+ );+ expect(eventSource).not.toMatch(+ /const shortcuts = \{[\s\S]*?window\.history\.back\(\)/,+ );+ });+});