diff --git a/src/logic/SystemPermissions.swift b/src/logic/SystemPermissions.swift index d3dd8bc9..a0086623 100644 --- a/src/logic/SystemPermissions.swift +++ b/src/logic/SystemPermissions.swift @@ -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() } @@ -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) } diff --git a/src/ui/Menubar.swift b/src/ui/Menubar.swift index c67a6df7..7eec8f86 100644 --- a/src/ui/Menubar.swift +++ b/src/ui/Menubar.swift @@ -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), @@ -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 {