diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 71e76f6..e7a28af 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -1721,7 +1721,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 172; + CURRENT_PROJECT_VERSION = 173; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = AutoCat; @@ -1750,7 +1750,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 172; + CURRENT_PROJECT_VERSION = 173; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = AutoCat; diff --git a/AutoCat/Screens/RecordsScreen/RecordsViewModel.swift b/AutoCat/Screens/RecordsScreen/RecordsViewModel.swift index 0404111..a3a41b9 100644 --- a/AutoCat/Screens/RecordsScreen/RecordsViewModel.swift +++ b/AutoCat/Screens/RecordsScreen/RecordsViewModel.swift @@ -56,7 +56,7 @@ final class RecordsViewModel: ACHudContainer { } func stopRecording() async { - await wrapWithToast { [weak self] in + await wrapWithToast(showProgress: false) { [weak self] in guard let self else { return } let record = try await recordService.stopRecording() try await storageService.add(record: record) diff --git a/AutoCatCore/Services/VehicleRecordService/VehicleRecordService.swift b/AutoCatCore/Services/VehicleRecordService/VehicleRecordService.swift index cf3d5f6..d007d2c 100644 --- a/AutoCatCore/Services/VehicleRecordService/VehicleRecordService.swift +++ b/AutoCatCore/Services/VehicleRecordService/VehicleRecordService.swift @@ -18,10 +18,9 @@ public actor VehicleRecordService { var url: URL? var date = Date() - var location: VehicleEventDto? @AutoCancellable - var locationTask: Task? + var locationTask: Task? public init( recordService: AudioRecordServiceProtocol, @@ -103,8 +102,18 @@ extension VehicleRecordService: VehicleRecordServiceProtocol { self.url = url try await recordService.startRecording(to: url) - locationTask = Task { - location = try await locationService.getRecentLocation() + + if locationTask == nil || locationTask?.isCancelled == true { + locationTask = Task { + do { + let location = try await locationService.getRecentLocation() + locationTask = nil + return location + } catch { + locationTask = nil + return nil + } + } } } @@ -114,11 +123,7 @@ extension VehicleRecordService: VehicleRecordServiceProtocol { throw VehicleRecordError.emptyUrl } - locationTask?.cancel() - locationTask = nil self.url = nil - let location = self.location - self.location = nil await recordService.stopRecording() @@ -126,6 +131,11 @@ extension VehicleRecordService: VehicleRecordServiceProtocol { async let durationTask = recordService.getDuration(from: url) let (text, duration) = await (recognitionTask, try? durationTask) + var location = try? await locationTask?.value + + // One location can be shared between multile records + // So, manually give each copy it's unique id + location?.id = UUID().uuidString let record = AudioRecordDto( path: url.lastPathComponent,