mac-helper 0.1.3 → 0.1.4

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/lib/app.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * file path based process running detect.
3
+ * for vscode, process name = `Code`, file is `Visual Studio Code.app`, the `Visual Studio Code` should be passed
4
+ */
5
+ export declare function isAppRunning(appName: string): Promise<boolean>;
package/lib/app.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAppRunning = void 0;
4
+ const child_process_1 = require("child_process");
5
+ /**
6
+ * file path based process running detect.
7
+ * for vscode, process name = `Code`, file is `Visual Studio Code.app`, the `Visual Studio Code` should be passed
8
+ */
9
+ async function isAppRunning(appName) {
10
+ return new Promise((resolve, reject) => {
11
+ (0, child_process_1.exec)(`ps -ax -o command`, (err, stdout, stderr) => {
12
+ if (err)
13
+ return reject(err);
14
+ const lines = stdout
15
+ .trim()
16
+ .split('\n')
17
+ .map((x) => x.trim())
18
+ .filter(Boolean);
19
+ const searchText = `${appName}.app/Contents/MacOS/`;
20
+ const running = !!lines.find((line) => line.includes(searchText));
21
+ resolve(running);
22
+ });
23
+ });
24
+ }
25
+ exports.isAppRunning = isAppRunning;
26
+ // isAppRunning('Visual Studio Code').then(console.log)
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './app';
1
2
  export * from './chrome';
2
3
  export * from './dialog';
3
4
  export * from './finder';
package/lib/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
+ __exportStar(require("./app"), exports);
19
20
  __exportStar(require("./chrome"), exports);
20
21
  __exportStar(require("./dialog"), exports);
21
22
  __exportStar(require("./finder"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const run_1 = require("@jxa/run");
4
+ /**
5
+ * 不太准确, 比如 vscode 进程 `Code` 在运行, 检测不到
6
+ */
7
+ async function isAppRunning(appName) {
8
+ return await (0, run_1.run)((appName) => {
9
+ const app = Application('System Events');
10
+ app.includeStandardAdditions = true;
11
+ const runningAppNames = app
12
+ .processes()
13
+ .map((p) => p.name());
14
+ return runningAppNames.includes(appName);
15
+ }, appName);
16
+ }
17
+ async function getRunningAppNames() {
18
+ return await (0, run_1.run)(() => {
19
+ const app = Application('System Events');
20
+ app.includeStandardAdditions = true;
21
+ const runningAppNames = app
22
+ .processes()
23
+ .map((p) => p.name());
24
+ return runningAppNames;
25
+ });
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mac-helper",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "useful helper for macOS",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -40,24 +40,24 @@
40
40
  "@jxa/sdef-to-dts": "^1.3.6",
41
41
  "@jxa/types": "^1.3.6",
42
42
  "@magicdawn/prettier-config": "^0.0.3",
43
- "@swc/core": "1.5.1",
43
+ "@swc/core": "1.5.7",
44
44
  "@types/fs-extra": "^11.0.4",
45
45
  "@types/mocha": "^10.0.6",
46
- "@types/node": "^20.12.7",
47
- "@typescript-eslint/eslint-plugin": "^7.7.1",
48
- "@typescript-eslint/parser": "^7.7.1",
49
- "@vitest/coverage-v8": "^1.5.2",
46
+ "@types/node": "^20.12.12",
47
+ "@typescript-eslint/eslint-plugin": "^7.10.0",
48
+ "@typescript-eslint/parser": "^7.10.0",
49
+ "@vitest/coverage-v8": "^1.6.0",
50
50
  "delay": "^6.0.0",
51
- "eslint": "^9.1.1",
51
+ "eslint": "^9.3.0",
52
52
  "eslint-config-prettier": "^9.1.0",
53
53
  "fs-extra": "^11.2.0",
54
54
  "husky": "^9.0.11",
55
55
  "jxa-common-used": "^0.0.3",
56
- "lint-staged": "^15.2.2",
56
+ "lint-staged": "^15.2.4",
57
57
  "prettier": "^3.2.5",
58
58
  "should": "^13.2.3",
59
59
  "typescript": "^5.4.5",
60
- "vitest": "^1.5.2"
60
+ "vitest": "^1.6.0"
61
61
  },
62
62
  "publishConfig": {
63
63
  "registry": "https://registry.npmjs.org"
@@ -66,5 +66,6 @@
66
66
  "*.{js,jsx,ts,tsx,less,md}": [
67
67
  "prettier --write"
68
68
  ]
69
- }
69
+ },
70
+ "packageManager": "pnpm@9.1.2+sha512.127dc83b9ea10c32be65d22a8efb4a65fb952e8fefbdfded39bdc3c97efc32d31b48b00420df2c1187ace28c921c902f0cb5a134a4d032b8b5295cbfa2c681e2"
70
71
  }
package/src/app.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { exec } from 'child_process'
2
+
3
+ /**
4
+ * file path based process running detect.
5
+ * for vscode, process name = `Code`, file is `Visual Studio Code.app`, the `Visual Studio Code` should be passed
6
+ */
7
+
8
+ export async function isAppRunning(appName: string): Promise<boolean> {
9
+ return new Promise((resolve, reject) => {
10
+ exec(`ps -ax -o command`, (err, stdout, stderr) => {
11
+ if (err) return reject(err)
12
+
13
+ const lines = stdout
14
+ .trim()
15
+ .split('\n')
16
+ .map((x) => x.trim())
17
+ .filter(Boolean)
18
+ const searchText = `${appName}.app/Contents/MacOS/`
19
+
20
+ const running = !!lines.find((line) => line.includes(searchText))
21
+ resolve(running)
22
+ })
23
+ })
24
+ }
25
+
26
+ // isAppRunning('Visual Studio Code').then(console.log)
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types='@jxa/global-type' />
2
2
  /// <reference types='@jxa/types' />
3
3
 
4
+ export * from './app'
4
5
  export * from './chrome'
5
6
  export * from './dialog'
6
7
  export * from './finder'
@@ -0,0 +1,28 @@
1
+ import { run } from '@jxa/run'
2
+ import type { SystemEvents } from '@jxa/types'
3
+
4
+ /**
5
+ * 不太准确, 比如 vscode 进程 `Code` 在运行, 检测不到
6
+ */
7
+
8
+ async function isAppRunning(appName: string): Promise<boolean> {
9
+ return await run((appName) => {
10
+ const app = Application<SystemEvents.SystemEvents.Application>('System Events')
11
+ app.includeStandardAdditions = true
12
+ const runningAppNames: string[] = app
13
+ .processes()
14
+ .map((p: SystemEvents.SystemEvents.Process) => p.name())
15
+ return runningAppNames.includes(appName)
16
+ }, appName)
17
+ }
18
+
19
+ async function getRunningAppNames(): Promise<string[]> {
20
+ return await run(() => {
21
+ const app = Application<SystemEvents.SystemEvents.Application>('System Events')
22
+ app.includeStandardAdditions = true
23
+ const runningAppNames: string[] = app
24
+ .processes()
25
+ .map((p: SystemEvents.SystemEvents.Process) => p.name())
26
+ return runningAppNames
27
+ })
28
+ }