fix(watch): handle missing workout and remove conflicting delegate
This commit is contained in:
@@ -15,11 +15,6 @@ private class SessionDelegate: NSObject, WCSessionDelegate {
|
|||||||
onActivationComplete?(activationState)
|
onActivationComplete?(activationState)
|
||||||
}
|
}
|
||||||
|
|
||||||
func session(_ session: WCSession, didReceiveMessage message: [String: Any]) {
|
|
||||||
print("[WatchConnectivity] Received message: \(message["type"] ?? "unknown")")
|
|
||||||
onMessageReceived?(message)
|
|
||||||
}
|
|
||||||
|
|
||||||
func session(_ session: WCSession, didReceiveMessage message: [String: Any], replyHandler: @escaping ([String: Any]) -> Void) {
|
func session(_ session: WCSession, didReceiveMessage message: [String: Any], replyHandler: @escaping ([String: Any]) -> Void) {
|
||||||
print("[WatchConnectivity] Received message with reply: \(message["type"] ?? "unknown")")
|
print("[WatchConnectivity] Received message with reply: \(message["type"] ?? "unknown")")
|
||||||
replyHandler(["status": "received"])
|
replyHandler(["status": "received"])
|
||||||
|
|||||||
@@ -153,6 +153,25 @@ export async function saveWatchCompletedWorkout(data: {
|
|||||||
? Math.round(data.laps.reduce((sum, l) => sum + (l.heartRate || 0), 0) / data.laps.length)
|
? Math.round(data.laps.reduce((sum, l) => sum + (l.heartRate || 0), 0) / data.laps.length)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
|
const existing = await db
|
||||||
|
.select({ id: workouts.id })
|
||||||
|
.from(workouts)
|
||||||
|
.where(eq(workouts.id, data.workoutId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (existing.length === 0) {
|
||||||
|
await db.insert(workouts).values({
|
||||||
|
id: data.workoutId,
|
||||||
|
name: "Watch Workout",
|
||||||
|
poolLength: 25,
|
||||||
|
finishedAt: new Date().toISOString(),
|
||||||
|
totalDuration: data.duration,
|
||||||
|
totalDistance: data.totalDistance || 0,
|
||||||
|
calories: data.calories || 0,
|
||||||
|
avgHeartRate,
|
||||||
|
source: "watch",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
await db
|
await db
|
||||||
.update(workouts)
|
.update(workouts)
|
||||||
.set({
|
.set({
|
||||||
@@ -164,6 +183,7 @@ export async function saveWatchCompletedWorkout(data: {
|
|||||||
source: "watch",
|
source: "watch",
|
||||||
})
|
})
|
||||||
.where(eq(workouts.id, data.workoutId));
|
.where(eq(workouts.id, data.workoutId));
|
||||||
|
}
|
||||||
|
|
||||||
for (const lap of data.laps) {
|
for (const lap of data.laps) {
|
||||||
await db.insert(laps).values({
|
await db.insert(laps).values({
|
||||||
|
|||||||
Reference in New Issue
Block a user