mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Show manual update notice every so often
This commit is contained in:
parent
00a69a9eab
commit
e2c0652eec
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<SuggestedWords?>("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<SuggestedWords?>("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)
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user