Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
josephpei committed Mar 12, 2021
1 parent d908dce commit 50f1396
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
13 changes: 13 additions & 0 deletions src/core/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ QString Configurator::getSecret()
return QString("");
}

QDateTime Configurator::getUpdateTime()
{
QList<Subscribe> subscribes = getSubscribes();
QDateTime time = QDateTime::currentDateTime();
for (auto & subscribe : subscribes) {
if (subscribe.name != "config") {
time = subscribe.updateTime;
break;
}
}
return time;
}

QList<Subscribe> Configurator::getSubscribes()
{
auto data = loadValue("subscribes").value<QList<QString>>();
Expand Down
2 changes: 2 additions & 0 deletions src/core/configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Configurator : public QObject {

QString getSecret();

QDateTime getUpdateTime();

QMap<QString, QString> diffConfigs();
void setMode(const QString& mode);
QString getMode();
Expand Down
32 changes: 21 additions & 11 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -298,7 +300,6 @@ void MainWindow::createTrayIcon()
trayMenu->addMenu(helpMenu);
trayMenu->addSeparator();

trayMenu->addAction(mainWindowAction);
trayMenu->addAction(quitAction);

trayIcon = new QSystemTrayIcon(this);
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -423,6 +424,15 @@ void MainWindow::configChange(QAction *action)
QString name = action->data().toString();
qDebug() << "Current config: " << name;
doConfigChange(name);
QList<Subscribe> 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);
// }
}

Expand Down
4 changes: 2 additions & 2 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 50f1396

Please sign in to comment.