Yep. AI rewrote the whole thing.
This commit is contained in:
@@ -4,22 +4,36 @@ import Combine
|
||||
/// Application delegate that bootstraps the notch overlay system.
|
||||
@MainActor
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private enum UITestLaunchArgument {
|
||||
static let regularActivation = "--uitest-regular-activation"
|
||||
static let showSettings = "--uitest-show-settings"
|
||||
static let openNotch = "--uitest-open-notch"
|
||||
}
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
private let settingsController = AppSettingsController.shared
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
NotchSettings.registerDefaults()
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
|
||||
if isRunningUITests {
|
||||
NSApp.setActivationPolicy(.regular)
|
||||
} else {
|
||||
NSApp.setActivationPolicy(.accessory)
|
||||
}
|
||||
|
||||
// Sync the launch-at-login toggle with the actual system state
|
||||
// in case the user toggled it from System Settings.
|
||||
UserDefaults.standard.set(LaunchAtLoginHelper.isEnabled, forKey: NotchSettings.Keys.launchAtLogin)
|
||||
settingsController.update {
|
||||
$0.display.launchAtLogin = LaunchAtLoginHelper.isEnabled
|
||||
}
|
||||
|
||||
ScreenManager.shared.start()
|
||||
observeDisplayPreference()
|
||||
observeSizePreferences()
|
||||
observeFontSizeChanges()
|
||||
observeTerminalThemeChanges()
|
||||
applyUITestLaunchBehaviorIfNeeded()
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
@@ -30,7 +44,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
/// Only rebuild windows when the display-count preference changes.
|
||||
private func observeDisplayPreference() {
|
||||
UserDefaults.standard.publisher(for: \.showOnAllDisplays)
|
||||
settingsController.$settings
|
||||
.map(\.display.showOnAllDisplays)
|
||||
.removeDuplicates()
|
||||
.dropFirst()
|
||||
.sink { _ in
|
||||
@@ -41,7 +56,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
/// Reposition (not rebuild) when any sizing preference changes.
|
||||
private func observeSizePreferences() {
|
||||
NotificationCenter.default.publisher(for: UserDefaults.didChangeNotification)
|
||||
settingsController.$settings
|
||||
.map(\.display.layoutSignature)
|
||||
.removeDuplicates()
|
||||
.dropFirst()
|
||||
.debounce(for: .milliseconds(300), scheduler: RunLoop.main)
|
||||
.sink { _ in
|
||||
ScreenManager.shared.repositionWindows()
|
||||
@@ -51,38 +69,49 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
/// Live-update terminal font size across all sessions.
|
||||
private func observeFontSizeChanges() {
|
||||
UserDefaults.standard.publisher(for: \.terminalFontSize)
|
||||
settingsController.$settings
|
||||
.map(\.terminal.fontSize)
|
||||
.removeDuplicates()
|
||||
.sink { newSize in
|
||||
guard newSize > 0 else { return }
|
||||
TerminalManager.shared.updateAllFontSizes(CGFloat(newSize))
|
||||
WorkspaceRegistry.shared.updateAllWorkspacesFontSizes(CGFloat(newSize))
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
/// Live-update terminal colors across all sessions.
|
||||
private func observeTerminalThemeChanges() {
|
||||
UserDefaults.standard.publisher(for: \.terminalTheme)
|
||||
settingsController.$settings
|
||||
.map(\.terminal.themeRawValue)
|
||||
.removeDuplicates()
|
||||
.sink { newTheme in
|
||||
TerminalManager.shared.updateAllThemes(TerminalTheme.resolve(newTheme))
|
||||
WorkspaceRegistry.shared.updateAllWorkspacesThemes(TerminalTheme.resolve(newTheme))
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - KVO key paths
|
||||
|
||||
private extension UserDefaults {
|
||||
@objc var terminalFontSize: Double {
|
||||
double(forKey: NotchSettings.Keys.terminalFontSize)
|
||||
private var launchArguments: [String] {
|
||||
ProcessInfo.processInfo.arguments
|
||||
}
|
||||
|
||||
@objc var terminalTheme: String {
|
||||
string(forKey: NotchSettings.Keys.terminalTheme) ?? NotchSettings.Defaults.terminalTheme
|
||||
private var isRunningUITests: Bool {
|
||||
launchArguments.contains(UITestLaunchArgument.regularActivation)
|
||||
|| launchArguments.contains(UITestLaunchArgument.showSettings)
|
||||
|| launchArguments.contains(UITestLaunchArgument.openNotch)
|
||||
}
|
||||
|
||||
@objc var showOnAllDisplays: Bool {
|
||||
bool(forKey: NotchSettings.Keys.showOnAllDisplays)
|
||||
private func applyUITestLaunchBehaviorIfNeeded() {
|
||||
guard isRunningUITests else { return }
|
||||
|
||||
DispatchQueue.main.async { @MainActor in
|
||||
if self.launchArguments.contains(UITestLaunchArgument.showSettings) {
|
||||
SettingsWindowController.shared.showSettings()
|
||||
}
|
||||
|
||||
if self.launchArguments.contains(UITestLaunchArgument.openNotch),
|
||||
let screenID = ScreenRegistry.shared.activeScreenID() {
|
||||
ScreenManager.shared.openNotch(screenID: screenID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user