Add more update fallbacks in case people are stubborn and block network

This commit is contained in:
Aleksandras Kostarevas 2024-03-15 10:47:20 -05:00
parent b15d882d77
commit 6490e2941b
3 changed files with 23 additions and 3 deletions

View File

@ -49,6 +49,7 @@ import org.futo.inputmethod.latin.uix.getSetting
import org.futo.inputmethod.updates.InstallReceiver
import org.futo.inputmethod.updates.LAST_UPDATE_CHECK_RESULT
import org.futo.inputmethod.updates.UpdateResult
import org.futo.inputmethod.updates.openURI
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.io.OutputStream
@ -179,6 +180,7 @@ private suspend fun downloadAndInstall(scope: CoroutineScope, context: Context,
Log.w("UpdateScreen", "Exception thrown while downloading and installing latest version of app.", e);
withContext(Dispatchers.Main) {
updateStatusText("Failed to download update: ${e.message}");
context.openURI(updateResult.apkUrl)
}
} finally {
inputStream?.close();

View File

@ -12,12 +12,15 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.tooling.preview.Preview
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.navigation.NavHostController
import org.futo.inputmethod.latin.BuildConfig
import org.futo.inputmethod.latin.uix.settings.SettingItem
import org.futo.inputmethod.latin.uix.settings.useDataStore
val LAST_UPDATE_CHECK_RESULT = stringPreferencesKey("last_update_check_result")
val LAST_UPDATE_CHECK_FAILED = booleanPreferencesKey("last_update_check_failed")
fun Context.openURI(uri: String, newTask: Boolean = false) {
try {
@ -36,6 +39,7 @@ fun Context.openURI(uri: String, newTask: Boolean = false) {
@Preview
fun ConditionalUpdate(navController: NavHostController) {
val (updateInfo, _) = useDataStore(key = LAST_UPDATE_CHECK_RESULT, default = "")
val (lastFailed, _) = useDataStore(key = LAST_UPDATE_CHECK_FAILED, default = false)
val lastUpdateResult = if(!LocalInspectionMode.current){
UpdateResult.fromString(updateInfo)
@ -55,6 +59,15 @@ fun ConditionalUpdate(navController: NavHostController) {
) {
Icon(Icons.Default.ArrowForward, contentDescription = "Go")
}
} else if(lastFailed) {
SettingItem(
title = "Failed to check for updates",
subtitle = "Tap to check manually",
onClick = {
context.openURI("https://voiceinput.futo.org/SuperSecretKeyboard/manual_update?version=${BuildConfig.VERSION_CODE}")
}
) {
Icon(Icons.Default.ArrowForward, contentDescription = "Go")
}
}
}

View File

@ -70,13 +70,18 @@ suspend fun checkForUpdateAndSaveToPreferences(context: Context): Boolean {
withContext(Dispatchers.IO) {
context.dataStore.edit {
it[LAST_UPDATE_CHECK_RESULT] = Json.encodeToString(updateResult)
it[LAST_UPDATE_CHECK_FAILED] = false
}
}
return true
} else {
context.dataStore.edit {
it[LAST_UPDATE_CHECK_FAILED] = true
}
return false
}
}
suspend fun retrieveSavedLastUpdateCheckResult(context: Context): UpdateResult? {
return UpdateResult.fromString(context.getSetting(LAST_UPDATE_CHECK_RESULT, ""))