Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ jobs:
- name: Ubuntu
version: latest
- name: macOS
version: 12
version: latest
- name: Windows
version: 2019
version: latest
arch: [x64]

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '22'
architecture: ${{ matrix.arch }}

- name: Install dependencies and build from source
Expand All @@ -40,7 +40,7 @@ jobs:
run: npm run prebuild

- name: 'Upload prebuilt binaries'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: prebuilds-${{ matrix.os.name }}-${{ matrix.arch }}
path: prebuilds
Expand All @@ -53,12 +53,12 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install Node.js with registry configured for publish
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '22'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies without building
Expand Down
99 changes: 37 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-selection",
"version": "0.2.0-alpha.0",
"version": "0.2.0-alpha.1",
"description": "Get current selected text by using system accessibility APIs",
"gypfile": true,
"main": "index.js",
Expand All @@ -18,11 +18,11 @@
"prebuild:fat": "npm run prebuild -- --arch x64+arm64"
},
"dependencies": {
"node-addon-api": "^4.3.0",
"node-gyp-build": "^4.4.0"
"node-addon-api": "^8.3.1",
"node-gyp-build": "^4.8.4"
},
"devDependencies": {
"node-fetch": "^3.2.3",
"prebuildify": "^5.0.0"
"node-fetch": "^3.3.2",
"prebuildify": "^6.0.1"
}
}
21 changes: 9 additions & 12 deletions src/selection_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,28 @@ pid_t GetFrontProcessID() {
if (!frontmostApplication) {
return 0;
}
pid_t pid = [frontmostApplication[@"NSApplicationProcessIdentifier"] intValue];
CFRelease(frontmostApplication);
return pid;
return [frontmostApplication[@"NSApplicationProcessIdentifier"] intValue];
}

std::optional<std::string> GetProcessName(pid_t pid) {
auto application = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
if (!application) {
return nil;
return std::nullopt;
}
auto url = [application executableURL];
if (!url) {
CFRelease(application);
return nil;
return std::nullopt;
}
auto name = [url lastPathComponent];
CFRelease(application);
return ToString(name);
}

std::optional<std::string> GetBundleIdentifier(pid_t pid) {
auto application = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
if (!application) {
return nil;
return std::nullopt;
}
auto bundle_identifier = [application bundleIdentifier];
CFRelease(application);
return ToString(bundle_identifier);
}

Expand Down Expand Up @@ -82,19 +77,21 @@ AXUIElementRef _GetFocusedElement(pid_t pid) {
return nil;
}

NSString *bundlerIdentifer = [NSString stringWithUTF8String:GetBundleIdentifier(pid)->c_str()];
auto bundleIdentifierOptional = GetBundleIdentifier(pid);
if (!bundleIdentifierOptional) {
return nil;
}
NSString *bundlerIdentifer = [NSString stringWithUTF8String:bundleIdentifierOptional->c_str()];
if ([appsManuallyEnableAx containsObject:bundlerIdentifer]) {
AXUIElementSetAttributeValue(application, CFSTR("AXManualAccessibility"), kCFBooleanTrue);
AXUIElementSetAttributeValue(application, CFSTR("AXEnhancedUserInterface"), kCFBooleanTrue);
}
CFRelease(bundlerIdentifer);

AXUIElementRef focusedElement;
auto error = AXUIElementCopyAttributeValue(application, kAXFocusedUIElementAttribute, (CFTypeRef *)&focusedElement);
if (error != kAXErrorSuccess) {
error = AXUIElementCopyAttributeValue(application, kAXFocusedWindowAttribute, (CFTypeRef *)&focusedElement);
}
CFRelease(application);
if (error != kAXErrorSuccess) {
return nil;
}
Expand Down