From 5d022d0a5fc0d70ce04e76028937ef4b83ebb1aa Mon Sep 17 00:00:00 2001 From: MM20 <15646950+MM2-0@users.noreply.github.com> Date: Sat, 27 Sep 2025 13:12:59 +0200 Subject: [PATCH] Add package name and class name to custom intent search action --- .../searchactions/EditSearchActionSheet.kt | 24 +++++++++++ .../searchactions/EditSearchActionSheetVM.kt | 43 +++++++++++++++++++ docs/docs/user-guide/search/quickactions.md | 12 ++++-- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/EditSearchActionSheet.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/EditSearchActionSheet.kt index 65def7c89..6e8346489 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/EditSearchActionSheet.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/EditSearchActionSheet.kt @@ -789,6 +789,30 @@ fun CustomizeCustomIntent(viewModel: EditSearchActionSheetVM) { singleLine = true, ) + val packageName = action.baseIntent.component?.packageName ?: action.baseIntent.`package` + + OutlinedTextField( + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + value = packageName ?: "", + onValueChange = { viewModel.setIntentPackage(it) }, + label = { Text("Package") }, + singleLine = true, + ) + + AnimatedVisibility(packageName != null) { + OutlinedTextField( + modifier = Modifier + .fillMaxWidth() + .padding(top = 8.dp), + value = action.baseIntent.component?.className ?: "", + onValueChange = { viewModel.setIntentClassName(it) }, + label = { Text("Class name") }, + singleLine = true, + ) + } + var showAdvanced by remember { mutableStateOf(false) diff --git a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/EditSearchActionSheetVM.kt b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/EditSearchActionSheetVM.kt index c2f088d31..50ebd478c 100644 --- a/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/EditSearchActionSheetVM.kt +++ b/app/ui/src/main/java/de/mm20/launcher2/ui/settings/searchactions/EditSearchActionSheetVM.kt @@ -521,6 +521,49 @@ class EditSearchActionSheetVM : ViewModel(), KoinComponent { } } + fun setIntentPackage(pkg: String) { + val searchAction = searchAction.value ?: return + this.searchAction.value = when (searchAction) { + is CustomIntentActionBuilder -> searchAction.copy( + baseIntent = searchAction.baseIntent.cloneFilter().also { + val extras = searchAction.baseIntent.extras?.deepCopy() ?: Bundle() + it.replaceExtras(extras) + if (pkg.isBlank()) { + it.`package` = null + it.component = null + } else if (it.component != null) { + it.component = ComponentName(pkg, it.component!!.className) + } else { + it.`package` = pkg + } + }, + ) + else -> searchAction + } + } + fun setIntentClassName(className: String) { + val searchAction = searchAction.value ?: return + this.searchAction.value = when (searchAction) { + is CustomIntentActionBuilder -> searchAction.copy( + baseIntent = searchAction.baseIntent.cloneFilter().also { + val extras = searchAction.baseIntent.extras?.deepCopy() ?: Bundle() + it.replaceExtras(extras) + + val pkg = it.component?.packageName ?: it.`package` + + if (className.isBlank()) { + it.`package` = pkg + it.component = null + } else if (pkg != null) { + it.`package` = null + it.component = ComponentName(pkg, className) + } + }, + ) + else -> searchAction + } + } + fun setQueryKey(key: String?) { val action = searchAction.value ?: return searchAction.value = when (action) { diff --git a/docs/docs/user-guide/search/quickactions.md b/docs/docs/user-guide/search/quickactions.md index 6f5236477..f522656e8 100644 --- a/docs/docs/user-guide/search/quickactions.md +++ b/docs/docs/user-guide/search/quickactions.md @@ -130,10 +130,8 @@ as data (URI) or as an extra: that is used to store the search term in the intent's extras. For example, you could use the key - `android.intent.extra.TEXT` to create an intent that shares the search term as text. You can - also - provide a template to format the extra value. Again, use the placeholder `${1}` to include the - search term in the template. + `android.intent.extra.TEXT`. You can also provide a template to format the extra value. Again, use + the placeholder `${1}` to include the search term in the template. #### Base intent @@ -151,6 +149,12 @@ The base intent defines the action. - **Data**: The [data URI](https://developer.android.com/reference/android/content/Intent#setData(android.net.Uri)) of the intent. Only used if the search term is not passed as data. +- **Package**: + The [package](https://developer.android.com/reference/android/content/Intent#setPackage(java.lang.String)) + of the intent. +- **Class name**: + The [component class name](https://developer.android.com/reference/android/content/Intent#setClassName(java.lang.String,%20java.lang.String), java.lang.String)) + of the intent. Requires a package to be set. #### Advanced settings