mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
feat: Automatic update subscription
This commit is contained in:
@@ -561,3 +561,53 @@ namespace NekoGui_sub {
|
||||
}
|
||||
}
|
||||
} // namespace NekoGui_sub
|
||||
|
||||
bool UI_update_all_groups_Updating = false;
|
||||
|
||||
#define should_skip_group(g) (g == nullptr || g->url.isEmpty() || g->archive || (onlyAllowed && g->skip_auto_update))
|
||||
|
||||
void serialUpdateSubscription(const QList<int> &groupsTabOrder, int _order, bool onlyAllowed) {
|
||||
// calculate next group
|
||||
int nextOrder = _order;
|
||||
std::shared_ptr<NekoGui::Group> nextGroup;
|
||||
forever {
|
||||
nextOrder += 1;
|
||||
if (nextOrder >= groupsTabOrder.size()) break;
|
||||
auto nextGid = groupsTabOrder[nextOrder];
|
||||
nextGroup = NekoGui::profileManager->GetGroup(nextGid);
|
||||
if (should_skip_group(nextGroup)) continue;
|
||||
break;
|
||||
}
|
||||
|
||||
// calculate this group
|
||||
auto group = NekoGui::profileManager->GetGroup(groupsTabOrder[_order]);
|
||||
if (group == nullptr) {
|
||||
UI_update_all_groups_Updating = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// v2.2: listener is moved to GroupItem, no refresh here.
|
||||
NekoGui_sub::groupUpdater->AsyncUpdate(group->url, group->id, [=] {
|
||||
if (nextGroup == nullptr) {
|
||||
UI_update_all_groups_Updating = false;
|
||||
} else {
|
||||
serialUpdateSubscription(groupsTabOrder, nextOrder, onlyAllowed);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void UI_update_all_groups(bool onlyAllowed) {
|
||||
if (UI_update_all_groups_Updating) {
|
||||
MW_show_log("The last subscription update has not exited.");
|
||||
return;
|
||||
}
|
||||
// first: freeze group order
|
||||
auto groupsTabOrder = NekoGui::profileManager->groupsTabOrder;
|
||||
for (const auto &gid: groupsTabOrder) {
|
||||
auto group = NekoGui::profileManager->GetGroup(gid);
|
||||
if (should_skip_group(group)) continue;
|
||||
// start
|
||||
UI_update_all_groups_Updating = true;
|
||||
serialUpdateSubscription(groupsTabOrder, groupsTabOrder.indexOf(gid), onlyAllowed);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user