ios: close store when app is about to terminate

This commit is contained in:
Evgeny Poberezkin
2023-10-01 10:58:16 +01:00
parent b26195e581
commit 5878d4608c
3 changed files with 15 additions and 0 deletions
+6
View File
@@ -45,7 +45,10 @@ func suspendBgRefresh() {
}
}
private var terminating = false
func terminateChat() {
terminating = true
suspendLockQueue.sync {
switch appStateGroupDefault.get() {
case .suspending:
@@ -73,6 +76,9 @@ private func _chatSuspended() {
if ChatModel.shared.chatRunning == true {
ChatReceiver.shared.stop()
}
if terminating {
chatCloseStore()
}
}
func activateChat(appState: AppState = .active) {
+7
View File
@@ -50,6 +50,13 @@ public func chatMigrateInit(_ useKey: String? = nil, confirmMigrations: Migratio
return result
}
public func chatCloseStore() {
let err = fromCString(chat_close_store(getChatCtrl()))
if err != "" {
logger.error("chatCloseStore error: \(err)")
}
}
public func resetChatCtrl() {
chatController = nil
migrationResult = nil
+2
View File
@@ -17,6 +17,8 @@ typedef void* chat_ctrl;
// the last parameter is used to return the pointer to chat controller
extern char *chat_migrate_init(char *path, char *key, char *confirm, chat_ctrl *ctrl);
extern char *chat_close_store(chat_ctrl ctl)
extern char *chat_open_store(chat_ctrl ctl, char *key);
extern char *chat_send_cmd(chat_ctrl ctl, char *cmd);
extern char *chat_recv_msg(chat_ctrl ctl);
extern char *chat_recv_msg_wait(chat_ctrl ctl, int wait);