Skip to content

Commit f412619

Browse files
committed
feat: add requestAccessibility method for macOS
1 parent 0a55ff5 commit f412619

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

lib/macos.mm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88

99
extern "C" AXError _AXUIElementGetWindow(AXUIElementRef, CGWindowID* out);
1010

11-
NSDictionary* opts = @{static_cast<id> (kAXTrustedCheckOptionPrompt): @YES};
12-
BOOL a = AXIsProcessTrustedWithOptions(static_cast<CFDictionaryRef> (opts));
11+
Napi::Boolean requestAccessibility(const Napi::CallbackInfo &info) {
12+
Napi::Env env{info.Env()};
13+
14+
NSDictionary* opts = @{static_cast<id> (kAXTrustedCheckOptionPrompt): @YES};
15+
BOOL a = AXIsProcessTrustedWithOptions(static_cast<CFDictionaryRef> (opts));
16+
17+
return Napi::Boolean::New(env, a);
18+
}
1319

1420
std::map<int, AXUIElementRef> m;
1521

@@ -223,6 +229,8 @@ AXUIElementRef getAXWindow(int pid, int handle) {
223229
Napi::Function::New(env, setWindowMinimized));
224230
exports.Set(Napi::String::New(env, "setWindowMaximized"),
225231
Napi::Function::New(env, setWindowMaximized));
232+
exports.Set(Napi::String::New(env, "requestAccessibility"),
233+
Napi::Function::New(env, requestAccessibility));
226234
return exports;
227235
}
228236

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
},
3131
"homepage": "https://github.com/sentialx/node-window-manager#readme",
3232
"devDependencies": {
33-
"@types/node": "12.0.8",
34-
"tslint": "5.17.0",
35-
"typescript": "3.5.1"
33+
"@types/node": "12.12.7",
34+
"tslint": "5.20.1",
35+
"typescript": "3.7.2"
3636
},
3737
"dependencies": {
38-
"node-addon-api": "1.6.3",
39-
"node-gyp": "5.0.0"
38+
"node-addon-api": "1.7.1",
39+
"node-gyp": "6.0.1"
4040
}
4141
}

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class WindowManager extends EventEmitter {
5151
});
5252
}
5353

54+
requestAccessibility = () => {
55+
if (platform() !== 'darwin') return false;
56+
return addon.requestAccessibility();
57+
}
58+
5459
getActiveWindow = () => {
5560
if (!addon) return;
5661
return new Window(addon.getActiveWindow());

0 commit comments

Comments
 (0)