Add background

This commit is contained in:
2026-02-27 12:03:02 +11:00
parent 4070904db8
commit 924c00d0c2
6 changed files with 40 additions and 0 deletions

View File

@@ -27,12 +27,14 @@
C4C93F2911B41BC19A2AE934 /* SettingsWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A973877BCE6084D0EBBBDBD /* SettingsWindowController.swift */; };
CC26C1677258E44F0D7B106A /* SwiftTermView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E47000112562615C7E59489 /* SwiftTermView.swift */; };
E9A064422790735E033E534F /* TerminalManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA6843B571B41986DE386F5F /* TerminalManager.swift */; };
EA604F3F38D6638C7236CDC2 /* LaunchAtLoginHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B567F3B5D006D2B35630CFF /* LaunchAtLoginHelper.swift */; };
F0130A88D1453CD199FA65D7 /* NSScreen+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0CED6A0F25A6E57D8AA308A /* NSScreen+Extensions.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
02FEFF9074A85F02C43D9408 /* NotchWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotchWindow.swift; sourceTree = "<group>"; };
0A973877BCE6084D0EBBBDBD /* SettingsWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsWindowController.swift; sourceTree = "<group>"; };
0B567F3B5D006D2B35630CFF /* LaunchAtLoginHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchAtLoginHelper.swift; sourceTree = "<group>"; };
15A290D4D21D6C01A583A372 /* ScreenManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenManager.swift; sourceTree = "<group>"; };
1E47000112562615C7E59489 /* SwiftTermView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftTermView.swift; sourceTree = "<group>"; };
1FC09C538CBE7C2D072008B2 /* NotchShape.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotchShape.swift; sourceTree = "<group>"; };
@@ -79,6 +81,7 @@
isa = PBXGroup;
children = (
3B72743F178231E0B06DD3DE /* HotkeyManager.swift */,
0B567F3B5D006D2B35630CFF /* LaunchAtLoginHelper.swift */,
EA1CD1DE020F0467AFB98DE3 /* PopoutWindowController.swift */,
15A290D4D21D6C01A583A372 /* ScreenManager.swift */,
0A973877BCE6084D0EBBBDBD /* SettingsWindowController.swift */,
@@ -223,6 +226,7 @@
88EBFBB2292659EA7C42A8F9 /* HotkeyBinding.swift in Sources */,
4D5125E11B4DDBDB3DFACBAF /* HotkeyManager.swift in Sources */,
7BD705CA6A34117929B362EC /* HotkeyRecorderView.swift in Sources */,
EA604F3F38D6638C7236CDC2 /* LaunchAtLoginHelper.swift in Sources */,
F0130A88D1453CD199FA65D7 /* NSScreen+Extensions.swift in Sources */,
2213F430F3D8A88033607CD2 /* NotchSettings.swift in Sources */,
4566E6B87CB62AF5C8D4B9D8 /* NotchShape.swift in Sources */,

View File

@@ -11,6 +11,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
NotchSettings.registerDefaults()
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)
ScreenManager.shared.start()
observeDisplayPreference()
observeSizePreferences()

View File

@@ -0,0 +1,24 @@
import ServiceManagement
/// Registers / unregisters the app as a login item using the
/// modern SMAppService API (macOS 13+).
enum LaunchAtLoginHelper {
static func setEnabled(_ enabled: Bool) {
let service = SMAppService.mainApp
do {
if enabled {
try service.register()
} else {
try service.unregister()
}
} catch {
print("[LaunchAtLogin] Failed to \(enabled ? "register" : "unregister"): \(error)")
}
}
/// Reads the current registration state from the system.
static var isEnabled: Bool {
SMAppService.mainApp.status == .enabled
}
}

View File

@@ -9,6 +9,7 @@ enum NotchSettings {
static let openNotchOnHover = "openNotchOnHover"
static let minimumHoverDuration = "minimumHoverDuration"
static let showMenuBarIcon = "showMenuBarIcon"
static let launchAtLogin = "launchAtLogin"
// Sizing closed state
static let notchHeight = "notchHeight"
@@ -58,6 +59,7 @@ enum NotchSettings {
static let openNotchOnHover: Bool = true
static let minimumHoverDuration: Double = 0.3
static let showMenuBarIcon: Bool = true
static let launchAtLogin: Bool = false
static let notchHeight: Double = 32
static let nonNotchHeight: Double = 32
@@ -102,6 +104,7 @@ enum NotchSettings {
Keys.openNotchOnHover: Defaults.openNotchOnHover,
Keys.minimumHoverDuration: Defaults.minimumHoverDuration,
Keys.showMenuBarIcon: Defaults.showMenuBarIcon,
Keys.launchAtLogin: Defaults.launchAtLogin,
Keys.notchHeight: Defaults.notchHeight,
Keys.nonNotchHeight: Defaults.nonNotchHeight,

View File

@@ -73,6 +73,7 @@ struct GeneralSettingsView: View {
@AppStorage(NotchSettings.Keys.openNotchOnHover) private var openNotchOnHover = NotchSettings.Defaults.openNotchOnHover
@AppStorage(NotchSettings.Keys.minimumHoverDuration) private var minimumHoverDuration = NotchSettings.Defaults.minimumHoverDuration
@AppStorage(NotchSettings.Keys.showMenuBarIcon) private var showMenuBarIcon = NotchSettings.Defaults.showMenuBarIcon
@AppStorage(NotchSettings.Keys.launchAtLogin) private var launchAtLogin = NotchSettings.Defaults.launchAtLogin
@AppStorage(NotchSettings.Keys.enableGestures) private var enableGestures = NotchSettings.Defaults.enableGestures
@AppStorage(NotchSettings.Keys.gestureSensitivity) private var gestureSensitivity = NotchSettings.Defaults.gestureSensitivity
@@ -89,6 +90,10 @@ struct GeneralSettingsView: View {
Section("Display") {
Toggle("Show on all displays", isOn: $showOnAllDisplays)
Toggle("Show menu bar icon", isOn: $showMenuBarIcon)
Toggle("Launch at login", isOn: $launchAtLogin)
.onChange(of: launchAtLogin) { _, newValue in
LaunchAtLoginHelper.setEnabled(newValue)
}
}
Section("Hover Behavior") {