Allow shutdown to be called by method handler
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2021-06-16 15:29:16 -07:00
parent 213a29c691
commit 87732a2ba2
3 changed files with 27 additions and 22 deletions

View File

@ -50,6 +50,7 @@ class FlwtchState extends State<Flwtch> {
//var columns = [1, 1, 2]; //var columns = [1, 1, 2];
late ProfileListState profs; late ProfileListState profs;
final MethodChannel notificationClickChannel = MethodChannel('im.cwtch.flwtch/notificationClickHandler'); final MethodChannel notificationClickChannel = MethodChannel('im.cwtch.flwtch/notificationClickHandler');
final MethodChannel shutdownMethodChannel = MethodChannel('im.cwtch.flwtch/shutdown');
final GlobalKey<NavigatorState> navKey = GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> navKey = GlobalKey<NavigatorState>();
@override @override
@ -59,6 +60,7 @@ class FlwtchState extends State<Flwtch> {
profs = ProfileListState(); profs = ProfileListState();
notificationClickChannel.setMethodCallHandler(_externalNotificationClicked); notificationClickChannel.setMethodCallHandler(_externalNotificationClicked);
shutdownMethodChannel.setMethodCallHandler(shutdown);
print("initState set cwtch..."); print("initState set cwtch...");
if (Platform.isAndroid) { if (Platform.isAndroid) {
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState); var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState);
@ -114,6 +116,7 @@ class FlwtchState extends State<Flwtch> {
} }
Future<void> shutdown(MethodCall call) async { Future<void> shutdown(MethodCall call) async {
cwtch.Shutdown();
// Wait a few seconds as shutting down things takes a little time.. // Wait a few seconds as shutting down things takes a little time..
Future.delayed(Duration(seconds: 2)).then((value) { Future.delayed(Duration(seconds: 2)).then((value) {
if (Platform.isAndroid) { if (Platform.isAndroid) {

View File

@ -120,7 +120,6 @@ class _ProfileMgrViewState extends State<ProfileMgrView> {
Widget continueButton = TextButton( Widget continueButton = TextButton(
child: Text(AppLocalizations.of(context)!.shutdownCwtchAction), child: Text(AppLocalizations.of(context)!.shutdownCwtchAction),
onPressed: () { onPressed: () {
Provider.of<FlwtchState>(context, listen: false).cwtch.Shutdown();
// Directly call the shutdown command, Android will do this for us... // Directly call the shutdown command, Android will do this for us...
Provider.of<FlwtchState>(context, listen: false).shutdown(MethodCall("")); Provider.of<FlwtchState>(context, listen: false).shutdown(MethodCall(""));
closeApp = true; closeApp = true;

View File

@ -9,26 +9,29 @@ class SplashView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Consumer<AppState>( return Consumer<AppState>(
builder: (context, appState, child) => Scaffold( builder: (context, appState, child) => Scaffold(
body: Center(child: Column( body: Center(
mainAxisAlignment: MainAxisAlignment.center, child: Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [
crossAxisAlignment: CrossAxisAlignment.center, Image(
children: [ image: AssetImage("assets/knott.png"),
Image(image: AssetImage("assets/knott.png"), filterQuality: FilterQuality.medium,
filterQuality: FilterQuality.medium, isAntiAlias: true,
isAntiAlias: true, width: 200,
width: 200, height: 200,
height: 200,), ),
Image(image: AssetImage("assets/cwtch_title.png"), Image(
filterQuality: FilterQuality.medium, image: AssetImage("assets/cwtch_title.png"),
isAntiAlias: true,), filterQuality: FilterQuality.medium,
Padding( isAntiAlias: true,
padding: const EdgeInsets.all(20.0), ),
child: Text(appState.appError == "" ? "Loading Cwtch..." : appState.appError, Padding(
style: TextStyle(fontSize: 16.0, color: appState.appError == "" ? Provider.of<Settings>(context).theme.mainTextColor() : Provider.of<Settings>(context).theme.textfieldErrorColor())), padding: const EdgeInsets.all(20.0),
), child: Text(appState.appError == "" ? "Loading Cwtch..." : appState.appError,
Image(image: AssetImage("assets/Open_Privacy_Logo_lightoutline.png")), style: TextStyle(
])), fontSize: 16.0, color: appState.appError == "" ? Provider.of<Settings>(context).theme.mainTextColor() : Provider.of<Settings>(context).theme.textfieldErrorColor())),
)); ),
Image(image: AssetImage("assets/Open_Privacy_Logo_lightoutline.png")),
])),
));
} }
} }