chore: fix accessibility permission check logic 🔧 #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.