fix: show toasts on main thread
This commit is contained in:
parent
836424e3f8
commit
1f4f386600
3 changed files with 15 additions and 22 deletions
|
|
@ -10,8 +10,7 @@ import com.aliucord.manager.manager.download.IDownloadManager
|
|||
import com.aliucord.manager.manager.download.KtorDownloadManager
|
||||
import com.aliucord.manager.patcher.StepRunner
|
||||
import com.aliucord.manager.patcher.steps.StepGroup
|
||||
import com.aliucord.manager.util.showToast
|
||||
import com.aliucord.manager.util.toPrecision
|
||||
import com.aliucord.manager.util.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.component.KoinComponent
|
||||
|
|
@ -90,12 +89,14 @@ abstract class DownloadStep : Step(), KoinComponent {
|
|||
try {
|
||||
verify()
|
||||
} catch (t: Throwable) {
|
||||
withContext(Dispatchers.Main) {
|
||||
context.showToast(R.string.installer_dl_verify_fail)
|
||||
}
|
||||
|
||||
mainThread { context.showToast(R.string.installer_dl_verify_fail) }
|
||||
container.log("Failed to verify file, deleting...")
|
||||
targetFile.delete()
|
||||
|
||||
try {
|
||||
targetFile.delete()
|
||||
} catch (_: Throwable) {
|
||||
// Ignore
|
||||
}
|
||||
throw t
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,7 @@ import com.aliucord.manager.patcher.steps.StepGroup
|
|||
import com.aliucord.manager.patcher.steps.base.Step
|
||||
import com.aliucord.manager.patcher.steps.base.StepState
|
||||
import com.aliucord.manager.ui.screens.patchopts.PatchOptions
|
||||
import com.aliucord.manager.util.getPackageVersion
|
||||
import com.aliucord.manager.util.showToast
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import com.aliucord.manager.util.*
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
|
|
@ -49,18 +46,12 @@ class DowngradeCheckStep(private val options: PatchOptions) : Step(), KoinCompon
|
|||
|
||||
if (currentVersion > targetVersion) {
|
||||
container.log("Current installed version is greater than target, forcing uninstallation")
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
context.showToast(R.string.installer_uninstall_new)
|
||||
}
|
||||
mainThread { context.showToast(R.string.installer_uninstall_new) }
|
||||
|
||||
when (val result = installers.getActiveInstaller().waitUninstall(options.packageName)) {
|
||||
is InstallerResult.Error -> throw Error("Failed to uninstall Aliucord: ${result.getDebugReason()}")
|
||||
is InstallerResult.Cancelled -> {
|
||||
withContext(Dispatchers.Main) {
|
||||
context.showToast(R.string.installer_uninstall_new)
|
||||
}
|
||||
|
||||
mainThread { context.showToast(R.string.installer_uninstall_new) }
|
||||
throw Error("Newer versions of Aliucord must be uninstalled prior to installing an older version")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ class PatchingScreenModel(
|
|||
|
||||
fun install() = screenModelScope.launchBlock {
|
||||
runnerJob?.cancel("Manual cancellation")
|
||||
steps = null
|
||||
mainThread { steps = null }
|
||||
|
||||
@SuppressLint("MemberExtensionConflict")
|
||||
installId = UUID.randomUUID().toString()
|
||||
|
|
@ -128,9 +128,10 @@ class PatchingScreenModel(
|
|||
val runner = KotlinPatchRunner(options)
|
||||
.also { stepRunner = it }
|
||||
|
||||
steps = runner.steps.groupBy { it.group }
|
||||
val newSteps = runner.steps.groupBy { it.group }
|
||||
.mapValues { it.value.toUnsafeImmutable() }
|
||||
.toUnsafeImmutable()
|
||||
mainThread { steps = newSteps }
|
||||
|
||||
// Intentionally delay to show the state change of the first step when it runs in the UI.
|
||||
// Without this, on a fast internet connection the step just immediately shows as "Success".
|
||||
|
|
@ -160,7 +161,7 @@ class PatchingScreenModel(
|
|||
mutableState.value = PatchingScreenState.Failed(installId = installId!!)
|
||||
|
||||
if (error is InsufficientStorageException) {
|
||||
application.showToast(R.string.installer_insufficient_storage)
|
||||
mainThread { application.showToast(R.string.installer_insufficient_storage) }
|
||||
}
|
||||
|
||||
error
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue