simen-keyboard-listener 1.1.4 → 1.1.6
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/README.md +71 -6
- package/dist/index.js +3 -1
- package/dist/index.mjs +3 -1
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -13,9 +13,7 @@ The package uses `optionalDependencies` to automatically install the correct nat
|
|
|
13
13
|
| Package | Platform |
|
|
14
14
|
|---------|----------|
|
|
15
15
|
| `@simen-keyboard-listener/darwin-arm64` | macOS Apple Silicon |
|
|
16
|
-
| `@simen-keyboard-listener/darwin-x64` | macOS Intel |
|
|
17
16
|
| `@simen-keyboard-listener/win32-x64` | Windows x64 |
|
|
18
|
-
| `@simen-keyboard-listener/win32-arm64` | Windows ARM64 |
|
|
19
17
|
|
|
20
18
|
### For Electron/Bundler Projects
|
|
21
19
|
|
|
@@ -37,9 +35,7 @@ If you're using webpack, electron-builder, or other bundlers, you may need to co
|
|
|
37
35
|
module.exports = {
|
|
38
36
|
externals: {
|
|
39
37
|
'@simen-keyboard-listener/darwin-arm64': 'commonjs @simen-keyboard-listener/darwin-arm64',
|
|
40
|
-
'@simen-keyboard-listener/darwin-x64': 'commonjs @simen-keyboard-listener/darwin-x64',
|
|
41
38
|
'@simen-keyboard-listener/win32-x64': 'commonjs @simen-keyboard-listener/win32-x64',
|
|
42
|
-
'@simen-keyboard-listener/win32-arm64': 'commonjs @simen-keyboard-listener/win32-arm64',
|
|
43
39
|
}
|
|
44
40
|
};
|
|
45
41
|
```
|
|
@@ -59,6 +55,75 @@ listener.addListener((event, isDown) => {
|
|
|
59
55
|
listener.removeListener(myListener);
|
|
60
56
|
```
|
|
61
57
|
|
|
58
|
+
## 开发与构建
|
|
59
|
+
|
|
60
|
+
### 构建原生模块
|
|
61
|
+
|
|
62
|
+
本项目包含 C++ 和 Swift 原生代码,需要编译为平台特定的二进制文件。构建脚本会自动处理编译和文件复制。
|
|
63
|
+
|
|
64
|
+
#### 一键构建(推荐)
|
|
65
|
+
|
|
66
|
+
自动检测当前平台并构建:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm run prebuild
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
此命令会:
|
|
73
|
+
- 自动检测当前操作系统和架构
|
|
74
|
+
- macOS:编译 Swift 辅助文件 + 构建原生模块 + 复制到 `packages/darwin-arm64/`
|
|
75
|
+
- Windows:构建原生模块 + 复制到 `packages/win32-x64/`
|
|
76
|
+
|
|
77
|
+
#### 手动指定平台构建
|
|
78
|
+
|
|
79
|
+
**Windows 平台:**
|
|
80
|
+
```bash
|
|
81
|
+
npm run prebuild:win
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**macOS 平台:**
|
|
85
|
+
```bash
|
|
86
|
+
npm run prebuild:mac
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### 仅复制已构建的文件
|
|
90
|
+
|
|
91
|
+
如果已经构建完成,只需要复制文件到 packages 目录:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npm run copy-native win32-x64 # Windows
|
|
95
|
+
npm run copy-native darwin-arm64 # macOS
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### 完整构建流程
|
|
99
|
+
|
|
100
|
+
如果需要构建 TypeScript 代码和原生模块:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npm run build
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
这会执行:
|
|
107
|
+
1. 编译 Swift 文件(macOS)
|
|
108
|
+
2. 构建原生模块(node-gyp)
|
|
109
|
+
3. 编译 TypeScript 代码
|
|
110
|
+
|
|
111
|
+
### 发布流程
|
|
112
|
+
|
|
113
|
+
发布所有平台包到 npm:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
npm run publish:all
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
发布脚本会:
|
|
120
|
+
1. 同步所有平台包的版本号
|
|
121
|
+
2. 检查 `.node` 文件是否存在
|
|
122
|
+
3. 依次发布各平台包
|
|
123
|
+
4. 最后发布主包
|
|
124
|
+
|
|
125
|
+
**注意:** 发布前需要确保所有平台的 `.node` 文件都已构建并复制到对应的 `packages/` 目录。
|
|
126
|
+
|
|
62
127
|
## API
|
|
63
128
|
|
|
64
129
|
### `getGlobalKeyboardListener(): IGlobalKeyboardListener`
|
|
@@ -91,8 +156,8 @@ interface IGlobalKeyEvent {
|
|
|
91
156
|
|
|
92
157
|
## Platform Support
|
|
93
158
|
|
|
94
|
-
- macOS (
|
|
95
|
-
- Windows
|
|
159
|
+
- macOS ARM64 (Apple Silicon)
|
|
160
|
+
- Windows x64
|
|
96
161
|
|
|
97
162
|
## Requirements
|
|
98
163
|
|
package/dist/index.js
CHANGED
|
@@ -82,7 +82,9 @@ function getNativeAddon() {
|
|
|
82
82
|
if (packageName) {
|
|
83
83
|
try {
|
|
84
84
|
const candidate = localRequire(packageName);
|
|
85
|
-
|
|
85
|
+
const hasCoreFunctions = candidate && typeof candidate.start === "function" && typeof candidate.stop === "function" && typeof candidate.isRunning === "function" && typeof candidate.checkPermission === "function";
|
|
86
|
+
const hasMacOSFunctions = IS_MACOS ? typeof candidate.getFocusedInputValue === "function" && typeof candidate.getFocusedInputSelectedText === "function" : true;
|
|
87
|
+
if (hasCoreFunctions && hasMacOSFunctions) {
|
|
86
88
|
nativeAddon = candidate;
|
|
87
89
|
return nativeAddon;
|
|
88
90
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -47,7 +47,9 @@ function getNativeAddon() {
|
|
|
47
47
|
if (packageName) {
|
|
48
48
|
try {
|
|
49
49
|
const candidate = localRequire(packageName);
|
|
50
|
-
|
|
50
|
+
const hasCoreFunctions = candidate && typeof candidate.start === "function" && typeof candidate.stop === "function" && typeof candidate.isRunning === "function" && typeof candidate.checkPermission === "function";
|
|
51
|
+
const hasMacOSFunctions = IS_MACOS ? typeof candidate.getFocusedInputValue === "function" && typeof candidate.getFocusedInputSelectedText === "function" : true;
|
|
52
|
+
if (hasCoreFunctions && hasMacOSFunctions) {
|
|
51
53
|
nativeAddon = candidate;
|
|
52
54
|
return nativeAddon;
|
|
53
55
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simen-keyboard-listener",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "Native global keyboard listener for macOS and Windows",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -20,7 +20,10 @@
|
|
|
20
20
|
"build:native": "npm run build:swift && node-gyp rebuild --directory=src/native",
|
|
21
21
|
"build:ts": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
22
22
|
"build": "npm run build:native && npm run build:ts",
|
|
23
|
-
"prebuild": "
|
|
23
|
+
"prebuild": "node scripts/prebuild-current.js",
|
|
24
|
+
"prebuild:win": "npx node-gyp rebuild --directory=src/native && node scripts/copy-native.js win32-x64",
|
|
25
|
+
"prebuild:mac": "npm run build:swift && npx node-gyp rebuild --directory=src/native && node scripts/copy-native.js darwin-arm64",
|
|
26
|
+
"copy-native": "node scripts/copy-native.js",
|
|
24
27
|
"prepublishOnly": "npm run build:ts",
|
|
25
28
|
"publish:all": "node scripts/publish.js"
|
|
26
29
|
},
|
|
@@ -46,8 +49,8 @@
|
|
|
46
49
|
"node-addon-api": "^8.0.0"
|
|
47
50
|
},
|
|
48
51
|
"optionalDependencies": {
|
|
49
|
-
"@simen-keyboard-listener/darwin-arm64": "1.1.
|
|
50
|
-
"@simen-keyboard-listener/win32-x64": "1.1.
|
|
52
|
+
"@simen-keyboard-listener/darwin-arm64": "1.1.6",
|
|
53
|
+
"@simen-keyboard-listener/win32-x64": "1.1.6"
|
|
51
54
|
},
|
|
52
55
|
"devDependencies": {
|
|
53
56
|
"@types/node": "^20.0.0",
|