Skip to content

Commit 94b96ab

Browse files
committed
fix: restore window when Dock icon is clicked
1 parent dbbc84b commit 94b96ab

2 files changed

Lines changed: 39 additions & 11 deletions

File tree

‎src-tauri/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ wait-timeout = "0.2"
3737

3838
[dev-dependencies]
3939
pretty_assertions = "1"
40+
tauri = { version = "2.8", features = ["test"] }

‎src-tauri/src/lib.rs‎

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,14 @@ fn open_project_link(target: String) -> CommandResult<()> {
305305
downloads::open_in_browser(project_link(&target)?)
306306
}
307307

308-
fn reveal_main(app: &tauri::AppHandle) {
309-
if let Some(window) = app.get_webview_window("main") {
310-
let _ = window.show();
311-
let _ = window.unminimize();
312-
let _ = window.set_focus();
313-
}
308+
fn reveal_main<R: Runtime>(app: &tauri::AppHandle<R>) -> bool {
309+
let Some(window) = app.get_webview_window("main") else {
310+
return false;
311+
};
312+
let _ = window.show();
313+
let _ = window.unminimize();
314+
let _ = window.set_focus();
315+
true
314316
}
315317

316318
fn should_reveal_main(button: MouseButton, button_state: MouseButtonState) -> bool {
@@ -351,7 +353,9 @@ fn install_tray(app: &tauri::App) -> tauri::Result<()> {
351353
}
352354
})
353355
.on_menu_event(move |app, event| match event.id.as_ref() {
354-
"open" => reveal_main(app),
356+
"open" => {
357+
reveal_main(app);
358+
}
355359
"quit" => app.exit(0),
356360
"toggle" => {
357361
let core = app.state::<AppCore>();
@@ -477,7 +481,7 @@ pub fn run() {
477481
#[cfg(target_os = "macos")]
478482
let autostart = autostart.macos_launcher(MacosLauncher::LaunchAgent);
479483

480-
tauri::Builder::default()
484+
let app = tauri::Builder::default()
481485
.plugin(tauri_plugin_dialog::init())
482486
.plugin(autostart.build())
483487
.setup(|app| {
@@ -529,13 +533,25 @@ pub fn run() {
529533
open_download,
530534
open_project_link,
531535
])
532-
.run(tauri::generate_context!())
533-
.expect("error while running GitBoost");
536+
.build(tauri::generate_context!())
537+
.expect("error while building GitBoost");
538+
539+
app.run(|app, event| {
540+
#[cfg(target_os = "macos")]
541+
if let tauri::RunEvent::Reopen { .. } = event {
542+
reveal_main(app);
543+
}
544+
545+
#[cfg(not(target_os = "macos"))]
546+
let _ = (app, event);
547+
});
534548
}
535549

536550
#[cfg(test)]
537551
mod tests {
538-
use super::{health_check_due, project_link, run_node_test, should_reveal_main, tray_labels};
552+
use super::{
553+
health_check_due, project_link, reveal_main, run_node_test, should_reveal_main, tray_labels,
554+
};
539555
use crate::models::{HealthSummary, NodeDefinition, NodeEntry, Settings};
540556
use std::time::Duration;
541557
use tauri::tray::{MouseButton, MouseButtonState};
@@ -591,6 +607,17 @@ mod tests {
591607
));
592608
}
593609

610+
#[test]
611+
fn reveal_main_targets_the_main_window() {
612+
let app = tauri::test::mock_app();
613+
assert!(!reveal_main(app.handle()));
614+
615+
tauri::WebviewWindowBuilder::new(&app, "main", tauri::WebviewUrl::default())
616+
.build()
617+
.unwrap();
618+
assert!(reveal_main(app.handle()));
619+
}
620+
594621
#[test]
595622
fn project_links_are_fixed_to_the_author_and_repository() {
596623
assert_eq!(

0 commit comments

Comments
 (0)