chatgui: synchronous DB write in saveChannelState/updateReadPosition, add shutdown debug logs
Replace gui_bridge_post_uasync_fn (async queue lost on shutdown) with direct chat_core_save_ui_state (sync SQLite write). SQLite WAL handles concurrent access. Add DEBUG_DEBUG traces in closeEvent, ~MainWindow, aboutToQuit.
This commit is contained in:
1 parent
393b7d36c8
commit
fdc30d1a4e
2 files changed
+9
-16
No files matched your search
@@ -85,7 +85,9 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath,
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: ~MainWindow — stopping utun node");
|
||||
if (m_node) { m_node->stop(); delete m_node; m_node = nullptr; }
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: ~MainWindow done");
|
||||
}
|
||||
|
||||
void MainWindow::setupUi() {
|
||||
@@ -230,7 +232,10 @@ void MainWindow::setupConnects() {
|
||||
m_db->getUnreadCount(channelId, lastReadMsgId));
|
||||
});
|
||||
|
||||
connect(qApp, &QApplication::aboutToQuit, m_messageList, &MessageList::saveChannelState);
|
||||
connect(qApp, &QApplication::aboutToQuit, this, [this]() {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: aboutToQuit — saving channel state");
|
||||
if (m_messageList) m_messageList->saveChannelState();
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::setupTray() {
|
||||
@@ -263,6 +268,7 @@ void MainWindow::setupTray() {
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: closeEvent — hiding to tray");
|
||||
hide();
|
||||
m_trayIcon->showMessage("Chat", "Application minimized to tray.",
|
||||
QSystemTrayIcon::Information, 2000);
|
||||
|
||||
@@ -302,13 +302,7 @@ void MessageList::saveChannelState() {
|
||||
auto saveKey = [&cid](const char* suffix, qint64 val) {
|
||||
QByteArray key = "ch_" + cid + suffix;
|
||||
QByteArray valStr = QByteArray::number(val);
|
||||
size_t klen = key.size(), vlen = valStr.size();
|
||||
size_t total = klen + 1 + vlen + 1;
|
||||
if (total > 256) return;
|
||||
void* arg = u_malloc(total);
|
||||
memcpy(arg, key.constData(), klen + 1);
|
||||
memcpy((char*)arg + klen + 1, valStr.constData(), vlen + 1);
|
||||
gui_bridge_post_uasync_fn(chat_core_save_ui_state_trampoline, arg);
|
||||
chat_core_save_ui_state(key.constData(), valStr.constData());
|
||||
};
|
||||
|
||||
if (lastReadMsgId > 0) saveKey("_last_read", lastReadMsgId);
|
||||
@@ -369,14 +363,7 @@ void MessageList::updateReadPosition() {
|
||||
QByteArray cid = m_currentChannelId.toUtf8();
|
||||
QByteArray key = "ch_" + cid + "_last_read";
|
||||
QByteArray valStr = QByteArray::number(m_lastReadMsgId);
|
||||
size_t klen = key.size(), vlen = valStr.size();
|
||||
size_t total = klen + 1 + vlen + 1;
|
||||
if (total <= 256) {
|
||||
void* arg = u_malloc(total);
|
||||
memcpy(arg, key.constData(), klen + 1);
|
||||
memcpy((char*)arg + klen + 1, valStr.constData(), vlen + 1);
|
||||
gui_bridge_post_uasync_fn(chat_core_save_ui_state_trampoline, arg);
|
||||
}
|
||||
chat_core_save_ui_state(key.constData(), valStr.constData());
|
||||
|
||||
emit readPositionChanged(m_currentChannelId, m_lastReadMsgId);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user