From 4bf13711550b96784dacc945a57400aabfbce570 Mon Sep 17 00:00:00 2001
From: Js0n <29531167+JasonKhew96@users.noreply.github.com>
Date: Mon, 11 Dec 2023 23:38:30 +0800
Subject: [PATCH] feat: launch and install from apk intent (#279)
close #90
---
manager/src/main/AndroidManifest.xml | 8 ++++
.../org/lsposed/lspatch/ui/page/HomeScreen.kt | 31 ++++++++++++++-
.../lsposed/lspatch/ui/page/NewPatchScreen.kt | 39 ++++++++++++++++---
.../lspatch/ui/page/manage/AppManagePage.kt | 6 ++-
4 files changed, 76 insertions(+), 8 deletions(-)
diff --git a/manager/src/main/AndroidManifest.xml b/manager/src/main/AndroidManifest.xml
index d051615f..f3d3f14d 100644
--- a/manager/src/main/AndroidManifest.xml
+++ b/manager/src/main/AndroidManifest.xml
@@ -23,6 +23,14 @@
+
+
+
+
+
+
+
+
diff --git a/manager/src/main/java/org/lsposed/lspatch/ui/page/NewPatchScreen.kt b/manager/src/main/java/org/lsposed/lspatch/ui/page/NewPatchScreen.kt
index 09bdc02e..3c8473d8 100644
--- a/manager/src/main/java/org/lsposed/lspatch/ui/page/NewPatchScreen.kt
+++ b/manager/src/main/java/org/lsposed/lspatch/ui/page/NewPatchScreen.kt
@@ -4,6 +4,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.pm.PackageInstaller
+import android.net.Uri
import android.util.Log
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
@@ -58,13 +59,18 @@ import org.lsposed.lspatch.util.ShizukuApi
private const val TAG = "NewPatchPage"
+const val ACTION_STORAGE = 0
+const val ACTION_APPLIST = 1
+const val ACTION_INTENT_INSTALL = 2
+
@OptIn(ExperimentalMaterial3Api::class)
@Destination
@Composable
fun NewPatchScreen(
navigator: DestinationsNavigator,
resultRecipient: ResultRecipient,
- from: String
+ id: Int,
+ data: Uri? = null
) {
val viewModel = viewModel()
val snackbarHost = LocalSnackbarHost.current
@@ -116,11 +122,34 @@ fun NewPatchScreen(
PatchState.INIT -> {
LaunchedEffect(Unit) {
LSPPackageManager.cleanTmpApkDir()
- when (from) {
- "storage" -> storageLauncher.launch(arrayOf("application/vnd.android.package-archive"))
- "applist" -> navigator.navigate(SelectAppsScreenDestination(false))
+ when (id) {
+ ACTION_STORAGE -> {
+ storageLauncher.launch(arrayOf("application/vnd.android.package-archive"))
+ viewModel.dispatch(ViewAction.DoneInit)
+ }
+
+ ACTION_APPLIST -> {
+ navigator.navigate(SelectAppsScreenDestination(false))
+ viewModel.dispatch(ViewAction.DoneInit)
+ }
+
+ ACTION_INTENT_INSTALL -> {
+ runBlocking {
+ data?.let { uri ->
+ LSPPackageManager.getAppInfoFromApks(listOf(uri)).onSuccess {
+ viewModel.dispatch(ViewAction.ConfigurePatch(it.first()))
+ }.onFailure {
+ lspApp.globalScope.launch {
+ snackbarHost.showSnackbar(
+ it.message ?: errorUnknown
+ )
+ }
+ navigator.navigateUp()
+ }
+ }
+ }
+ }
}
- viewModel.dispatch(ViewAction.DoneInit)
}
}
PatchState.SELECTING -> {
diff --git a/manager/src/main/java/org/lsposed/lspatch/ui/page/manage/AppManagePage.kt b/manager/src/main/java/org/lsposed/lspatch/ui/page/manage/AppManagePage.kt
index 1a48d1ab..a062a374 100644
--- a/manager/src/main/java/org/lsposed/lspatch/ui/page/manage/AppManagePage.kt
+++ b/manager/src/main/java/org/lsposed/lspatch/ui/page/manage/AppManagePage.kt
@@ -48,6 +48,8 @@ import org.lsposed.lspatch.share.LSPConfig
import org.lsposed.lspatch.ui.component.AnywhereDropdown
import org.lsposed.lspatch.ui.component.AppItem
import org.lsposed.lspatch.ui.component.LoadingDialog
+import org.lsposed.lspatch.ui.page.ACTION_APPLIST
+import org.lsposed.lspatch.ui.page.ACTION_STORAGE
import org.lsposed.lspatch.ui.page.SelectAppsResult
import org.lsposed.lspatch.ui.page.destinations.NewPatchScreenDestination
import org.lsposed.lspatch.ui.page.destinations.SelectAppsScreenDestination
@@ -329,7 +331,7 @@ fun AppManageFab(navigator: DestinationsNavigator) {
modifier = Modifier.fillMaxWidth(),
colors = ButtonDefaults.textButtonColors(contentColor = MaterialTheme.colorScheme.secondary),
onClick = {
- navigator.navigate(NewPatchScreenDestination("storage"))
+ navigator.navigate(NewPatchScreenDestination(id = ACTION_STORAGE))
showNewPatchDialog = false
}
) {
@@ -343,7 +345,7 @@ fun AppManageFab(navigator: DestinationsNavigator) {
modifier = Modifier.fillMaxWidth(),
colors = ButtonDefaults.textButtonColors(contentColor = MaterialTheme.colorScheme.secondary),
onClick = {
- navigator.navigate(NewPatchScreenDestination("applist"))
+ navigator.navigate(NewPatchScreenDestination(id = ACTION_APPLIST))
showNewPatchDialog = false
}
) {