This commit is contained in:
problematicconsumer
2023-10-07 20:22:21 +03:30
parent e752461ad2
commit f1ebafd766
7 changed files with 41 additions and 29 deletions

View File

@@ -59,7 +59,6 @@ class MainActivity : FlutterFragmentActivity(), ServiceConnection.Callback {
fun startService() {
if (!ServiceNotification.checkPermission()) {
// Log.d(TAG, "missing notification permission")
grantNotificationPermission()
return
}
@@ -81,15 +80,26 @@ class MainActivity : FlutterFragmentActivity(), ServiceConnection.Callback {
}
}
private suspend fun prepare() = withContext(Dispatchers.Main) {
try {
val intent = VpnService.prepare(this@MainActivity)
if (intent != null) {
startActivityForResult(intent, VPN_PERMISSION_REQUEST_CODE)
true
} else {
false
}
} catch (e: Exception) {
onServiceAlert(Alert.RequestVPNPermission, e.message)
false
}
}
override fun onServiceStatusChanged(status: Status) {
Log.d(TAG, "service status changed: $status")
serviceStatus.postValue(status)
}
override fun onServiceAlert(type: Alert, message: String?) {
Log.d(TAG, "service alert: $type")
serviceAlerts.postValue(ServiceEvent(Status.Stopped, type, message))
}
@@ -154,22 +164,6 @@ class MainActivity : FlutterFragmentActivity(), ServiceConnection.Callback {
}
}
private suspend fun prepare() = withContext(Dispatchers.Main) {
try {
val intent = VpnService.prepare(this@MainActivity)
if (intent != null) {
// prepareLauncher.launch(intent)
startActivityForResult(intent, VPN_PERMISSION_REQUEST_CODE)
true
} else {
false
}
} catch (e: Exception) {
onServiceAlert(Alert.RequestVPNPermission, e.message)
false
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == VPN_PERMISSION_REQUEST_CODE) {

View File

@@ -172,5 +172,9 @@ object DefaultNetworkListener {
}
}
private fun unregister() = Application.connectivity.unregisterNetworkCallback(Callback)
private fun unregister() {
runCatching {
Application.connectivity.unregisterNetworkCallback(Callback)
}
}
}

View File

@@ -7,7 +7,7 @@ class ProxyService : Service(), PlatformInterfaceWrapper {
private val service = BoxService(this, this)
override fun onStartCommand(intent: Intent, flags: Int, startId: Int) =
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int) =
service.onStartCommand(intent, flags, startId)
override fun onBind(intent: Intent) = service.onBind(intent)