Merge pull request #53 from cjpais/fix-check-updates-window

make sure to focus window when clicking 'check for updates'
This commit is contained in:
CJ Pais 2025-07-28 08:54:52 -07:00 committed by GitHub
commit 836ba0f7ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -26,6 +26,28 @@ struct ShortcutToggleStates {
type ManagedToggleState = Mutex<ShortcutToggleStates>; type ManagedToggleState = Mutex<ShortcutToggleStates>;
fn show_main_window(app: &AppHandle) {
if let Some(main_window) = app.get_webview_window("main") {
// First, ensure the window is visible
if let Err(e) = main_window.show() {
eprintln!("Failed to show window: {}", e);
}
// Then, bring it to the front and give it focus
if let Err(e) = main_window.set_focus() {
eprintln!("Failed to focus window: {}", e);
}
// Optional: On macOS, ensure the app becomes active if it was an accessory
#[cfg(target_os = "macos")]
{
if let Err(e) = app.set_activation_policy(tauri::ActivationPolicy::Regular) {
eprintln!("Failed to set activation policy to Regular: {}", e);
}
}
} else {
eprintln!("Main window not found");
}
}
#[tauri::command] #[tauri::command]
fn trigger_update_check(app: AppHandle) -> Result<(), String> { fn trigger_update_check(app: AppHandle) -> Result<(), String> {
app.emit("check-for-updates", ()) app.emit("check-for-updates", ())
@ -98,29 +120,10 @@ pub fn run() {
.icon_as_template(true) .icon_as_template(true)
.on_menu_event(|app, event| match event.id.as_ref() { .on_menu_event(|app, event| match event.id.as_ref() {
"settings" => { "settings" => {
if let Some(settings_window) = app.get_webview_window("main") { show_main_window(app);
// First, ensure the window is visible
if let Err(e) = settings_window.show() {
eprintln!("Failed to show window: {}", e);
}
// Then, bring it to the front and give it focus
if let Err(e) = settings_window.set_focus() {
eprintln!("Failed to focus window: {}", e);
}
// Optional: On macOS, ensure the app becomes active if it was an accessory
#[cfg(target_os = "macos")]
{
if let Err(e) =
app.set_activation_policy(tauri::ActivationPolicy::Regular)
{
eprintln!("Failed to set activation policy to Regular: {}", e);
}
}
} else {
eprintln!("Main window not found");
}
} }
"check_updates" => { "check_updates" => {
show_main_window(app);
let _ = app.emit("check-for-updates", ()); let _ = app.emit("check-for-updates", ());
} }
"quit" => { "quit" => {