Implement single-instance lock

Add a mechanism to prevent multiple instances of the desktop client from
running simultaneously. This is achieved by creating a lock file. The
first instance successfully acquires the lock, while subsequent attempts
by other instances will fail, prompting them to exit gracefully. This
ensures data integrity and prevents potential conflicts.
This commit is contained in:
2026-04-18 11:37:16 +02:00
parent cdfa5ae90e
commit bb29671733
4 changed files with 137 additions and 3 deletions
+9
View File
@@ -38,3 +38,12 @@ pub fn snapshot_cache_path() -> Result<PathBuf, PathError> {
.map(|dirs| dirs.data_local_dir().join("oneliners_cache.json"))
.ok_or(PathError::NoDataDir)
}
/// File path for the single-instance advisory lock. Held by the running
/// process for its entire lifetime; a second launch attempting to lock
/// the same file gets `WouldBlock` and exits cleanly.
pub fn lock_file_path() -> Result<PathBuf, PathError> {
ProjectDirs::from("", "", "doctate")
.map(|dirs| dirs.data_local_dir().join("client.lock"))
.ok_or(PathError::NoDataDir)
}