✨ single instance
This commit is contained in:
@@ -10,7 +10,7 @@ use std::time::{Duration, Instant};
|
||||
|
||||
use tauri::Manager;
|
||||
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut};
|
||||
// use tauri_plugin_window_state::Builder as windowStatePlugin;
|
||||
use tauri_plugin_window_state::Builder as windowStatePlugin;
|
||||
use util::{get_data_dir, get_pake_config};
|
||||
use window::get_window;
|
||||
|
||||
@@ -23,21 +23,22 @@ pub fn run_app() {
|
||||
|
||||
// Save the value of toggle_app_shortcut before pake_config is moved
|
||||
let activation_shortcut = pake_config.windows[0].activation_shortcut.clone();
|
||||
// let init_fullscreen = pake_config.windows[0].fullscreen;
|
||||
let init_fullscreen = pake_config.windows[0].fullscreen;
|
||||
|
||||
// let window_state_plugin = if init_fullscreen {
|
||||
// windowStatePlugin::default()
|
||||
// .with_state_flags(tauri_plugin_window_state::StateFlags::FULLSCREEN)
|
||||
// .build()
|
||||
// } else {
|
||||
// windowStatePlugin::default().build()
|
||||
// };
|
||||
let window_state_plugin = if init_fullscreen {
|
||||
windowStatePlugin::default()
|
||||
.with_state_flags(tauri_plugin_window_state::StateFlags::FULLSCREEN)
|
||||
.build()
|
||||
} else {
|
||||
windowStatePlugin::default().build()
|
||||
};
|
||||
|
||||
tauri_app
|
||||
// .plugin(window_state_plugin)
|
||||
.plugin(window_state_plugin)
|
||||
.plugin(tauri_plugin_oauth::init())
|
||||
.plugin(tauri_plugin_http::init())
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_single_instance::init(|_, _, _| ()))
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
download_file,
|
||||
download_file_by_binary
|
||||
@@ -48,7 +49,7 @@ pub fn run_app() {
|
||||
let _window = get_window(app, &pake_config, data_dir);
|
||||
|
||||
// Prevent initial shaking
|
||||
// _window.show().unwrap();
|
||||
_window.show().unwrap();
|
||||
|
||||
if show_system_tray {
|
||||
let _ = set_system_tray(app.app_handle());
|
||||
@@ -101,21 +102,25 @@ pub fn run_app() {
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
#[cfg(target_os = "macos")]
|
||||
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
|
||||
let window = window.clone();
|
||||
api.prevent_close();
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let window_handle = window.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
if window_handle.is_fullscreen().unwrap_or(false) {
|
||||
window_handle.set_fullscreen(false).unwrap();
|
||||
if window.is_fullscreen().unwrap_or(false) {
|
||||
window.set_fullscreen(false).unwrap();
|
||||
// Give a small delay to ensure the full-screen exit operation is completed.
|
||||
tokio::time::sleep(Duration::from_millis(900)).await;
|
||||
}
|
||||
window_handle.minimize().unwrap();
|
||||
window_handle.hide().unwrap();
|
||||
window.minimize().unwrap();
|
||||
window.hide().unwrap();
|
||||
});
|
||||
api.prevent_close();
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
window.destroy().unwrap();
|
||||
}
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
|
||||
Reference in New Issue
Block a user