SPB Git

Repository Public License

SettingsPages.swift 11.9 KB 181 lines swift

1// ORIX Alarm2// File: App/Features/Settings/SettingsPages.swift3// Description: Pages pushed from Settings: default alarm sound picker with preview, "How ORIX Alarm works" and the privacy summary.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import AlarmCore8import SwiftUI910// MARK: Default alarm sound11struct DefaultSoundPickerView: View {12    @Environment(AppModel.self) private var model13    private var player: SoundPlayer { SoundPlayer.shared }1415    var body: some View {16        ScrollView {17            VStack(spacing: 10) {18                ForEach(SoundCatalog.alarmSounds) { sound in19                    let selected = model.settings.defaultSoundID == sound.id20                    let playing = player.previewingID == sound.id21                    HStack(spacing: 10) {22                        Button {23                            Haptics.play(.selection)24                            model.updateSettings { $0.defaultSoundID = sound.id }25                        } label: {26                            HStack(spacing: 12) {27                                Image(systemName: selected ? "checkmark.circle.fill" : "circle").font(.title3)28                                    .foregroundStyle(selected ? Theme.sunrise : Theme.textTertiary)29                                Text(sound.title).font(.orixHeadline)30                                Spacer(minLength: 0)31                            }32                            .frame(minHeight: 52).contentShape(Rectangle())33                        }34                        .buttonStyle(.plain)35                        .accessibilityLabel(sound.title)36                        .accessibilityAddTraits(selected ? .isSelected : [])37                        .accessibilityIdentifier("settings.sound.\(sound.id)")38                        Button { player.togglePreview(alarmSoundID: sound.id) } label: {39                            Image(systemName: playing ? "stop.fill" : "play.fill").font(.body.weight(.bold))40                                .foregroundStyle(playing ? Theme.midnight : Theme.textPrimary)41                                .frame(width: 48, height: 48)42                                .background(playing ? AnyShapeStyle(Theme.sunriseGradient) : AnyShapeStyle(Theme.surfaceRaised), in: Circle())43                        }44                        .buttonStyle(.plain)45                        .accessibilityLabel(playing ? "Stop preview of \(sound.title)" : "Preview \(sound.title)")46                        .accessibilityIdentifier("settings.sound.preview.\(sound.id)")47                    }48                    .glassCard(padding: 12, radius: 20, tint: selected ? Theme.sunrise : nil)49                }50                Text("Previews are played by the app at the current volume. The real alarm is played by iOS and can differ in loudness.")51                    .font(.orixCaption).foregroundStyle(Theme.textSecondary)52                    .frame(maxWidth: .infinity, alignment: .leading).padding(.horizontal, 4).padding(.top, 6)53            }54            .padding(.horizontal, 20).padding(.top, 8)55        }56        .contentMargins(.bottom, 96, for: .scrollContent)57        .navigationTitle("Default alarm sound")58        .navigationBarTitleDisplayMode(.inline)59        .orixScreen()60        .onDisappear { player.stopPreview() }61    }62}6364// MARK: Explanation pages65/// One titled block of an explanation page.66private struct InfoBlock: View {67    let symbol: String68    var tint: Color = Theme.gold69    let title: LocalizedStringKey70    let paragraphs: [LocalizedStringKey]7172    var body: some View {73        VStack(alignment: .leading, spacing: 10) {74            Label { Text(title).font(.orixHeadline) } icon: { Image(systemName: symbol).foregroundStyle(tint) }75                .accessibilityAddTraits(.isHeader)76            ForEach(Array(paragraphs.enumerated()), id: \.offset) { _, paragraph in77                Text(paragraph).font(.orixBody).foregroundStyle(Theme.textSecondary)78                    .frame(maxWidth: .infinity, alignment: .leading)79            }80        }81        .glassCard()82    }83}8485struct HowItWorksView: View {86    var body: some View {87        ScrollView {88            VStack(spacing: Theme.spacing) {89                InfoBlock(symbol: "alarm.fill", tint: Theme.sunrise, title: "Alarms are held by iOS", paragraphs: [90                    "When you save an alarm, ORIX Alarm registers it with the system through AlarmKit. From then on iOS owns it: the alarm rings when the app is closed, when the iPhone is locked, and in silent mode or a Focus.",91                    "The app cannot ring by itself. If the alarm permission is refused, or if iOS rejects an alarm, it is shown as “Not scheduled” and will not ring. “Check alarms now” in Settings compares your alarms with what iOS really holds and repairs differences.",92                    "An iPhone that is switched off or out of battery cannot ring.",93                ])94                InfoBlock(symbol: "hand.raised.fill", tint: Theme.azure, title: "You can always stop an alarm", paragraphs: [95                    "iOS always lets you stop or silence a ringing alarm from the lock screen. No app can remove that, and ORIX Alarm does not pretend to.",96                    "Missions are a commitment you make with yourself, not a lock. After you stop the alarm, the app opens the mission and waits for you. An emergency exit is always available; using it is recorded as a bypass.",97                    "Stopping the alarm, finishing a mission and confirming that you are up are three separate things. The app never assumes you are awake because the alarm was stopped.",98                ])99                InfoBlock(symbol: "sun.horizon.fill", tint: Theme.gold, title: "Progressive wake needs Nightstand mode", paragraphs: [100                    "The gentle soundscape and the sunrise screen before the alarm only run while ORIX Alarm stays open in Nightstand mode, ideally with the iPhone on its charger.",101                    "iOS does not allow an app to start audio or light the screen on its own while it is closed or the iPhone is locked. Without Nightstand mode, the main alarm still rings at its time; only the gentle lead-in is skipped.",102                ])103                InfoBlock(symbol: "waveform", tint: Theme.violet, title: "Alarm sounds", paragraphs: [104                    "Alarm sounds are short bundled loops, because iOS limits the length of the sound a system alarm can play and repeats it while the alarm rings. Longer soundscapes are only used in Nightstand mode.",105                    "The real alarm is played by iOS, not by the app, so it can sound different in loudness from a preview.",106                ])107                InfoBlock(symbol: "figure.walk", tint: Theme.success, title: "Steps and QR codes", paragraphs: [108                    "Step counting uses the motion sensors of the iPhone and is approximate: a few steps may be missed or added, and the count arrives with a small delay. Carry the iPhone while walking.",109                    "QR missions use the camera to recognise a code you registered. Both missions always have a fallback so a missing permission or a sensor problem never traps you.",110                ])111                InfoBlock(symbol: "chart.xyaxis.line", tint: Theme.peach, title: "What the statistics are", paragraphs: [112                    "Insights count recorded events only: an alarm ringing, you stopping it, snoozes, missions, wake confirmations. When the app was closed, a ring is recorded from the schedule rather than observed.",113                    "ORIX Alarm does not measure sleep. The sleep planner works with time in bed, which is a plan, not a measurement.",114                ])115                InfoBlock(symbol: "internaldrive.fill", tint: Theme.azure, title: "What is stored", paragraphs: [116                    "Your alarms, scenarios, settings, sleep plan, registered QR tags (as digests only) and the history of events are stored in files on this iPhone. Nothing leaves the device unless you export a file yourself.",117                ])118            }119            .padding(.horizontal, 20).padding(.top, 8)120        }121        .contentMargins(.bottom, 96, for: .scrollContent)122        .navigationTitle("How ORIX Alarm works")123        .navigationBarTitleDisplayMode(.inline)124        .orixScreen()125        .accessibilityIdentifier("settings.howItWorks.page")126    }127}128129struct PrivacySummaryView: View {130    private let points: [(symbol: String, title: LocalizedStringKey, text: LocalizedStringKey)] = [131        ("person.crop.circle.badge.xmark", "No account", "There is nothing to sign up for and no profile."),132        ("eye.slash.fill", "No tracking", "No advertising identifier, no cross-app tracking, no fingerprinting."),133        ("shippingbox.fill", "No analytics SDK", "The app contains no third-party code and no analytics or crash-reporting library."),134        ("network.slash", "No network requests", "ORIX Alarm never connects to a server. It works the same in airplane mode."),135        ("camera.fill", "Camera stays on device", "Camera frames are used only to recognise your QR code during a mission or registration. They are not saved or sent. Only a digest of the code's content is kept."),136        ("figure.walk.motion", "Motion stays on device", "Step counts are read live during a step mission and are not stored beyond the result of the mission."),137        ("bell.badge.fill", "Notifications are local", "Evening reminders are local notifications created on this iPhone, only if you turn them on."),138        ("square.and.arrow.up.fill", "Your data is yours", "You can export everything to a readable file, import it back, or erase it all in Settings."),139    ]140141    var body: some View {142        ScrollView {143            VStack(spacing: Theme.spacing) {144                VStack(alignment: .leading, spacing: 8) {145                    Image(systemName: "lock.shield.fill").font(.system(size: 40)).foregroundStyle(Theme.success).accessibilityHidden(true)146                    Text("Everything stays on this iPhone").font(.orixTitle)147                    Text("ORIX Alarm collects nothing. It has no server to send anything to.")148                        .font(.orixBody).foregroundStyle(Theme.textSecondary)149                }150                .frame(maxWidth: .infinity, alignment: .leading)151                .glassCard(tint: Theme.success)152                VStack(alignment: .leading, spacing: 16) {153                    ForEach(Array(points.enumerated()), id: \.offset) { _, point in154                        HStack(alignment: .top, spacing: 12) {155                            Image(systemName: point.symbol).font(.callout.weight(.semibold)).foregroundStyle(Theme.gold)156                                .frame(width: 34, height: 34).background(Theme.surfaceRaised, in: RoundedRectangle(cornerRadius: 10, style: .continuous))157                                .accessibilityHidden(true)158                            VStack(alignment: .leading, spacing: 3) {159                                Text(point.title).font(.orixHeadline)160                                Text(point.text).font(.orixCaption).foregroundStyle(Theme.textSecondary)161                            }162                        }163                        .accessibilityElement(children: .combine)164                    }165                }166                .frame(maxWidth: .infinity, alignment: .leading)167                .glassCard()168                Text("Permissions used: alarms (to ring), camera (QR missions), motion (step missions), notifications (optional evening reminders). Each is requested only when the feature needs it and can be revoked in the Settings app.")169                    .font(.orixCaption).foregroundStyle(Theme.textSecondary)170                    .frame(maxWidth: .infinity, alignment: .leading).padding(.horizontal, 4)171            }172            .padding(.horizontal, 20).padding(.top, 8)173        }174        .contentMargins(.bottom, 96, for: .scrollContent)175        .navigationTitle("Privacy")176        .navigationBarTitleDisplayMode(.inline)177        .orixScreen()178        .accessibilityIdentifier("settings.privacy.page")179    }180}181
Files main
Menu

Theme