Desktop: Limit application to a single instance (#3441)

* only allow single instance

* more reliable CEF cache cleanup

* some cleanup

* fix lock file location

* add simple signal handling

* fix skew handles on desktop

* mac remove unused helpers
This commit is contained in:
Timon
2025-12-03 19:13:15 +01:00
committed by GitHub
parent 600fb5c28f
commit 39b5229df7
15 changed files with 206 additions and 34 deletions
+19 -1
View File
@@ -23,6 +23,8 @@ use cef::CefHandler;
use cli::Cli;
use event::CreateAppEventSchedulerEventLoopExt;
use crate::consts::APP_LOCK_FILE_NAME;
pub fn start() {
tracing_subscriber::fmt().with_env_filter(EnvFilter::from_default_env()).init();
@@ -36,6 +38,22 @@ pub fn start() {
return;
}
let mut lock = pidlock::Pidlock::new_validated(dirs::app_data_dir().join(APP_LOCK_FILE_NAME)).unwrap();
match lock.acquire() {
Ok(lock) => {
tracing::info!("Acquired application lock");
lock
}
Err(pidlock::PidlockError::LockExists) => {
tracing::error!("Another instance is already running, Exiting.");
exit(0);
}
Err(err) => {
tracing::error!("Failed to acquire application lock: {err}");
exit(1);
}
};
App::init();
let cli = Cli::parse();
@@ -56,7 +74,7 @@ pub fn start() {
}
Err(cef::InitError::AlreadyRunning) => {
tracing::error!("Another instance is already running, Exiting.");
exit(0);
exit(1);
}
Err(cef::InitError::InitializationFailed(code)) => {
tracing::error!("Cef initialization failed with code: {code}");