aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-18 01:27:17 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-18 01:34:24 +0530
commitdc8f27c5c36a212336318f62c1c45e31bb9d95d6 (patch)
treef5f240e3141e1853a81a7334ddacdb4e5b6cd6e3 /WireGuard/WireGuard/UI/macOS/AppDelegate.swift
parentmacOS: Fix autolayout errors on Add Empty Tunnel (diff)
downloadwireguard-apple-dc8f27c5c36a212336318f62c1c45e31bb9d95d6.tar.xz
wireguard-apple-dc8f27c5c36a212336318f62c1c45e31bb9d95d6.zip
macOS: Rafactor by introducing a TunnelsTracker
The TunnelTracker is now the central place to track what the current tunnel is, and for keeping track of the tunnel list. Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/macOS/AppDelegate.swift')
-rw-r--r--WireGuard/WireGuard/UI/macOS/AppDelegate.swift36
1 files changed, 28 insertions, 8 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
index 3f089875..95c1aa6a 100644
--- a/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
+++ b/WireGuard/WireGuard/UI/macOS/AppDelegate.swift
@@ -6,8 +6,12 @@ import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
+ var tunnelsManager: TunnelsManager?
+ var tunnelsTracker: TunnelsTracker?
var statusItemController: StatusItemController?
- var currentTunnelStatusObserver: AnyObject?
+
+ var manageTunnelsRootVC: ManageTunnelsRootViewController?
+ var manageTunnelsWindowObject: NSWindow?
func applicationDidFinishLaunching(_ aNotification: Notification) {
Logger.configureGlobal(withFilePath: FileManager.appLogFileURL?.path)
@@ -20,19 +24,35 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
let tunnelsManager: TunnelsManager = result.value!
- let statusItemController = StatusItemController()
let statusMenu = StatusMenu(tunnelsManager: tunnelsManager)
+ statusMenu.windowDelegate = self
+ let statusItemController = StatusItemController()
statusItemController.statusItem.menu = statusMenu
- statusItemController.currentTunnel = statusMenu.currentTunnel
- self.currentTunnelStatusObserver = statusMenu.observe(\.currentTunnel) { statusMenu, _ in
- statusItemController.currentTunnel = statusMenu.currentTunnel
- }
+
+ let tunnelsTracker = TunnelsTracker(tunnelsManager: tunnelsManager)
+ tunnelsTracker.statusMenu = statusMenu
+ tunnelsTracker.statusItemController = statusItemController
+
+ self.tunnelsManager = tunnelsManager
+ self.tunnelsTracker = tunnelsTracker
self.statusItemController = statusItemController
+ }
+ }
+}
- tunnelsManager.tunnelsListDelegate = statusMenu
- tunnelsManager.activationDelegate = statusMenu
+extension AppDelegate: StatusMenuWindowDelegate {
+ func manageTunnelsWindow() -> NSWindow {
+ if manageTunnelsWindowObject == nil {
+ manageTunnelsRootVC = ManageTunnelsRootViewController(tunnelsManager: tunnelsManager!)
+ let window = NSWindow(contentViewController: manageTunnelsRootVC!)
+ window.title = tr("macWindowTitleManageTunnels")
+ window.setContentSize(NSSize(width: 800, height: 480))
+ window.setFrameAutosaveName(NSWindow.FrameAutosaveName("ManageTunnelsWindow")) // Auto-save window position and size
+ manageTunnelsWindowObject = window
+ tunnelsTracker?.manageTunnelsRootVC = manageTunnelsRootVC
}
+ return manageTunnelsWindowObject!
}
}