From cb2fabd11cfe0b05de1a57bae055e3ef99466b22 Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Sat, 25 Mar 2023 14:52:41 +0900 Subject: [PATCH] feat: remember splitter state --- main/NekoRay.cpp | 1 + main/NekoRay_DataStore.hpp | 1 + main/NekoRay_Utils.cpp | 2 +- main/NekoRay_Utils.hpp | 2 +- sub/GroupUpdater.cpp | 2 +- ui/mainwindow.cpp | 10 +++++++--- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/main/NekoRay.cpp b/main/NekoRay.cpp index 49f97d2b2..4147bf5b2 100644 --- a/main/NekoRay.cpp +++ b/main/NekoRay.cpp @@ -73,6 +73,7 @@ namespace NekoRay { _add(new configItem("log_ignore", &log_ignore, itemType::stringList)); _add(new configItem("start_minimal", &start_minimal, itemType::boolean)); _add(new configItem("max_log_line", &max_log_line, itemType::integer)); + _add(new configItem("splitter_state", &splitter_state, itemType::string)); #ifndef Q_OS_WIN _add(new configItem("vpn_already_admin", &vpn_already_admin, itemType::boolean)); #endif diff --git a/main/NekoRay_DataStore.hpp b/main/NekoRay_DataStore.hpp index a67b4cc3b..0b0da7110 100644 --- a/main/NekoRay_DataStore.hpp +++ b/main/NekoRay_DataStore.hpp @@ -89,6 +89,7 @@ namespace NekoRay { QStringList log_ignore = {}; bool start_minimal = false; int max_log_line = 200; + QString splitter_state = ""; // Subscription QString user_agent = "Nekoray/1.0 (Prefer Clash Format)"; diff --git a/main/NekoRay_Utils.cpp b/main/NekoRay_Utils.cpp index 4397fb169..cac07bc3c 100644 --- a/main/NekoRay_Utils.cpp +++ b/main/NekoRay_Utils.cpp @@ -35,7 +35,7 @@ QStringList SplitLinesSkipSharp(const QString &_string) { return newLines; } -QString DecodeB64IfValid(const QString &input, QByteArray::Base64Options options) { +QByteArray DecodeB64IfValid(const QString &input, QByteArray::Base64Options options) { Qt515Base64::Base64Options newOptions = Qt515Base64::Base64Option::AbortOnBase64DecodingErrors; if (options.testFlag(QByteArray::Base64UrlEncoding)) newOptions |= Qt515Base64::Base64Option::Base64UrlEncoding; if (options.testFlag(QByteArray::OmitTrailingEquals)) newOptions |= Qt515Base64::Base64Option::OmitTrailingEquals; diff --git a/main/NekoRay_Utils.hpp b/main/NekoRay_Utils.hpp index fb6b0c46f..d6d012fcf 100644 --- a/main/NekoRay_Utils.hpp +++ b/main/NekoRay_Utils.hpp @@ -47,7 +47,7 @@ QStringList SplitLinesSkipSharp(const QString &_string); // Base64 -QString DecodeB64IfValid(const QString &input, QByteArray::Base64Options options = QByteArray::Base64Option::Base64Encoding); +QByteArray DecodeB64IfValid(const QString &input, QByteArray::Base64Options options = QByteArray::Base64Option::Base64Encoding); // URL diff --git a/sub/GroupUpdater.cpp b/sub/GroupUpdater.cpp index 00f18ea0a..03cd10941 100644 --- a/sub/GroupUpdater.cpp +++ b/sub/GroupUpdater.cpp @@ -72,7 +72,7 @@ namespace NekoRay::sub { if (ent->bean->version == -114514) return; auto j = DecodeB64IfValid(link.fragment().toUtf8(), QByteArray::Base64UrlEncoding); if (j.isEmpty()) return; - ent->bean->FromJsonBytes(j.toUtf8()); + ent->bean->FromJsonBytes(j); MW_show_log("nekoray format: " + ent->bean->DisplayTypeAndName()); } diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 4c7f50538..0391b5a87 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -112,6 +112,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(ui->toolButton_update, &QToolButton::clicked, this, [=] { runOnNewThread([=] { CheckUpdate(); }); }); // Setup log UI + ui->splitter->restoreState(DecodeB64IfValid(NekoRay::dataStore->splitter_state)); new SyntaxHighlighter(false, qvLogDocument); qvLogDocument->setUndoRedoEnabled(false); ui->masterLogBrowser->setUndoRedoEnabled(false); @@ -588,20 +589,24 @@ void MainWindow::on_menu_hotkey_settings_triggered() { void MainWindow::on_commitDataRequest() { qDebug() << "Start of data save"; + // if (!isMaximized()) { auto olds = NekoRay::dataStore->mw_size; auto news = QString("%1x%2").arg(size().width()).arg(size().height()); if (olds != news) { NekoRay::dataStore->mw_size = news; - NekoRay::dataStore->Save(); } } // + NekoRay::dataStore->splitter_state = ui->splitter->saveState().toBase64(); + // auto last_id = NekoRay::dataStore->started_id; neko_stop(); if (NekoRay::dataStore->remember_enable && last_id >= 0) { - NekoRay::dataStore->UpdateStartedId(last_id); + NekoRay::dataStore->remember_id = last_id; } + // + NekoRay::dataStore->Save(); qDebug() << "End of data save"; } @@ -1497,7 +1502,6 @@ void MainWindow::on_masterLogBrowser_customContextMenuRequested(const QPoint &po bool MainWindow::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { auto mouseEvent = dynamic_cast(event); - if (obj == ui->label_running && mouseEvent->button() == Qt::LeftButton && running != nullptr) { speedtest_current(); return true;