diff --git a/tools/chatgui/src/mainwindow.cpp b/tools/chatgui/src/mainwindow.cpp index 9c2b5250..39493aaa 100644 --- a/tools/chatgui/src/mainwindow.cpp +++ b/tools/chatgui/src/mainwindow.cpp @@ -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); diff --git a/tools/chatgui/src/messagelist.cpp b/tools/chatgui/src/messagelist.cpp index d63384d0..701863c8 100644 --- a/tools/chatgui/src/messagelist.cpp +++ b/tools/chatgui/src/messagelist.cpp @@ -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); }