From 87732a2ba2ce12cfaebcf0150562f3c6474790f4 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Wed, 16 Jun 2021 15:29:16 -0700 Subject: [PATCH] Allow shutdown to be called by method handler --- lib/main.dart | 3 +++ lib/views/profilemgrview.dart | 1 - lib/views/splashView.dart | 45 +++++++++++++++++++---------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0d4c2c8..7589d12 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -50,6 +50,7 @@ class FlwtchState extends State { //var columns = [1, 1, 2]; late ProfileListState profs; final MethodChannel notificationClickChannel = MethodChannel('im.cwtch.flwtch/notificationClickHandler'); + final MethodChannel shutdownMethodChannel = MethodChannel('im.cwtch.flwtch/shutdown'); final GlobalKey navKey = GlobalKey(); @override @@ -59,6 +60,7 @@ class FlwtchState extends State { profs = ProfileListState(); notificationClickChannel.setMethodCallHandler(_externalNotificationClicked); + shutdownMethodChannel.setMethodCallHandler(shutdown); print("initState set cwtch..."); if (Platform.isAndroid) { var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler, globalTorStatus, NullNotificationsManager(), globalAppState); @@ -114,6 +116,7 @@ class FlwtchState extends State { } Future shutdown(MethodCall call) async { + cwtch.Shutdown(); // Wait a few seconds as shutting down things takes a little time.. Future.delayed(Duration(seconds: 2)).then((value) { if (Platform.isAndroid) { diff --git a/lib/views/profilemgrview.dart b/lib/views/profilemgrview.dart index 950793a..ce2d23f 100644 --- a/lib/views/profilemgrview.dart +++ b/lib/views/profilemgrview.dart @@ -120,7 +120,6 @@ class _ProfileMgrViewState extends State { Widget continueButton = TextButton( child: Text(AppLocalizations.of(context)!.shutdownCwtchAction), onPressed: () { - Provider.of(context, listen: false).cwtch.Shutdown(); // Directly call the shutdown command, Android will do this for us... Provider.of(context, listen: false).shutdown(MethodCall("")); closeApp = true; diff --git a/lib/views/splashView.dart b/lib/views/splashView.dart index 5ae7d17..78ffaf3 100644 --- a/lib/views/splashView.dart +++ b/lib/views/splashView.dart @@ -9,26 +9,29 @@ class SplashView extends StatelessWidget { @override Widget build(BuildContext context) { return Consumer( - builder: (context, appState, child) => Scaffold( - body: Center(child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Image(image: AssetImage("assets/knott.png"), - filterQuality: FilterQuality.medium, - isAntiAlias: true, - width: 200, - height: 200,), - Image(image: AssetImage("assets/cwtch_title.png"), - filterQuality: FilterQuality.medium, - isAntiAlias: true,), - Padding( - padding: const EdgeInsets.all(20.0), - child: Text(appState.appError == "" ? "Loading Cwtch..." : appState.appError, - style: TextStyle(fontSize: 16.0, color: appState.appError == "" ? Provider.of(context).theme.mainTextColor() : Provider.of(context).theme.textfieldErrorColor())), - ), - Image(image: AssetImage("assets/Open_Privacy_Logo_lightoutline.png")), - ])), - )); + builder: (context, appState, child) => Scaffold( + body: Center( + child: Column(mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ + Image( + image: AssetImage("assets/knott.png"), + filterQuality: FilterQuality.medium, + isAntiAlias: true, + width: 200, + height: 200, + ), + Image( + image: AssetImage("assets/cwtch_title.png"), + filterQuality: FilterQuality.medium, + isAntiAlias: true, + ), + Padding( + padding: const EdgeInsets.all(20.0), + child: Text(appState.appError == "" ? "Loading Cwtch..." : appState.appError, + style: TextStyle( + fontSize: 16.0, color: appState.appError == "" ? Provider.of(context).theme.mainTextColor() : Provider.of(context).theme.textfieldErrorColor())), + ), + Image(image: AssetImage("assets/Open_Privacy_Logo_lightoutline.png")), + ])), + )); } }