qdesk 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4,6 +4,11 @@ import process from "node:process";
4
4
  import { normalizeChord, startListening } from "./chord-utils.js";
5
5
  import { setScreenHue } from "./screen-hue.js";
6
6
  import { activateWindowByHandle, getActiveWindowHandleAndName, } from "./window-utils.js";
7
+ import { isAlreadyRunning } from "./process-utils.js";
8
+ if (isAlreadyRunning()) {
9
+ console.error("Another instance is already running. Exiting.");
10
+ process.exit(1);
11
+ }
7
12
  // Configure this chord at the top of file.
8
13
  const DEFAULT_ADD_CHORD = "win+ctrl+a";
9
14
  const DEFAULT_DROP_CHORD = "win+ctrl+d";
@@ -0,0 +1,18 @@
1
+ import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
+ const LOCK_FILE = path.join(os.tmpdir(), "qdesk.lock");
5
+ export function isAlreadyRunning() {
6
+ if (fs.existsSync(LOCK_FILE)) {
7
+ const pid = parseInt(fs.readFileSync(LOCK_FILE, "utf8").trim());
8
+ try {
9
+ process.kill(pid, 0);
10
+ return true;
11
+ }
12
+ catch {
13
+ // stale lock, fall through
14
+ }
15
+ }
16
+ fs.writeFileSync(LOCK_FILE, String(process.pid));
17
+ return false;
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdesk",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",