mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-09 07:28:14 -07:00
Small fix updateChecker
This commit is contained in:
parent
2c71dde228
commit
f2c981928f
2 changed files with 24 additions and 12 deletions
|
|
@ -35,12 +35,15 @@ class Update extends _$Update {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
UpdatesModel build() {
|
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) {
|
if (!checkForUpdates) {
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
return UpdatesModel();
|
return UpdatesModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
ref.onDispose(() {
|
ref.onDispose(() {
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
});
|
});
|
||||||
|
|
@ -56,6 +59,16 @@ class Update extends _$Update {
|
||||||
return UpdatesModel();
|
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 {
|
Future<List<ReleaseInfo>> _fetchLatest() async {
|
||||||
final latest = await updateChecker.fetchRecentReleases();
|
final latest = await updateChecker.fetchRecentReleases();
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,9 @@ class _SettingsUpdateInformationState extends ConsumerState<SettingsUpdateInform
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
child: Column(
|
child: ListView(
|
||||||
spacing: 8,
|
// spacing: 8,
|
||||||
|
shrinkWrap: true,
|
||||||
children: [
|
children: [
|
||||||
const Divider(),
|
const Divider(),
|
||||||
SettingsListTile(
|
SettingsListTile(
|
||||||
|
|
@ -61,16 +62,14 @@ class _SettingsUpdateInformationState extends ConsumerState<SettingsUpdateInform
|
||||||
.update((value) => value.copyWith(checkForUpdates: !checkForUpdate)),
|
.update((value) => value.copyWith(checkForUpdates: !checkForUpdate)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (checkForUpdate) ...[
|
if (latestRelease != null)
|
||||||
if (latestRelease != null)
|
UpdateInformation(
|
||||||
UpdateInformation(
|
releaseInfo: latestRelease,
|
||||||
releaseInfo: latestRelease,
|
expanded: true,
|
||||||
expanded: true,
|
),
|
||||||
|
...otherReleases.where((element) => element != latestRelease).map(
|
||||||
|
(value) => UpdateInformation(releaseInfo: value),
|
||||||
),
|
),
|
||||||
...otherReleases.where((element) => element != latestRelease).map(
|
|
||||||
(value) => UpdateInformation(releaseInfo: value),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue