Waiting for location in audio recordings

This commit is contained in:
Selim Mustafaev 2025-10-15 14:54:01 +03:00
parent 23cf2018ff
commit e7e2cb311f
3 changed files with 21 additions and 11 deletions

View File

@ -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;

View File

@ -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)

View File

@ -18,10 +18,9 @@ public actor VehicleRecordService {
var url: URL?
var date = Date()
var location: VehicleEventDto?
@AutoCancellable
var locationTask: Task<Void,Error>?
var locationTask: Task<VehicleEventDto?,Error>?
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,