fix(watch): handle missing workout and remove conflicting delegate

This commit is contained in:
2026-08-08 12:19:57 +02:00
parent f3b3a8b944
commit 38082afdb9
2 changed files with 25 additions and 10 deletions
-5
View File
@@ -15,11 +15,6 @@ private class SessionDelegate: NSObject, WCSessionDelegate {
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) {
print("[WatchConnectivity] Received message with reply: \(message["type"] ?? "unknown")")
replyHandler(["status": "received"])
+20
View File
@@ -153,6 +153,25 @@ export async function saveWatchCompletedWorkout(data: {
? Math.round(data.laps.reduce((sum, l) => sum + (l.heartRate || 0), 0) / data.laps.length)
: 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
.update(workouts)
.set({
@@ -164,6 +183,7 @@ export async function saveWatchCompletedWorkout(data: {
source: "watch",
})
.where(eq(workouts.id, data.workoutId));
}
for (const lap of data.laps) {
await db.insert(laps).values({