new: update active profile and its ping,

This commit is contained in:
Hiddify
2024-02-13 03:55:28 +01:00
parent 467a757de2
commit 07e345c7d2
3 changed files with 24 additions and 5 deletions

View File

@@ -26,7 +26,25 @@ Stream<ProxyItemEntity?> activeProxyGroup(ActiveProxyGroupRef ref) async* {
.watch(proxyRepositoryProvider)
.watchActiveProxies()
.map((event) => event.getOrElse((l) => throw l))
.map((event) => event.firstOrNull?.items.firstOrNull);
.map((event) {
final Map<String, ProxyGroupEntity> itemMap =
event.fold({}, (Map<String, ProxyGroupEntity> map, item) {
map[item.tag] = item;
return map;
});
// Start from the item with the tag "Select"
var current = itemMap["select"];
ProxyItemEntity? selected;
// Traverse through the map based on the selected tag until reaching the end
while (current != null) {
selected = current.items.firstOrNull;
current = itemMap[selected?.tag];
}
return selected;
});
}
@riverpod