Fix coroutine stuck
This commit is contained in:
parent
5db7ecf7bd
commit
667ac6282f
|
|
@ -5,7 +5,8 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.util.Log
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.launch
|
||||
import org.lsposed.lspatch.lspApp
|
||||
import org.lsposed.lspatch.util.LSPPackageManager
|
||||
|
||||
class AppBroadcastReceiver : BroadcastReceiver() {
|
||||
|
|
@ -30,7 +31,7 @@ class AppBroadcastReceiver : BroadcastReceiver() {
|
|||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action in actions) {
|
||||
runBlocking {
|
||||
lspApp.globalScope.launch {
|
||||
Log.i(TAG, "Received intent: $intent")
|
||||
LSPPackageManager.fetchAppList()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ private fun InstallDialog(patchApp: AppInfo, onFinish: (Int, String?) -> Unit) {
|
|||
val scope = rememberCoroutineScope()
|
||||
var uninstallFirst by remember { mutableStateOf(ShizukuApi.isPackageInstalledWithoutPatch(patchApp.app.packageName)) }
|
||||
var installing by remember { mutableStateOf(0) }
|
||||
val doInstall = suspend {
|
||||
suspend fun doInstall() {
|
||||
Log.i(TAG, "Installing app ${patchApp.app.packageName}")
|
||||
installing = 1
|
||||
val (status, message) = LSPPackageManager.install()
|
||||
|
|
|
|||
|
|
@ -229,8 +229,8 @@ fun AppManageBody(
|
|||
}
|
||||
)
|
||||
val uninstallSuccessfully = stringResource(R.string.manage_uninstall_successfully)
|
||||
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (it.resultCode == Activity.RESULT_OK) {
|
||||
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
scope.launch {
|
||||
snackbarHost.showSnackbar(uninstallSuccessfully)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class NewPatchViewModel : ViewModel() {
|
|||
}
|
||||
|
||||
fun dispatch(action: ViewAction) {
|
||||
viewModelScope.launch {
|
||||
when (action) {
|
||||
is ViewAction.DoneInit -> doneInit()
|
||||
is ViewAction.ConfigurePatch -> configurePatch(action.app)
|
||||
|
|
@ -73,6 +74,7 @@ class NewPatchViewModel : ViewModel() {
|
|||
is ViewAction.LaunchPatch -> launchPatch()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun doneInit() {
|
||||
patchState = PatchState.SELECTING
|
||||
|
|
@ -95,9 +97,8 @@ class NewPatchViewModel : ViewModel() {
|
|||
patchState = PatchState.PATCHING
|
||||
}
|
||||
|
||||
private fun launchPatch() {
|
||||
private suspend fun launchPatch() {
|
||||
logger.i("Launch patch")
|
||||
viewModelScope.launch {
|
||||
patchState = try {
|
||||
Patcher.patch(logger, patchOptions)
|
||||
PatchState.FINISHED
|
||||
|
|
@ -110,4 +111,3 @@ class NewPatchViewModel : ViewModel() {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.lsposed.lspatch.Patcher
|
||||
import org.lsposed.lspatch.lspApp
|
||||
|
|
@ -69,8 +70,8 @@ class AppManageViewModel : ViewModel() {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun dispatch(action: ViewAction) {
|
||||
withContext(viewModelScope.coroutineContext) {
|
||||
fun dispatch(action: ViewAction) {
|
||||
viewModelScope.launch {
|
||||
when (action) {
|
||||
is ViewAction.UpdateLoader -> updateLoader(action.appInfo, action.config)
|
||||
is ViewAction.ClearUpdateLoaderResult -> updateLoaderState = ProcessingState.Idle
|
||||
|
|
|
|||
Loading…
Reference in New Issue