diff --git a/include/ui/mainwindow.h b/include/ui/mainwindow.h index e3cf794..46c8bd2 100644 --- a/include/ui/mainwindow.h +++ b/include/ui/mainwindow.h @@ -86,6 +86,8 @@ public: void DownloadAssets(const QString &geoipUrl, const QString &geositeUrl); + void ResetAssets(QString geoipUrl, QString geositeUrl); + void UpdateConnectionList(const QMap& toUpdate, const QMap& toAdd); void UpdateConnectionListWithRecreate(const QList& connections); diff --git a/include/ui/setting/dialog_basic_settings.ui b/include/ui/setting/dialog_basic_settings.ui index 6752ff3..9905ab6 100644 --- a/include/ui/setting/dialog_basic_settings.ui +++ b/include/ui/setting/dialog_basic_settings.ui @@ -762,18 +762,6 @@ Geo Assets and Rule-sets - - - - <html><head/><body><p>Remove the - currently generated rule-sets so that they can be regenerated</p></body></html> - - - - Remove Generated Rule-sets - - - @@ -812,6 +800,28 @@ + + + + <html><head/><body><p>Remove the + currently generated rule-sets so that they can be regenerated</p></body></html> + + + + Remove Generated Rule-sets + + + + + + + <html><head/><body><p>Downloads and replaces the geo asstes, and removes all generated rule-sets, then restarts the proxy</p></body></html> + + + Reset All Assets + + + diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 0f00209..25c50c8 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -563,6 +563,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(t, &QTimer::timeout, this, [&] { Configs_sys::logCounter.fetchAndStoreRelaxed(0); }); t->start(1000); + // auto update timer TM_auto_update_subsctiption = new QTimer; TM_auto_update_subsctiption_Reset_Minute = [&](int m) { TM_auto_update_subsctiption->stop(); @@ -571,6 +572,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(TM_auto_update_subsctiption, &QTimer::timeout, this, [&] { UI_update_all_groups(true); }); TM_auto_update_subsctiption_Reset_Minute(Configs::dataStore->sub_auto_update); + // asset updater timer + + if (!Configs::dataStore->flag_tray) show(); if (Configs::NeedGeoAssets()) { @@ -712,6 +716,13 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) DownloadAssets(splitted[1], splitted[2]); }); } + if (info.contains("ResetAssets")) + { + auto splitted = info.split(";"); + runOnNewThread([=](){ + ResetAssets(splitted[1], splitted[2]); + }); + } // if (info == "RestartProgram") { this->exit_reason = 2; @@ -2306,6 +2317,25 @@ void MainWindow::DownloadAssets(const QString &geoipUrl, const QString &geositeU MW_show_log(tr("Geo Asset update completed!")); } +void MainWindow::ResetAssets(QString geoipUrl, QString geositeUrl) +{ + if (geoipUrl.isEmpty()) geoipUrl = Configs::dataStore->geoip_download_url; + if (geositeUrl.isEmpty()) geositeUrl = Configs::dataStore->geosite_download_url; + DownloadAssets(geoipUrl, geositeUrl); + auto entries = QDir(RULE_SETS_DIR).entryList(QDir::Files); + for (const auto &item: entries) { + if (!QFile(RULE_SETS_DIR + "/" + item).remove()) { + MW_show_log("Failed to remove " + item + ", stop the core then try again"); + } + } + MW_show_log(tr("Removed all rule-set files")); + + runOnUiThread([=] + { + if (Configs::dataStore->started_id >= 0) profile_start(Configs::dataStore->started_id); + }); +} + // to parse versions of format Throne-1.2.3-beta.2 or Throne-1.2.3 bool isNewer(QString version) { if (QString(NKR_VERSION).isEmpty()) return false; diff --git a/src/ui/setting/dialog_basic_settings.cpp b/src/ui/setting/dialog_basic_settings.cpp index 1a48fb4..0dab1ae 100644 --- a/src/ui/setting/dialog_basic_settings.cpp +++ b/src/ui/setting/dialog_basic_settings.cpp @@ -130,6 +130,10 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) } MW_show_log(tr("Removed all rule-set files")); }); + connect(ui->reset_assets, &QPushButton::clicked, this, [=]() + { + MW_dialog_message(Dialog_DialogBasicSettings, "ResetAssets;"+ui->geoip_url->currentText()+";"+ui->geosite_url->currentText()); + }); // Mux D_LOAD_INT(mux_concurrency)