Closed kentbetita closed 6 months ago
We could also update the condition from getWindowInformation
for consistency:
// Run the AppleScript to get the URL if the active window is a compatible browser and accessibility permissions are enabled.
if !disableAccessibilityPermission {
if let bundleIdentifier = app.bundleIdentifier,
let script = getActiveBrowserTabURLAppleScriptCommand(bundleIdentifier),
let url = runAppleScript(source: script) {
output["url"] = url
}
}
but from my testing it has been working fine for both cases. This is optional.
Description
This pull request addresses an issue where the package was incorrectly prompting for accessibility permissions even when the
disableAccessibilityPermission
option was set tofalse
.Changes
main.swift
to ensure that the accessibility permission prompt is conditionally executed based on thedisableAccessibilityPermission
flag.AXIsProcessTrustedWithOptions
call within an explicit if block to prevent unintended permission prompts.Problem
The original code used a comma-separated list of conditions in an if statement, which in Swift, functions as a logical AND operator. This meant that both conditions had to be evaluated, and as long as the first condition
(!disableAccessibilityPermission)
wastrue
(i.e.,disableAccessibilityPermission
wasfalse
), the second condition(!AXIsProcessTrustedWithOptions(["AXTrustedCheckOptionPrompt": true] as CFDictionary))
would also be evaluated.This led to a situation where, even when
disableAccessibilityPermission
was set to false, the code would still trigger the accessibility permission check because the second condition was always checked, thus resulting in an unintended prompt for accessibility permission.Solution
The solution involved restructuring the conditional statement to ensure that the
AXIsProcessTrustedWithOptions
check is only performed whendisableAccessibilityPermission
is explicitly set to false. Now, the second condition is entirely dependent on the first condition being true. This change respects the user's preference for thedisableAccessibilityPermission
flag and prevents the accessibility permission prompt from appearing unless it is necessary.Testing
npm test
onactive-win
projectdev
andprod
environment by compilingactive-win
locally and pasting themain
file unto my electron apps'node_modules/active-win
directoryDisclaimer
Please note that while I am not a Swift developer by profession, I have taken care to ensure that the changes proposed in this pull request adhere to best practices to the best of my knowledge and have been thoroughly tested.