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

commit fc449922b736704ce095514aa1da38c808308952
parent 97ef4b3b1fa9a970e24aeeafc47c0e02c79dbbc1
Author: Jean Schurger <jean@schurger.org>
Date:   Sat, 14 Nov 2026 13:46:48 -0500

Dive and Ready screens replace the home screen instead of covering it (no system close button while the touch screen is locked); introduction at first launch asking for every permission up front; option to hide the demo dive; Apple's dive session no longer started on top of the workout; version 0.6

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7deYJa9LG8PgUSQ5UR5LY

Diffstat:
MOpenRemoraWatch/DiveRuntime.swift | 3++-
MOpenRemoraWatch/DiveSession.swift | 19++++++++++++++++---
MOpenRemoraWatch/DiveView.swift | 3++-
MOpenRemoraWatch/EntryPosition.swift | 5+++++
MOpenRemoraWatch/Localizable.xcstrings | 220+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MOpenRemoraWatch/RootView.swift | 85++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
AOpenRemoraWatch/SetupView.swift | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mproject.yml | 2+-
8 files changed, 400 insertions(+), 35 deletions(-)

diff --git a/OpenRemoraWatch/DiveRuntime.swift b/OpenRemoraWatch/DiveRuntime.swift @@ -58,7 +58,8 @@ final class DiveRuntime: NSObject, @preconcurrency WKExtendedRuntimeSessionDeleg case .error: why = String(localized: "error") @unknown default: why = String(localized: "ended (reason \(reason.rawValue))") } - onChange?(false, error.map { "\(why) (\($0.localizedDescription))" } ?? why) + // Domain and code: the localized text alone does not tell the errors apart. + onChange?(false, error.map { "\(why) (\(($0 as NSError).domain) \(($0 as NSError).code): \($0.localizedDescription))" } ?? why) } } diff --git a/OpenRemoraWatch/DiveSession.swift b/OpenRemoraWatch/DiveSession.swift @@ -86,11 +86,17 @@ final class DiveSession { } private func readScreenLock() { - let locked = WKInterfaceDevice.current().isWaterLockEnabled + var locked = WKInterfaceDevice.current().isWaterLockEnabled + // Screenshots and tests in the simulator: `-locked`, or `-lockToggle` (changes every 3 s). + if Self.forcedLock { locked = true } + if Self.toggledLock { locked = Int(Date().timeIntervalSinceReferenceDate / 3) % 2 == 0 } if locked != screenLocked { screenLocked = locked } if locked, isReady || isDiving, !diagnostics.lockSeen { diagnostics.lockSeen = true } } + private static let forcedLock = CommandLine.arguments.contains("-locked") + private static let toggledLock = CommandLine.arguments.contains("-lockToggle") + /// The vibration of each cue of the dive logic. private static func haptic(for cue: DiveCue) -> WKHapticType { switch cue { @@ -124,10 +130,17 @@ final class DiveSession { monitor.startManually() } - /// Apple's dive session (screen locked) and Action button wired to the app. + /// Action button wired to the app, and the app kept in the foreground. The diving workout does that (and + /// the watch locks its screen); starting Apple's dive session on top of it fails on the watch + /// (WKExtendedRuntimeSessionError), so it is only started when the workout could not be. The session the + /// system starts by itself below 1 m is still adopted (`AppDelegate`). private func startDiveSession() { guard SubmersionSource.isAvailable else { return } - runtime.start() + if workout.state == .running { + diagnostics.runtime = String(localized: "not requested (workout running)") + } else { + runtime.start() + } Task { [diagnostics] in diagnostics.donation = await ActionButton.offerNextAction() ?? String(localized: "donated") } diff --git a/OpenRemoraWatch/DiveView.swift b/OpenRemoraWatch/DiveView.swift @@ -15,6 +15,7 @@ struct DiveView: View { var body: some View { let s = session.status + let locked = session.screenLocked @Bindable var session = session Group { if dimmed { @@ -31,7 +32,7 @@ struct DiveView: View { .background { if session.isAlarming && !dimmed { AlarmFlash() } } .toolbar { // Useless while the touch screen is locked (long press on the crown unlocks it). - if !session.screenLocked { + if !locked { ToolbarItem(placement: .cancellationAction) { Button("End", role: .destructive) { session.end() } } diff --git a/OpenRemoraWatch/EntryPosition.swift b/OpenRemoraWatch/EntryPosition.swift @@ -21,6 +21,11 @@ final class EntryPosition: NSObject, CLLocationManagerDelegate { manager.desiredAccuracy = kCLLocationAccuracyBest } + /// Asks for the permission ahead of time (introduction), without taking a fix. + func requestAuthorization() { + if manager.authorizationStatus == .notDetermined { manager.requestWhenInUseAuthorization() } + } + func start() { fix = nil switch manager.authorizationStatus { diff --git a/OpenRemoraWatch/Localizable.xcstrings b/OpenRemoraWatch/Localizable.xcstrings @@ -71,6 +71,16 @@ } } }, + "Action button": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Bouton Action" + } + } + } + }, "Action button: %lld presses received": { "localizations": { "en": { @@ -271,6 +281,16 @@ } } }, + "Continue": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Continuer" + } + } + } + }, "Demo": { "localizations": { "fr": { @@ -341,6 +361,16 @@ } } }, + "Done": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Terminé" + } + } + } + }, "Duration": { "localizations": { "fr": { @@ -371,6 +401,16 @@ } } }, + "From the watch face: opens \"Ready to dive\".": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Depuis le cadran : ouvre « Prêt à plonger »." + } + } + } + }, "From there, it goes to Sub Rascasse.": { "localizations": { "fr": { @@ -401,6 +441,16 @@ } } }, + "Health: your dives are saved there.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Santé : vos plongées y sont enregistrées." + } + } + } + }, "Last trial": { "localizations": { "fr": { @@ -411,6 +461,16 @@ } } }, + "Location: the entry point, taken before the dive.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Position : le point de mise à l'eau, relevé avant la plongée." + } + } + } + }, "Logbook": { "localizations": { "fr": { @@ -421,6 +481,16 @@ } } }, + "Long press on the crown to unlock: the End button comes back.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Appui long sur la couronne pour déverrouiller : le bouton Fin revient." + } + } + } + }, "Looking for the GPS position…": { "localizations": { "fr": { @@ -501,6 +571,16 @@ } } }, + "Motion & Fitness: the depth sensor.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Mouvements et forme : le capteur de profondeur." + } + } + } + }, "N": { "localizations": { "fr": { @@ -561,6 +641,16 @@ } } }, + "Next": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Suivant" + } + } + } + }, "Next action: %@": { "localizations": { "fr": { @@ -651,6 +741,26 @@ } } }, + "Off: the demo dive and the demo entries of the logbook are hidden.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Désactivé : la plongée de démonstration et les plongées de démonstration du carnet sont cachées." + } + } + } + }, + "On \"Ready\": starts the dive.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Sur « Prêt » : démarre la plongée." + } + } + } + }, "On the iPhone": { "localizations": { "fr": { @@ -671,6 +781,26 @@ } } }, + "Options": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Options" + } + } + } + }, + "Permissions": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Autorisations" + } + } + } + }, "Position": { "localizations": { "fr": { @@ -891,6 +1021,16 @@ } } }, + "Show the introduction again": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Revoir l'introduction" + } + } + } + }, "Site": { "localizations": { "fr": { @@ -981,6 +1121,26 @@ } } }, + "The touch screen is locked.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "L'écran tactile est verrouillé." + } + } + } + }, + "The watch asks for them now, not on the way to the water. Each one can be refused.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "La montre les demande maintenant, pas au moment d'aller à l'eau. Chacune peut être refusée." + } + } + } + }, "The watch can fail or measure wrongly during the dive.": { "localizations": { "fr": { @@ -1001,6 +1161,26 @@ } } }, + "Turn the crown to change page.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Tournez la couronne pour changer de page." + } + } + } + }, + "Underwater": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Sous l'eau" + } + } + } + }, "W": { "localizations": { "fr": { @@ -1031,6 +1211,26 @@ } } }, + "Waiting…": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "En attente…" + } + } + } + }, + "Watch Settings > Action Button > Dive > Open Rémora.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "Réglages de la montre > Bouton Action > Plongée > Open Rémora." + } + } + } + }, "Water": { "localizations": { "fr": { @@ -1041,6 +1241,16 @@ } } }, + "While diving: marks a point, runs the stopwatch or sets the bearing, depending on the page.": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "En plongée : pose un repère, lance le chrono ou fixe le cap, selon la page." + } + } + } + }, "Yes": { "localizations": { "fr": { @@ -1201,6 +1411,16 @@ } } }, + "not requested (workout running)": { + "localizations": { + "fr": { + "stringUnit": { + "state": "translated", + "value": "non demandée (séance d'entraînement en cours)" + } + } + } + }, "ppO2": { "localizations": { "fr": { diff --git a/OpenRemoraWatch/RootView.swift b/OpenRemoraWatch/RootView.swift @@ -7,9 +7,53 @@ struct RootView: View { @Environment(LogStore.self) private var store @Environment(DiveSession.self) private var session @State private var path: [DiveLog] = [] + @AppStorage("showDemo") private var showDemo = true + @AppStorage(Setup.key) private var setupDone = 0 + /// Screenshots skip the introduction (`-acceptTerms`); `-setup` shows it. + private var needsSetup: Bool { + if CommandLine.arguments.contains("-setup") { return setupDone < Setup.version } + return setupDone < Setup.version && !CommandLine.arguments.contains("-acceptTerms") + } + + /// The dive and "Ready" screens replace the home screen instead of covering it: a cover gets a close + /// button from the system, which the locked touch screen makes useless and which must not end anything. var body: some View { - @Bindable var session = session + Group { + if needsSetup { + SetupView() + } else if session.isDiving { + NavigationStack { DiveView() } + } else if session.isReady { + NavigationStack { ReadyView() } + } else { + home + } + } + .onChange(of: session.finishedDive) { _, dive in + guard let dive else { return } + path = [dive] + session.finishedDive = nil + } + .task(id: needsSetup) { + // The permissions are asked by the introduction; afterwards this only starts the sensor. + guard !needsSetup else { return } + session.listen() + if !CommandLine.arguments.contains("-demo") { await session.workout.requestAuthorization() } + } + .task { + if CommandLine.arguments.contains(where: { $0 == "-showDive" || $0 == "-showProfile" }), let dive = store.dives.first { path = [dive] } + if CommandLine.arguments.contains("-simulate") { + session.startSimulation(CommandLine.arguments.contains("-deep") ? .deep : .reef, + speed: CommandLine.arguments.contains("-slow") ? 8 : 30) + } + if CommandLine.arguments.contains("-ready") { session.getReady() } + } + } + + private var dives: [DiveLog] { showDemo ? store.dives : store.dives.filter { $0.source != .simulation } } + + private var home: some View { NavigationStack(path: $path) { List { if session.sensorAvailable { @@ -25,14 +69,14 @@ struct RootView: View { } Section("Logbook") { - if store.dives.isEmpty { + if dives.isEmpty { Text("No dives").foregroundStyle(.secondary) } - ForEach(store.dives) { dive in + ForEach(dives) { dive in NavigationLink(value: dive) { DiveRow(dive: dive) } } .onDelete { offsets in - let dives = store.dives + let dives = dives for i in offsets { store.remove(dives[i]) } } } @@ -54,16 +98,15 @@ struct RootView: View { Section { NavigationLink { CompassScreen() } label: { Label("Compass", systemImage: "location.north.line") } NavigationLink { SettingsView() } label: { Label("Settings", systemImage: "gearshape") } - Button { session.startSimulation() } label: { - Label("Demo dive", systemImage: "play.circle") + NavigationLink { OptionsView() } label: { Label("Options", systemImage: "slider.horizontal.3") } + if showDemo { + Button { session.startSimulation() } label: { + Label("Demo dive", systemImage: "play.circle") + } } } footer: { Text("Secondary computer, not certified. To be used with a primary dive computer.") } - - if session.sensorAvailable || CommandLine.arguments.contains("-demo") { - Section("Last trial") { DiagnosticsRows() } - } } .navigationTitle("Open Rémora") .navigationDestination(for: DiveLog.self) { dive in @@ -71,23 +114,6 @@ struct RootView: View { else { DiveDetailView(dive: dive) } } } - .fullScreenCover(isPresented: .constant(session.isDiving)) { DiveView() } - .fullScreenCover(isPresented: .constant(session.isReady && !session.isDiving)) { ReadyView() } - .onChange(of: session.finishedDive) { _, dive in - guard let dive else { return } - path = [dive] - session.finishedDive = nil - } - .task { - session.listen() - if !CommandLine.arguments.contains("-demo") { await session.workout.requestAuthorization() } - if CommandLine.arguments.contains(where: { $0 == "-showDive" || $0 == "-showProfile" }), let dive = store.dives.first { path = [dive] } - if CommandLine.arguments.contains("-simulate") { - session.startSimulation(CommandLine.arguments.contains("-deep") ? .deep : .reef, - speed: CommandLine.arguments.contains("-slow") ? 8 : 30) - } - if CommandLine.arguments.contains("-ready") { session.getReady() } - } } } @@ -121,13 +147,14 @@ struct ReadyView: View { @Environment(DiveSession.self) private var session var body: some View { + let locked = session.screenLocked VStack(spacing: 4) { Label("Ready", systemImage: "water.waves").font(.title3.bold()).foregroundStyle(.cyan) Text("Starts on submersion or with the Action button").font(.caption2) .foregroundStyle(.secondary).multilineTextAlignment(.center) .lineLimit(2).minimumScaleFactor(0.7).fixedSize(horizontal: false, vertical: true) PositionLine(position: session.position) - if session.screenLocked { + if locked { Label("Screen locked: long press on the crown", systemImage: "lock.fill") .font(.caption2).foregroundStyle(.cyan).multilineTextAlignment(.center) } @@ -145,7 +172,7 @@ struct ReadyView: View { } .toolbar { // Useless while the touch screen is locked: it comes back once unlocked (long press on the crown). - if !session.screenLocked { + if !locked { ToolbarItem(placement: .cancellationAction) { Button("Cancel") { session.cancelReady() } } diff --git a/OpenRemoraWatch/SetupView.swift b/OpenRemoraWatch/SetupView.swift @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0-only +import SwiftUI + +/// Introduction shown once, after the terms: asks for every permission up front (so that no system prompt +/// appears on the way to the water), then explains the Action button and the locked screen. +/// Raising `Setup.version` shows it again; "Show the introduction again" in the options does too. +enum Setup { + static let version = 1 + static let key = "setupVersion" +} + +struct SetupView: View { + @Environment(DiveSession.self) private var session + @AppStorage(Setup.key) private var done = 0 + @State private var step = 0 + @State private var asking = false + + var body: some View { + ScrollView { + VStack(alignment: .leading, spacing: 8) { + switch step { + case 0: + page(icon: "checkmark.shield", title: "Permissions", + lines: ["Motion & Fitness: the depth sensor.", + "Health: your dives are saved there.", + "Location: the entry point, taken before the dive."], + note: "The watch asks for them now, not on the way to the water. Each one can be refused.") + Button(asking ? "Waiting…" : "Continue") { + asking = true + Task { + await session.workout.requestAuthorization() + session.listen() + session.position.requestAuthorization() + asking = false + step = 1 + } + } + .disabled(asking) + case 1: + page(icon: "button.programmable", title: "Action button", + lines: ["Watch Settings > Action Button > Dive > Open Rémora.", + "From the watch face: opens \"Ready to dive\".", + "On \"Ready\": starts the dive.", + "While diving: marks a point, runs the stopwatch or sets the bearing, depending on the page."], + note: nil) + Button("Next") { step = 2 } + default: + page(icon: "lock.fill", title: "Underwater", + lines: ["The touch screen is locked.", + "Turn the crown to change page.", + "Long press on the crown to unlock: the End button comes back."], + note: nil) + Button("Done") { done = Setup.version } + } + } + .buttonStyle(.borderedProminent) + .tint(.cyan) + .padding(.horizontal) + } + } + + @ViewBuilder + private func page(icon: String, title: LocalizedStringKey, lines: [LocalizedStringKey], + note: LocalizedStringKey?) -> some View { + Label(title, systemImage: icon).font(.headline).foregroundStyle(.cyan) + ForEach(Array(lines.enumerated()), id: \.offset) { _, line in + HStack(alignment: .firstTextBaseline, spacing: 6) { + Text(verbatim: "•") + Text(line).fixedSize(horizontal: false, vertical: true) + } + .font(.footnote) + } + if let note { + Text(note).font(.caption2).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true) + } + } +} + +/// Options of the app itself (the dive settings are in "Settings"). +struct OptionsView: View { + @AppStorage("showDemo") private var showDemo = true + @AppStorage(Setup.key) private var setupDone = 0 + + var body: some View { + List { + Section { + Toggle("Demo dive", isOn: $showDemo) + } footer: { + Text("Off: the demo dive and the demo entries of the logbook are hidden.") + } + Section { + Button("Show the introduction again") { setupDone = 0 } + } + Section("Last trial") { DiagnosticsRows() } + } + .navigationTitle("Options") + } +} diff --git a/project.yml b/project.yml @@ -15,7 +15,7 @@ settings: base: DEVELOPMENT_TEAM: CM5RQKJH56 CODE_SIGN_STYLE: Automatic - MARKETING_VERSION: "0.5" + MARKETING_VERSION: "0.6" CURRENT_PROJECT_VERSION: "1" SWIFT_VERSION: "6.0" SWIFT_EMIT_LOC_STRINGS: YES