diff --git a/FastMemos/ViewModels/AppState.swift b/FastMemos/ViewModels/AppState.swift index 5df7709..a7df51c 100644 --- a/FastMemos/ViewModels/AppState.swift +++ b/FastMemos/ViewModels/AppState.swift @@ -1,5 +1,6 @@ import Foundation import SwiftUI +import ServiceManagement /// Global app state that persists settings and manages authentication class AppState: ObservableObject { @@ -10,11 +11,23 @@ class AppState: ObservableObject { @Published var isLoading: Bool = false @Published var lastError: String? + @Published var launchAtLogin: Bool = false { + didSet { + if launchAtLogin { + try? SMAppService.mainApp.register() + } else { + try? SMAppService.mainApp.unregister() + } + } + } + private let keychainService = KeychainService() private lazy var apiService = MemosAPIService() init() { loadSettings() + // Check current launch at login status + launchAtLogin = SMAppService.mainApp.status == .enabled } // MARK: - Settings Persistence diff --git a/FastMemos/Views/SettingsView.swift b/FastMemos/Views/SettingsView.swift index c976663..95a9789 100644 --- a/FastMemos/Views/SettingsView.swift +++ b/FastMemos/Views/SettingsView.swift @@ -25,6 +25,18 @@ struct SettingsView: View { ScrollView { VStack(alignment: .leading, spacing: 20) { + // General Section + VStack(alignment: .leading, spacing: 8) { + Label("General", systemImage: "gearshape") + .font(.subheadline) + .fontWeight(.medium) + + Toggle("Launch at login", isOn: $appState.launchAtLogin) + .toggleStyle(.switch) + } + + Divider() + // Default Visibility Section VStack(alignment: .leading, spacing: 8) { Label("Default Visibility", systemImage: "eye")