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