mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-11-29 09:11:17 +01:00
Replaces the trailing mode pill in the Dynamic Island expanded
region (which was redundant — the bottom row already shows the
SIM/ERG pill) with an `xmark.circle.fill` button.
Tapping the button:
1. Fires a new `StopRideIntent` App Intent.
2. That intent posts a Darwin notification
`de.jonasbark.swiftcontrol.overlay.action.stop`.
3. `AppDelegate.swift`'s observer forwards `action: 'stop'` over
the `bike_control/overlay_actions_ios` MethodChannel.
4. `IosOverlayController._stopRide`:
- `core.connection.disconnectAll()`
- `core.connection.stop()`
- `core.settings.setOverlayEnabled(false)` so Navigation's
auto-show doesn't immediately re-open the activity on the
next BLE reconnect.
- `hide()` ends the Live Activity.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
57 lines
1.9 KiB
Swift
57 lines
1.9 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
|
|
// Names matched in AppDelegate.swift's Darwin-notification observers.
|
|
private let darwinDecrement = "de.jonasbark.swiftcontrol.overlay.action.decrement" as CFString
|
|
private let darwinIncrement = "de.jonasbark.swiftcontrol.overlay.action.increment" as CFString
|
|
private let darwinStop = "de.jonasbark.swiftcontrol.overlay.action.stop" as CFString
|
|
|
|
private func postDarwin(_ name: CFString) {
|
|
CFNotificationCenterPostNotification(
|
|
CFNotificationCenterGetDarwinNotifyCenter(),
|
|
CFNotificationName(name),
|
|
nil, nil, true
|
|
)
|
|
}
|
|
|
|
/// Fired by the `-` button in the Live Activity. Posts a Darwin notification
|
|
/// the main BikeControl process is listening for; the main app then dispatches
|
|
/// `def.shiftDown()` / `setManualErgPower(... -5)` depending on the active
|
|
/// trainer mode.
|
|
@available(iOS 17.0, *)
|
|
struct ShiftPrimaryDecrementIntent: LiveActivityIntent {
|
|
static var title: LocalizedStringResource = "Shift Down"
|
|
static var openAppWhenRun: Bool = false
|
|
|
|
func perform() async throws -> some IntentResult {
|
|
postDarwin(darwinDecrement)
|
|
return .result()
|
|
}
|
|
}
|
|
|
|
/// Fired by the `+` button in the Live Activity.
|
|
@available(iOS 17.0, *)
|
|
struct ShiftPrimaryIncrementIntent: LiveActivityIntent {
|
|
static var title: LocalizedStringResource = "Shift Up"
|
|
static var openAppWhenRun: Bool = false
|
|
|
|
func perform() async throws -> some IntentResult {
|
|
postDarwin(darwinIncrement)
|
|
return .result()
|
|
}
|
|
}
|
|
|
|
/// Fired by the close button in the Dynamic Island. The main BikeControl
|
|
/// process disconnects all trainer/controller devices and dismisses the
|
|
/// Live Activity.
|
|
@available(iOS 17.0, *)
|
|
struct StopRideIntent: LiveActivityIntent {
|
|
static var title: LocalizedStringResource = "End Ride"
|
|
static var openAppWhenRun: Bool = false
|
|
|
|
func perform() async throws -> some IntentResult {
|
|
postDarwin(darwinStop)
|
|
return .result()
|
|
}
|
|
}
|