Skip to content

Commit

Permalink
show message in settings on second update
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Jan 6, 2024
1 parent 65d6eed commit 6648d61
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
23 changes: 20 additions & 3 deletions app/src/main/java/com/geode/launcher/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ fun SettingsScreen(
val updateStatus by releaseViewModel.uiState.collectAsState()

val snackbarHostState = remember { SnackbarHostState() }
var showUpdateInProgress by remember { mutableStateOf(false) }

if (showUpdateInProgress) {
LaunchedEffect(snackbarHostState) {
snackbarHostState.showSnackbar(
context.getString(R.string.preference_check_for_updates_already_updating)
)
showUpdateInProgress = false
}
}

Scaffold(
snackbarHost = {
Expand Down Expand Up @@ -213,9 +223,16 @@ fun SettingsScreen(
)
},
modifier = Modifier
.clickable(onClick = {
releaseViewModel.runReleaseCheck()
}, role = Role.Button)
.clickable(
onClick = {
if (releaseViewModel.isInUpdate) {
showUpdateInProgress = true
} else {
releaseViewModel.runReleaseCheck()
}
},
role = Role.Button
)
) {
UpdateIndicator(snackbarHostState, updateStatus)
}
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/java/com/geode/launcher/api/ReleaseViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.geode.launcher.utils.ReleaseManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.transformWhile
Expand Down Expand Up @@ -49,21 +48,21 @@ class ReleaseViewModel(private val application: Application): ViewModel() {
private val _uiState = MutableStateFlow<ReleaseUIState>(ReleaseUIState.Finished())
val uiState = _uiState.asStateFlow()

private var isInUpdateCheck = false
val isInUpdate
get() = ReleaseManager.get(application).isInUpdate

var hasPerformedCheck = false
private set

fun runReleaseCheck() {
// don't run multiple checks
if (isInUpdateCheck) {
if (isInUpdate) {
return
}

hasPerformedCheck = true

viewModelScope.launch {
isInUpdateCheck = true

val releaseFlow = ReleaseManager.get(application)
.checkForUpdates()

Expand All @@ -80,8 +79,6 @@ class ReleaseViewModel(private val application: Application): ViewModel() {
// send the mapped state to the ui
_uiState.value = it
}

isInUpdateCheck = false
}
}
}
7 changes: 2 additions & 5 deletions app/src/main/java/com/geode/launcher/utils/ReleaseManager.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.geode.launcher.utils

import android.content.Context
import com.geode.launcher.api.Asset
import com.geode.launcher.api.Release
import com.geode.launcher.api.ReleaseRepository
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
Expand All @@ -13,7 +11,6 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import java.io.File
import java.io.IOException
Expand Down Expand Up @@ -157,8 +154,8 @@ class ReleaseManager private constructor(

// check if an update is needed
if (latestVersion <= currentVersion) {
uiState.value = ReleaseManagerState.Finished()
return
// uiState.value = ReleaseManagerState.Finished()
// return
}

beginUpdate(release)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
<string name="preference_check_for_updates_none_found">No updates found.</string>
<string name="preference_check_for_updates_success">Geode has been updated!</string>
<string name="preference_check_for_updates_downloading">Downloading update…</string>
<string name="preference_check_for_updates_already_updating">An update is already in progress!</string>
</resources>

0 comments on commit 6648d61

Please sign in to comment.