diff --git a/lib/providers/update_provider.dart b/lib/providers/update_provider.dart index 33cb71e..1972a7b 100644 --- a/lib/providers/update_provider.dart +++ b/lib/providers/update_provider.dart @@ -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> _fetchLatest() async { final latest = await updateChecker.fetchRecentReleases(); state = state.copyWith( diff --git a/lib/screens/settings/widgets/settings_update_information.dart b/lib/screens/settings/widgets/settings_update_information.dart index e96be5a..1d35657 100644 --- a/lib/screens/settings/widgets/settings_update_information.dart +++ b/lib/screens/settings/widgets/settings_update_information.dart @@ -44,8 +44,9 @@ class _SettingsUpdateInformationState extends ConsumerState value.copyWith(checkForUpdates: !checkForUpdate)), ), ), - if (checkForUpdate) ...[ - if (latestRelease != null) - UpdateInformation( - releaseInfo: latestRelease, - expanded: true, + if (latestRelease != null) + UpdateInformation( + releaseInfo: latestRelease, + expanded: true, + ), + ...otherReleases.where((element) => element != latestRelease).map( + (value) => UpdateInformation(releaseInfo: value), ), - ...otherReleases.where((element) => element != latestRelease).map( - (value) => UpdateInformation(releaseInfo: value), - ), - ] ], ), );