Skip to content

Commit

Permalink
Resolve permissions Android
Browse files Browse the repository at this point in the history
  • Loading branch information
KristijanMitrik committed Jan 9, 2025
1 parent 8752517 commit 41a1347
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class WireguardDartPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
private var config: com.wireguard.config.Config? = null
private var tunnel: WireguardTunnel? = null
private var tunnelName: String? = null
private var permissionsResultCallback: Result? = null
private var status: ConnectionStatus = ConnectionStatus.disconnected
set(value) {
field = value
Expand All @@ -60,6 +61,16 @@ class WireguardDartPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?): Boolean {
if (requestCode == PERMISSIONS_REQUEST_CODE) {
havePermission = resultCode == Activity.RESULT_OK
if (havePermission) {
permissionsResultCallback?.success(null)
} else {
permissionsResultCallback?.error(
"err_setup_tunnel",
"Permissions are not given",
null
)

}
}
return havePermission
}
Expand Down Expand Up @@ -170,11 +181,9 @@ class WireguardDartPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
flutterError(result, "Tunnel name is invalid")
return@launch
}
permissionsResultCallback = result
checkPermission()
if (havePermission) {
initTunnel(tunnelName)
}
result.success(null)
initTunnel(tunnelName)
}
}

Expand Down

0 comments on commit 41a1347

Please sign in to comment.