Asset fix: - nas_logo_clean.imageset/Contents.json now registers the 512px PNG at all three scales (1x/2x/3x) so iOS uses it on every device type. Previously only 1x was wired causing the image to be missing on Retina. - Logo rendered with thin AppTheme.inkQuaternary ring overlay so its dark-background edge stays legible against any app background color. LoginView overhaul: - New hierarchy: Kisani title → 90pt logo → NAS displayName → username - Staggered spring entrance (0.06–0.32s delays, asymmetric ease) - "Switch User" replaces "More options" — calls store.signOut() to clear connection/session/onboarding and return to ConnectView. - MoreOptionsSheet removed (no longer needed). ConnectionStore: - Added lock() — ends session but preserves saved connection (returns to LoginView for Face ID re-auth without losing NAS credentials). - signOut() now clearly documented as clearing everything. - Removed duplicate sectionLabel() from SettingsView (canonical version lives in LANTriggerSection.swift as a top-level free function). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
128 lines
5.5 KiB
Swift
128 lines
5.5 KiB
Swift
import Foundation
|
|
import Combine
|
|
|
|
private func ud<T: Decodable>(_ type: T.Type, key: String) -> T? {
|
|
guard let data = UserDefaults.standard.data(forKey: key) else { return nil }
|
|
return try? JSONDecoder().decode(type, from: data)
|
|
}
|
|
|
|
private func saveUD<T: Encodable>(_ value: T?, key: String) {
|
|
guard let value else { UserDefaults.standard.removeObject(forKey: key); return }
|
|
if let data = try? JSONEncoder().encode(value) { UserDefaults.standard.set(data, forKey: key) }
|
|
}
|
|
|
|
final class ConnectionStore: ObservableObject {
|
|
static let shared = ConnectionStore()
|
|
|
|
@Published var savedConnection: NASConnection? {
|
|
didSet {
|
|
if let conn = savedConnection { SavedConnections.save(conn) }
|
|
else { SavedConnections.delete() }
|
|
}
|
|
}
|
|
@Published var backupFilter: BackupFilter {
|
|
didSet { saveUD(backupFilter, key: "backupFilter") }
|
|
}
|
|
@Published var trustedSSIDs: [String] {
|
|
didSet { UserDefaults.standard.set(trustedSSIDs, forKey: "trustedSSIDs") }
|
|
}
|
|
@Published var lanTriggerEnabled: Bool {
|
|
didSet { UserDefaults.standard.set(lanTriggerEnabled, forKey: "lanTriggerEnabled") }
|
|
}
|
|
@Published var startDelaySeconds: Int {
|
|
didSet { UserDefaults.standard.set(startDelaySeconds, forKey: "startDelaySeconds") }
|
|
}
|
|
@Published var chargingOnlyMode: Bool {
|
|
didSet { UserDefaults.standard.set(chargingOnlyMode, forKey: "chargingOnlyMode") }
|
|
}
|
|
@Published var quietHoursEnabled: Bool {
|
|
didSet { UserDefaults.standard.set(quietHoursEnabled, forKey: "quietHoursEnabled") }
|
|
}
|
|
@Published var quietHoursStart: Int {
|
|
didSet { UserDefaults.standard.set(quietHoursStart, forKey: "quietHoursStart") }
|
|
}
|
|
@Published var quietHoursEnd: Int {
|
|
didSet { UserDefaults.standard.set(quietHoursEnd, forKey: "quietHoursEnd") }
|
|
}
|
|
|
|
// Session — not persisted, resets on every app launch
|
|
@Published var isSessionActive = false
|
|
|
|
// Onboarding — persisted so we only show each step once
|
|
@Published var onboardingPhotoShown: Bool {
|
|
didSet { UserDefaults.standard.set(onboardingPhotoShown, forKey: "onboardingPhotoShown") }
|
|
}
|
|
|
|
// Appearance
|
|
@Published var appearanceMode: AppearanceMode {
|
|
didSet { UserDefaults.standard.set(appearanceMode.rawValue, forKey: "appearanceMode") }
|
|
}
|
|
|
|
// Cellular & remote access
|
|
@Published var allowCellularBackup: Bool {
|
|
didSet { UserDefaults.standard.set(allowCellularBackup, forKey: "allowCellularBackup") }
|
|
}
|
|
@Published var useTailscaleWhenRemote: Bool {
|
|
didSet { UserDefaults.standard.set(useTailscaleWhenRemote, forKey: "useTailscaleWhenRemote") }
|
|
}
|
|
@Published var tailscaleHost: String {
|
|
didSet { UserDefaults.standard.set(tailscaleHost, forKey: "tailscaleHost") }
|
|
}
|
|
|
|
@Published private(set) var historyEntries: [BackupHistoryEntry] = []
|
|
|
|
private init() {
|
|
savedConnection = SavedConnections.load()
|
|
backupFilter = ud(BackupFilter.self, key: "backupFilter") ?? BackupFilter()
|
|
trustedSSIDs = UserDefaults.standard.stringArray(forKey: "trustedSSIDs") ?? []
|
|
lanTriggerEnabled = UserDefaults.standard.object(forKey: "lanTriggerEnabled") as? Bool ?? true
|
|
startDelaySeconds = UserDefaults.standard.object(forKey: "startDelaySeconds") as? Int ?? 30
|
|
chargingOnlyMode = UserDefaults.standard.object(forKey: "chargingOnlyMode") as? Bool ?? true
|
|
quietHoursEnabled = UserDefaults.standard.object(forKey: "quietHoursEnabled") as? Bool ?? false
|
|
quietHoursStart = UserDefaults.standard.object(forKey: "quietHoursStart") as? Int ?? 23
|
|
quietHoursEnd = UserDefaults.standard.object(forKey: "quietHoursEnd") as? Int ?? 7
|
|
onboardingPhotoShown = UserDefaults.standard.bool(forKey: "onboardingPhotoShown")
|
|
appearanceMode = AppearanceMode(rawValue: UserDefaults.standard.string(forKey: "appearanceMode") ?? "") ?? .system
|
|
allowCellularBackup = UserDefaults.standard.object(forKey: "allowCellularBackup") as? Bool ?? false
|
|
useTailscaleWhenRemote = UserDefaults.standard.object(forKey: "useTailscaleWhenRemote") as? Bool ?? false
|
|
tailscaleHost = UserDefaults.standard.string(forKey: "tailscaleHost") ?? ""
|
|
historyEntries = ud([BackupHistoryEntry].self, key: "historyEntries") ?? []
|
|
}
|
|
|
|
func appendHistoryEntry(_ entry: BackupHistoryEntry) {
|
|
historyEntries.insert(entry, at: 0)
|
|
saveUD(historyEntries, key: "historyEntries")
|
|
}
|
|
|
|
func removeHistoryEntries(at offsets: IndexSet) {
|
|
historyEntries.remove(atOffsets: offsets)
|
|
saveUD(historyEntries, key: "historyEntries")
|
|
}
|
|
|
|
func clearHistory() {
|
|
historyEntries = []
|
|
UserDefaults.standard.removeObject(forKey: "historyEntries")
|
|
}
|
|
|
|
/// Locks the screen — keeps the saved connection but requires Face ID again.
|
|
func lock() {
|
|
isSessionActive = false
|
|
}
|
|
|
|
/// Clears everything: connection, session, and onboarding state. Returns to ConnectView.
|
|
func signOut() {
|
|
isSessionActive = false
|
|
onboardingPhotoShown = false
|
|
savedConnection = nil
|
|
}
|
|
|
|
var isInQuietHours: Bool {
|
|
guard quietHoursEnabled else { return false }
|
|
let hour = Calendar.current.component(.hour, from: Date())
|
|
if quietHoursStart > quietHoursEnd {
|
|
return hour >= quietHoursStart || hour < quietHoursEnd
|
|
}
|
|
return hour >= quietHoursStart && hour < quietHoursEnd
|
|
}
|
|
}
|