feat: better cancelled install flow

This commit is contained in:
rushiiMachine 2024-07-31 13:54:55 -07:00
parent 3ec7412c54
commit c5eded4f63
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
3 changed files with 17 additions and 3 deletions

View file

@ -18,6 +18,7 @@ import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.base.StepState
import com.aliucord.manager.installer.steps.install.InstallStep
import com.aliucord.manager.manager.PathManager
import com.aliucord.manager.manager.PreferencesManager
import com.aliucord.manager.ui.screens.installopts.InstallOptions
import com.aliucord.manager.ui.util.toUnsafeImmutable
import com.aliucord.manager.util.*
@ -33,11 +34,14 @@ class InstallModel(
private val application: Application,
private val paths: PathManager,
private val options: InstallOptions,
private val prefs: PreferencesManager,
) : StateScreenModel<InstallScreenState>(InstallScreenState.Pending) {
private var startTime: Date? = null
private var installJob: Job? = null
private var stepRunner: StepRunner? = null
val devMode get() = prefs.devMode
var installSteps by mutableStateOf<ImmutableMap<StepGroup, ImmutableList<Step>>?>(null)
private set

View file

@ -66,7 +66,12 @@ class InstallScreen(private val data: InstallOptions) : Screen, Parcelable {
LaunchedEffect(state) {
if (state is InstallScreenState.CloseScreen)
navigator.back(currentActivity = null)
navigator.popUntilRoot()
}
// Go home directly if install was successful
BackHandler(state is InstallScreenState.Success) {
navigator.popUntilRoot()
}
// Prevent screen from turning off while working
@ -81,7 +86,7 @@ class InstallScreen(private val data: InstallOptions) : Screen, Parcelable {
// Only show exit warning if currently working
val onTryExit: () -> Unit = remember {
{
if (state == InstallScreenState.Working) {
if (state == InstallScreenState.Working && !model.devMode) {
showAbortWarning = true
} else {
navigator.back(currentActivity = null)

View file

@ -28,6 +28,7 @@ import com.aliucord.manager.ui.screens.installopts.components.options.TextInstal
import com.aliucord.manager.ui.util.*
import com.aliucord.manager.util.isIgnoringBatteryOptimizations
import com.aliucord.manager.util.requestNoBatteryOptimizations
import kotlinx.coroutines.delay
class InstallOptionsScreen(
private val supportedVersion: DiscordVersion = DiscordVersion.None,
@ -41,6 +42,10 @@ class InstallOptionsScreen(
val model = getScreenModel<InstallOptionsModel>()
LaunchedEffect(Unit) {
// Ensure that when popping this screen off the stack that permission requests don't get triggered
// The coroutine context local to this screen gets cancelled and never continues after the delay()
delay(1000)
InstallNotifications.requestPermissions(context)
if (!context.isIgnoringBatteryOptimizations())
@ -132,7 +137,7 @@ class InstallOptionsScreen(
FilledTonalButton(
enabled = model.isConfigValid,
onClick = { navigator replace InstallScreen(model.generateConfig()) },
onClick = { navigator.push(InstallScreen(model.generateConfig())) },
colors = ButtonDefaults.filledTonalButtonColors(
contentColor = MaterialTheme.colorScheme.primary,
),