From b16797bb8d875448e6e6fa80a904b17c2962fe48 Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Wed, 18 Sep 2024 20:50:51 +0100 Subject: [PATCH 1/2] feat: add iOS Open VPN Settings --- .../kotlin/org/ooni/probe/SetupDependencies.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt b/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt index f0d33179b..c84dfe71d 100644 --- a/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt +++ b/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt @@ -70,7 +70,18 @@ class SetupDependencies( launchUrl = ::launchUrl, startSingleRunInner = ::startSingleRun, configureAutoRun = ::configureAutoRun, - openVpnSettings = { false }, + openVpnSettings = { + val url = "App-prefs:General&path=ManagedConfigurationList" + NSURL.URLWithString(url)?.let { + if (UIApplication.sharedApplication.canOpenURL(it)) { + UIApplication.sharedApplication.openURL(it) + return@let true + } else { + Logger.e { "Cannot open URL: $url" } + return@let false + } + }?:false + }, ) fun startSingleRun(spec: RunSpecification) { From 637225809311a498863a3496e4e2ea1c2da5dd2c Mon Sep 17 00:00:00 2001 From: Norbel AMBANUMBEN Date: Wed, 18 Sep 2024 20:56:32 +0100 Subject: [PATCH 2/2] extract function --- .../org/ooni/probe/SetupDependencies.kt | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt b/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt index c84dfe71d..b412ea3dd 100644 --- a/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt +++ b/composeApp/src/iosMain/kotlin/org/ooni/probe/SetupDependencies.kt @@ -70,18 +70,7 @@ class SetupDependencies( launchUrl = ::launchUrl, startSingleRunInner = ::startSingleRun, configureAutoRun = ::configureAutoRun, - openVpnSettings = { - val url = "App-prefs:General&path=ManagedConfigurationList" - NSURL.URLWithString(url)?.let { - if (UIApplication.sharedApplication.canOpenURL(it)) { - UIApplication.sharedApplication.openURL(it) - return@let true - } else { - Logger.e { "Cannot open URL: $url" } - return@let false - } - }?:false - }, + openVpnSettings = ::openVpnSettings, ) fun startSingleRun(spec: RunSpecification) { @@ -246,4 +235,17 @@ class SetupDependencies( operation.completionBlock = { task.setTaskCompletedWithSuccess(!operation.isCancelled()) } operationQueue.addOperation(operation) } + + private fun openVpnSettings(): Boolean { + val url = "App-prefs:General&path=ManagedConfigurationList" + return NSURL.URLWithString(url)?.let { + if (UIApplication.sharedApplication.canOpenURL(it)) { + UIApplication.sharedApplication.openURL(it) + return@let true + } else { + Logger.e { "Cannot open URL: $url" } + return@let false + } + } ?: false + } }