Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

fix: restore window from tray on Windows (closes #1343)

Tw934ba7e65d76bf
diff --git a/AGENTS.md b/AGENTS.md
index 5339a1bd..405c6cce 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -106,7 +106,7 @@ 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. 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"`).
+- 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"`). Two Windows-specific constraints hold that toggle together (#1343): the tray click handler must match `button_state == MouseButtonState::Up`, because Windows emits `TrayIconEvent::Click` twice per physical click and reacting to both runs the toggle twice; and `any_app_window_visible` must exclude minimized windows, because `hide_on_close` minimizes before hiding and Windows keeps `IsWindowVisible` true while a window is iconic. Locked by `tests/unit/tray-toggle-visibility.test.ts`.
- 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.
diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs
index 8ddcf8a0..b2a4824c 100644
--- a/src-tauri/src/app/setup.rs
+++ b/src-tauri/src/app/setup.rs
@@ -7,7 +7,7 @@ use std::sync::{atomic::AtomicBool, Arc, Mutex};
use std::time::{Duration, Instant};
use tauri::{
menu::{MenuBuilder, MenuItemBuilder},
- tray::{TrayIconBuilder, TrayIconEvent},
+ tray::{MouseButton, MouseButtonState, TrayIconBuilder, TrayIconEvent},
AppHandle, Manager,
};
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
@@ -75,8 +75,16 @@ 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 TrayIconEvent::Click {
+ button,
+ button_state,
+ ..
+ } = event
+ {
+ // Windows emits Click twice per physical click (Down then Up).
+ // Reacting to both runs the toggle twice, so a hidden window is
+ // shown and immediately re-hidden and the tray looks dead (#1343).
+ if button == MouseButton::Left && button_state == MouseButtonState::Up {
// Any tray toggle claims visibility control from startup reveal.
cancel_startup_reveal(&click_revealed);
toggle_all_app_windows(tray.app_handle(), _init_fullscreen);
diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rs
index 00d4b379..a2e92a08 100644
--- a/src-tauri/src/app/window.rs
+++ b/src-tauri/src/app/window.rs
@@ -228,11 +228,16 @@ pub fn reveal_built_window(window: &WebviewWindow) {
let _ = window.set_focus();
}
-/// True when any Pake webview window is currently visible.
+/// True when any Pake webview window is currently on screen.
+///
+/// A minimized window does not count. Windows keeps `IsWindowVisible` true while
+/// a window is iconic, and `hide_on_close` minimizes before hiding, so treating
+/// minimized as visible makes the tray toggle hide an already-invisible window
+/// instead of restoring it (#1343).
pub fn any_app_window_visible(app: &AppHandle) -> bool {
- app.webview_windows()
- .values()
- .any(|window| window.is_visible().unwrap_or(false))
+ app.webview_windows().values().any(|window| {
+ window.is_visible().unwrap_or(false) && !window.is_minimized().unwrap_or(false)
+ })
}
/// Hide every webview window (main + multi-window clones). Used by tray Hide
diff --git a/tests/unit/tray-toggle-visibility.test.ts b/tests/unit/tray-toggle-visibility.test.ts
new file mode 100644
index 00000000..1887492b
--- /dev/null
+++ b/tests/unit/tray-toggle-visibility.test.ts
@@ -0,0 +1,47 @@
+import fs from 'node:fs';
+import path from 'node:path';
+import { describe, expect, it } from 'vitest';
+
+const rustRoot = path.join(process.cwd(), 'src-tauri', 'src');
+const setupSource = fs.readFileSync(
+ path.join(rustRoot, 'app', 'setup.rs'),
+ 'utf8',
+);
+const windowSource = fs.readFileSync(
+ path.join(rustRoot, 'app', 'window.rs'),
+ 'utf8',
+);
+
+describe('tray click toggle (#1343)', () => {
+ it('acts on one edge of the click, not both', () => {
+ // Windows emits TrayIconEvent::Click twice per physical click, Down then
+ // Up. Matching on button alone runs the toggle twice, so a hidden window is
+ // shown and immediately re-hidden.
+ const handler = setupSource.slice(
+ setupSource.indexOf('.on_tray_icon_event('),
+ );
+ expect(handler).toContain('button_state');
+ expect(handler).toMatch(/button_state\s*==\s*MouseButtonState::Up/);
+ });
+
+ it('treats a minimized window as not on screen', () => {
+ // hide_on_close minimizes before hiding, and Windows keeps IsWindowVisible
+ // true while a window is iconic. Without the is_minimized check the toggle
+ // reads a minimized window as visible and hides it instead of restoring it.
+ const fn = windowSource.slice(
+ windowSource.indexOf('pub fn any_app_window_visible'),
+ windowSource.indexOf('pub fn hide_all_app_windows'),
+ );
+ expect(fn).toMatch(/!window\.is_minimized\(\)\.unwrap_or\(false\)/);
+ });
+
+ it('clears the iconic state on every restore path', () => {
+ // Tray menu Show, tray click, and the activation shortcut all restore
+ // through show_all_app_windows, so unminimize has to live there.
+ const fn = windowSource.slice(
+ windowSource.indexOf('pub fn show_all_app_windows'),
+ windowSource.indexOf('pub fn toggle_all_app_windows'),
+ );
+ expect(fn).toContain('unminimize()');
+ });
+});