Fix sing-box:// URL scheme import in ComposeActivity
The deep link handling was missing after migrating to Compose UI.
This commit is contained in:
@@ -117,6 +117,8 @@ class ComposeActivity : ComponentActivity(), ServiceConnection.Callback {
|
||||
private var currentAlert by mutableStateOf<Pair<Alert, String?>?>(null)
|
||||
private var showLocationPermissionDialog by mutableStateOf(false)
|
||||
private var showBackgroundLocationDialog by mutableStateOf(false)
|
||||
private var showImportProfileDialog by mutableStateOf(false)
|
||||
private var pendingImportProfile by mutableStateOf<Triple<String, String, String>?>(null)
|
||||
|
||||
private val notificationPermissionLauncher =
|
||||
registerForActivityResult(
|
||||
@@ -175,6 +177,8 @@ class ComposeActivity : ComponentActivity(), ServiceConnection.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
handleIntent(intent)
|
||||
|
||||
setContent {
|
||||
SFATheme {
|
||||
SFAApp()
|
||||
@@ -182,6 +186,26 @@ class ComposeActivity : ComponentActivity(), ServiceConnection.Callback {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
handleIntent(intent)
|
||||
}
|
||||
|
||||
private fun handleIntent(intent: Intent?) {
|
||||
val uri = intent?.data ?: return
|
||||
if (uri.scheme == "sing-box" && uri.host == "import-remote-profile") {
|
||||
try {
|
||||
val profile = Libbox.parseRemoteProfileImportLink(uri.toString())
|
||||
pendingImportProfile = Triple(profile.name, profile.host, profile.url)
|
||||
showImportProfileDialog = true
|
||||
} catch (e: Exception) {
|
||||
lifecycleScope.launch {
|
||||
GlobalEventBus.emit(UiEvent.ErrorMessage(e.message ?: "Failed to parse profile link"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
fun startService() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && !ServiceNotification.checkPermission()) {
|
||||
@@ -285,6 +309,41 @@ class ComposeActivity : ComponentActivity(), ServiceConnection.Callback {
|
||||
}, onDismiss = { showBackgroundLocationDialog = false })
|
||||
}
|
||||
|
||||
// Handle import remote profile dialog
|
||||
if (showImportProfileDialog && pendingImportProfile != null) {
|
||||
val (name, host, url) = pendingImportProfile!!
|
||||
AlertDialog(
|
||||
onDismissRequest = {
|
||||
showImportProfileDialog = false
|
||||
pendingImportProfile = null
|
||||
},
|
||||
title = { Text(stringResource(R.string.import_remote_profile)) },
|
||||
text = { Text(stringResource(R.string.import_remote_profile_message, name, host)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
startActivity(
|
||||
Intent(this@ComposeActivity, NewProfileComposeActivity::class.java).apply {
|
||||
putExtra(NewProfileComposeActivity.EXTRA_IMPORT_NAME, name)
|
||||
putExtra(NewProfileComposeActivity.EXTRA_IMPORT_URL, url)
|
||||
},
|
||||
)
|
||||
showImportProfileDialog = false
|
||||
pendingImportProfile = null
|
||||
}) {
|
||||
Text(stringResource(R.string.ok))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = {
|
||||
showImportProfileDialog = false
|
||||
pendingImportProfile = null
|
||||
}) {
|
||||
Text(stringResource(android.R.string.cancel))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// Handle update check prompt dialog (shown only once on first launch)
|
||||
var showUpdateCheckPrompt by remember { mutableStateOf(!Settings.updateCheckPrompted) }
|
||||
if (showUpdateCheckPrompt) {
|
||||
|
||||
Reference in New Issue
Block a user