Files
LockInBroMacOS/LockInBro/LockInBroApp.swift

61 lines
2.0 KiB
Swift
Raw Permalink Normal View History

// LockInBroApp.swift App entry point with menu bar + main window
2026-03-28 14:53:40 -04:00
import SwiftUI
2026-03-29 06:29:18 -04:00
// MARK: - AppDelegate (subprocess cleanup on quit)
final class AppDelegate: NSObject, NSApplicationDelegate {
/// Called for normal quits (Cmd+Q), window close, and SIGTERM.
/// Ensures the argus subprocess is killed before the process exits.
func applicationWillTerminate(_ notification: Notification) {
// applicationWillTerminate runs on the main thread, so we can safely
// call @MainActor methods synchronously via assumeIsolated.
MainActor.assumeIsolated {
SessionManager.shared.stopMonitoring()
}
}
}
2026-03-28 14:53:40 -04:00
@main
struct LockInBroApp: App {
2026-03-29 06:29:18 -04:00
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@State private var auth = AuthManager.shared
@State private var session = SessionManager.shared
2026-03-28 14:53:40 -04:00
var body: some Scene {
// Main window
WindowGroup("LockInBro") {
2026-03-28 14:53:40 -04:00
ContentView()
.environment(auth)
.environment(session)
2026-03-29 06:29:18 -04:00
.onChange(of: auth.isLoggedIn, initial: true) { _, loggedIn in
if loggedIn {
// Show HUD and start always-on monitoring as soon as user logs in
2026-03-29 00:58:22 -04:00
FloatingPanelController.shared.show(session: session)
2026-03-29 06:29:18 -04:00
Task { await session.startMonitoring() }
2026-03-29 00:58:22 -04:00
} else {
FloatingPanelController.shared.close()
}
}
}
.defaultSize(width: 840, height: 580)
// Menu bar extra
MenuBarExtra {
MenuBarView()
.environment(auth)
.environment(session)
} label: {
// Show a filled icon when a session is active
if session.isSessionActive {
Image(systemName: "brain.head.profile")
.symbolEffect(.pulse)
} else {
Image(systemName: "brain.head.profile")
}
2026-03-28 14:53:40 -04:00
}
.menuBarExtraStyle(.window)
2026-03-28 14:53:40 -04:00
}
}