Small fix updateChecker

This commit is contained in:
PartyDonut 2025-06-02 16:49:55 +02:00
parent 2c71dde228
commit f2c981928f
2 changed files with 24 additions and 12 deletions

View file

@ -35,12 +35,15 @@ class Update extends _$Update {
@override
UpdatesModel build() {
final checkForUpdates = ref.watch(clientSettingsProvider.select((value) => value.checkForUpdates));
ref.listen(
clientSettingsProvider.select((value) => value.checkForUpdates), (previous, next) => toggleUpdateChecker(next));
final checkForUpdates = ref.read(clientSettingsProvider.select((value) => value.checkForUpdates));
if (!checkForUpdates) {
_timer?.cancel();
return UpdatesModel();
}
ref.onDispose(() {
_timer?.cancel();
});
@ -56,6 +59,16 @@ class Update extends _$Update {
return UpdatesModel();
}
void toggleUpdateChecker(bool checkForUpdates) {
_timer?.cancel();
if (checkForUpdates) {
_timer = Timer.periodic(const Duration(minutes: 30), (timer) {
_fetchLatest();
});
_fetchLatest();
}
}
Future<List<ReleaseInfo>> _fetchLatest() async {
final latest = await updateChecker.fetchRecentReleases();
state = state.copyWith(