Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Feb 7, 2024
1 parent ed03128 commit f5947f2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.aliucord.manager.installer.steps

import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.base.StepState
import com.aliucord.manager.manager.PreferencesManager
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.delay
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

/**
* The minimum time that is required to occur between step switches, to avoid
* quickly switching the step groups in the UI. (very disorienting)
* Larger delay leads to a perception that it's doing more work than it actually is.
*/
const val MINIMUM_STEP_DELAY: Long = 600L

abstract class StepRunner : KoinComponent {
private val preferences: PreferencesManager by inject()

Expand Down Expand Up @@ -35,10 +41,9 @@ abstract class StepRunner : KoinComponent {
val error = step.executeCatching(this@StepRunner)
if (error != null) return error

// Add delay for human psychology and
// better group visibility in UI (the active group can change way too fast)
if (!preferences.devMode && step.durationMs < 500) {
delay(500L - step.durationMs)
// Skip minimum run time when in dev mode
if (!preferences.devMode && step.durationMs < MINIMUM_STEP_DELAY) {
delay(MINIMUM_STEP_DELAY - step.durationMs)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import androidx.annotation.StringRes
import androidx.compose.runtime.*
import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.koin.core.time.measureTimedValue
import kotlin.math.roundToInt

Expand Down Expand Up @@ -62,7 +64,9 @@ abstract class Step {
// Execute this steps logic while timing it
val (error, executionTimeMs) = measureTimedValue {
try {
execute(container)
withContext(Dispatchers.Default) {
execute(container)
}

if (state != StepState.Skipped)
state = StepState.Success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ class DownloadManager(application: Application) {
.addRequestHeader("User-Agent", "Aliucord Manager/${BuildConfig.VERSION_NAME}")
.apply {
// Disable gzip on emulator due to https compression bug
println(Build.PRODUCT)
// if (Build.PRODUCT == "google_sdk") {
Log.i(BuildConfig.TAG, "Disabling DownloadManager compression")
if (Build.FINGERPRINT.contains("emulator")) {
Log.d(BuildConfig.TAG, "Disabling DownloadManager compression")
addRequestHeader("Accept-Encoding", null)
// }
}
}
.let(downloadManager::enqueue)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class InstallModel(
.mapValues { it.value.toUnsafeImmutable() }
.toUnsafeImmutable()

// Intentionally delay to show the state change of the first step in UI when it runs
// without it, on a fast internet it just immediately shows as "Success"
delay(600)

// Execute all the steps and catch any errors
when (val error = runner.executeAll()) {
// Successfully installed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class InstallScreen : Screen {
title = { Text(stringResource(R.string.installer)) },
navigationIcon = {
IconButton(
// TODO: only show warning when in progress
onClick = { showAbortWarning = true },
) {
Icon(
Expand Down Expand Up @@ -93,7 +94,13 @@ class InstallScreen : Screen {
.fillMaxWidth()
.padding(16.dp)
) {
var expandedGroup by remember { mutableStateOf(StepGroup.Prepare) }
var expandedGroup by remember { mutableStateOf<StepGroup?>(StepGroup.Prepare) }

// Close all groups when successfully finished everything
LaunchedEffect(state.value) {
if (state.value == InstallScreenState.Success)
expandedGroup = null
}

model.installSteps?.let { groupedSteps ->
for ((group, steps) in groupedSteps.entries) key(group) {
Expand Down

0 comments on commit f5947f2

Please sign in to comment.