mirror of
https://github.com/cinnyapp/cinny-desktop.git
synced 2025-01-14 02:15:14 +00:00
Add single-instance tauri plugin (#261)
Co-authored-by: lukas <lukas.walter@aceart.de>
This commit is contained in:
parent
c5ddfa91a2
commit
5872ab9ea4
15
src-tauri/Cargo.lock
generated
15
src-tauri/Cargo.lock
generated
|
@ -450,6 +450,7 @@ dependencies = [
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
|
"tauri-plugin-single-instance",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3631,6 +3632,20 @@ dependencies = [
|
||||||
"tauri-utils",
|
"tauri-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-plugin-single-instance"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "git+https://github.com/tauri-apps/plugins-workspace?branch=v1#562425644ef7c11a7b301a30c07a8c8b545621a8"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"tauri",
|
||||||
|
"thiserror",
|
||||||
|
"windows-sys 0.52.0",
|
||||||
|
"zbus",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-runtime"
|
name = "tauri-runtime"
|
||||||
version = "0.14.3"
|
version = "0.14.3"
|
||||||
|
|
|
@ -18,6 +18,7 @@ tauri-build = { version = "1.5.2", features = [] }
|
||||||
serde_json = "1.0.109"
|
serde_json = "1.0.109"
|
||||||
serde = { version = "1.0.193", features = ["derive"] }
|
serde = { version = "1.0.193", features = ["derive"] }
|
||||||
tauri = { version = "1.6.7", features = ["api-all", "devtools", "system-tray", "updater"] }
|
tauri = { version = "1.6.7", features = ["api-all", "devtools", "system-tray", "updater"] }
|
||||||
|
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# by default Tauri runs in production mode
|
# by default Tauri runs in production mode
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
all(not(debug_assertions), target_os = "windows"),
|
all(not(debug_assertions), target_os = "windows"),
|
||||||
windows_subsystem = "windows"
|
windows_subsystem = "windows"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
use tauri::Manager;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
mod menu;
|
mod menu;
|
||||||
mod tray;
|
mod tray;
|
||||||
|
@ -17,6 +19,23 @@ fn main() {
|
||||||
.on_system_tray_event(tray::system_tray_handler);
|
.on_system_tray_event(tray::system_tray_handler);
|
||||||
|
|
||||||
builder
|
builder
|
||||||
|
.plugin(tauri_plugin_single_instance::init(|app, _, _| {
|
||||||
|
let tray_handle = match app.tray_handle_by_id(crate::tray::TRAY_LABEL) {
|
||||||
|
Some(h) => h,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
let window = app.get_window("main").unwrap();
|
||||||
|
|
||||||
|
if !window.is_visible().unwrap() || window.is_minimized().unwrap() {
|
||||||
|
window.unminimize().unwrap();
|
||||||
|
window.show().unwrap();
|
||||||
|
window.set_focus().unwrap();
|
||||||
|
tray_handle
|
||||||
|
.get_item("toggle")
|
||||||
|
.set_title("Hide Cinny")
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}))
|
||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while building tauri application")
|
.expect("error while building tauri application")
|
||||||
.run(run_event_handler)
|
.run(run_event_handler)
|
||||||
|
|
|
@ -3,7 +3,7 @@ use tauri::{
|
||||||
SystemTrayMenuItem, WindowEvent, SystemTrayHandle, Window,
|
SystemTrayMenuItem, WindowEvent, SystemTrayHandle, Window,
|
||||||
};
|
};
|
||||||
|
|
||||||
const TRAY_LABEL: &'static str = "main-tray";
|
pub const TRAY_LABEL: &'static str = "main-tray";
|
||||||
|
|
||||||
pub fn window_event_handler<R: tauri::Runtime>(
|
pub fn window_event_handler<R: tauri::Runtime>(
|
||||||
app: &tauri::AppHandle<R>,
|
app: &tauri::AppHandle<R>,
|
||||||
|
|
Loading…
Reference in a new issue