diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9da890..8a25baf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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 diff --git a/package-lock.json b/package-lock.json index cfcfebe..e37ed89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,21 +1,21 @@ { "name": "node-selection", - "version": "0.2.0-alpha.0", + "version": "0.2.0-alpha.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "node-selection", - "version": "0.2.0-alpha.0", + "version": "0.2.0-alpha.1", "hasInstallScript": true, "license": "MIT", "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" } }, "node_modules/base64-js": { @@ -111,15 +111,6 @@ "once": "^1.4.0" } }, - "node_modules/execspawn": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/execspawn/-/execspawn-1.0.1.tgz", - "integrity": "sha1-gob53efOzeeQX73ATiTzaPI/jaY=", - "dev": true, - "dependencies": { - "util-extend": "^1.0.1" - } - }, "node_modules/fetch-blob": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.1.5.tgz", @@ -224,9 +215,13 @@ } }, "node_modules/node-addon-api": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", - "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==" + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.3.1.tgz", + "integrity": "sha512-lytcDEdxKjGJPTLEfW4mYMigRezMlyJY8W4wxJK8zE533Jlb8L8dRuObJFWg2P+AuOIxoCgKF+2Oq4d4Zd0OUA==", + "license": "MIT", + "engines": { + "node": "^18 || ^20 || >= 21" + } }, "node_modules/node-domexception": { "version": "1.0.0", @@ -248,10 +243,11 @@ } }, "node_modules/node-fetch": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.3.tgz", - "integrity": "sha512-AXP18u4pidSZ1xYXRDPY/8jdv3RAozIt/WLNR/MBGZAz+xjtlr90RvCnsvHQRiXyWliZF/CpytExp32UU67/SA==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", "dev": true, + "license": "MIT", "dependencies": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", @@ -266,9 +262,10 @@ } }, "node_modules/node-gyp-build": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.4.0.tgz", - "integrity": "sha512-amJnQCcgtRVw9SvoebO3BKGESClrfXGCUTX9hSn1OuGQTQBOZmVd0Z0OlecpuRksKvbsUqALE8jls/ErClAPuQ==", + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", + "license": "MIT", "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", @@ -306,12 +303,12 @@ } }, "node_modules/prebuildify": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/prebuildify/-/prebuildify-5.0.0.tgz", - "integrity": "sha512-XhuFIeZx8Tk8e8yn3h5e+CE572pecpdKPrVubUIW0HctP3fpzh4eSWoHR1eOoQNTtxBUt1ixPLHPLbOTYi6STw==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/prebuildify/-/prebuildify-6.0.1.tgz", + "integrity": "sha512-8Y2oOOateom/s8dNBsGIcnm6AxPmLH4/nanQzL5lQMU+sC0CMhzARZHizwr36pUPLdvBnOkCNQzxg4djuFSgIw==", "dev": true, + "license": "MIT", "dependencies": { - "execspawn": "^1.0.1", "minimist": "^1.2.5", "mkdirp-classic": "^0.5.3", "node-abi": "^3.3.0", @@ -411,12 +408,6 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true }, - "node_modules/util-extend": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/util-extend/-/util-extend-1.0.3.tgz", - "integrity": "sha1-p8IW0mdUUWljeztu3GypEZ4v+T8=", - "dev": true - }, "node_modules/web-streams-polyfill": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.0.tgz", @@ -501,15 +492,6 @@ "once": "^1.4.0" } }, - "execspawn": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/execspawn/-/execspawn-1.0.1.tgz", - "integrity": "sha1-gob53efOzeeQX73ATiTzaPI/jaY=", - "dev": true, - "requires": { - "util-extend": "^1.0.1" - } - }, "fetch-blob": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.1.5.tgz", @@ -578,9 +560,9 @@ } }, "node-addon-api": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", - "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==" + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.3.1.tgz", + "integrity": "sha512-lytcDEdxKjGJPTLEfW4mYMigRezMlyJY8W4wxJK8zE533Jlb8L8dRuObJFWg2P+AuOIxoCgKF+2Oq4d4Zd0OUA==" }, "node-domexception": { "version": "1.0.0", @@ -589,9 +571,9 @@ "dev": true }, "node-fetch": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.2.3.tgz", - "integrity": "sha512-AXP18u4pidSZ1xYXRDPY/8jdv3RAozIt/WLNR/MBGZAz+xjtlr90RvCnsvHQRiXyWliZF/CpytExp32UU67/SA==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", "dev": true, "requires": { "data-uri-to-buffer": "^4.0.0", @@ -600,9 +582,9 @@ } }, "node-gyp-build": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.4.0.tgz", - "integrity": "sha512-amJnQCcgtRVw9SvoebO3BKGESClrfXGCUTX9hSn1OuGQTQBOZmVd0Z0OlecpuRksKvbsUqALE8jls/ErClAPuQ==" + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==" }, "npm-run-path": { "version": "3.1.0", @@ -629,12 +611,11 @@ "dev": true }, "prebuildify": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/prebuildify/-/prebuildify-5.0.0.tgz", - "integrity": "sha512-XhuFIeZx8Tk8e8yn3h5e+CE572pecpdKPrVubUIW0HctP3fpzh4eSWoHR1eOoQNTtxBUt1ixPLHPLbOTYi6STw==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/prebuildify/-/prebuildify-6.0.1.tgz", + "integrity": "sha512-8Y2oOOateom/s8dNBsGIcnm6AxPmLH4/nanQzL5lQMU+sC0CMhzARZHizwr36pUPLdvBnOkCNQzxg4djuFSgIw==", "dev": true, "requires": { - "execspawn": "^1.0.1", "minimist": "^1.2.5", "mkdirp-classic": "^0.5.3", "node-abi": "^3.3.0", @@ -721,12 +702,6 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", "dev": true }, - "util-extend": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/util-extend/-/util-extend-1.0.3.tgz", - "integrity": "sha1-p8IW0mdUUWljeztu3GypEZ4v+T8=", - "dev": true - }, "web-streams-polyfill": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.0.tgz", diff --git a/package.json b/package.json index f912143..d1fd8d5 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/src/selection_mac.mm b/src/selection_mac.mm index 50a290a..76aa729 100644 --- a/src/selection_mac.mm +++ b/src/selection_mac.mm @@ -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 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 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); } @@ -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; }