macOS: Fix appearance of main menu when showing the manage window

This commit is contained in:
Roopesh Chander 2019-05-09 18:39:06 +05:30
parent b779114ccc
commit 4f79bf7b9b
2 changed files with 19 additions and 5 deletions

View File

@ -100,11 +100,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
func applicationShouldTerminateAfterLastWindowClosed(_ application: NSApplication) -> Bool {
application.setActivationPolicy(.accessory)
AppDelegate.setAppAppearsInDock(false)
return false
}
}
extension AppDelegate {
static func setAppAppearsInDock(_ enabled: Bool) {
if enabled {
if NSApp.activationPolicy() != .regular {
// It looks like we need to go from deactivated to activated with policy as .regular
// for our app's main menu to show up.
NSApp.deactivate()
NSApp.setActivationPolicy(.regular)
}
NSApp.activate(ignoringOtherApps: true)
} else {
NSApp.setActivationPolicy(.accessory)
}
}
}
extension AppDelegate {
@objc func aboutClicked() {
var appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown"

View File

@ -151,15 +151,13 @@ class StatusMenu: NSMenu {
}
@objc func manageTunnelsClicked() {
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
AppDelegate.setAppAppearsInDock(true)
guard let manageTunnelsWindow = windowDelegate?.manageTunnelsWindow() else { return }
manageTunnelsWindow.makeKeyAndOrderFront(self)
}
@objc func importTunnelsClicked() {
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
AppDelegate.setAppAppearsInDock(true)
guard let manageTunnelsWindow = windowDelegate?.manageTunnelsWindow() else { return }
manageTunnelsWindow.makeKeyAndOrderFront(self)
ImportPanelPresenter.presentImportPanel(tunnelsManager: tunnelsManager, sourceVC: manageTunnelsWindow.contentViewController)