allow overwriting on manual checks

This commit is contained in:
qimiko committed 2024-01-12 16:55:08 -07:00
1 parent 50d062149e
commit 7cdbe45ad6
4 files changed
+9 -9

No files matched your search

@@ -132,7 +132,7 @@ fun UpdateMessageIndicator(
if (allowRetry) {
OutlinedButton(
onClick = {
releaseViewModel.runReleaseCheck()
releaseViewModel.runReleaseCheck(true)
},
) {
Text(stringResource(R.string.release_fetch_button_retry))
@@ -340,7 +340,7 @@ fun MainScreen(
Row {
Button(
onClick = { releaseViewModel.runReleaseCheck() },
onClick = { releaseViewModel.runReleaseCheck(true) },
enabled = !releaseViewModel.isInUpdate
) {
Icon(
@@ -316,7 +316,7 @@ fun SettingsScreen(
if (releaseViewModel.isInUpdate) {
showUpdateInProgress = true
} else {
releaseViewModel.runReleaseCheck()
releaseViewModel.runReleaseCheck(true)
}
},
role = Role.Button
@@ -86,12 +86,12 @@ class ReleaseViewModel(private val application: Application): ViewModel() {
}
}
fun runReleaseCheck() {
fun runReleaseCheck(isManual: Boolean = false) {
hasPerformedCheck = true
viewModelScope.launch {
val releaseFlow = ReleaseManager.get(application)
.checkForUpdates()
.checkForUpdates(isManual)
syncUiState(releaseFlow)
}
@@ -138,7 +138,7 @@ class ReleaseManager private constructor(
_uiState.value = ReleaseManagerState.Finished(true)
}
private suspend fun checkForNewRelease() {
private suspend fun checkForNewRelease(allowOverwriting: Boolean = false) {
val release = try {
getLatestRelease()
} catch (e: Exception) {
@@ -167,7 +167,7 @@ class ReleaseManager private constructor(
// check if the file was externally modified
val fileLastModified = sharedPreferences.getLong(PreferenceUtils.Key.CURRENT_RELEASE_MODIFIED)
if (fileLastModified != 0L && fileLastModified != geodeFile.lastModified()) {
if (!allowOverwriting && fileLastModified != 0L && fileLastModified != geodeFile.lastModified()) {
sendError(UpdateException(UpdateException.Reason.EXTERNAL_FILE_IN_USE))
return
}
@@ -217,11 +217,11 @@ class ReleaseManager private constructor(
* @return Flow that tracks the state of the update.
*/
@OptIn(DelicateCoroutinesApi::class)
fun checkForUpdates(): StateFlow<ReleaseManagerState> {
fun checkForUpdates(isManual: Boolean = false): StateFlow<ReleaseManagerState> {
if (!isInUpdate) {
_uiState.value = ReleaseManagerState.InUpdateCheck
updateJob = GlobalScope.launch {
checkForNewRelease()
checkForNewRelease(isManual)
}
}