feat: ensure single instance to prevent duplicate daemon and tray icons
Some checks are pending
Build & Release / Build & test (push) Waiting to run
Build & Release / Build .deb (push) Blocked by required conditions

This commit is contained in:
Khoa Vo 2026-06-29 20:33:10 +07:00
parent 88d39b4475
commit 389c58e1fa
2 changed files with 18 additions and 0 deletions

View file

@ -505,6 +505,15 @@ fn recover_display_env() {
} }
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
// Ensure single instance to avoid duplicate daemon processes
let _listener = match std::os::unix::net::UnixListener::bind("\0vietc-daemon-lock") {
Ok(l) => l,
Err(_) => {
eprintln!("[vietc] Another instance is already running. Exiting.");
std::process::exit(0);
}
};
recover_display_env(); recover_display_env();
let config_path = config::find_config_path(); let config_path = config::find_config_path();
let config = Config::load()?; let config = Config::load()?;

View file

@ -180,6 +180,15 @@ fn config_path() -> PathBuf {
} }
fn main() { fn main() {
// Ensure single instance to avoid duplicate tray icons
let _listener = match std::os::unix::net::UnixListener::bind("\0vietc-tray-lock") {
Ok(l) => l,
Err(_) => {
eprintln!("[vietc-tray] Another instance is already running. Exiting.");
std::process::exit(0);
}
};
eprintln!("[vietc-tray] Starting"); eprintln!("[vietc-tray] Starting");
// Start daemon (with password prompt if first launch) // Start daemon (with password prompt if first launch)