mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-26 00:58:13 +08:00
+24
-11
@@ -1,4 +1,5 @@
|
||||
use clap::Parser;
|
||||
use std::io::Write;
|
||||
use std::process::exit;
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use winit::event_loop::EventLoop;
|
||||
@@ -38,26 +39,35 @@ 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) => {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let Ok(lock_file) = std::fs::OpenOptions::new()
|
||||
.read(true)
|
||||
.write(true)
|
||||
.create(true)
|
||||
.truncate(true)
|
||||
.open(dirs::app_data_dir().join(APP_LOCK_FILE_NAME))
|
||||
else {
|
||||
tracing::error!("Failed to open lock file, Exiting.");
|
||||
exit(1);
|
||||
};
|
||||
let mut lock = fd_lock::RwLock::new(lock_file);
|
||||
let lock = match lock.try_write() {
|
||||
Ok(mut guard) => {
|
||||
tracing::info!("Acquired application lock");
|
||||
lock
|
||||
let _ = guard.set_len(0);
|
||||
let _ = write!(guard, "{}", std::process::id());
|
||||
let _ = guard.sync_all();
|
||||
guard
|
||||
}
|
||||
Err(pidlock::PidlockError::LockExists) => {
|
||||
Err(_) => {
|
||||
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();
|
||||
|
||||
let wgpu_context = futures::executor::block_on(gpu_context::create_wgpu_context());
|
||||
|
||||
let event_loop = EventLoop::new().unwrap();
|
||||
@@ -94,6 +104,9 @@ pub fn start() {
|
||||
|
||||
event_loop.run_app(&mut app).unwrap();
|
||||
|
||||
// Explicitly drop the instance lock
|
||||
drop(lock);
|
||||
|
||||
// Workaround for a Windows-specific exception that occurs when `app` is dropped.
|
||||
// The issue causes the window to hang for a few seconds before closing.
|
||||
// Appears to be related to CEF object destruction order.
|
||||
|
||||
Reference in New Issue
Block a user