From ac7a3e5b96cee5b0f87bdd1804b635bd51f77fe3 Mon Sep 17 00:00:00 2001 From: Avently Date: Thu, 22 Feb 2024 21:24:19 +0700 Subject: [PATCH] changes --- .../UserSettings/MigrateToAnotherDevice.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/ios/Shared/Views/UserSettings/MigrateToAnotherDevice.swift b/apps/ios/Shared/Views/UserSettings/MigrateToAnotherDevice.swift index f5bfacb11..8dba43c1d 100644 --- a/apps/ios/Shared/Views/UserSettings/MigrateToAnotherDevice.swift +++ b/apps/ios/Shared/Views/UserSettings/MigrateToAnotherDevice.swift @@ -62,7 +62,7 @@ struct MigrateToAnotherDevice: View { @State private var alert: MigrateToAnotherDeviceViewAlert? @State private var authorized = !UserDefaults.standard.bool(forKey: DEFAULT_PERFORM_LA) @State private var chatWasStoppedInitially: Bool = true - @State private var tempDatabaseUrl = urlForTemporaryDatabase() + private let tempDatabaseUrl = urlForTemporaryDatabase() @State private var chatReceiver: MigrationChatReceiver? = nil @State private var backDisabled: Bool = false @@ -140,7 +140,8 @@ struct MigrateToAnotherDevice: View { await cancelUploadedAchive(fileId, ctrl) } chatReceiver?.stop() - try? FileManager.default.removeItem(at: tempDatabaseUrl) + try? FileManager.default.removeItem(atPath: "\(tempDatabaseUrl.path)_chat.db") + try? FileManager.default.removeItem(atPath: "\(tempDatabaseUrl.path)_agent.db") try? FileManager.default.removeItem(at: getMigrationTempFilesDirectory()) } } @@ -282,6 +283,8 @@ struct MigrateToAnotherDevice: View { } .onAppear { chatReceiver?.stop() + try? FileManager.default.removeItem(atPath: "\(tempDatabaseUrl.path)_chat.db") + try? FileManager.default.removeItem(atPath: "\(tempDatabaseUrl.path)_agent.db") } } @@ -426,10 +429,7 @@ struct MigrateToAnotherDevice: View { } } - private func initDatabaseIfNeeded() -> (chat_ctrl, User)? { - // Remove previous one if this isn't a first try - try? FileManager.default.removeItem(at: tempDatabaseUrl) - tempDatabaseUrl = MigrateToAnotherDevice.urlForTemporaryDatabase() + private func initTemporaryDatabase() -> (chat_ctrl, User)? { let (status, ctrl) = chatInitTemporaryDatabase(url: tempDatabaseUrl) showErrorOnMigrationIfNeeded(status, $alert) do { @@ -444,7 +444,7 @@ struct MigrateToAnotherDevice: View { private func startUploading(_ totalBytes: Int64, _ archivePath: URL) { Task { - guard let ctrlAndUser = initDatabaseIfNeeded() else { + guard let ctrlAndUser = initTemporaryDatabase() else { return migrationState = .uploadFailed(totalBytes: totalBytes, archivePath: archivePath) } let (ctrl, user) = ctrlAndUser @@ -657,7 +657,7 @@ class MigrationChatReceiver { receiveMessages = false receiveLoop?.cancel() receiveLoop = nil - //chat_close_store(ctrl) + chat_close_store(ctrl) } }