Stabilize iOS/watchOS/tvOS apps and add cross-platform audit remediation
This commit is contained in:
@@ -9,9 +9,12 @@ import Foundation
|
||||
import WatchConnectivity
|
||||
import SwiftUI
|
||||
import HealthKit
|
||||
import os
|
||||
import SharedCore
|
||||
|
||||
class WatchMainViewModel: NSObject, ObservableObject {
|
||||
static let shared = WatchMainViewModel()
|
||||
let logger = Logger(subsystem: "com.werkout.watch", category: "session")
|
||||
|
||||
var session: WCSession
|
||||
|
||||
@@ -29,46 +32,46 @@ class WatchMainViewModel: NSObject, ObservableObject {
|
||||
session.activate()
|
||||
|
||||
}
|
||||
|
||||
private func send(_ action: WatchActions) {
|
||||
do {
|
||||
let data = try JSONEncoder().encode(action)
|
||||
DataSender.send(data)
|
||||
} catch {
|
||||
logger.error("Failed to encode watch action: \(error.localizedDescription, privacy: .public)")
|
||||
}
|
||||
}
|
||||
|
||||
// actions from view
|
||||
func nextExercise() {
|
||||
let nextExerciseAction = WatchActions.nextExercise
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
DataSender.send(data)
|
||||
send(.nextExercise)
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
|
||||
func restartExercise() {
|
||||
let nextExerciseAction = WatchActions.restartExercise
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
DataSender.send(data)
|
||||
send(.restartExercise)
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
|
||||
func previousExercise() {
|
||||
let nextExerciseAction = WatchActions.previousExercise
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
DataSender.send(data)
|
||||
send(.previousExercise)
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
|
||||
func completeWorkout() {
|
||||
let nextExerciseAction = WatchActions.stopWorkout
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
DataSender.send(data)
|
||||
send(.stopWorkout)
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
}
|
||||
|
||||
func pauseWorkout() {
|
||||
let nextExerciseAction = WatchActions.pauseWorkout
|
||||
let data = try! JSONEncoder().encode(nextExerciseAction)
|
||||
DataSender.send(data)
|
||||
send(.pauseWorkout)
|
||||
WKInterfaceDevice.current().play(.start)
|
||||
WatchWorkout.shared.togglePaused()
|
||||
}
|
||||
|
||||
func dataToAction(messageData: Data) {
|
||||
if let model = try? JSONDecoder().decode(PhoneToWatchActions.self, from: messageData) {
|
||||
do {
|
||||
let model = try WatchPayloadValidation.decode(PhoneToWatchActions.self, from: messageData)
|
||||
DispatchQueue.main.async {
|
||||
switch model {
|
||||
case .inExercise(let newWatchPackageModel):
|
||||
@@ -87,6 +90,8 @@ class WatchMainViewModel: NSObject, ObservableObject {
|
||||
WatchWorkout.shared.startWorkout()
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
logger.error("Rejected PhoneToWatchActions payload: \(error.localizedDescription, privacy: .public)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user