Skip to content

Commit

Permalink
fix: permission callout could show even with permission granted
Browse files Browse the repository at this point in the history
closes #3801
  • Loading branch information
lwouis committed Nov 14, 2024
1 parent 2594427 commit 9585c92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/logic/SystemPermissions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ class SystemPermissions {
let accessibility = accessibilityIsGranted()
let screenRecording = screenRecordingIsGranted()
logger.d(accessibility, screenRecording, preStartupPermissionsPassed)
Menubar.permissionCalloutMenuItems?.forEach {
$0.isHidden = screenRecording != .skipped
}
Menubar.togglePermissionCallout(screenRecording == .skipped)
if accessibility == .notGranted {
App.app.restart()
}
Expand All @@ -82,9 +80,7 @@ class SystemPermissions {
let accessibility = accessibilityIsGranted()
let screenRecording = screenRecordingIsGranted()
logger.d(accessibility, screenRecording, preStartupPermissionsPassed)
Menubar.permissionCalloutMenuItems?.forEach {
$0.isHidden = screenRecording != .skipped
}
Menubar.togglePermissionCallout(screenRecording == .skipped)
if accessibility != App.app.permissionsWindow?.accessibilityView?.permissionStatus {
App.app.permissionsWindow?.accessibilityView.updatePermissionStatus(accessibility)
}
Expand Down
14 changes: 12 additions & 2 deletions src/ui/Menubar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class Menubar {
permissionCalloutMenuItem.view = PermissionCallout()
let calloutSeparator = NSMenuItem.separator()
permissionCalloutMenuItems = [permissionCalloutMenuItem, calloutSeparator]
menu.addItem(permissionCalloutMenuItem)
menu.addItem(calloutSeparator)
menu.addItem(
withTitle: String(format: NSLocalizedString("About %@", comment: "Menubar option. %@ is AltTab"), App.name),
action: #selector(App.app.showAboutTab),
Expand Down Expand Up @@ -55,6 +53,18 @@ class Menubar {
menubarIconCallback(nil)
}

// NSMenuItem.isHidden isn't reliable with custom views. We add/remove to hide/show these items
static func togglePermissionCallout(_ show: Bool) {
permissionCalloutMenuItems?.enumerated().forEach { offset, element in
if show && !menu.items.contains(element) {
menu.insertItem(element, at: offset)
}
if !show && menu.items.contains(element) {
menu.removeItem(element)
}
}
}

@objc static func statusItemOnClick() {
// NSApp.currentEvent == nil if the icon is "clicked" through VoiceOver
if let type = NSApp.currentEvent?.type, type != .leftMouseDown {
Expand Down

0 comments on commit 9585c92

Please sign in to comment.