feat: add single instance plugin to prevent multiple app instances
Integrates tauri_plugin_single_instance to ensure only one instance of the application runs at a time. When attempting to launch a second instance, it will focus the existing window instead.
This commit is contained in:
@@ -237,7 +237,22 @@ async fn update_tray_menu(
|
|||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
let builder = tauri::Builder::default()
|
let mut builder = tauri::Builder::default();
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "windows", target_os = "linux"))]
|
||||||
|
{
|
||||||
|
builder = builder.plugin(tauri_plugin_single_instance::init(
|
||||||
|
|app, _args, _cwd| {
|
||||||
|
if let Some(window) = app.get_webview_window("main") {
|
||||||
|
let _ = window.unminimize();
|
||||||
|
let _ = window.show();
|
||||||
|
let _ = window.set_focus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let builder = builder
|
||||||
// 拦截窗口关闭:仅隐藏窗口,保持进程与托盘常驻
|
// 拦截窗口关闭:仅隐藏窗口,保持进程与托盘常驻
|
||||||
.on_window_event(|window, event| match event {
|
.on_window_event(|window, event| match event {
|
||||||
tauri::WindowEvent::CloseRequested { api, .. } => {
|
tauri::WindowEvent::CloseRequested { api, .. } => {
|
||||||
|
|||||||
Reference in New Issue
Block a user