feat: Prevent exiting installer on new back button as well and show why exiting is not possible during patching

This commit is contained in:
Alberto Ponces 2022-09-19 17:40:06 +01:00
parent 2a2bb8212f
commit bed2cf76d5
4 changed files with 27 additions and 10 deletions

View File

@ -95,7 +95,8 @@
"installErrorDialogTitle": "Error", "installErrorDialogTitle": "Error",
"installErrorDialogText1": "Root install is not possible with the current patches selection.\nRepatch your app or choose non-root install.", "installErrorDialogText1": "Root install is not possible with the current patches selection.\nRepatch your app or choose non-root install.",
"installErrorDialogText2": "Non-root install is not possible with the current patches selection.\nRepatch your app or choose root install if you have your device rooted.", "installErrorDialogText2": "Non-root install is not possible with the current patches selection.\nRepatch your app or choose root install if you have your device rooted.",
"installErrorDialogText3": "Root install is not possible as the original APK was selected from storage.\nSelect an installed app or choose non-root install." "installErrorDialogText3": "Root install is not possible as the original APK was selected from storage.\nSelect an installed app or choose non-root install.",
"noExit": "Installer is still running..."
}, },
"settingsView": { "settingsView": {
"widgetTitle": "Settings", "widgetTitle": "Settings",

View File

@ -29,6 +29,7 @@ class InstallerView extends StatelessWidget {
color: Theme.of(context).textTheme.headline6!.color, color: Theme.of(context).textTheme.headline6!.color,
), ),
), ),
onBackButtonPressed: () => model.onWillPop(context),
actions: <Widget>[ actions: <Widget>[
Visibility( Visibility(
visible: !model.isPatching && !model.hasErrors, visible: !model.isPatching && !model.hasErrors,
@ -143,13 +144,7 @@ class InstallerView extends StatelessWidget {
], ],
), ),
), ),
onWillPop: () async { onWillPop: () => model.onWillPop(context),
if (!model.isPatching) {
model.cleanPatcher();
Navigator.of(context).pop();
}
return false;
},
), ),
); );
} }

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_background/flutter_background.dart'; import 'package:flutter_background/flutter_background.dart';
import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/models/patch.dart'; import 'package:revanced_manager/models/patch.dart';
@ -215,4 +216,21 @@ class InstallerViewModel extends BaseViewModel {
break; break;
} }
} }
Future<bool> onWillPop(BuildContext context) async {
if (isPatching) {
Fluttertoast.showToast(
msg: FlutterI18n.translate(
context,
'installerView.noExit',
),
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
);
return false;
}
cleanPatcher();
Navigator.of(context).pop();
return true;
}
} }

View File

@ -5,6 +5,7 @@ class CustomSliverAppBar extends StatelessWidget {
final List<Widget>? actions; final List<Widget>? actions;
final PreferredSizeWidget? bottom; final PreferredSizeWidget? bottom;
final bool isMainView; final bool isMainView;
final Function()? onBackButtonPressed;
const CustomSliverAppBar({ const CustomSliverAppBar({
Key? key, Key? key,
@ -12,6 +13,7 @@ class CustomSliverAppBar extends StatelessWidget {
this.actions, this.actions,
this.bottom, this.bottom,
this.isMainView = false, this.isMainView = false,
this.onBackButtonPressed,
}) : super(key: key); }) : super(key: key);
@override @override
@ -24,7 +26,7 @@ class CustomSliverAppBar extends StatelessWidget {
automaticallyImplyLeading: !isMainView, automaticallyImplyLeading: !isMainView,
flexibleSpace: FlexibleSpaceBar( flexibleSpace: FlexibleSpaceBar(
titlePadding: EdgeInsets.only( titlePadding: EdgeInsets.only(
bottom: 14.0, bottom: bottom != null ? 16.0 : 14.0,
left: isMainView ? 20.0 : 55.0, left: isMainView ? 20.0 : 55.0,
), ),
title: title, title: title,
@ -36,7 +38,8 @@ class CustomSliverAppBar extends StatelessWidget {
Icons.arrow_back, Icons.arrow_back,
color: Theme.of(context).textTheme.headline6!.color, color: Theme.of(context).textTheme.headline6!.color,
), ),
onPressed: () => Navigator.of(context).pop(), onPressed:
onBackButtonPressed ?? () => Navigator.of(context).pop(),
), ),
backgroundColor: MaterialStateColor.resolveWith( backgroundColor: MaterialStateColor.resolveWith(
(states) => states.contains(MaterialState.scrolledUnder) (states) => states.contains(MaterialState.scrolledUnder)