Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix accessibility permission check logic 馃敡 #180

Conversation

kentbetita
Copy link
Contributor

@kentbetita kentbetita commented Mar 1, 2024

Description

This pull request addresses an issue where the package was incorrectly prompting for accessibility permissions even when the disableAccessibilityPermission option was set to false.

Changes

  • Updated the logic in main.swift to ensure that the accessibility permission prompt is conditionally executed based on the disableAccessibilityPermission flag.
  • Wrapped the 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) was true (i.e., disableAccessibilityPermission was false), 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 when disableAccessibilityPermission 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 the disableAccessibilityPermission flag and prevents the accessibility permission prompt from appearing unless it is necessary.

Testing

  • Made sure VSCode and terminal did not have accessibility or screen recording permissions
  • Tested changes with npm test on active-win project
  • Tested on my electron app in dev and prod environment by compiling active-win locally and pasting the main file unto my electron apps' node_modules/active-win directory

Disclaimer

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.

@kentbetita kentbetita marked this pull request as ready for review March 1, 2024 07:43
@kentbetita
Copy link
Contributor Author

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.

@sindresorhus sindresorhus merged commit 34659a0 into sindresorhus:main Mar 2, 2024
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants