Skip to content

Commit

Permalink
Do not maximize main window on new instance
Browse files Browse the repository at this point in the history
  • Loading branch information
martpie committed Sep 30, 2024
1 parent 696f9ed commit 01ad926
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
11 changes: 1 addition & 10 deletions src-tauri/src/libs/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
use log::info;
use std::{ffi::OsStr, path::PathBuf, time::Instant};
use tauri::{Runtime, Theme, WebviewWindow};
use tauri::Theme;
use walkdir::WalkDir;

use crate::plugins::config::SYSTEM_THEME;
Expand Down Expand Up @@ -75,15 +75,6 @@ pub fn scan_dir(path: &PathBuf, allowed_extensions: &[&str]) -> Vec<PathBuf> {
.collect()
}

/**
* Ensure a window is shown and visible
*/
pub fn show_window<R: Runtime>(window: &WebviewWindow<R>) {
window.maximize().unwrap();
window.show().unwrap();
window.set_focus().unwrap();
}

/**
* Give an arbitrary string (usually the theme value from the config), returns
* a Tauri theme
Expand Down
5 changes: 3 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod libs;
mod plugins;

use libs::file_associations::setup_file_associations;
use libs::utils::{get_theme_from_name, show_window};
use libs::utils::get_theme_from_name;
use log::LevelFilter;
use plugins::config::ConfigManager;
use tauri::{Manager, WebviewUrl, WebviewWindowBuilder};
Expand Down Expand Up @@ -47,8 +47,9 @@ async fn main() {
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_single_instance::init(|app_handle, _, _| {
// Focus on the already running app in case the app is opened again
let window = app_handle.get_webview_window("main").unwrap();
show_window(&window);
window.set_focus().unwrap();
}))
.plugin(
tauri_plugin_window_state::Builder::default()
Expand Down

0 comments on commit 01ad926

Please sign in to comment.