From e38fbf4a348201241522a90d09221e609ad58d2d Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 16 Feb 2018 22:21:30 +0100 Subject: Broadcast failed daemon startup and dismiss startup dialog --- app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt | 7 +++++++ app/src/main/java/org/pacien/tincapp/intent/Actions.kt | 1 + app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt | 1 + 3 files changed, 9 insertions(+) (limited to 'app') diff --git a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt index 9fa5e44..2dd1c46 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt @@ -117,6 +117,7 @@ class StartActivity : BaseActivity() { } private val startupBroadcastReceiver = SimpleBroadcastReceiver(IntentFilter(Actions.EVENT_CONNECTED), this::onVpnStart) + private val errorBroadcastReceiver = SimpleBroadcastReceiver(IntentFilter(Actions.EVENT_ABORTED), this::onVpnStartError) private var connectDialog: ProgressDialog? = null @@ -148,10 +149,12 @@ class StartActivity : BaseActivity() { super.onResume() if (TincVpnService.isConnected()) openStatusActivity() startupBroadcastReceiver.register() + errorBroadcastReceiver.register() } override fun onPause() { startupBroadcastReceiver.unregister() + errorBroadcastReceiver.unregister() super.onPause() } @@ -169,6 +172,10 @@ class StartActivity : BaseActivity() { finish() } + private fun onVpnStartError() { + connectDialog?.dismiss() + } + private fun openStatusActivity() = startActivity(Intent(this, StatusActivity::class.java)) } diff --git a/app/src/main/java/org/pacien/tincapp/intent/Actions.kt b/app/src/main/java/org/pacien/tincapp/intent/Actions.kt index 4650952..c6e0fec 100644 --- a/app/src/main/java/org/pacien/tincapp/intent/Actions.kt +++ b/app/src/main/java/org/pacien/tincapp/intent/Actions.kt @@ -12,6 +12,7 @@ object Actions { const val ACTION_DISCONNECT = "$PREFIX.DISCONNECT" const val EVENT_CONNECTED = "$PREFIX.CONNECTED" const val EVENT_DISCONNECTED = "$PREFIX.DISCONNECTED" + const val EVENT_ABORTED = "$PREFIX.ABORTED" const val TINC_SCHEME = "tinc" fun buildNetworkUri(netName: String, passphrase: String? = null): Uri = diff --git a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt index ce41b89..0937006 100644 --- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt +++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt @@ -118,6 +118,7 @@ class TincVpnService : VpnService() { else Log.e(TAG, msg) + broadcastEvent(Actions.EVENT_ABORTED) App.alert(R.string.title_unable_to_start_tinc, msg, if (docTopic != null) resources.getString(R.string.app_doc_url_format, docTopic) else null) } -- cgit v1.2.3