From 50f1396f631c7642d9a3f30a4cf9b0d8e1bc3916 Mon Sep 17 00:00:00 2001 From: josephpei Date: Fri, 12 Mar 2021 15:55:33 +0800 Subject: [PATCH] minor update --- CMakeLists.txt | 2 +- src/core/configurator.cpp | 13 +++++++++++++ src/core/configurator.h | 2 ++ src/mainwindow.cpp | 32 +++++++++++++++++++++----------- src/mainwindow.h | 4 ++-- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19aa292..59a6d32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Debug CACHE STRING "Options are: None, Debug, Release, RelWithDebInfo, MinSizeRel." FORCE) endif() -project(qClash VERSION 0.2.0) +project(qClash VERSION 0.2.1) if (DEFINED VERSION_SUFIX AND NOT "${VERSION_SUFIX}" STREQUAL "") set(QCLASH_VERSION_SUFIX "-${VERSION_SUFIX}") diff --git a/src/core/configurator.cpp b/src/core/configurator.cpp index 4d26a49..f4ad0c4 100644 --- a/src/core/configurator.cpp +++ b/src/core/configurator.cpp @@ -86,6 +86,19 @@ QString Configurator::getSecret() return QString(""); } +QDateTime Configurator::getUpdateTime() +{ + QList subscribes = getSubscribes(); + QDateTime time = QDateTime::currentDateTime(); + for (auto & subscribe : subscribes) { + if (subscribe.name != "config") { + time = subscribe.updateTime; + break; + } + } + return time; +} + QList Configurator::getSubscribes() { auto data = loadValue("subscribes").value>(); diff --git a/src/core/configurator.h b/src/core/configurator.h index 33c9e8c..8f94dd8 100644 --- a/src/core/configurator.h +++ b/src/core/configurator.h @@ -54,6 +54,8 @@ class Configurator : public QObject { QString getSecret(); + QDateTime getUpdateTime(); + QMap diffConfigs(); void setMode(const QString& mode); QString getMode(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c6441b6..cb524ef 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -25,7 +25,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) - , timer(new QTimer) + , periodicTimer(new QTimer) + , startTimer(new QTimer) , pageButtons(new QButtonGroup) , modeButtons(new QButtonGroup) , clashCore(ClashCore::instance()) @@ -120,16 +121,17 @@ bool MainWindow::initClash() qDebug() << "Current configs: " << ClashApi::getConfigs(); ClashApi::setSecret(configurator.getSecret()); - connect(timer, &QTimer::timeout, this, &MainWindow::updateSubscribes); - timer->start(12*60*60*1000); + connect(periodicTimer, &QTimer::timeout, this, &MainWindow::updateSubscribes); + periodicTimer->start(12*60*60*1000); + + if (configurator.getUpdateTime().secsTo(QDateTime::currentDateTime()) > 24*60*60) { + startTimer->singleShot(10 * 1000, this, SLOT(updateSubscribes())); + } return true; } void MainWindow::createActions() { - mainWindowAction = new QAction(tr("Show MainWindow"), this); - connect(mainWindowAction, &QAction::triggered, this, &MainWindow::showMainWindow); - quitAction = new QAction(tr("&Quit"), this); connect(quitAction, &QAction::triggered, qApp, &QApplication::quit); @@ -298,7 +300,6 @@ void MainWindow::createTrayIcon() trayMenu->addMenu(helpMenu); trayMenu->addSeparator(); - trayMenu->addAction(mainWindowAction); trayMenu->addAction(quitAction); trayIcon = new QSystemTrayIcon(this); @@ -393,11 +394,11 @@ void MainWindow::autoUpdateSubConfigChange(bool autoUpdate) { configurator.setAutoUpdate(autoUpdate); if (autoUpdate) { - if (!timer->isActive()) - timer->start(); + if (!periodicTimer->isActive()) + periodicTimer->start(); } else { - if (timer->isActive()) - timer->stop(); + if (periodicTimer->isActive()) + periodicTimer->stop(); } } @@ -423,6 +424,15 @@ void MainWindow::configChange(QAction *action) QString name = action->data().toString(); qDebug() << "Current config: " << name; doConfigChange(name); + QList subscribes = configurator.getSubscribes(); + int i = 0; + for (; i < subscribes.size(); ++i) { + if (subscribes[i].name == name) + break; + } + ui->configComboBox->blockSignals(true); + ui->configComboBox->setCurrentIndex(i); + ui->configComboBox->blockSignals(false); // } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 57ac88a..0a22828 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -84,13 +84,13 @@ private slots: // QVBoxLayout* proxiesLayout; FlowLayout* proxiesLayout; - QTimer* timer; + QTimer* periodicTimer; + QTimer* startTimer; void createActions(); void createTrayIcon(); // tray menus & actions - QAction *mainWindowAction; QAction *quitAction; QActionGroup *modeActionsGroup;