Skip to content

Commit cedcf21

Browse files
committed
fix potential system crash when permissions are revoked
1 parent 9e9c73e commit cedcf21

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Appresize/AppDelegate.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ extension AppDelegate {
126126
showRestartPrompt()
127127
stopPermissionMonitoring() // Stop monitoring after showing prompt
128128
}
129+
// Check if permissions were just revoked (changed from true to false)
130+
else if lastPermissionState && !currentPermissionState {
131+
log(.warning, "Accessibility permissions revoked - immediately deactivating to prevent system crashes")
132+
stateMachine.deactivate()
133+
showPermissionRevokedAlert()
134+
}
129135

130136
lastPermissionState = currentPermissionState
131137
}

Appresize/Functions.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ func showRestartPrompt() {
3939
}
4040
}
4141

42+
func showPermissionRevokedAlert() {
43+
let alert = NSAlert()
44+
alert.alertStyle = .warning
45+
alert.messageText = "Accessibility permissions revoked"
46+
alert.informativeText = """
47+
Appresize has detected that accessibility permissions were removed.
48+
49+
Window management has been automatically disabled to prevent system instability.
50+
51+
To re-enable window management, please grant accessibility permissions again in System Settings.
52+
"""
53+
alert.addButton(withTitle: "Open System Settings")
54+
alert.addButton(withTitle: "OK")
55+
56+
switch alert.runModal() {
57+
case .alertFirstButtonReturn:
58+
let url = URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!
59+
NSWorkspace.shared.open(url)
60+
default:
61+
break
62+
}
63+
}
64+
4265

4366
func restartApp() {
4467
let bundlePath = Bundle.main.bundlePath

0 commit comments

Comments
 (0)