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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user