Skip to content

Commit

Permalink
feat: remember splitter state
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Mar 25, 2023
1 parent 180a764 commit cb2fabd
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions main/NekoRay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions main/NekoRay_DataStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand Down
2 changes: 1 addition & 1 deletion main/NekoRay_Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion main/NekoRay_Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sub/GroupUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
10 changes: 7 additions & 3 deletions ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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";
}

Expand Down Expand Up @@ -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<QMouseEvent *>(event);

if (obj == ui->label_running && mouseEvent->button() == Qt::LeftButton && running != nullptr) {
speedtest_current();
return true;
Expand Down

0 comments on commit cb2fabd

Please sign in to comment.