mac-helper 0.7.0 → 0.8.1
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/dialog.js +1 -0
- package/lib/finder.d.ts +7 -0
- package/lib/finder.js +27 -7
- package/package.json +23 -32
- package/src/chrome.ts +1 -1
- package/src/dialog.ts +2 -1
- package/src/finder.ts +29 -9
package/lib/dialog.js
CHANGED
package/lib/finder.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const PathFinder: {
|
|
|
5
5
|
allSelected(): Promise<string[]>;
|
|
6
6
|
singleSelected(): Promise<string | undefined>;
|
|
7
7
|
setSelected(filePaths: string[]): Promise<void>;
|
|
8
|
+
getActiveTabDir: typeof PathFinder_getActiveTabDir;
|
|
8
9
|
};
|
|
9
10
|
export declare const Finder: {
|
|
10
11
|
allSelected(): Promise<string[]>;
|
|
@@ -15,6 +16,11 @@ export declare const QSpace: {
|
|
|
15
16
|
allSelected(): Promise<string[]>;
|
|
16
17
|
singleSelected(): Promise<string | undefined>;
|
|
17
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* 获取 activeTab dir, 当没有 selection 时可用,
|
|
21
|
+
* 要求只能有一个 visible window, 从 jxa 这一层无法区分 window z-index
|
|
22
|
+
*/
|
|
23
|
+
declare function PathFinder_getActiveTabDir(): Promise<string | undefined>;
|
|
18
24
|
export type QSpaceFileItem = {
|
|
19
25
|
id: () => string;
|
|
20
26
|
name: () => string;
|
|
@@ -26,3 +32,4 @@ export declare function isRepresentQS(file: string): boolean;
|
|
|
26
32
|
* 处理 `@pf` `@qs`, ignore case
|
|
27
33
|
*/
|
|
28
34
|
export declare function normalizeInputFileList(fileList: string[]): Promise<string[]>;
|
|
35
|
+
export {};
|
package/lib/finder.js
CHANGED
|
@@ -7,11 +7,11 @@ exports.QSpace = exports.Finder = exports.PathFinder = void 0;
|
|
|
7
7
|
exports.isRepresentPF = isRepresentPF;
|
|
8
8
|
exports.isRepresentQS = isRepresentQS;
|
|
9
9
|
exports.normalizeInputFileList = normalizeInputFileList;
|
|
10
|
-
const run_1 = require("@jxa/run");
|
|
11
|
-
const es_toolkit_1 = require("es-toolkit");
|
|
12
10
|
const node_os_1 = require("node:os");
|
|
13
11
|
const node_path_1 = __importDefault(require("node:path"));
|
|
14
12
|
const node_url_1 = require("node:url");
|
|
13
|
+
const run_1 = require("@jxa/run");
|
|
14
|
+
const es_toolkit_1 = require("es-toolkit");
|
|
15
15
|
const promise_map_1 = __importDefault(require("promise.map"));
|
|
16
16
|
const app_1 = require("./app");
|
|
17
17
|
/**
|
|
@@ -27,6 +27,7 @@ exports.PathFinder = {
|
|
|
27
27
|
setSelected(filePaths) {
|
|
28
28
|
return PathFinder_setSelected(filePaths);
|
|
29
29
|
},
|
|
30
|
+
getActiveTabDir: PathFinder_getActiveTabDir,
|
|
30
31
|
};
|
|
31
32
|
exports.Finder = {
|
|
32
33
|
allSelected() {
|
|
@@ -67,8 +68,7 @@ async function PathFinder_singleSelected() {
|
|
|
67
68
|
}
|
|
68
69
|
const firstFilePath = await (0, run_1.run)(() => {
|
|
69
70
|
const app = Application('Path Finder');
|
|
70
|
-
|
|
71
|
-
return arr[0];
|
|
71
|
+
return (app.selection() || [])[0]?.posixPath();
|
|
72
72
|
});
|
|
73
73
|
return firstFilePath;
|
|
74
74
|
}
|
|
@@ -78,6 +78,29 @@ async function PathFinder_setSelected(filePaths) {
|
|
|
78
78
|
app.select(filePaths);
|
|
79
79
|
}, filePaths);
|
|
80
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* 获取 activeTab dir, 当没有 selection 时可用,
|
|
83
|
+
* 要求只能有一个 visible window, 从 jxa 这一层无法区分 window z-index
|
|
84
|
+
*/
|
|
85
|
+
async function PathFinder_getActiveTabDir() {
|
|
86
|
+
if (!(await (0, app_1.isAppRunning)('Path Finder')))
|
|
87
|
+
return;
|
|
88
|
+
const visibleWindowCount = await (0, run_1.run)(() => {
|
|
89
|
+
const app = Application('Path Finder');
|
|
90
|
+
return app.finderWindows.whose({ visible: true }).length;
|
|
91
|
+
});
|
|
92
|
+
if (!visibleWindowCount)
|
|
93
|
+
return;
|
|
94
|
+
if (visibleWindowCount > 1) {
|
|
95
|
+
throw new Error('Multiple visible PathFinder window not supported in PathFinder_getActiveTabDir');
|
|
96
|
+
}
|
|
97
|
+
const dir = await (0, run_1.run)(() => {
|
|
98
|
+
const app = Application('Path Finder');
|
|
99
|
+
const w = app.finderWindows.whose({ visible: true })[0];
|
|
100
|
+
return w.target.posixPath();
|
|
101
|
+
});
|
|
102
|
+
return dir;
|
|
103
|
+
}
|
|
81
104
|
/* #endregion */
|
|
82
105
|
/* #region Finder */
|
|
83
106
|
async function Finder_allSelected() {
|
|
@@ -129,6 +152,3 @@ async function normalizeInputFileList(fileList) {
|
|
|
129
152
|
}, (0, node_os_1.availableParallelism)())).flat());
|
|
130
153
|
}
|
|
131
154
|
/* #endregion */
|
|
132
|
-
// ;(async () => {
|
|
133
|
-
// console.log(await normalizeInputFileList(['@pf']))
|
|
134
|
-
// })()
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mac-helper",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"packageManager": "pnpm@
|
|
3
|
+
"version": "0.8.1",
|
|
4
|
+
"packageManager": "pnpm@11.1.3+sha512.c85357fe17ca12dd23dd7071822666dfd7e3cb76fe214e3370b5ea2fb34f2a231185509b63e717f3cd0acb38dd3f8d82bcd5e8172400ae678b70ea4fbed0896d",
|
|
5
5
|
"description": "useful helper for macOS",
|
|
6
|
-
"
|
|
7
|
-
"mac",
|
|
8
|
-
"helper",
|
|
9
|
-
"mac-helper"
|
|
10
|
-
],
|
|
6
|
+
"author": "magicdawn",
|
|
11
7
|
"license": "MIT",
|
|
12
8
|
"homepage": "https://github.com/magicdawn/mac-helper#readme",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/magicdawn/mac-helper/issues"
|
|
15
|
-
},
|
|
16
9
|
"repository": {
|
|
17
10
|
"type": "git",
|
|
18
11
|
"url": "git+ssh://git@github.com/magicdawn/mac-helper.git"
|
|
19
12
|
},
|
|
20
|
-
"
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/magicdawn/mac-helper/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"mac",
|
|
18
|
+
"helper",
|
|
19
|
+
"mac-helper"
|
|
20
|
+
],
|
|
21
|
+
"main": "lib/index.js",
|
|
22
|
+
"types": "lib/index.d.ts",
|
|
21
23
|
"files": [
|
|
22
24
|
"lib/",
|
|
23
25
|
"src/"
|
|
24
26
|
],
|
|
25
|
-
"main": "lib/index.js",
|
|
26
|
-
"types": "lib/index.d.ts",
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"registry": "https://registry.npmjs.org"
|
|
29
29
|
},
|
|
@@ -39,38 +39,29 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@jxa/run": "^1.4.0",
|
|
42
|
-
"es-toolkit": "^1.
|
|
42
|
+
"es-toolkit": "^1.46.1",
|
|
43
43
|
"promise.map": "^1.1.3"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@jxa/global-type": "^1.4.0",
|
|
47
47
|
"@jxa/sdef-to-dts": "^1.4.0",
|
|
48
48
|
"@jxa/types": "^1.4.0",
|
|
49
|
-
"@magicdawn/eslint-config": "^1.6.
|
|
49
|
+
"@magicdawn/eslint-config": "^1.6.5",
|
|
50
50
|
"@magicdawn/prettier-config": "^0.1.0",
|
|
51
51
|
"@types/fs-extra": "^11.0.4",
|
|
52
|
-
"@types/node": "^25.
|
|
53
|
-
"@vitest/coverage-v8": "^4.1.
|
|
52
|
+
"@types/node": "^25.8.0",
|
|
53
|
+
"@vitest/coverage-v8": "^4.1.6",
|
|
54
54
|
"delay": "^7.0.0",
|
|
55
|
-
"eslint": "^
|
|
55
|
+
"eslint": "^10.4.0",
|
|
56
56
|
"eslint-config-prettier": "^10.1.8",
|
|
57
|
-
"fs-extra": "^11.3.
|
|
57
|
+
"fs-extra": "^11.3.5",
|
|
58
58
|
"husky": "^9.1.7",
|
|
59
59
|
"jxa-common-used": "^0.0.3",
|
|
60
|
-
"lint-staged": "^
|
|
61
|
-
"prettier": "^3.8.
|
|
60
|
+
"lint-staged": "^17.0.5",
|
|
61
|
+
"prettier": "^3.8.3",
|
|
62
62
|
"should": "^13.2.3",
|
|
63
|
-
"typescript": "^
|
|
64
|
-
"vitest": "^4.1.
|
|
65
|
-
},
|
|
66
|
-
"pnpm": {
|
|
67
|
-
"onlyBuiltDependencies": [
|
|
68
|
-
"@swc/core",
|
|
69
|
-
"core-js",
|
|
70
|
-
"es5-ext",
|
|
71
|
-
"esbuild",
|
|
72
|
-
"unrs-resolver"
|
|
73
|
-
]
|
|
63
|
+
"typescript": "^6.0.3",
|
|
64
|
+
"vitest": "^4.1.6"
|
|
74
65
|
},
|
|
75
66
|
"lint-staged": {
|
|
76
67
|
"*.{js,jsx,ts,tsx,less,md}": [
|
package/src/chrome.ts
CHANGED
package/src/dialog.ts
CHANGED
|
@@ -59,7 +59,7 @@ async function chooseFromList(
|
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
if (!selected) return
|
|
62
|
-
const label = selected[0]
|
|
62
|
+
const label = (selected as any)[0]
|
|
63
63
|
|
|
64
64
|
if (!usingOption) {
|
|
65
65
|
return label
|
|
@@ -129,3 +129,4 @@ async function chooseMultipleFromList(
|
|
|
129
129
|
// .then((selected) => {
|
|
130
130
|
// console.log(selected)
|
|
131
131
|
// })
|
|
132
|
+
// dialog.prompt('hello', 'world').then(console.log)
|
package/src/finder.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { run as jxaRun } from '@jxa/run'
|
|
2
|
-
import { uniq } from 'es-toolkit'
|
|
3
|
-
import type { PathFinder as PathFinderType } from 'jxa-common-used'
|
|
4
1
|
import { availableParallelism } from 'node:os'
|
|
5
2
|
import path from 'node:path'
|
|
6
3
|
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { run as jxaRun } from '@jxa/run'
|
|
5
|
+
import { uniq } from 'es-toolkit'
|
|
7
6
|
import pmap from 'promise.map'
|
|
8
7
|
import { isAppRunning } from './app'
|
|
8
|
+
import type { PathFinder as PathFinderType } from 'jxa-common-used'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* `App` named epxorts
|
|
@@ -20,6 +20,7 @@ export const PathFinder = {
|
|
|
20
20
|
setSelected(filePaths: string[]) {
|
|
21
21
|
return PathFinder_setSelected(filePaths)
|
|
22
22
|
},
|
|
23
|
+
getActiveTabDir: PathFinder_getActiveTabDir,
|
|
23
24
|
}
|
|
24
25
|
export const Finder = {
|
|
25
26
|
allSelected() {
|
|
@@ -62,8 +63,7 @@ async function PathFinder_singleSelected(): Promise<string | undefined> {
|
|
|
62
63
|
}
|
|
63
64
|
const firstFilePath: string | undefined = await jxaRun(() => {
|
|
64
65
|
const app = Application<PathFinderType>('Path Finder')
|
|
65
|
-
|
|
66
|
-
return arr[0]
|
|
66
|
+
return (app.selection() || [])[0]?.posixPath()
|
|
67
67
|
})
|
|
68
68
|
return firstFilePath
|
|
69
69
|
}
|
|
@@ -74,6 +74,30 @@ async function PathFinder_setSelected(filePaths: string[]) {
|
|
|
74
74
|
app.select(filePaths)
|
|
75
75
|
}, filePaths)
|
|
76
76
|
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 获取 activeTab dir, 当没有 selection 时可用,
|
|
80
|
+
* 要求只能有一个 visible window, 从 jxa 这一层无法区分 window z-index
|
|
81
|
+
*/
|
|
82
|
+
async function PathFinder_getActiveTabDir(): Promise<string | undefined> {
|
|
83
|
+
if (!(await isAppRunning('Path Finder'))) return
|
|
84
|
+
|
|
85
|
+
const visibleWindowCount: number = await jxaRun(() => {
|
|
86
|
+
const app = Application<PathFinderType>('Path Finder')
|
|
87
|
+
return app.finderWindows.whose({ visible: true }).length
|
|
88
|
+
})
|
|
89
|
+
if (!visibleWindowCount) return
|
|
90
|
+
if (visibleWindowCount > 1) {
|
|
91
|
+
throw new Error('Multiple visible PathFinder window not supported in PathFinder_getActiveTabDir')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const dir: string = await jxaRun(() => {
|
|
95
|
+
const app = Application<PathFinderType>('Path Finder')
|
|
96
|
+
const w = app.finderWindows.whose({ visible: true })[0]
|
|
97
|
+
return w.target.posixPath()
|
|
98
|
+
})
|
|
99
|
+
return dir
|
|
100
|
+
}
|
|
77
101
|
/* #endregion */
|
|
78
102
|
|
|
79
103
|
/* #region Finder */
|
|
@@ -152,7 +176,3 @@ export async function normalizeInputFileList(fileList: string[]) {
|
|
|
152
176
|
)
|
|
153
177
|
}
|
|
154
178
|
/* #endregion */
|
|
155
|
-
|
|
156
|
-
// ;(async () => {
|
|
157
|
-
// console.log(await normalizeInputFileList(['@pf']))
|
|
158
|
-
// })()
|