From f9ea8e1096638e0ad2e487b37a2f3d9c39519b63 Mon Sep 17 00:00:00 2001 From: Mike Simms Date: Mon, 28 Aug 2023 10:55:28 -0400 Subject: [PATCH] Better handling of orphaned activities. --- View Models/LiveActivityVM.swift | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/View Models/LiveActivityVM.swift b/View Models/LiveActivityVM.swift index db4d36d..72259b3 100644 --- a/View Models/LiveActivityVM.swift +++ b/View Models/LiveActivityVM.swift @@ -97,21 +97,27 @@ class LiveActivityVM : ObservableObject { let orphanedActivityIdPtr = UnsafeRawPointer(ConvertActivityIndexToActivityId(orphanedActivityIndex)) // const char*, no need to dealloc let orphanedActivityTypePtr = UnsafeRawPointer(GetHistoricalActivityType(orphanedActivityIndex)) + var activityRecreated = false defer { orphanedActivityTypePtr!.deallocate() } - activityTypeToUse = String(cString: orphanedActivityTypePtr!.assumingMemoryBound(to: CChar.self)) + let orphanedActivityType = String(cString: orphanedActivityTypePtr!.assumingMemoryBound(to: CChar.self)) + if orphanedActivityType.count > 0 { + activityTypeToUse = orphanedActivityType - if recreateOrphanedActivities { - ReCreateOrphanedActivity(orphanedActivityIndex) - - self.activityId = String(cString: orphanedActivityIdPtr!.assumingMemoryBound(to: CChar.self)) - self.isInProgress = true - isNewActivity = false + if recreateOrphanedActivities { + ReCreateOrphanedActivity(orphanedActivityIndex) + + self.activityId = String(cString: orphanedActivityIdPtr!.assumingMemoryBound(to: CChar.self)) + self.isInProgress = true + isNewActivity = false + activityRecreated = true + } } - else { + + if activityRecreated == false { self.loadHistoricalActivityByIndex(activityIndex: orphanedActivityIndex) } }