From e2c0652eecf81d57ed6571ddcb63224536a8194e Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Fri, 15 Mar 2024 13:57:57 -0500 Subject: [PATCH] Show manual update notice every so often --- .../futo/inputmethod/latin/uix/UixManager.kt | 31 +++++++++++++++++ .../latin/xlm/LanguageModelFacilitator.kt | 33 ++++++++++--------- .../org/futo/inputmethod/updates/Update.kt | 10 +++++- .../inputmethod/updates/UpdateChecking.kt | 5 +++ 4 files changed, 62 insertions(+), 17 deletions(-) diff --git a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt index ba514fd7e..50b3f484c 100644 --- a/java/src/org/futo/inputmethod/latin/uix/UixManager.kt +++ b/java/src/org/futo/inputmethod/latin/uix/UixManager.kt @@ -54,6 +54,9 @@ import org.futo.inputmethod.latin.uix.actions.EmojiAction import org.futo.inputmethod.latin.uix.settings.SettingsActivity import org.futo.inputmethod.latin.uix.theme.ThemeOption import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper +import org.futo.inputmethod.updates.DEFER_MANUAL_UPDATE_UNTIL +import org.futo.inputmethod.updates.MANUAL_UPDATE_PERIOD_MS +import org.futo.inputmethod.updates.openManualUpdateCheck import org.futo.inputmethod.updates.retrieveSavedLastUpdateCheckResult @@ -421,6 +424,34 @@ class UixManager(private val latinIME: LatinIME) { context.startActivity(intent) } } + } else { + val defermentTime = latinIME.getSetting(DEFER_MANUAL_UPDATE_UNTIL, Long.MAX_VALUE) + if(System.currentTimeMillis() > defermentTime) { + numSuggestionsSinceNotice = 0 + currentNotice.value = object : ImportantNotice { + @Composable + override fun getText(): String { + return "Please tap to check for updates" + } + + override fun onDismiss(context: Context) { + currentNotice.value = null + } + + override fun onOpen(context: Context) { + currentNotice.value = null + context.openManualUpdateCheck() + + runBlocking { + latinIME.setSetting( + DEFER_MANUAL_UPDATE_UNTIL, + System.currentTimeMillis() + MANUAL_UPDATE_PERIOD_MS + ) + } + } + } + + } } } diff --git a/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt b/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt index ded164649..d76dc1f85 100644 --- a/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt +++ b/java/src/org/futo/inputmethod/latin/xlm/LanguageModelFacilitator.kt @@ -171,24 +171,25 @@ public class LanguageModelFacilitator( } private suspend fun processUpdateSuggestionStrip(values: PredictionInputValues) { + if(keyboardSwitcher.keyboard == null) return + computationSemaphore.acquire() - val autocorrectThreshold = context.getSetting(AutocorrectThresholdSetting) - var transformerWeight = context.getSetting(BinaryDictTransformerWeightSetting) - - - val holder = AsyncResultHolder("Suggest") - inputLogic.getSuggestedWords( - settings.current, - keyboardSwitcher.keyboard, - keyboardSwitcher.keyboardShiftMode, - values.inputStyle, - SuggestedWords.NOT_A_SEQUENCE_NUMBER - ) { suggestedWords -> - holder.set(suggestedWords) - } - try { + val autocorrectThreshold = context.getSetting(AutocorrectThresholdSetting) + var transformerWeight = context.getSetting(BinaryDictTransformerWeightSetting) + + val holder = AsyncResultHolder("Suggest") + inputLogic.getSuggestedWords( + settings.current, + keyboardSwitcher.keyboard, + keyboardSwitcher.keyboardShiftMode, + values.inputStyle, + SuggestedWords.NOT_A_SEQUENCE_NUMBER + ) { suggestedWords -> + holder.set(suggestedWords) + } + val job = Job() CoroutineScope(Dispatchers.Default + job).launch { delay(500) @@ -220,7 +221,7 @@ public class LanguageModelFacilitator( settingsValues.mTransformerPredictionEnabled ) val proximityInfoHandle = keyboard.proximityInfo.nativeProximityInfo - + val suggestionResults = SuggestionResults( 14, values.ngramContext.isBeginningOfSentenceContext, false) diff --git a/java/src/org/futo/inputmethod/updates/Update.kt b/java/src/org/futo/inputmethod/updates/Update.kt index 9b1e54ac3..d8b12ab4a 100644 --- a/java/src/org/futo/inputmethod/updates/Update.kt +++ b/java/src/org/futo/inputmethod/updates/Update.kt @@ -13,6 +13,7 @@ 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.longPreferencesKey import androidx.datastore.preferences.core.stringPreferencesKey import androidx.navigation.NavHostController import org.futo.inputmethod.latin.BuildConfig @@ -22,6 +23,9 @@ 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") +val DEFER_MANUAL_UPDATE_UNTIL = longPreferencesKey("defer_manual_update_until") +const val MANUAL_UPDATE_PERIOD_MS = 1000L * 60L * 60L * 24L * 14L // Every two weeks + fun Context.openURI(uri: String, newTask: Boolean = false) { try { val intent = Intent(Intent.ACTION_VIEW, Uri.parse(uri)) @@ -35,6 +39,10 @@ fun Context.openURI(uri: String, newTask: Boolean = false) { } } +fun Context.openManualUpdateCheck() { + openURI("https://voiceinput.futo.org/SuperSecretKeyboard/manual_update?version=${BuildConfig.VERSION_CODE}", newTask = true) +} + @Composable @Preview fun ConditionalUpdate(navController: NavHostController) { @@ -64,7 +72,7 @@ fun ConditionalUpdate(navController: NavHostController) { 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}") + context.openManualUpdateCheck() } ) { 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 9c1b695cc..dabacb9d5 100644 --- a/java/src/org/futo/inputmethod/updates/UpdateChecking.kt +++ b/java/src/org/futo/inputmethod/updates/UpdateChecking.kt @@ -71,12 +71,17 @@ suspend fun checkForUpdateAndSaveToPreferences(context: Context): Boolean { context.dataStore.edit { it[LAST_UPDATE_CHECK_RESULT] = Json.encodeToString(updateResult) it[LAST_UPDATE_CHECK_FAILED] = false + it[DEFER_MANUAL_UPDATE_UNTIL] = System.currentTimeMillis() + MANUAL_UPDATE_PERIOD_MS } } return true } else { context.dataStore.edit { it[LAST_UPDATE_CHECK_FAILED] = true + + if(it[DEFER_MANUAL_UPDATE_UNTIL] == null) { + it[DEFER_MANUAL_UPDATE_UNTIL] = System.currentTimeMillis() + MANUAL_UPDATE_PERIOD_MS + } } return false