3
0
Fork 0

Show a message on android if permissions were denied (#65)

This commit is contained in:
Nate Brown 2022-08-05 16:42:31 -05:00 committed by GitHub
parent 958b15d711
commit e3780bda1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 2 deletions

View File

@ -356,7 +356,8 @@ class MainActivity: FlutterActivity() {
return result.success(null) return result.success(null)
} }
return result.error("denied", "User did not grant permission", null) //NOTE: flutter side doesn't care about the message currently, only the code
return result.error("PERMISSIONS", "User did not grant permission", null)
} else if (requestCode == VPN_START_CODE) { } else if (requestCode == VPN_START_CODE) {
// We are processing a response for permissions while starting the VPN (or reusing code in the event we already have perms) // We are processing a response for permissions while starting the VPN (or reusing code in the event we already have perms)

View File

@ -32,6 +32,8 @@ class MainScreen extends StatefulWidget {
class _MainScreenState extends State<MainScreen> { class _MainScreenState extends State<MainScreen> {
bool ready = false; bool ready = false;
List<Site> sites; List<Site> sites;
// A set of widgets to display in a column that represents an error blocking us from moving forward entirely
List<Widget> error;
static const platform = MethodChannel('net.defined.mobileNebula/NebulaVpnService'); static const platform = MethodChannel('net.defined.mobileNebula/NebulaVpnService');
@ -69,6 +71,14 @@ class _MainScreenState extends State<MainScreen> {
} }
Widget _buildBody() { Widget _buildBody() {
if (error != null) {
return Center(child: Padding(child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: error,
), padding: EdgeInsets.symmetric(vertical: 0, horizontal: 10)));
}
if (!ready) { if (!ready) {
return Center( return Center(
child: PlatformCircularProgressIndicator(cupertino: (_, __) { child: PlatformCircularProgressIndicator(cupertino: (_, __) {
@ -197,7 +207,44 @@ rmXnR1yvDZi1VPVmnNVY8NMsQpEpbbYlq7rul+ByQvg=
_loadSites() async { _loadSites() async {
if (Platform.isAndroid) { if (Platform.isAndroid) {
await platform.invokeMethod("android.requestPermissions"); try {
await platform.invokeMethod("android.requestPermissions");
} on PlatformException catch (err) {
if (err.code == "PERMISSIONS") {
setState(() {
error = [
Text("Permissions Required",
style: TextStyle(fontWeight: FontWeight.bold)),
Text(
"VPN permissions are required for nebula to run, click the button below request and accept the appropriate permissions.",
textAlign: TextAlign.center
),
ElevatedButton(
onPressed: () {
error = null;
_loadSites();
},
child: Text("Request Permissions")
),
];
});
} else {
setState(() {
error = [
Text("Unknown Error", style: TextStyle(fontWeight: FontWeight.bold)),
Text(err.message, textAlign: TextAlign.center)
];
});
}
} catch (err) {
setState(() {
error = [
Text("Unknown Error", style: TextStyle(fontWeight: FontWeight.bold)),
Text(err.message, textAlign: TextAlign.center)
];
});
}
} }
//TODO: This can throw, we need to show an error dialog //TODO: This can throw, we need to show an error dialog