Repository Public
1import MCCCore2import SwiftUI3import UIKit4import UserNotifications56// Panes about this device: appearance, local lock, notifications, about / diagnostics.78struct AppearancePane: View {9 @Environment(AppModel.self) private var app10 @Environment(\.mccTheme) private var theme1112 var body: some View {13 PaneScaffold(pane: .appearance) {14 SectionCard(tr("settings.pane.appearance")) {15 ForEach(AppearancePreference.allCases) { a in16 let on = app.appearance == a17 Button { app.appearance = a } label: {18 HStack {19 Label(a.title, systemImage: a == .dark ? "moon" : a == .light ? "sun.max" : "circle.lefthalf.filled").foregroundStyle(theme.textPrimary)20 Spacer(minLength: Tokens.Space.s3)21 if on { Image(systemName: "checkmark").foregroundStyle(theme.accent).accessibilityHidden(true) }22 }23 .frame(minHeight: Tokens.Size.touchMin)24 .contentShape(Rectangle())25 }26 .buttonStyle(.plain)27 .hoverEffect(.highlight)28 .accessibilityAddTraits(on ? [.isSelected] : [])29 .accessibilityIdentifier("settings-appearance-" + a.rawValue)30 }31 Text(tr("settings.appearance.help")).font(.footnote).foregroundStyle(theme.textTertiary)32 }33 }34 }35}3637struct AppLockPane: View {38 @Environment(AppModel.self) private var app39 @Environment(\.mccTheme) private var theme40 @State private var working = false4142 var body: some View {43 let biometry = AppLock.biometryType44 PaneScaffold(pane: .appLock) {45 InfoBanner(tone: .info, title: tr("settings.lock.local_title"), message: tr("settings.lock.local_message"))46 SectionCard(tr("settings.pane.appLock")) {47 Toggle(isOn: Binding(get: { app.lock.isEnabled }, set: { on in48 if on {49 working = true50 Task { _ = await app.lock.enable(reason: tr("settings.lock.enable_reason")); working = false }51 } else {52 app.lock.isEnabled = false53 }54 })) {55 Label(tr("settings.lock.toggle", SettingsLogic.biometryLabel(biometry)), systemImage: SettingsLogic.biometrySymbol(biometry))56 }57 .frame(minHeight: Tokens.Size.touchMin)58 .disabled(working)59 .accessibilityIdentifier("settings-lock-toggle")60 switch app.lock.lastError {61 case .unavailable(let m)?, .failed(let m)?:62 InfoBanner(tone: .warning, title: tr("settings.lock.error"), message: m).accessibilityIdentifier("settings-lock-error")63 default: EmptyView()64 }65 if app.lock.isEnabled {66 Picker(tr("settings.lock.grace"), selection: Binding(get: { app.lock.gracePeriod }, set: { app.lock.gracePeriod = $0 })) {67 ForEach(SettingsLogic.graceOptions, id: \.self) { Text(SettingsLogic.graceLabel($0)).tag($0) }68 }69 .frame(minHeight: Tokens.Size.touchMin)70 .accessibilityIdentifier("settings-lock-grace")71 }72 }73 }74 }75}7677struct NotificationsPane: View {78 @Environment(AppModel.self) private var app79 @Environment(\.mccTheme) private var theme80 @Environment(\.openURL) private var openURL81 @Session private var session8283 var body: some View {84 @Bindable var push = app.push85 let status = push.authorization86 PaneScaffold(pane: .notifications, load: { await app.push.refreshAuthorization() }) {87 SectionCard(tr("settings.notifications.permission")) {88 StatusLabel(trDynamic("settings.notifications.status." + SettingsLogic.authorizationKey(status)),89 tone: status == .authorized || status == .provisional ? .ok : status == .denied ? .warning : .neutral)90 .accessibilityIdentifier("settings-notifications-status")91 if status == .notDetermined {92 Button { Task { await app.push.requestAuthorization() } } label: {93 Label(tr("settings.notifications.request"), systemImage: "bell.badge").frame(minHeight: Tokens.Size.touchMin)94 }95 .buttonStyle(.mccProminent)96 .accessibilityIdentifier("settings-notifications-request")97 } else if status == .denied, let url = URL(string: UIApplication.openSettingsURLString) {98 Button { openURL(url) } label: { Label(tr("settings.notifications.open_settings"), systemImage: "gear").frame(minHeight: Tokens.Size.touchMin) }99 .buttonStyle(.bordered)100 .accessibilityIdentifier("settings-notifications-open-settings")101 }102 Text(tr("settings.notifications.open_only")).font(.footnote).foregroundStyle(theme.textTertiary)103 }104 SectionCard(tr("settings.notifications.local")) {105 Toggle(tr("settings.notifications.local_toggle"), isOn: $push.localAlerts)106 .frame(minHeight: Tokens.Size.touchMin)107 .accessibilityIdentifier("settings-notifications-local")108 Text(tr("settings.notifications.local_help")).font(.footnote).foregroundStyle(theme.textTertiary)109 }110 SectionCard(tr("settings.notifications.remote")) {111 InfoBanner(tone: .info, title: tr("settings.notifications.remote_title"), message: tr("settings.notifications.remote_message"))112 InfoRow(tr("settings.notifications.environment"), AppEnvironment.pushIsProduction ? "production" : "development")113 InfoRow(tr("settings.notifications.token_uploaded"), push.tokenUploadedAt.map { Format.dateTime($0) } ?? tr("settings.never"))114 if let e = push.registrationError {115 InfoRow(tr("settings.notifications.registration_error"), e)116 }117 }118 }119 }120}121122struct AboutPane: View {123 @Environment(AppModel.self) private var app124 @Environment(\.mccTheme) private var theme125 @Session private var session126 @State private var copied = false127128 private var diagnostics: SettingsLogic.Diagnostics {129 let info = Bundle.main.infoDictionary ?? [:]130 let device = DeviceInfo.current()131 let v = session.admin.version.value132 return SettingsLogic.Diagnostics(appVersion: info["CFBundleShortVersionString"] as? String ?? "?", build: info["CFBundleVersion"] as? String ?? "?",133 system: "iOS " + device.osVersion, model: device.model, origin: session.configuration.origin.absoluteString,134 serverVersion: v?.version, apiVersion: v?.apiVersion, stream: SettingsLogic.streamKey(session.streamState),135 offline: session.isOffline, lastEventAt: session.lastEventAt, language: Localization.shared.language.rawValue,136 userHandle: session.user?.handle, role: session.user?.role.rawValue)137 }138139 var body: some View {140 let d = diagnostics141 let r = session.admin.version142 PaneScaffold(pane: .about, load: { await r.loadIfNeeded(maxAge: 300) }, reload: { await r.load() }) {143 SectionCard(tr("settings.about.app")) {144 InfoRow(tr("settings.about.version"), "\(d.appVersion) (\(d.build))")145 InfoRow(tr("settings.about.system"), d.system)146 InfoRow(tr("settings.devices.model"), d.model)147 InfoRow(tr("settings.devices.label"), DeviceInfo.storedLabel())148 }149 SectionCard(tr("settings.about.server")) {150 InfoRow(tr("settings.about.origin"), d.origin, monospaced: true)151 ResourceSection(resource: r) { v in152 VStack(alignment: .leading, spacing: Tokens.Space.s3) {153 InfoRow(tr("settings.about.server_version"), v.version)154 InfoRow(tr("settings.about.api_version"), v.apiVersion)155 InfoRow(tr("settings.about.commit"), v.commit, monospaced: true)156 if let b = v.builtAt { InfoRow(tr("settings.about.built"), Format.dateTime(b)) }157 if let m = v.minAppVersion { InfoRow(tr("settings.about.min_app"), m) }158 }159 }160 }161 SectionCard(tr("settings.about.connection")) {162 StatusLabel(trDynamic("settings.about.stream." + SettingsLogic.streamKey(session.streamState)), tone: SettingsLogic.streamTone(session.streamState))163 .accessibilityValue(SettingsLogic.streamKey(session.streamState))164 .accessibilityIdentifier("settings-stream-state")165 if case .reconnecting(let attempt, let retryAt, let lastError) = session.streamState {166 InfoRow(tr("settings.about.retry"), tr("settings.about.retry_value", attempt, Format.time(retryAt, seconds: true)))167 InfoRow(tr("settings.about.last_error"), lastError)168 }169 InfoRow(tr("settings.about.last_event"), session.lastEventAt.map { Format.time($0, seconds: true) } ?? tr("settings.never"))170 InfoRow(tr("settings.about.reachability"), session.isOffline ? tr("stale.offline.title") : tr("settings.about.online"))171 if let since = session.offlineSince { InfoRow(tr("settings.about.offline_since"), Format.dateTime(since)) }172 }173 Button {174 UIPasteboard.general.string = d.text175 copied = true176 } label: {177 Label(tr(copied ? "settings.secret.copied" : "settings.about.copy"), systemImage: copied ? "checkmark" : "doc.on.doc").frame(maxWidth: .infinity, minHeight: Tokens.Size.touchMin)178 }179 .buttonStyle(.bordered)180 .accessibilityIdentifier("settings-copy-diagnostics")181 Text(tr("settings.about.copy_help")).font(.footnote).foregroundStyle(theme.textTertiary)182 }183 }184}185