Refactor app update

This commit is contained in:
problematicconsumer
2023-09-20 22:38:38 +03:30
parent 59365653b8
commit 8958c72fe6
11 changed files with 210 additions and 23 deletions

View File

@@ -22,16 +22,19 @@ class AboutPage extends HookConsumerWidget {
ref.listen(
appUpdateNotifierProvider,
(_, next) async {
if (!context.mounted) return;
switch (next) {
case AsyncData(value: final remoteVersion?):
await NewVersionDialog(
case AppUpdateStateAvailable(:final versionInfo):
return NewVersionDialog(
appInfo.presentVersion,
remoteVersion,
versionInfo,
canIgnore: false,
).show(context);
case AsyncError(:final error):
if (!context.mounted) return;
CustomToast.error(t.printError(error)).show(context);
case AppUpdateStateError(:final error):
return CustomToast.error(t.printError(error)).show(context);
case AppUpdateStateNotAvailable():
return CustomToast.success(t.appUpdate.notAvailableMsg)
.show(context);
}
},
);
@@ -91,15 +94,18 @@ class AboutPage extends HookConsumerWidget {
if (appInfo.release.allowCustomUpdateChecker)
ListTile(
title: Text(t.about.checkForUpdate),
trailing: appUpdate.isLoading
? const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(),
)
: const Icon(Icons.update),
onTap: () {
ref.invalidate(appUpdateNotifierProvider);
trailing: switch (appUpdate) {
AppUpdateStateChecking() => const SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(),
),
_ => const Icon(Icons.update),
},
onTap: () async {
await ref
.read(appUpdateNotifierProvider.notifier)
.check();
},
),
ListTile(