From 828b36f290671bf451692ea211f784b45a8b0298 Mon Sep 17 00:00:00 2001 From: evgeny Date: Thu, 29 Oct 2026 11:16:37 +0100 Subject: [PATCH] Keep failed settings teardown retryable and preserve UI until database stop succeeds --- .../main/java/com/utun/chat/data/NativeLib.kt | 20 ++++++++++++------- .../com/utun/chat/viewmodel/ChatViewModel.kt | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/data/NativeLib.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/data/NativeLib.kt index f00335ed..77ab7088 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/data/NativeLib.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/data/NativeLib.kt @@ -67,8 +67,8 @@ object NativeLib { } fun restart(dbPath: String, controlPort: Int, configText: String): Boolean { - prepareForCoreStop() - return nativeRestart(configText).also { coreStopping = false } + try { prepareForCoreStop(); return nativeRestart(configText) } + finally { coreStopping = false } } /** Снять frontend-владельцев перед stop/restart/сменой ключей. Неподтверждённый CallService либо ещё @@ -95,7 +95,7 @@ object NativeLib { return nativeUpdateSockets(configText) } - fun isReady(): Boolean = !coreStopping && nativeIsRunning() + fun isReady(): Boolean = nativeIsRunning() fun getMyNodeId(): Long = nativeGetMyNodeId() @@ -154,8 +154,8 @@ object NativeLib { fun setUdpLogTarget(ip: String, port: Int) { nativeSetUdpLogTarget(ip, port) } /** Принимает полный INI для пересоздания ядра с новой сохранённой идентичностью; true подтверждает приём запроса. */ fun regenerateKeys(configText: String): Boolean { - prepareForCoreStop() - return nativeRegenerateKeys(configText).also { coreStopping = false } + try { prepareForCoreStop(); return nativeRegenerateKeys(configText) } + finally { coreStopping = false } } /* ── Channel members ── */ @@ -315,8 +315,14 @@ object NativeLib { /* ── P2P аудио-звонок (сигналинг) ── */ /** true — копия команды принята живым worker; результат согласования приходит CALL_* событием. */ - fun callStart(channelId: String, peerNodeId: Long, callId: Long): Boolean = nativeCallStart(channelId, peerNodeId, callId) - fun callAccept(callId: Long): Boolean = nativeCallAccept(callId) + fun callStart(channelId: String, peerNodeId: Long, callId: Long): Boolean { + if (coreStopping) { LogManager.addLog("WARN", "Call", "Start rejected during core teardown id=$callId"); return false } + return nativeCallStart(channelId, peerNodeId, callId) + } + fun callAccept(callId: Long): Boolean { + if (coreStopping) { LogManager.addLog("WARN", "Call", "Accept rejected during core teardown id=$callId"); return false } + return nativeCallAccept(callId) + } fun callDecline(callId: Long): Boolean = nativeCallDecline(callId) fun callHangup(callId: Long): Boolean = nativeCallHangup(callId) fun callContinue(callId: Long): Boolean = nativeCallContinue(callId) diff --git a/tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt b/tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt index 1128c01a..b1f4a5e2 100644 --- a/tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt +++ b/tools/chatgui-android/app/src/main/java/com/utun/chat/viewmodel/ChatViewModel.kt @@ -1866,10 +1866,10 @@ class ChatViewModel : ViewModel() { viewModelScope.launch { try { HeadlessService.awaitStartup() - clearState() withContext(Dispatchers.IO) { val wasRunning = NativeLib.isReady() NativeLib.stop() + withContext(Dispatchers.Main) { clearState() } val cleared = NativeLib.clearDatabase() if (!cleared) LogManager.addLog("ERROR", "CFG", "database reset rejected by native backend") if (wasRunning) {