44//
55
66import Charts
7+ import ServiceManagement
78import SwiftUI
89
910// MARK: - Stream Detail View
@@ -1529,7 +1530,7 @@ struct AutoPushRulesView: View {
15291530struct SettingsView : View {
15301531 @Bindable var appState : AppState
15311532
1532- @State private var startOnLaunch : Bool = false
1533+ @State private var openAtLogin : Bool = false
15331534 @State private var showNotifications : Bool = false
15341535 @State private var customBinaryPath : String = " "
15351536 @State private var customConfigPath : String = " "
@@ -1616,9 +1617,22 @@ struct SettingsView: View {
16161617 }
16171618 }
16181619
1619- Section ( " Server " ) {
1620- Toggle ( " Start server on app launch " , isOn: $startOnLaunch)
1621- . onChange ( of: startOnLaunch) { hasChanges = true }
1620+ Section ( " App " ) {
1621+ Toggle ( " Open at Login " , isOn: $openAtLogin)
1622+ . onChange ( of: openAtLogin) {
1623+ if #available( macOS 13 . 0 , * ) {
1624+ do {
1625+ if openAtLogin {
1626+ try SMAppService . mainApp. register ( )
1627+ } else {
1628+ try SMAppService . mainApp. unregister ( )
1629+ }
1630+ } catch {
1631+ print ( " [Settings] Login item toggle failed: \( error) " )
1632+ openAtLogin = !openAtLogin // revert on failure
1633+ }
1634+ }
1635+ }
16221636 Toggle ( " Show notifications " , isOn: $showNotifications)
16231637 . onChange ( of: showNotifications) { hasChanges = true }
16241638 }
@@ -1758,7 +1772,9 @@ struct SettingsView: View {
17581772 . navigationBarBackButtonHidden ( true )
17591773 . frame ( maxWidth: . infinity, maxHeight: . infinity)
17601774 . onAppear {
1761- startOnLaunch = UserDefaults . standard. bool ( forKey: " LaunchAtStartup " )
1775+ if #available( macOS 13 . 0 , * ) {
1776+ openAtLogin = SMAppService . mainApp. status == . enabled
1777+ }
17621778 showNotifications = UserDefaults . standard. bool ( forKey: " ShowNotifications " )
17631779 customBinaryPath = UserDefaults . standard. string ( forKey: " CustomBinaryPath " ) ?? " "
17641780 customConfigPath = UserDefaults . standard. string ( forKey: " CustomConfigPath " ) ?? " "
@@ -1767,7 +1783,6 @@ struct SettingsView: View {
17671783 }
17681784
17691785 private func savePreferences( ) {
1770- UserDefaults . standard. set ( startOnLaunch, forKey: " LaunchAtStartup " )
17711786 UserDefaults . standard. set ( showNotifications, forKey: " ShowNotifications " )
17721787 UserDefaults . standard. set ( customBinaryPath. trimmed, forKey: " CustomBinaryPath " )
17731788 UserDefaults . standard. set ( customConfigPath. trimmed, forKey: " CustomConfigPath " )
0 commit comments