mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
improve group update
This commit is contained in:
@@ -55,6 +55,7 @@ namespace NekoRay::sub {
|
||||
auto j = DecodeB64IfValid(link.fragment().toUtf8(), QByteArray::Base64UrlEncoding);
|
||||
if (j.isEmpty()) return;
|
||||
ent->bean->FromJsonBytes(j.toUtf8());
|
||||
showLog("nekoray format: " + ent->bean->DisplayTypeAndName());
|
||||
}
|
||||
|
||||
// SOCKS
|
||||
@@ -290,16 +291,8 @@ namespace NekoRay::sub {
|
||||
#endif
|
||||
}
|
||||
|
||||
// 不要刷新,下载导入完会自己刷新
|
||||
void GroupUpdater::AsyncUpdate(const QString &str, int _sub_gid,
|
||||
QObject *caller, const std::function<void()> &callback) {
|
||||
if (caller != nullptr && callback != nullptr) {
|
||||
connectOnce(this, &GroupUpdater::AsyncUpdateCallback, caller,
|
||||
[=](QObject *receiver) {
|
||||
if (receiver == caller) callback();
|
||||
});
|
||||
}
|
||||
|
||||
// 在新的 thread 运行
|
||||
void GroupUpdater::AsyncUpdate(const QString &str, int _sub_gid, const std::function<void()> &finish) {
|
||||
auto content = str.trimmed();
|
||||
bool asURL = false;
|
||||
|
||||
@@ -316,7 +309,8 @@ namespace NekoRay::sub {
|
||||
|
||||
runOnNewThread([=] {
|
||||
Update(str, _sub_gid, asURL);
|
||||
emit AsyncUpdateCallback(caller);
|
||||
emit asyncUpdateCallback(_sub_gid);
|
||||
if (finish != nullptr) finish();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,14 +18,13 @@ namespace NekoRay::sub {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
void AsyncUpdate(const QString &str, int _sub_gid = -1,
|
||||
QObject *caller = nullptr, const std::function<void()> &callback = nullptr);
|
||||
void AsyncUpdate(const QString &str, int _sub_gid = -1, const std::function<void()> &finish = nullptr);
|
||||
|
||||
void Update(const QString &_str, int _sub_gid = -1, bool _not_sub_as_url = false);
|
||||
|
||||
signals:
|
||||
|
||||
void AsyncUpdateCallback(QObject *caller);
|
||||
void asyncUpdateCallback(int gid);
|
||||
};
|
||||
|
||||
extern GroupUpdater *groupUpdater;
|
||||
|
||||
@@ -58,13 +58,13 @@ void DialogManageGroups::on_update_all_clicked() {
|
||||
for (const auto &gid: NekoRay::profileManager->_groups) {
|
||||
auto group = NekoRay::profileManager->GetGroup(gid);
|
||||
if (group == nullptr || group->url.isEmpty()) continue;
|
||||
_update_one_group(NekoRay::profileManager->_groups.indexOf(gid));
|
||||
UI_update_one_group(NekoRay::profileManager->_groups.indexOf(gid));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DialogManageGroups::_update_one_group(int _order) {
|
||||
void UI_update_one_group(int _order) {
|
||||
// calculate next group
|
||||
int nextOrder = _order;
|
||||
QSharedPointer<NekoRay::Group> nextGroup;
|
||||
@@ -81,17 +81,8 @@ void DialogManageGroups::_update_one_group(int _order) {
|
||||
auto group = NekoRay::profileManager->GetGroup(NekoRay::profileManager->_groups[_order]);
|
||||
if (group == nullptr) return;
|
||||
|
||||
NekoRay::sub::groupUpdater->AsyncUpdate(group->url, group->id, this, [=] {
|
||||
// refresh ui
|
||||
for (int i = 0; i < ui->listWidget->count(); i++) {
|
||||
auto w = ui->listWidget->itemWidget(ui->listWidget->item(i));
|
||||
if (w == nullptr) return;
|
||||
auto item = dynamic_cast<GroupItem *>(w);
|
||||
if (item->ent->id == group->id) {
|
||||
item->refresh_data();
|
||||
}
|
||||
}
|
||||
//
|
||||
if (nextGroup != nullptr) _update_one_group(nextOrder);
|
||||
// v2.2: listener is moved to GroupItem, no refresh here.
|
||||
NekoRay::sub::groupUpdater->AsyncUpdate(group->url, group->id, [=] {
|
||||
if (nextGroup != nullptr) UI_update_one_group(nextOrder);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,11 +22,13 @@ public:
|
||||
private:
|
||||
Ui::DialogManageGroups *ui;
|
||||
|
||||
void _update_one_group(int _order);
|
||||
|
||||
private slots:
|
||||
|
||||
void on_add_clicked();
|
||||
|
||||
void on_update_all_clicked();
|
||||
};
|
||||
|
||||
// 更新所有订阅 关闭分组窗口时 更新动作继续执行
|
||||
|
||||
void UI_update_one_group(int _order);
|
||||
|
||||
@@ -1169,9 +1169,7 @@ void MainWindow::on_menu_update_subscripton_triggered() {
|
||||
if (group->url.isEmpty()) return;
|
||||
if (mw_sub_updating) return;
|
||||
mw_sub_updating = true;
|
||||
NekoRay::sub::groupUpdater->AsyncUpdate(group->url, group->id, this, [=] {
|
||||
mw_sub_updating = false;
|
||||
});
|
||||
NekoRay::sub::groupUpdater->AsyncUpdate(group->url, group->id, [&] { mw_sub_updating = false; });
|
||||
}
|
||||
|
||||
void MainWindow::on_menu_remove_unavailable_triggered() {
|
||||
|
||||
@@ -51,6 +51,8 @@ GroupItem::GroupItem(QWidget *parent, const QSharedPointer<NekoRay::Group> &ent,
|
||||
if (ent == nullptr) return;
|
||||
|
||||
connect(this, &GroupItem::edit_clicked, this, &GroupItem::on_edit_clicked);
|
||||
connect(NekoRay::sub::groupUpdater, &NekoRay::sub::GroupUpdater::asyncUpdateCallback,
|
||||
this, [=](int gid) { if (gid == this->ent->id) refresh_data(); });
|
||||
|
||||
refresh_data();
|
||||
}
|
||||
@@ -96,9 +98,7 @@ void GroupItem::refresh_data() {
|
||||
}
|
||||
|
||||
void GroupItem::on_update_sub_clicked() {
|
||||
NekoRay::sub::groupUpdater->AsyncUpdate(ent->url, ent->id, this, [=] {
|
||||
refresh_data();
|
||||
});
|
||||
NekoRay::sub::groupUpdater->AsyncUpdate(ent->url, ent->id);
|
||||
}
|
||||
|
||||
void GroupItem::on_edit_clicked() {
|
||||
|
||||
Reference in New Issue
Block a user