commit 97ef4b3b1fa9a970e24aeeafc47c0e02c79dbbc1
parent a3bfbd879f30c2f70861aafb6118074ee8ca1a2f
Author: Jean Schurger <jean@schurger.org>
Date: Sat, 14 Nov 2026 12:08:50 -0500
Screen lock read from the watch itself (Water Lock), so that Cancel and End are hidden whenever the touch screen is locked; lock state in the last-trial diagnostics
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7deYJa9LG8PgUSQ5UR5LY
Diffstat:
3 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/OpenRemoraWatch/DiveSession.swift b/OpenRemoraWatch/DiveSession.swift
@@ -37,8 +37,10 @@ final class DiveSession {
let workout = DiveWorkout()
/// Apple's dive session: app in the foreground and touch screen locked.
let runtime = DiveRuntime()
- /// Touch screen locked by the dive session (long press on the crown to leave it).
+ /// Touch screen locked (Water Lock; long press on the crown to leave it). Read from the watch itself,
+ /// not deduced from the dive session: the system also locks the screen on its own.
private(set) var screenLocked = false
+ @ObservationIgnored private var lockWatch: Task<Void, Never>?
/// Page of the dive screen (0 main, 1 details, 2 compass): crown or Action button.
var divePage = 0
/// Banner shown for a few seconds after an Action button press.
@@ -69,10 +71,24 @@ final class DiveSession {
Self.current = self
monitor.onDiveStarted = { [weak self] simulation in self?.diveStarted(simulation: simulation) }
monitor.onDiveEnded = { [weak self] saved, simulation in self?.diveEnded(saved, simulation: simulation) }
- runtime.onChange = { [weak self] locked, text in
- self?.screenLocked = locked
+ runtime.onChange = { [weak self] _, text in
self?.diagnostics.runtime = text
+ self?.readScreenLock()
}
+ // Water Lock has no notification: it is read twice a second.
+ lockWatch = Task { [weak self] in
+ while !Task.isCancelled {
+ try? await Task.sleep(for: .milliseconds(500))
+ guard let self else { return }
+ self.readScreenLock()
+ }
+ }
+ }
+
+ private func readScreenLock() {
+ let locked = WKInterfaceDevice.current().isWaterLockEnabled
+ if locked != screenLocked { screenLocked = locked }
+ if locked, isReady || isDiving, !diagnostics.lockSeen { diagnostics.lockSeen = true }
}
/// The vibration of each cue of the dive logic.
@@ -269,8 +285,11 @@ final class Diagnostics {
var runtime: String { didSet { defaults.set(runtime, forKey: "diag.runtime") } }
var donation: String { didSet { defaults.set(donation, forKey: "diag.donation") } }
private(set) var startedAt: Date?
+ /// The watch reported its screen as locked during the session.
+ var lockSeen: Bool { didSet { defaults.set(lockSeen, forKey: "diag.lock") } }
init() {
+ lockSeen = defaults.bool(forKey: "diag.lock")
presses = defaults.integer(forKey: "diag.presses")
deepestPress = defaults.object(forKey: "diag.deepest") as? Double
runtime = defaults.string(forKey: "diag.runtime") ?? String(localized: "never requested")
@@ -281,6 +300,7 @@ final class Diagnostics {
func reset() {
presses = 0
deepestPress = nil
+ lockSeen = false
startedAt = Date()
defaults.set(0, forKey: "diag.presses")
defaults.removeObject(forKey: "diag.deepest")
diff --git a/OpenRemoraWatch/Localizable.xcstrings b/OpenRemoraWatch/Localizable.xcstrings
@@ -811,6 +811,26 @@
}
}
},
+ "Screen lock: not seen": {
+ "localizations": {
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Verrouillage de l'écran : pas vu"
+ }
+ }
+ }
+ },
+ "Screen lock: seen": {
+ "localizations": {
+ "fr": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Verrouillage de l'écran : vu"
+ }
+ }
+ }
+ },
"Screen locked: long press on the crown": {
"localizations": {
"fr": {
diff --git a/OpenRemoraWatch/RootView.swift b/OpenRemoraWatch/RootView.swift
@@ -193,6 +193,7 @@ struct DiagnosticsRows: View {
}
Text("Next action: \(d.donation)").foregroundStyle(.secondary)
Text("Dive session: \(d.runtime)").foregroundStyle(.secondary)
+ Text(d.lockSeen ? "Screen lock: seen" : "Screen lock: not seen").foregroundStyle(.secondary)
if let start = d.startedAt {
Text(start.formatted(date: .abbreviated, time: .shortened)).foregroundStyle(.secondary)
}