macOS: Minor refactor of StatusMenuWindowDelegate

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-05-15 16:16:00 +05:30
parent 586a592b68
commit 9bf304a9ac
2 changed files with 18 additions and 13 deletions

View File

@ -124,9 +124,13 @@ extension AppDelegate {
}
extension AppDelegate: StatusMenuWindowDelegate {
func manageTunnelsWindow() -> NSWindow {
func showManageTunnelsWindow(completion: ((NSWindow?) -> Void)?) {
guard let tunnelsManager = tunnelsManager else {
completion?(nil)
return
}
if manageTunnelsWindowObject == nil {
manageTunnelsRootVC = ManageTunnelsRootViewController(tunnelsManager: tunnelsManager!)
manageTunnelsRootVC = ManageTunnelsRootViewController(tunnelsManager: tunnelsManager)
let window = NSWindow(contentViewController: manageTunnelsRootVC!)
window.title = tr("macWindowTitleManageTunnels")
window.setContentSize(NSSize(width: 800, height: 480))
@ -134,7 +138,10 @@ extension AppDelegate: StatusMenuWindowDelegate {
manageTunnelsWindowObject = window
tunnelsTracker?.manageTunnelsRootVC = manageTunnelsRootVC
}
return manageTunnelsWindowObject!
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
manageTunnelsWindowObject!.makeKeyAndOrderFront(self)
completion?(manageTunnelsWindowObject)
}
}

View File

@ -4,7 +4,7 @@
import Cocoa
protocol StatusMenuWindowDelegate: class {
func manageTunnelsWindow() -> NSWindow
func showManageTunnelsWindow(completion: ((NSWindow?) -> Void)?)
}
class StatusMenu: NSMenu {
@ -151,18 +151,16 @@ class StatusMenu: NSMenu {
}
@objc func manageTunnelsClicked() {
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
guard let manageTunnelsWindow = windowDelegate?.manageTunnelsWindow() else { return }
manageTunnelsWindow.makeKeyAndOrderFront(self)
windowDelegate?.showManageTunnelsWindow(completion: nil)
}
@objc func importTunnelsClicked() {
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
guard let manageTunnelsWindow = windowDelegate?.manageTunnelsWindow() else { return }
manageTunnelsWindow.makeKeyAndOrderFront(self)
ImportPanelPresenter.presentImportPanel(tunnelsManager: tunnelsManager, sourceVC: manageTunnelsWindow.contentViewController)
windowDelegate?.showManageTunnelsWindow { [weak self] manageTunnelsWindow in
guard let self = self else { return }
guard let manageTunnelsWindow = manageTunnelsWindow else { return }
ImportPanelPresenter.presentImportPanel(tunnelsManager: self.tunnelsManager,
sourceVC: manageTunnelsWindow.contentViewController)
}
}
}