mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 22:06:17 +00:00
40 lines
931 B
TypeScript
40 lines
931 B
TypeScript
import path from "node:path";
|
|
import fs from "node:fs";
|
|
import { SystemPath } from "./system-path";
|
|
import { logger } from "./logger";
|
|
|
|
export class Lock {
|
|
private static lockFilePath = path.join(
|
|
SystemPath.getPath("temp"),
|
|
"hydra-launcher.lock"
|
|
);
|
|
|
|
public static async acquireLock() {
|
|
return new Promise<void>((resolve, reject) => {
|
|
fs.writeFile(this.lockFilePath, "", (err) => {
|
|
if (err) {
|
|
logger.error("Error acquiring the lock", err);
|
|
reject(err);
|
|
}
|
|
|
|
logger.info("Acquired the lock");
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
|
|
public static async releaseLock() {
|
|
return new Promise<void>((resolve, reject) => {
|
|
fs.unlink(this.lockFilePath, (err) => {
|
|
if (err) {
|
|
logger.error("Error releasing the lock", err);
|
|
reject(err);
|
|
}
|
|
|
|
logger.info("Released the lock");
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
}
|