All checks were successful
Ascently - Docs Deploy / build-and-push (pull_request) Successful in 8m4s
44 lines
1.3 KiB
Swift
44 lines
1.3 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
|
|
/// Starts a climbing session at the most recently visited gym.
|
|
/// Exposed to Shortcuts so users can begin logging without opening the app.
|
|
struct StartLastGymSessionIntent: AppIntent {
|
|
|
|
static var title: LocalizedStringResource {
|
|
"Start Last Gym Session"
|
|
}
|
|
|
|
static var description: IntentDescription {
|
|
IntentDescription(
|
|
"Begin a new climbing session using the most recent gym you visited in Ascently."
|
|
)
|
|
}
|
|
|
|
static var openAppWhenRun: Bool {
|
|
true
|
|
}
|
|
|
|
func perform() async throws -> some IntentResult & ProvidesDialog {
|
|
// Delay to ensure app has time to fully initialize if just launched
|
|
try? await Task.sleep(nanoseconds: 1_000_000_000) // 1 second
|
|
|
|
let summary = try await SessionIntentController().startSessionWithLastUsedGym()
|
|
|
|
// Give Live Activity extra time to start
|
|
try? await Task.sleep(nanoseconds: 500_000_000) // 0.5 seconds
|
|
|
|
return .result(
|
|
dialog: Self.successDialog(for: summary.gymName)
|
|
)
|
|
}
|
|
|
|
private static func successDialog(for gymName: String) -> IntentDialog {
|
|
IntentDialog("Session started at \(gymName). Have an awesome climb!")
|
|
}
|
|
|
|
static var parameterSummary: some ParameterSummary {
|
|
Summary("Start a session at my last gym")
|
|
}
|
|
}
|