Add starting modules from manager

This commit is contained in:
Nullptr 2022-09-23 00:04:25 +08:00
parent f7c6af53ec
commit 415f434d08
No known key found for this signature in database
7 changed files with 71 additions and 10 deletions

View File

@ -15,7 +15,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath("org.eclipse.jgit:org.eclipse.jgit:6.0.0.202111291000-r") classpath("org.eclipse.jgit:org.eclipse.jgit:6.3.0.202209071007-r")
classpath(kotlin("gradle-plugin", version = "1.7.10")) classpath(kotlin("gradle-plugin", version = "1.7.10"))
} }
} }

View File

@ -42,6 +42,14 @@ android {
} }
sourceSets["main"].assets.srcDirs(rootProject.projectDir.resolve("out/assets")) sourceSets["main"].assets.srcDirs(rootProject.projectDir.resolve("out/assets"))
applicationVariants.all {
kotlin.sourceSets {
getByName(name) {
kotlin.srcDir("build/generated/ksp/$name/kotlin")
}
}
}
} }
afterEvaluate { afterEvaluate {
@ -49,12 +57,6 @@ afterEvaluate {
val variantLowered = variant.name.toLowerCase() val variantLowered = variant.name.toLowerCase()
val variantCapped = variant.name.capitalize() val variantCapped = variant.name.capitalize()
kotlin.sourceSets {
getByName(variant.name) {
kotlin.srcDir("build/generated/ksp/${variant.name}/kotlin")
}
}
task<Copy>("copy${variantCapped}Assets") { task<Copy>("copy${variantCapped}Assets") {
dependsOn(":appstub:copy$variantCapped") dependsOn(":appstub:copy$variantCapped")
dependsOn(":patch-loader:copy$variantCapped") dependsOn(":patch-loader:copy$variantCapped")
@ -96,7 +98,6 @@ dependencies {
implementation("androidx.preference:preference:1.2.0") implementation("androidx.preference:preference:1.2.0")
implementation("androidx.room:room-ktx:$roomVersion") implementation("androidx.room:room-ktx:$roomVersion")
implementation("androidx.room:room-runtime:$roomVersion") implementation("androidx.room:room-runtime:$roomVersion")
implementation("com.google.accompanist:accompanist-drawablepainter:$accompanistVersion")
implementation("com.google.accompanist:accompanist-navigation-animation:$accompanistVersion") implementation("com.google.accompanist:accompanist-navigation-animation:$accompanistVersion")
implementation("com.google.accompanist:accompanist-pager:$accompanistVersion") implementation("com.google.accompanist:accompanist-pager:$accompanistVersion")
implementation("com.google.accompanist:accompanist-swiperefresh:$accompanistVersion") implementation("com.google.accompanist:accompanist-swiperefresh:$accompanistVersion")

View File

@ -35,6 +35,10 @@ fun AnywhereDropdown(
} }
LaunchedEffect(state) { LaunchedEffect(state) {
if (state is PressInteraction.Press) {
val i = state as PressInteraction.Press
offset = i.pressPosition
}
if (state is PressInteraction.Release) { if (state is PressInteraction.Release) {
val i = state as PressInteraction.Release val i = state as PressInteraction.Release
offset = i.press.pressPosition offset = i.press.pressPosition

View File

@ -141,6 +141,7 @@ fun AppManageBody(
expanded = expanded, expanded = expanded,
onDismissRequest = { expanded = false }, onDismissRequest = { expanded = false },
onClick = { expanded = true }, onClick = { expanded = true },
onLongClick = { expanded = true },
surface = { surface = {
AppItem( AppItem(
icon = LSPPackageManager.getIcon(it.first), icon = LSPPackageManager.getIcon(it.first),
@ -164,6 +165,10 @@ fun AppManageBody(
) )
} }
) { ) {
DropdownMenuItem(
text = { Text(text = it.first.label, color = MaterialTheme.colorScheme.primary) },
onClick = {}, enabled = false
)
val shizukuUnavailable = stringResource(R.string.shizuku_unavailable) val shizukuUnavailable = stringResource(R.string.shizuku_unavailable)
if (it.second.lspConfig.VERSION_CODE < LSPConfig.instance.VERSION_CODE || BuildConfig.DEBUG) { if (it.second.lspConfig.VERSION_CODE < LSPConfig.instance.VERSION_CODE || BuildConfig.DEBUG) {
DropdownMenuItem( DropdownMenuItem(

View File

@ -1,15 +1,20 @@
package org.lsposed.lspatch.ui.page.manage package org.lsposed.lspatch.ui.page.manage
import android.content.Intent
import android.net.Uri
import android.provider.Settings
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.SpanStyle
@ -25,6 +30,7 @@ import org.lsposed.lspatch.util.LSPPackageManager
@Composable @Composable
fun ModuleManageBody() { fun ModuleManageBody() {
val context = LocalContext.current
val viewModel = viewModel<ModuleManageViewModel>() val viewModel = viewModel<ModuleManageViewModel>()
if (viewModel.appList.isEmpty()) { if (viewModel.appList.isEmpty()) {
Box(Modifier.fillMaxSize()) { Box(Modifier.fillMaxSize()) {
@ -45,10 +51,11 @@ fun ModuleManageBody() {
key = { it.first.app.packageName } key = { it.first.app.packageName }
) { ) {
var expanded by remember { mutableStateOf(false) } var expanded by remember { mutableStateOf(false) }
val launchIntent = remember { LSPPackageManager.getLaunchIntentForPackage(it.first.app.packageName) }
AnywhereDropdown( AnywhereDropdown(
expanded = expanded, expanded = expanded,
onDismissRequest = { expanded = false }, onDismissRequest = { expanded = false },
onClick = { /* TODO: Start module */ }, onClick = { launchIntent?.let { context.startActivity(it) } },
onLongClick = { expanded = true }, onLongClick = { expanded = true },
surface = { surface = {
AppItem( AppItem(
@ -74,7 +81,26 @@ fun ModuleManageBody() {
) )
} }
) { ) {
// TODO: Implement DropdownMenuItem(
text = { Text(text = it.first.label, color = MaterialTheme.colorScheme.primary) },
onClick = {}, enabled = false
)
if (launchIntent != null) {
DropdownMenuItem(
text = { Text(stringResource(R.string.manage_module_settings)) },
onClick = { context.startActivity(launchIntent) }
)
}
DropdownMenuItem(
text = { Text(stringResource(R.string.manage_app_info)) },
onClick = {
val intent = Intent(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", it.first.app.packageName, null)
)
context.startActivity(intent)
}
)
} }
} }
} }

View File

@ -187,4 +187,27 @@ object LSPPackageManager {
} }
} }
} }
fun getLaunchIntentForPackage(packageName: String): Intent? {
val intentToResolve = Intent(Intent.ACTION_MAIN)
intentToResolve.addCategory(Intent.CATEGORY_INFO)
intentToResolve.setPackage(packageName)
var ris = lspApp.packageManager.queryIntentActivities(intentToResolve, 0)
if (ris.size <= 0) {
intentToResolve.removeCategory(Intent.CATEGORY_INFO)
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER)
intentToResolve.setPackage(packageName)
ris = lspApp.packageManager.queryIntentActivities(intentToResolve, 0)
}
if (ris.size <= 0) return null
return Intent(intentToResolve)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setClassName(
ris[0].activityInfo.packageName,
ris[0].activityInfo.name
)
}
} }

View File

@ -38,6 +38,8 @@
<string name="manage_optimize_failed">Optimize failed</string> <string name="manage_optimize_failed">Optimize failed</string>
<string name="manage_uninstall_successfully">Uninstall successfully</string> <string name="manage_uninstall_successfully">Uninstall successfully</string>
<string name="manage_no_modules">No modules yet</string> <string name="manage_no_modules">No modules yet</string>
<string name="manage_module_settings">Module settings</string>
<string name="manage_app_info">App info</string>
<!-- New Patch Screen --> <!-- New Patch Screen -->
<string name="screen_new_patch">New Patch</string> <string name="screen_new_patch">New Patch</string>