-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMegaplanMenuBarApp.swift
More file actions
77 lines (65 loc) · 2.74 KB
/
MegaplanMenuBarApp.swift
File metadata and controls
77 lines (65 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import SwiftUI
@main
struct MegaplanMenuBarApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject private var appState: AppState
@StateObject private var notificationListViewModel: NotificationListViewModel
@StateObject private var settingsViewModel: SettingsViewModel
init() {
AppLogger.info("MegaplanMenuBarApp initializing...")
let appState = AppState()
_appState = StateObject(wrappedValue: appState)
_notificationListViewModel = StateObject(wrappedValue: NotificationListViewModel(appState: appState))
_settingsViewModel = StateObject(wrappedValue: SettingsViewModel(appState: appState))
}
var body: some Scene {
Settings {
SettingsView()
.environmentObject(appState)
.environmentObject(settingsViewModel)
.frame(width: 480, height: 500)
}
}
}
/// App delegate to manage the status bar controller lifecycle.
final class AppDelegate: NSObject, NSApplicationDelegate {
private var statusBarController: StatusBarController?
private var appState: AppState?
private var notificationListViewModel: NotificationListViewModel?
private var settingsViewModel: SettingsViewModel?
func applicationDidFinishLaunching(_ notification: Notification) {
AppLogger.info("AppDelegate: applicationDidFinishLaunching")
// Create shared state objects
let appState = AppState()
let notificationListViewModel = NotificationListViewModel(appState: appState)
let settingsViewModel = SettingsViewModel(appState: appState)
self.appState = appState
self.notificationListViewModel = notificationListViewModel
self.settingsViewModel = settingsViewModel
// Create content view for popover
let contentView = NotificationListView()
.environmentObject(appState)
.environmentObject(notificationListViewModel)
.environmentObject(settingsViewModel)
.frame(minWidth: 340, maxWidth: 400, minHeight: 600, maxHeight: 1000)
// Setup status bar controller
let controller = StatusBarController()
controller.setup(
appState: appState,
settingsViewModel: settingsViewModel,
contentView: contentView
)
self.statusBarController = controller
AppLogger.info("AppDelegate: Status bar setup complete")
}
func applicationWillTerminate(_ notification: Notification) {
AppLogger.info("AppDelegate: applicationWillTerminate")
cleanup()
}
private func cleanup() {
statusBarController = nil
settingsViewModel = nil
notificationListViewModel = nil
appState = nil
}
}