android, desktop: prevent migration when network conf wasn't applied (#4615)

* android, desktop: prevent migration when network conf wasn't applied

* name of param
This commit is contained in:
Stanislav Dmitrenko
2024-08-07 23:42:31 +09:00
committed by GitHub
parent b3d15f97f0
commit 1a6245fe51
4 changed files with 12 additions and 4 deletions
@@ -529,7 +529,10 @@ object ChatController {
suspend fun startChatWithTemporaryDatabase(ctrl: ChatCtrl, netCfg: NetCfg): User? {
Log.d(TAG, "startChatWithTemporaryDatabase")
val migrationActiveUser = apiGetActiveUser(null, ctrl) ?: apiCreateActiveUser(null, Profile(displayName = "Temp", fullName = ""), ctrl = ctrl)
apiSetNetworkConfig(netCfg, ctrl)
if (!apiSetNetworkConfig(netCfg, ctrl)) {
Log.e(TAG, "Error setting network config, stopping migration")
return null
}
apiSetAppFilePaths(
getMigrationTempFilesDirectory().absolutePath,
getMigrationTempFilesDirectory().absolutePath,
@@ -337,7 +337,7 @@ fun SubscriptionStatusIndicator(click: (() -> Unit)) {
val scope = rememberCoroutineScope()
suspend fun setSubsTotal() {
if (chatModel.currentUser.value != null) {
if (chatModel.currentUser.value != null && chatModel.controller.hasChatCtrl() && chatModel.chatRunning.value == true) {
val r = chatModel.controller.getAgentSubsTotal(chatModel.remoteHostId())
if (r != null) {
subs = r.first
@@ -516,8 +516,11 @@ suspend fun initTemporaryDatabase(tempDatabaseFile: File, netCfg: NetCfg): Pair<
try {
if (ctrl != null) {
val user = startChatWithTemporaryDatabase(ctrl, netCfg)
return if (user != null) ctrl to user else null
if (user != null) return ctrl to user
chatCloseStore(ctrl)
}
File(tempDatabaseFile.absolutePath + "_chat.db").delete()
File(tempDatabaseFile.absolutePath + "_agent.db").delete()
} catch (e: Throwable) {
Log.e(TAG, "Error while starting chat in temporary database: ${e.stackTraceToString()}")
}
@@ -515,7 +515,9 @@ private fun MutableState<MigrationToState?>.prepareDatabase(
withLongRunningApi {
val ctrlAndUser = initTemporaryDatabase(tempDatabaseFile, netCfg)
if (ctrlAndUser == null) {
state = MigrationToState.DownloadFailed(0, link, archivePath(), netCfg)
// Probably, something wrong with network config or database initialization, let's start from scratch
state = MigrationToState.PasteOrScanLink
MigrationToDeviceState.save(null)
return@withLongRunningApi
}