Skip to content

Commit a5d6d5d

Browse files
committed
fix: Prevents multiple app instances
1 parent 3d72493 commit a5d6d5d

3 files changed

Lines changed: 66 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 47 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/plumeimpactor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ image = "0.25"
3030
rfd = "0.16.0"
3131
open = "5.3.3"
3232
notify-rust = "4.11.7"
33+
single-instance = "0.3.3"
3334

3435
[target.'cfg(target_os = "macos")'.dependencies]
3536
plume_gestalt = { path = "../../crates/plume_gestalt" }

apps/plumeimpactor/src/main.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
use crate::refresh::spawn_refresh_daemon;
44

5+
#[cfg(any(target_os = "linux", target_os = "windows"))]
6+
use single_instance::SingleInstance;
7+
58
mod appearance;
69
mod defaults;
710
mod refresh;
@@ -16,6 +19,21 @@ fn main() -> iced::Result {
1619
env_logger::init();
1720
let _ = rustls::crypto::ring::default_provider().install_default();
1821

22+
#[cfg(any(target_os = "linux", target_os = "windows"))]
23+
let _single_instance = match SingleInstance::new(APP_NAME) {
24+
Ok(instance) => {
25+
if !instance.is_single() {
26+
log::info!("Another instance is already running; exiting.");
27+
return Ok(());
28+
}
29+
Some(instance)
30+
}
31+
Err(err) => {
32+
log::warn!("Failed to acquire single-instance lock: {err}");
33+
None
34+
}
35+
};
36+
1937
#[cfg(target_os = "linux")]
2038
{
2139
gtk::init().expect("GTK init failed");

0 commit comments

Comments
 (0)