feat: Automatic update subscription

This commit is contained in:
arm64v8a
2023-07-24 13:58:28 +09:00
parent 42b4367f01
commit dad2013a00
21 changed files with 300 additions and 141 deletions

View File

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