diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/UpdateScreen.kt b/java/src/org/futo/inputmethod/latin/uix/settings/UpdateScreen.kt index 31addbc67..2d263c1ce 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/UpdateScreen.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/UpdateScreen.kt @@ -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(); diff --git a/java/src/org/futo/inputmethod/updates/Update.kt b/java/src/org/futo/inputmethod/updates/Update.kt index 0bf799ffd..9b1e54ac3 100644 --- a/java/src/org/futo/inputmethod/updates/Update.kt +++ b/java/src/org/futo/inputmethod/updates/Update.kt @@ -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") + } } } diff --git a/java/src/org/futo/inputmethod/updates/UpdateChecking.kt b/java/src/org/futo/inputmethod/updates/UpdateChecking.kt index 6492ea7e9..9c1b695cc 100644 --- a/java/src/org/futo/inputmethod/updates/UpdateChecking.kt +++ b/java/src/org/futo/inputmethod/updates/UpdateChecking.kt @@ -70,12 +70,17 @@ 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 + return false + } } suspend fun retrieveSavedLastUpdateCheckResult(context: Context): UpdateResult? {