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.

feat(runtime): left click opens a menu-bar-only Mac app's window

Tw93274aa7288e8f
diff --git a/src-tauri/src/app/config.rs b/src-tauri/src/app/config.rs
index e1bd2c0f..25d5baf5 100644
--- a/src-tauri/src/app/config.rs
+++ b/src-tauri/src/app/config.rs
@@ -176,7 +176,6 @@ impl PakeConfig {
}
/// The Dock icon goes only when the menu bar icon is there to open the app.
- #[cfg_attr(not(target_os = "macos"), allow(dead_code))]
pub fn hides_dock_icon(&self) -> bool {
self.windows[0].hide_dock_icon && self.show_system_tray()
}
diff --git a/src-tauri/src/app/setup.rs b/src-tauri/src/app/setup.rs
index c1b6138c..8102730a 100644
--- a/src-tauri/src/app/setup.rs
+++ b/src-tauri/src/app/setup.rs
@@ -53,6 +53,7 @@ pub fn set_system_tray(
_init_fullscreen: bool,
allow_multi_window: bool,
startup_revealed: Arc<AtomicBool>,
+ left_click_toggles_window: bool,
) -> tauri::Result<()> {
if !show_system_tray {
app.remove_tray_by_id("pake-tray");
@@ -84,6 +85,10 @@ pub fn set_system_tray(
let click_revealed = startup_revealed;
let mut tray_builder = TrayIconBuilder::new()
.menu(&menu)
+ // A menu-bar-only Mac app has no Dock icon, so its menu bar icon is the
+ // way back to the window: a left click toggles the window there, as it
+ // does on Windows, and the menu moves to a right click.
+ .show_menu_on_left_click(!left_click_toggles_window)
.on_menu_event(move |app, event| match event.id().as_ref() {
"tray_new_window" => {
open_additional_window_safe(app);
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 63191177..5ef0fec9 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -510,6 +510,7 @@ pub fn run_app() {
init_fullscreen,
multi_window,
startup_window_revealed.clone(),
+ cfg!(target_os = "macos") && pake_config.hides_dock_icon(),
)?;
set_global_shortcut(
app.app_handle(),
diff --git a/tests/unit/tray-toggle-visibility.test.ts b/tests/unit/tray-toggle-visibility.test.ts
index 1887492b..6e53d6f2 100644
--- a/tests/unit/tray-toggle-visibility.test.ts
+++ b/tests/unit/tray-toggle-visibility.test.ts
@@ -24,6 +24,20 @@ describe('tray click toggle (#1343)', () => {
expect(handler).toMatch(/button_state\s*==\s*MouseButtonState::Up/);
});
+ it('gives a menu-bar-only Mac app the window on left click', () => {
+ // With no Dock icon the menu bar icon is the only way back to the window,
+ // so there the left click toggles it and the menu moves to a right click.
+ // Every other app keeps the menu on left click.
+ expect(setupSource).toMatch(
+ /\.show_menu_on_left_click\(!left_click_toggles_window\)/,
+ );
+ const libSource = fs.readFileSync(path.join(rustRoot, 'lib.rs'), 'utf8');
+ const call = libSource.slice(libSource.indexOf('set_system_tray('));
+ expect(call.slice(0, call.indexOf(')?;'))).toMatch(
+ /cfg!\(target_os = "macos"\) && pake_config\.hides_dock_icon\(\)/,
+ );
+ });
+
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