add reset assets button

This commit is contained in:
Nova 2025-08-01 11:21:11 +03:30
parent 1e1941807e
commit 1e47e7a626
4 changed files with 58 additions and 12 deletions

View File

@ -86,6 +86,8 @@ public:
void DownloadAssets(const QString &geoipUrl, const QString &geositeUrl);
void ResetAssets(QString geoipUrl, QString geositeUrl);
void UpdateConnectionList(const QMap<QString, Stats::ConnectionMetadata>& toUpdate, const QMap<QString, Stats::ConnectionMetadata>& toAdd);
void UpdateConnectionListWithRecreate(const QList<Stats::ConnectionMetadata>& connections);

View File

@ -762,18 +762,6 @@
<string>Geo Assets and Rule-sets</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QPushButton" name="remove_srs_btn">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Remove the
currently generated rule-sets so that they can be regenerated&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;
</string>
</property>
<property name="text">
<string>Remove Generated Rule-sets</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout_9">
@ -812,6 +800,28 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="remove_srs_btn">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Remove the
currently generated rule-sets so that they can be regenerated&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;
</string>
</property>
<property name="text">
<string>Remove Generated Rule-sets</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="reset_assets">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Downloads and replaces the geo asstes, and removes all generated rule-sets, then restarts the proxy&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Reset All Assets</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -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;

View File

@ -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)