From 95a0bcf5d861b98f632f3b766b4d09bf4947be37 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Wed, 17 Aug 2022 13:48:56 +0100 Subject: [PATCH] fix: use a try-finally while handling background task creation, prevent opening patches while disabled and fix loading label --- .../views/installer/installer_viewmodel.dart | 36 +++++++++++-------- lib/ui/views/patcher/patcher_view.dart | 4 ++- lib/ui/widgets/latest_commit_card.dart | 12 ++----- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index fb8bb7f2..f25f19db 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -17,20 +17,23 @@ class InstallerViewModel extends BaseViewModel { bool isInstalled = false; Future initialize() async { - await FlutterBackground.initialize( - androidConfig: const FlutterBackgroundAndroidConfig( - notificationTitle: 'Patching', - notificationText: 'ReVanced Manager is patching', - notificationImportance: AndroidNotificationImportance.Default, - notificationIcon: AndroidResource( - name: 'ic_notification', - defType: 'drawable', + try { + await FlutterBackground.initialize( + androidConfig: const FlutterBackgroundAndroidConfig( + notificationTitle: 'Patching', + notificationText: 'ReVanced Manager is patching', + notificationImportance: AndroidNotificationImportance.Default, + notificationIcon: AndroidResource( + name: 'ic_notification', + defType: 'drawable', + ), ), - ), - ); - await FlutterBackground.enableBackgroundExecution(); - await locator().handlePlatformChannelMethods(); - await runPatcher(); + ); + await FlutterBackground.enableBackgroundExecution(); + } finally { + await locator().handlePlatformChannelMethods(); + await runPatcher(); + } } void updateProgress(double value) { @@ -95,8 +98,11 @@ class InstallerViewModel extends BaseViewModel { } else { updateLog('No app or patches selected! Aborting'); } - await FlutterBackground.disableBackgroundExecution(); - isPatching = false; + try { + await FlutterBackground.disableBackgroundExecution(); + } finally { + isPatching = false; + } } void installResult() async { diff --git a/lib/ui/views/patcher/patcher_view.dart b/lib/ui/views/patcher/patcher_view.dart index 0033d256..3aa06215 100644 --- a/lib/ui/views/patcher/patcher_view.dart +++ b/lib/ui/views/patcher/patcher_view.dart @@ -55,7 +55,9 @@ class PatcherView extends StatelessWidget { ? (model.dimPatchesCard() ? 0.5 : 1) : (model.dimPatchesCard() ? 0.75 : 1), child: PatchSelectorCard( - onPressed: model.navigateToPatchesSelector, + onPressed: model.dimPatchesCard() + ? () => {} + : model.navigateToPatchesSelector, color: Theme.of(context).colorScheme.primary, ), ), diff --git a/lib/ui/widgets/latest_commit_card.dart b/lib/ui/widgets/latest_commit_card.dart index 8fbd1dff..b6395ae9 100644 --- a/lib/ui/widgets/latest_commit_card.dart +++ b/lib/ui/widgets/latest_commit_card.dart @@ -49,12 +49,8 @@ class _LatestCommitCardState extends State { 'revanced', 'revanced-patcher', ), - initialData: FlutterI18n.translate( - context, - 'latestCommitCard.loadingLabel', - ), builder: (context, snapshot) => Text( - snapshot.data!.isNotEmpty + snapshot.hasData && snapshot.data!.isNotEmpty ? FlutterI18n.translate( context, 'latestCommitCard.timeagoLabel', @@ -86,12 +82,8 @@ class _LatestCommitCardState extends State { 'revanced', 'revanced-manager', ), - initialData: FlutterI18n.translate( - context, - 'latestCommitCard.loadingLabel', - ), builder: (context, snapshot) => Text( - snapshot.data!.isNotEmpty + snapshot.hasData && snapshot.data!.isNotEmpty ? FlutterI18n.translate( context, 'latestCommitCard.timeagoLabel',