Skip to content

Commit

Permalink
Setup: Fix changing Shizuku from OFF to ON not always reloading avail…
Browse files Browse the repository at this point in the history
…able data areas
  • Loading branch information
d4rken committed Dec 6, 2023
1 parent 838daa0 commit d66f96d
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import eu.darken.sdmse.common.flow.replayingShare
import eu.darken.sdmse.common.rngString
import eu.darken.sdmse.common.shizuku.ShizukuManager
import eu.darken.sdmse.common.shizuku.ShizukuSettings
import eu.darken.sdmse.common.shizuku.canUseShizukuNow
import eu.darken.sdmse.setup.SetupModule
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
Expand Down Expand Up @@ -74,7 +76,7 @@ class ShizukuSetupModule @Inject constructor(

suspend fun toggleUseShizuku(useShizuku: Boolean?) {
log(TAG) { "toggleUseShizuku(useShizuku=$useShizuku)" }

val couldUseShizuku = shizukuManager.canUseShizukuNow()
if (useShizuku == true && shizukuManager.isGranted() == false) {
val grantResult = coroutineScope {
val eventResult = async {
Expand All @@ -95,6 +97,12 @@ class ShizukuSetupModule @Inject constructor(
shizukuSettings.useShizuku.value(useShizuku)
}

if (!couldUseShizuku && useShizuku == true) {
// TODO find a smarter way to do this, i.e. by waiting for a specific event.
// Small delay to allow Shizuku service to bind
delay(1500)
}

dataAreaManager.reload()
}

Expand Down

0 comments on commit d66f96d

Please sign in to comment.