open-remora

Open Remora, a free secondary dive computer for Apple Watch Ultra
git clone https://git.schurger.org/open-remora.git
Log | Files | Refs | README | LICENSE

SetupView.swift (4190B)


      1 // SPDX-License-Identifier: GPL-2.0-only
      2 import SwiftUI
      3 
      4 /// Introduction shown once, after the terms: asks for every permission up front (so that no system prompt
      5 /// appears on the way to the water), then explains the Action button and the locked screen.
      6 /// Raising `Setup.version` shows it again; "Show the introduction again" in the options does too.
      7 enum Setup {
      8     static let version = 1
      9     static let key = "setupVersion"
     10 }
     11 
     12 struct SetupView: View {
     13     @Environment(DiveSession.self) private var session
     14     @AppStorage(Setup.key) private var done = 0
     15     @State private var step = 0
     16     @State private var asking = false
     17 
     18     var body: some View {
     19         ScrollView {
     20             VStack(alignment: .leading, spacing: 8) {
     21                 switch step {
     22                 case 0:
     23                     page(icon: "checkmark.shield", title: "Permissions",
     24                          lines: ["Motion & Fitness: the depth sensor.",
     25                                  "Health: your dives are saved there.",
     26                                  "Location: the entry point, taken before the dive."],
     27                          note: "The watch asks for them now, not on the way to the water. Each one can be refused.")
     28                     Button(asking ? "Waiting…" : "Continue") {
     29                         asking = true
     30                         Task {
     31                             await session.workout.requestAuthorization()
     32                             session.listen()
     33                             session.position.requestAuthorization()
     34                             asking = false
     35                             step = 1
     36                         }
     37                     }
     38                     .disabled(asking)
     39                 case 1:
     40                     page(icon: "button.programmable", title: "Action button",
     41                          lines: ["Watch Settings > Action Button > Dive > Open Rémora.",
     42                                  "From the watch face: opens \"Ready to dive\".",
     43                                  "On \"Ready\": starts the dive.",
     44                                  "While diving: marks a point, runs the stopwatch or sets the bearing, depending on the page."],
     45                          note: nil)
     46                     Button("Next") { step = 2 }
     47                 default:
     48                     page(icon: "lock.fill", title: "Underwater",
     49                          lines: ["The touch screen is locked.",
     50                                  "Turn the crown to change page.",
     51                                  "Long press on the crown to unlock: the End button comes back."],
     52                          note: nil)
     53                     Button("Done") { done = Setup.version }
     54                 }
     55             }
     56             .buttonStyle(.borderedProminent)
     57             .tint(.cyan)
     58             .padding(.horizontal)
     59         }
     60     }
     61 
     62     @ViewBuilder
     63     private func page(icon: String, title: LocalizedStringKey, lines: [LocalizedStringKey],
     64                       note: LocalizedStringKey?) -> some View {
     65         Label(title, systemImage: icon).font(.headline).foregroundStyle(.cyan)
     66         ForEach(Array(lines.enumerated()), id: \.offset) { _, line in
     67             HStack(alignment: .firstTextBaseline, spacing: 6) {
     68                 Text(verbatim: "•")
     69                 Text(line).fixedSize(horizontal: false, vertical: true)
     70             }
     71             .font(.footnote)
     72         }
     73         if let note {
     74             Text(note).font(.caption2).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
     75         }
     76     }
     77 }
     78 
     79 /// Options of the app itself (the dive settings are in "Settings").
     80 struct OptionsView: View {
     81     @AppStorage("showDemo") private var showDemo = true
     82     @AppStorage(Setup.key) private var setupDone = 0
     83 
     84     var body: some View {
     85         List {
     86             Section {
     87                 Toggle("Demo dive", isOn: $showDemo)
     88             } footer: {
     89                 Text("Off: the demo dive and the demo entries of the logbook are hidden.")
     90             }
     91             Section {
     92                 Button("Show the introduction again") { setupDone = 0 }
     93             }
     94             Section("Last trial") { DiagnosticsRows() }
     95         }
     96         .navigationTitle("Options")
     97     }
     98 }