Browse Source

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.
topo_upd
Evgeny 2 months ago
parent
commit
fdc30d1a4e
  1. 8
      tools/chatgui/src/mainwindow.cpp
  2. 17
      tools/chatgui/src/messagelist.cpp

8
tools/chatgui/src/mainwindow.cpp

@ -85,7 +85,9 @@ MainWindow::MainWindow(QWidget *parent, DbManager* db, const QString& cfgPath,
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: ~MainWindow — stopping utun node");
if (m_node) { m_node->stop(); delete m_node; m_node = nullptr; } if (m_node) { m_node->stop(); delete m_node; m_node = nullptr; }
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: ~MainWindow done");
} }
void MainWindow::setupUi() { void MainWindow::setupUi() {
@ -230,7 +232,10 @@ void MainWindow::setupConnects() {
m_db->getUnreadCount(channelId, lastReadMsgId)); 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() { void MainWindow::setupTray() {
@ -263,6 +268,7 @@ void MainWindow::setupTray() {
} }
void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::closeEvent(QCloseEvent *event) {
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "MainWindow: closeEvent — hiding to tray");
hide(); hide();
m_trayIcon->showMessage("Chat", "Application minimized to tray.", m_trayIcon->showMessage("Chat", "Application minimized to tray.",
QSystemTrayIcon::Information, 2000); QSystemTrayIcon::Information, 2000);

17
tools/chatgui/src/messagelist.cpp

@ -302,13 +302,7 @@ void MessageList::saveChannelState() {
auto saveKey = [&cid](const char* suffix, qint64 val) { auto saveKey = [&cid](const char* suffix, qint64 val) {
QByteArray key = "ch_" + cid + suffix; QByteArray key = "ch_" + cid + suffix;
QByteArray valStr = QByteArray::number(val); QByteArray valStr = QByteArray::number(val);
size_t klen = key.size(), vlen = valStr.size(); chat_core_save_ui_state(key.constData(), valStr.constData());
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);
}; };
if (lastReadMsgId > 0) saveKey("_last_read", lastReadMsgId); if (lastReadMsgId > 0) saveKey("_last_read", lastReadMsgId);
@ -369,14 +363,7 @@ void MessageList::updateReadPosition() {
QByteArray cid = m_currentChannelId.toUtf8(); QByteArray cid = m_currentChannelId.toUtf8();
QByteArray key = "ch_" + cid + "_last_read"; QByteArray key = "ch_" + cid + "_last_read";
QByteArray valStr = QByteArray::number(m_lastReadMsgId); QByteArray valStr = QByteArray::number(m_lastReadMsgId);
size_t klen = key.size(), vlen = valStr.size(); chat_core_save_ui_state(key.constData(), valStr.constData());
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);
}
emit readPositionChanged(m_currentChannelId, m_lastReadMsgId); emit readPositionChanged(m_currentChannelId, m_lastReadMsgId);
} }

Loading…
Cancel
Save