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

DiveIntents.swift (1392B)


      1 // SPDX-License-Identifier: GPL-2.0-only
      2 import AppIntents
      3 
      4 /// Action button of the Apple Watch Ultra (Settings > Action Button > Dive > Open Rémora).
      5 /// First press: launches the app and does "Ready to dive". Following presses, including underwater
      6 /// where the touch screen is locked: `DiveActionIntent`.
      7 struct StartDiveSessionIntent: StartDiveIntent {
      8     static let title: LocalizedStringResource = "Ready to dive"
      9 
     10     @MainActor
     11     func perform() async throws -> some IntentResult {
     12         DiveSession.current?.getReady()
     13         return .result(actionButtonIntent: DiveActionIntent())
     14     }
     15 }
     16 
     17 /// Action button press during the dive session.
     18 struct DiveActionIntent: AppIntent {
     19     static let title: LocalizedStringResource = "Dive action"
     20 
     21     @MainActor
     22     func perform() async throws -> some IntentResult {
     23         DiveSession.current?.actionPressed()
     24         return .result()
     25     }
     26 }
     27 
     28 enum ActionButton {
     29     /// Session started from the screen (not from the Action button): the next action is still donated
     30     /// to the system, so that the Action button reaches the app during the dive.
     31     static func offerNextAction() async -> String? {
     32         do {
     33             try await StartDiveSessionIntent().donate(result: .result(actionButtonIntent: DiveActionIntent()))
     34             return nil
     35         } catch {
     36             return error.localizedDescription
     37         }
     38     }
     39 }