Update check: the public GitHub releases, daily on start and from Settings › About
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
ReleaseCheck reads api.github.com's list of this repository's releases over plain HTTPS, compares with the installed version (a beta sorts below its release; -debug is left off), and offers the newest one the person may have: betas only to a beta install or with Include betas on. On start it runs at most once a day while Look for new versions is on (default: on in a beta, off in a release) and announces a version once, in a notification on its own low channel that opens the release page. Check for an update works in both builds; the full build's own installer stays for a found release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
18 files changed
+559
-22
No files matched your search
@@ -20,7 +20,9 @@ class LembasApp : Application() {
|
||||
NotificationChannel(CHANNEL_ASKS, getString(R.string.channel_asks), NotificationManager.IMPORTANCE_HIGH),
|
||||
NotificationChannel(CHANNEL_SCHEDULED, getString(R.string.channel_scheduled), NotificationManager.IMPORTANCE_DEFAULT),
|
||||
NotificationChannel(CHANNEL_SCHEDULED_FAILURES, getString(R.string.channel_scheduled_failures), NotificationManager.IMPORTANCE_HIGH),
|
||||
).onEach { it.lockscreenVisibility = android.app.Notification.VISIBILITY_PRIVATE },
|
||||
).onEach { it.lockscreenVisibility = android.app.Notification.VISIBILITY_PRIVATE } +
|
||||
// A new version of the app says nothing about the account.
|
||||
NotificationChannel(CHANNEL_UPDATES, getString(R.string.channel_updates), NotificationManager.IMPORTANCE_LOW),
|
||||
)
|
||||
// LLeMbas 2.0 has no reports, so 0.1's channel for them goes rather than sit empty in
|
||||
// the system's settings.
|
||||
@@ -32,6 +34,7 @@ class LembasApp : Application() {
|
||||
const val CHANNEL_ASKS = "asks"
|
||||
const val CHANNEL_SCHEDULED = "scheduled_results"
|
||||
const val CHANNEL_SCHEDULED_FAILURES = "scheduled_failures"
|
||||
const val CHANNEL_UPDATES = "updates"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ import eu.llembas.android.ui.scheduled.SchedulingModelsScreen
|
||||
import eu.llembas.android.ui.settings.SettingsScreen
|
||||
import eu.llembas.android.ui.signin.SignInScreen
|
||||
import eu.llembas.android.ui.theme.LembasTheme
|
||||
import eu.llembas.android.update.ReleaseCheck
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
@@ -71,6 +72,8 @@ class MainActivity : ComponentActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
take(intent)
|
||||
followLanguage()
|
||||
// At most once a day, and only while Settings › About says so (update/ReleaseCheck.kt).
|
||||
lifecycleScope.launch { runCatching { ReleaseCheck(this@MainActivity).daily() } }
|
||||
if (Build.VERSION.SDK_INT >= 33 &&
|
||||
ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
|
||||
@@ -89,6 +89,13 @@ data class Prefs(
|
||||
val lastAssistChat: String = "",
|
||||
val lastAssistTitle: String = "",
|
||||
val lastAssistAt: Long = 0,
|
||||
/** Settings › About: look for new versions (null: on in a beta, off in a release). */
|
||||
val updateCheck: Boolean? = null,
|
||||
/** ... and include betas (null: on in a beta, off in a release). */
|
||||
val updateBetas: Boolean? = null,
|
||||
val updateCheckedAt: Long = 0,
|
||||
/** The last version a notification announced, so it is announced once. */
|
||||
val updateNotified: String = "",
|
||||
) {
|
||||
companion object {
|
||||
const val VOICE_LEMBAS = "lembas"
|
||||
|
||||
@@ -28,6 +28,7 @@ import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.Assistant
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.Dns
|
||||
import androidx.compose.material.icons.filled.Download
|
||||
import androidx.compose.material.icons.filled.Info
|
||||
import androidx.compose.material.icons.filled.Mic
|
||||
import androidx.compose.material.icons.filled.Notifications
|
||||
@@ -35,9 +36,11 @@ import androidx.compose.material.icons.filled.NotificationsActive
|
||||
import androidx.compose.material.icons.filled.Palette
|
||||
import androidx.compose.material.icons.filled.PhoneAndroid
|
||||
import androidx.compose.material.icons.filled.RecordVoiceOver
|
||||
import androidx.compose.material.icons.filled.Science
|
||||
import androidx.compose.material.icons.filled.SystemUpdate
|
||||
import androidx.compose.material.icons.filled.Timer
|
||||
import androidx.compose.material.icons.filled.Translate
|
||||
import androidx.compose.material.icons.filled.Update
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@@ -77,7 +80,13 @@ import eu.llembas.android.auth.Prefs
|
||||
import eu.llembas.android.lembas
|
||||
import eu.llembas.android.push.Push
|
||||
import eu.llembas.android.ui.theme.LocalPalette
|
||||
import eu.llembas.android.update.AppVersion
|
||||
import eu.llembas.android.update.ReleaseCheck
|
||||
import eu.llembas.android.update.UpdateOffer
|
||||
import eu.llembas.android.update.UpdateResult
|
||||
import eu.llembas.android.update.Updater
|
||||
import eu.llembas.android.update.checksUpdates
|
||||
import eu.llembas.android.update.offersBetas
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/** What the settings page does; every action has a do-nothing default for the screenshots. */
|
||||
@@ -95,6 +104,10 @@ interface SettingsActions {
|
||||
fun assistantListens(on: Boolean) {}
|
||||
fun readAloud(on: Boolean) {}
|
||||
fun checkUpdate() {}
|
||||
fun openRelease() {}
|
||||
fun installUpdate() {}
|
||||
fun updateCheck(on: Boolean) {}
|
||||
fun updateBetas(on: Boolean) {}
|
||||
}
|
||||
|
||||
/** What the settings page shows. */
|
||||
@@ -105,8 +118,12 @@ data class SettingsState(
|
||||
val hasDistributor: Boolean = false,
|
||||
val pushNote: String? = null,
|
||||
val updateNote: String? = null,
|
||||
/** A newer release the last check found: the row opens its page, the full build can install it. */
|
||||
val updateFound: String? = null,
|
||||
val version: String = "",
|
||||
val selfUpdate: Boolean = false,
|
||||
/** Whether the app itself is a beta: the update settings' defaults follow it. */
|
||||
val beta: Boolean = false,
|
||||
/** Whether the phone has a speech recogniser of its own (Settings › Voice input › Phone). */
|
||||
val phoneRecognizer: Boolean = false,
|
||||
)
|
||||
@@ -121,6 +138,8 @@ fun SettingsScreen(onBack: () -> Unit, onAddInstance: () -> Unit) {
|
||||
val prefs by store.prefs.collectAsState(initial = Prefs())
|
||||
var pushNote by remember { mutableStateOf<String?>(null) }
|
||||
var updateNote by remember { mutableStateOf<String?>(null) }
|
||||
var updateFound by remember { mutableStateOf<UpdateOffer?>(null) }
|
||||
val beta = remember { AppVersion.parse(BuildConfig.VERSION_NAME)?.isBeta ?: false }
|
||||
val distributors = remember { Push.distributors(context) }
|
||||
val actions = remember {
|
||||
object : SettingsActions {
|
||||
@@ -182,8 +201,40 @@ fun SettingsScreen(onBack: () -> Unit, onAddInstance: () -> Unit) {
|
||||
}
|
||||
|
||||
override fun checkUpdate() {
|
||||
updateNote = context.getString(R.string.update_checking)
|
||||
scope.launch {
|
||||
when (val found = ReleaseCheck(context).check()) {
|
||||
is UpdateResult.Newer -> {
|
||||
updateFound = found.offer
|
||||
updateNote = context.getString(R.string.update_available, found.offer.version.toString())
|
||||
}
|
||||
|
||||
UpdateResult.Current -> {
|
||||
updateFound = null
|
||||
updateNote = context.getString(R.string.update_none)
|
||||
}
|
||||
|
||||
UpdateResult.Unreachable -> updateNote = context.getString(R.string.update_unreachable)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun openRelease() {
|
||||
updateFound?.let { offer -> runCatching { context.startActivity(ReleaseCheck.open(offer.page)) } }
|
||||
}
|
||||
|
||||
// The full build's own installer, for a release (llembas.eu names its APK and hash).
|
||||
override fun installUpdate() {
|
||||
scope.launch { updateNote = Updater(context).checkAndOffer() }
|
||||
}
|
||||
|
||||
override fun updateCheck(on: Boolean) {
|
||||
scope.launch { store.savePrefs { it.copy(updateCheck = on) } }
|
||||
}
|
||||
|
||||
override fun updateBetas(on: Boolean) {
|
||||
scope.launch { store.savePrefs { it.copy(updateBetas = on) } }
|
||||
}
|
||||
}
|
||||
}
|
||||
SettingsContent(
|
||||
@@ -194,8 +245,10 @@ fun SettingsScreen(onBack: () -> Unit, onAddInstance: () -> Unit) {
|
||||
hasDistributor = distributors.isNotEmpty(),
|
||||
pushNote = pushNote,
|
||||
updateNote = updateNote,
|
||||
updateFound = updateFound?.version?.toString(),
|
||||
version = BuildConfig.VERSION_NAME,
|
||||
selfUpdate = BuildConfig.SELF_UPDATE,
|
||||
beta = beta,
|
||||
phoneRecognizer = remember { PhoneRecognizer.available(context) },
|
||||
),
|
||||
actions,
|
||||
@@ -402,15 +455,42 @@ fun SettingsContent(state: SettingsState, actions: SettingsActions, onBack: () -
|
||||
item {
|
||||
Group(stringResource(R.string.settings_about)) {
|
||||
SettingRow(Icons.Filled.Info, stringResource(R.string.about_version, state.version), onClick = {})
|
||||
if (state.selfUpdate) {
|
||||
Rule()
|
||||
// A found release: the row opens its page; until then it checks.
|
||||
SettingRow(
|
||||
Icons.Filled.SystemUpdate,
|
||||
stringResource(R.string.update_check),
|
||||
subtitle = state.updateNote,
|
||||
onClick = if (state.updateFound != null) actions::openRelease else actions::checkUpdate,
|
||||
)
|
||||
// The full build installs a release itself; a beta is installed from its page.
|
||||
val found = state.updateFound
|
||||
if (state.selfUpdate && found != null && !found.contains("-")) {
|
||||
Rule()
|
||||
SettingRow(
|
||||
Icons.Filled.SystemUpdate,
|
||||
stringResource(R.string.update_check),
|
||||
subtitle = state.updateNote,
|
||||
onClick = actions::checkUpdate,
|
||||
Icons.Filled.Download,
|
||||
stringResource(R.string.update_install, found),
|
||||
onClick = actions::installUpdate,
|
||||
)
|
||||
}
|
||||
Rule()
|
||||
val checks = state.prefs.checksUpdates(state.beta)
|
||||
SettingRow(
|
||||
Icons.Filled.Update,
|
||||
stringResource(R.string.update_auto),
|
||||
subtitle = stringResource(R.string.update_auto_line),
|
||||
onClick = { actions.updateCheck(!checks) },
|
||||
trailing = { Switch(checked = checks, onCheckedChange = actions::updateCheck) },
|
||||
)
|
||||
Rule()
|
||||
val betas = state.prefs.offersBetas(state.beta)
|
||||
SettingRow(
|
||||
Icons.Filled.Science,
|
||||
stringResource(R.string.update_betas),
|
||||
subtitle = stringResource(R.string.update_betas_line),
|
||||
onClick = { actions.updateBetas(!betas) },
|
||||
trailing = { Switch(checked = betas, onCheckedChange = actions::updateBetas) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
package eu.llembas.android.update
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Notification
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import eu.llembas.android.BuildConfig
|
||||
import eu.llembas.android.LembasApp
|
||||
import eu.llembas.android.R
|
||||
import eu.llembas.android.api.LembasJson
|
||||
import eu.llembas.android.api.SharedHttp
|
||||
import eu.llembas.android.api.await
|
||||
import eu.llembas.android.auth.Prefs
|
||||
import eu.llembas.android.lembas
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
import okhttp3.Request
|
||||
|
||||
/** A version as the releases name it: `1.2.3`, or `1.2.3-beta.4`, which sorts below `1.2.3`. */
|
||||
data class AppVersion(val major: Int, val minor: Int, val patch: Int, val beta: Int?) : Comparable<AppVersion> {
|
||||
val isBeta: Boolean get() = beta != null
|
||||
|
||||
override fun compareTo(other: AppVersion): Int = compareValuesBy(
|
||||
this,
|
||||
other,
|
||||
{ it.major },
|
||||
{ it.minor },
|
||||
{ it.patch },
|
||||
// A release sorts above every beta of itself.
|
||||
{ it.beta ?: Int.MAX_VALUE },
|
||||
)
|
||||
|
||||
override fun toString(): String = "$major.$minor.$patch" + (beta?.let { "-beta.$it" } ?: "")
|
||||
|
||||
companion object {
|
||||
private val SHAPE = Regex("""^v?(\d+)\.(\d+)\.(\d+)(?:-beta\.(\d+))?$""")
|
||||
|
||||
/**
|
||||
* A tag or a version name; a test build's `-debug…` is left off first. Anything else
|
||||
* (`-rc.1`, a typo) is not a version this check knows, and is never offered.
|
||||
*/
|
||||
fun parse(text: String): AppVersion? {
|
||||
val match = SHAPE.matchEntire(text.trim().substringBefore("-debug")) ?: return null
|
||||
val (a, b, c, beta) = match.destructured
|
||||
return AppVersion(a.toInt(), b.toInt(), c.toInt(), beta.takeIf { it.isNotEmpty() }?.toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** One of GitHub's releases, as far as the check needs it. */
|
||||
@Serializable
|
||||
data class PublicRelease(
|
||||
@SerialName("tag_name") val tag: String,
|
||||
val prerelease: Boolean = false,
|
||||
val draft: Boolean = false,
|
||||
@SerialName("html_url") val page: String = "",
|
||||
)
|
||||
|
||||
/** A newer release to tell the person about: its version and the page its APKs are on. */
|
||||
data class UpdateOffer(val version: AppVersion, val page: String)
|
||||
|
||||
/** What a check found. */
|
||||
sealed interface UpdateResult {
|
||||
data class Newer(val offer: UpdateOffer) : UpdateResult
|
||||
|
||||
data object Current : UpdateResult
|
||||
|
||||
data object Unreachable : UpdateResult
|
||||
}
|
||||
|
||||
/**
|
||||
* The update check: the public releases of the app on GitHub, read over plain HTTPS -- no
|
||||
* Google service, no account, nothing sent but the request itself. It runs when the app starts,
|
||||
* at most once a day and only while Settings › About › *Look for new versions* is on (on by
|
||||
* default in a beta, off in a release), and when the person taps *Check for an update*. A newer
|
||||
* release becomes a notification that opens its page, where the APKs are; installing stays the
|
||||
* person's step (or F-Droid's, or Obtainium's).
|
||||
*
|
||||
* Betas are offered to a beta, or to anyone who turned *Include betas* on.
|
||||
*/
|
||||
class ReleaseCheck(private val context: Context) {
|
||||
suspend fun check(): UpdateResult = withContext(Dispatchers.IO) {
|
||||
val prefs = context.lembas.instances.prefs.first()
|
||||
val installed = AppVersion.parse(BuildConfig.VERSION_NAME) ?: return@withContext UpdateResult.Current
|
||||
try {
|
||||
val releases = SharedHttp.newCall(
|
||||
Request.Builder().url(RELEASES).header("Accept", "application/vnd.github+json").build(),
|
||||
).await().use {
|
||||
if (!it.isSuccessful) return@withContext UpdateResult.Unreachable
|
||||
LembasJson.decodeFromString(ListSerializer(PublicRelease.serializer()), it.body!!.string())
|
||||
}
|
||||
newest(releases, installed, prefs.offersBetas(installed.isBeta))
|
||||
?.let { UpdateResult.Newer(it) } ?: UpdateResult.Current
|
||||
} catch (e: Exception) {
|
||||
UpdateResult.Unreachable
|
||||
}
|
||||
}
|
||||
|
||||
/** On start: once a day at most, when the setting is on; a release is announced once. */
|
||||
suspend fun daily(now: Long = System.currentTimeMillis()) {
|
||||
val store = context.lembas.instances
|
||||
val prefs = store.prefs.first()
|
||||
val installed = AppVersion.parse(BuildConfig.VERSION_NAME) ?: return
|
||||
if (!prefs.checksUpdates(installed.isBeta) || !due(prefs.updateCheckedAt, now)) return
|
||||
val found = check()
|
||||
if (found == UpdateResult.Unreachable) return
|
||||
store.savePrefs { it.copy(updateCheckedAt = now) }
|
||||
val offer = (found as? UpdateResult.Newer)?.offer ?: return
|
||||
if (offer.version.toString() == prefs.updateNotified) return
|
||||
notify(offer)
|
||||
store.savePrefs { it.copy(updateNotified = offer.version.toString()) }
|
||||
}
|
||||
|
||||
fun notify(offer: UpdateOffer) {
|
||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) return
|
||||
val page = PendingIntent.getActivity(
|
||||
context,
|
||||
NOTIFICATION,
|
||||
open(offer.page),
|
||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
|
||||
)
|
||||
val text = context.getString(R.string.update_notice_text)
|
||||
val notice = NotificationCompat.Builder(context, LembasApp.CHANNEL_UPDATES)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(context.getString(R.string.update_notice_title, offer.version.toString()))
|
||||
.setContentText(text)
|
||||
.setStyle(NotificationCompat.BigTextStyle().bigText(text))
|
||||
.setContentIntent(page)
|
||||
.setAutoCancel(true)
|
||||
.setCategory(Notification.CATEGORY_RECOMMENDATION)
|
||||
// Nothing from the account: the app's version is fine on a locked screen.
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
.build()
|
||||
NotificationManagerCompat.from(context).notify(NOTIFICATION, notice)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val REPOSITORY = "https://github.com/LLeMbas/LLeMbas-Android"
|
||||
const val RELEASES = "https://api.github.com/repos/LLeMbas/LLeMbas-Android/releases?per_page=30"
|
||||
private const val DAY_MS = 24L * 60 * 60 * 1000
|
||||
private const val NOTIFICATION = 0x11e4
|
||||
|
||||
/** The newest release later than [installed] that may be offered; drafts never are. */
|
||||
fun newest(releases: List<PublicRelease>, installed: AppVersion, betas: Boolean): UpdateOffer? = releases
|
||||
.asSequence()
|
||||
.filter { !it.draft }
|
||||
.mapNotNull { r -> AppVersion.parse(r.tag)?.let { it to r } }
|
||||
// A pre-release is a beta whatever its tag says, and a beta tag is one whatever GitHub says.
|
||||
.filter { (v, r) -> betas || (!v.isBeta && !r.prerelease) }
|
||||
.filter { (v, _) -> v > installed }
|
||||
.maxByOrNull { (v, _) -> v }
|
||||
?.let { (v, r) -> UpdateOffer(v, r.page.ifBlank { "$REPOSITORY/releases/tag/${r.tag}" }) }
|
||||
|
||||
fun due(last: Long, now: Long): Boolean = last <= 0 || now - last >= DAY_MS || now < last
|
||||
|
||||
fun open(url: String): Intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
}
|
||||
|
||||
/** *Look for new versions*: as chosen, else on in a beta and off in a release. */
|
||||
fun Prefs.checksUpdates(installedIsBeta: Boolean): Boolean = updateCheck ?: installedIsBeta
|
||||
|
||||
/** *Include betas*: as chosen, else on in a beta and off in a release. */
|
||||
fun Prefs.offersBetas(installedIsBeta: Boolean): Boolean = updateBetas ?: installedIsBeta
|
||||
@@ -319,6 +319,16 @@
|
||||
<string name="update_allow_installs">Povolte aplikaci LLeMbas instalovat aktualizace a pak to zkontrolujte znovu.</string>
|
||||
<string name="update_bad_file">Stažený soubor neodpovídal verzi a byl zahozen.</string>
|
||||
<string name="update_installing">Instaluje se %1$s…</string>
|
||||
<string name="update_checking">Kontroluje se…</string>
|
||||
<string name="update_available">Je k dispozici %1$s. Klepnutím otevřete stránku vydání.</string>
|
||||
<string name="update_install">Nainstalovat %1$s</string>
|
||||
<string name="update_auto">Hledat nové verze</string>
|
||||
<string name="update_auto_line">Nejvýš jednou denně, při spuštění, si aplikace přečte z GitHubu seznam vydání LLeMbas pro Android a upozorněním vám dá vědět, když je k dispozici novější. Nic o vás ani o vaší instanci se neposílá. Ve verzi beta zapnuto, jinak vypnuto.</string>
|
||||
<string name="update_betas">Včetně beta verzí</string>
|
||||
<string name="update_betas_line">Nabízet i testovací verze, nejen vydání. Zapnuto, když je tato aplikace sama beta.</string>
|
||||
<string name="channel_updates">Aktualizace aplikace</string>
|
||||
<string name="update_notice_title">LLeMbas pro Android %1$s</string>
|
||||
<string name="update_notice_text">Je k dispozici novější verze. Klepnutím otevřete stránku vydání.</string>
|
||||
<string name="assist_hint">Zeptejte se na cokoli</string>
|
||||
<string name="assist_signed_out">Nejprve se v aplikaci přihlaste k instanci LLeMbas.</string>
|
||||
<string name="assist_open_app">Otevřít aplikaci</string>
|
||||
|
||||
@@ -319,6 +319,16 @@
|
||||
<string name="update_allow_installs">Erlauben Sie LLeMbas, Updates zu installieren, und prüfen Sie dann erneut.</string>
|
||||
<string name="update_bad_file">Der Download stimmte nicht mit der Version überein und wurde verworfen.</string>
|
||||
<string name="update_installing">%1$s wird installiert…</string>
|
||||
<string name="update_checking">Wird geprüft…</string>
|
||||
<string name="update_available">%1$s ist verfügbar. Tippen Sie, um die Release-Seite zu öffnen.</string>
|
||||
<string name="update_install">%1$s installieren</string>
|
||||
<string name="update_auto">Nach neuen Versionen suchen</string>
|
||||
<string name="update_auto_line">Höchstens einmal am Tag, beim Start, liest die App die Liste der Releases von LLeMbas für Android auf GitHub und meldet per Benachrichtigung, wenn es eine neuere gibt. Nichts über Sie oder Ihre Instanz wird gesendet. In einer Beta standardmäßig an, sonst aus.</string>
|
||||
<string name="update_betas">Betas einbeziehen</string>
|
||||
<string name="update_betas_line">Auch Testversionen anbieten, nicht nur Releases. Standardmäßig an, wenn diese App selbst eine Beta ist.</string>
|
||||
<string name="channel_updates">App-Updates</string>
|
||||
<string name="update_notice_title">LLeMbas für Android %1$s</string>
|
||||
<string name="update_notice_text">Eine neuere Version ist verfügbar. Tippen Sie, um die Release-Seite zu öffnen.</string>
|
||||
<string name="assist_hint">Fragen Sie irgendetwas</string>
|
||||
<string name="assist_signed_out">Melden Sie sich zuerst in der App bei einer LLeMbas-Instanz an.</string>
|
||||
<string name="assist_open_app">App öffnen</string>
|
||||
|
||||
@@ -319,6 +319,16 @@
|
||||
<string name="update_allow_installs">Permita que LLeMbas instale actualizaciones y vuelva a comprobarlo.</string>
|
||||
<string name="update_bad_file">La descarga no coincidía con la versión y se descartó.</string>
|
||||
<string name="update_installing">Instalando %1$s…</string>
|
||||
<string name="update_checking">Comprobando…</string>
|
||||
<string name="update_available">%1$s está disponible. Toque para abrir su página de publicación.</string>
|
||||
<string name="update_install">Instalar %1$s</string>
|
||||
<string name="update_auto">Buscar nuevas versiones</string>
|
||||
<string name="update_auto_line">Como mucho una vez al día, al iniciarse, la aplicación lee en GitHub la lista de versiones de LLeMbas para Android y le avisa con una notificación cuando hay una más reciente. No se envía nada sobre usted ni sobre su instancia. Activado por defecto en una beta; si no, desactivado.</string>
|
||||
<string name="update_betas">Incluir betas</string>
|
||||
<string name="update_betas_line">Ofrecer también versiones de prueba, no solo publicaciones. Activado por defecto cuando esta aplicación es una beta.</string>
|
||||
<string name="channel_updates">Actualizaciones de la aplicación</string>
|
||||
<string name="update_notice_title">LLeMbas para Android %1$s</string>
|
||||
<string name="update_notice_text">Hay una versión más reciente. Toque para abrir su página de publicación.</string>
|
||||
<string name="assist_hint">Pregunte lo que quiera</string>
|
||||
<string name="assist_signed_out">Primero inicie sesión en una instancia de LLeMbas en la aplicación.</string>
|
||||
<string name="assist_open_app">Abrir la aplicación</string>
|
||||
|
||||
@@ -319,6 +319,16 @@
|
||||
<string name="update_allow_installs">Autorisez LLeMbas à installer des mises à jour, puis vérifiez à nouveau.</string>
|
||||
<string name="update_bad_file">Le téléchargement ne correspondait pas à la version et a été rejeté.</string>
|
||||
<string name="update_installing">Installation de %1$s…</string>
|
||||
<string name="update_checking">Vérification…</string>
|
||||
<string name="update_available">%1$s est disponible. Touchez pour ouvrir sa page de publication.</string>
|
||||
<string name="update_install">Installer %1$s</string>
|
||||
<string name="update_auto">Rechercher de nouvelles versions</string>
|
||||
<string name="update_auto_line">Au plus une fois par jour, au démarrage, l’application lit sur GitHub la liste des versions de LLeMbas pour Android et vous prévient par une notification lorsqu’il en existe une plus récente. Rien sur vous ni sur votre instance n’est envoyé. Activé par défaut dans une bêta, désactivé sinon.</string>
|
||||
<string name="update_betas">Inclure les bêtas</string>
|
||||
<string name="update_betas_line">Proposer aussi les versions de test, pas seulement les publications. Activé par défaut quand cette application est elle-même une bêta.</string>
|
||||
<string name="channel_updates">Mises à jour de l’application</string>
|
||||
<string name="update_notice_title">LLeMbas pour Android %1$s</string>
|
||||
<string name="update_notice_text">Une version plus récente est disponible. Touchez pour ouvrir sa page de publication.</string>
|
||||
<string name="assist_hint">Demandez n\'importe quoi</string>
|
||||
<string name="assist_signed_out">Connectez-vous d\'abord à une instance LLeMbas dans l\'application.</string>
|
||||
<string name="assist_open_app">Ouvrir l\'application</string>
|
||||
|
||||
@@ -319,6 +319,16 @@
|
||||
<string name="update_allow_installs">Engedélyezze, hogy az LLeMbas frissítéseket telepítsen, majd ellenőrizze újra.</string>
|
||||
<string name="update_bad_file">A letöltés nem egyezett a verzióval, és el lett dobva.</string>
|
||||
<string name="update_installing">%1$s telepítése…</string>
|
||||
<string name="update_checking">Ellenőrzés…</string>
|
||||
<string name="update_available">Elérhető a(z) %1$s. Koppintson a kiadás oldalának megnyitásához.</string>
|
||||
<string name="update_install">%1$s telepítése</string>
|
||||
<string name="update_auto">Új verziók keresése</string>
|
||||
<string name="update_auto_line">Naponta legfeljebb egyszer, induláskor az alkalmazás beolvassa a GitHubról a LLeMbas Androidra kiadásainak listáját, és értesítésben jelzi, ha van újabb. Önről és a példányáról semmit sem küld. Béta verzióban alapból bekapcsolva, egyébként kikapcsolva.</string>
|
||||
<string name="update_betas">Béták is</string>
|
||||
<string name="update_betas_line">Tesztverziók felajánlása is, nem csak kiadásoké. Alapból bekapcsolva, ha ez az alkalmazás maga is béta.</string>
|
||||
<string name="channel_updates">Alkalmazásfrissítések</string>
|
||||
<string name="update_notice_title">LLeMbas Androidra %1$s</string>
|
||||
<string name="update_notice_text">Újabb verzió érhető el. Koppintson a kiadás oldalának megnyitásához.</string>
|
||||
<string name="assist_hint">Kérdezzen bármit</string>
|
||||
<string name="assist_signed_out">Először jelentkezzen be egy LLeMbas példányba az alkalmazásban.</string>
|
||||
<string name="assist_open_app">Alkalmazás megnyitása</string>
|
||||
|
||||
@@ -319,6 +319,16 @@
|
||||
<string name="update_allow_installs">Consenti a LLeMbas di installare gli aggiornamenti, poi controlla di nuovo.</string>
|
||||
<string name="update_bad_file">Il download non corrispondeva alla versione ed è stato scartato.</string>
|
||||
<string name="update_installing">Installazione di %1$s…</string>
|
||||
<string name="update_checking">Controllo in corso…</string>
|
||||
<string name="update_available">%1$s è disponibile. Tocca per aprire la pagina della release.</string>
|
||||
<string name="update_install">Installa %1$s</string>
|
||||
<string name="update_auto">Cerca nuove versioni</string>
|
||||
<string name="update_auto_line">Al massimo una volta al giorno, all’avvio, l’app legge da GitHub l’elenco delle release di LLeMbas per Android e la avvisa con una notifica quando ce n’è una più recente. Non viene inviato nulla su di lei o sulla sua istanza. Attivo per impostazione predefinita in una beta, altrimenti disattivato.</string>
|
||||
<string name="update_betas">Includi le beta</string>
|
||||
<string name="update_betas_line">Offri anche le versioni di prova, non solo le release. Attivo per impostazione predefinita quando questa app è essa stessa una beta.</string>
|
||||
<string name="channel_updates">Aggiornamenti dell’app</string>
|
||||
<string name="update_notice_title">LLeMbas per Android %1$s</string>
|
||||
<string name="update_notice_text">È disponibile una versione più recente. Tocca per aprire la pagina della release.</string>
|
||||
<string name="assist_hint">Chiedi qualsiasi cosa</string>
|
||||
<string name="assist_signed_out">Accedi prima a un\'istanza LLeMbas nell\'app.</string>
|
||||
<string name="assist_open_app">Apri l\'app</string>
|
||||
|
||||
@@ -319,6 +319,16 @@
|
||||
<string name="update_allow_installs">Zezwól LLeMbas na instalowanie aktualizacji, a potem sprawdź ponownie.</string>
|
||||
<string name="update_bad_file">Pobrany plik nie zgadzał się z wersją i został odrzucony.</string>
|
||||
<string name="update_installing">Instalowanie %1$s…</string>
|
||||
<string name="update_checking">Sprawdzanie…</string>
|
||||
<string name="update_available">Dostępna jest wersja %1$s. Dotknij, aby otworzyć jej stronę wydania.</string>
|
||||
<string name="update_install">Zainstaluj %1$s</string>
|
||||
<string name="update_auto">Szukaj nowych wersji</string>
|
||||
<string name="update_auto_line">Najwyżej raz dziennie, przy uruchomieniu, aplikacja odczytuje z GitHuba listę wydań LLeMbas na Androida i daje znać powiadomieniem, gdy jest nowsza. Nic o tobie ani o twojej instancji nie jest wysyłane. W wersji beta domyślnie włączone, w przeciwnym razie wyłączone.</string>
|
||||
<string name="update_betas">Uwzględniaj bety</string>
|
||||
<string name="update_betas_line">Proponuj też wersje testowe, nie tylko wydania. Domyślnie włączone, gdy ta aplikacja sama jest betą.</string>
|
||||
<string name="channel_updates">Aktualizacje aplikacji</string>
|
||||
<string name="update_notice_title">LLeMbas na Androida %1$s</string>
|
||||
<string name="update_notice_text">Dostępna jest nowsza wersja. Dotknij, aby otworzyć jej stronę wydania.</string>
|
||||
<string name="assist_hint">Zapytaj o cokolwiek</string>
|
||||
<string name="assist_signed_out">Najpierw zaloguj się do instancji LLeMbas w aplikacji.</string>
|
||||
<string name="assist_open_app">Otwórz aplikację</string>
|
||||
|
||||
@@ -319,6 +319,16 @@
|
||||
<string name="update_allow_installs">Povoľte aplikácii LLeMbas instalovať aktualizácie a potom to skontrolujte znova.</string>
|
||||
<string name="update_bad_file">Stiahnutý súbor nezodpovedal verzii a bol zahodený.</string>
|
||||
<string name="update_installing">Inštaluje sa %1$s…</string>
|
||||
<string name="update_checking">Kontroluje sa…</string>
|
||||
<string name="update_available">Je dostupná %1$s. Ťuknutím otvoríte stránku vydania.</string>
|
||||
<string name="update_install">Nainštalovať %1$s</string>
|
||||
<string name="update_auto">Hľadať nové verzie</string>
|
||||
<string name="update_auto_line">Najviac raz denne, pri spustení, si aplikácia prečíta z GitHubu zoznam vydaní LLeMbas pre Android a upozornením vám dá vedieť, keď je dostupná novšia. Nič o vás ani o vašej inštancii sa neposiela. V beta verzii zapnuté, inak vypnuté.</string>
|
||||
<string name="update_betas">Vrátane beta verzií</string>
|
||||
<string name="update_betas_line">Ponúkať aj testovacie verzie, nielen vydania. Zapnuté, keď je táto aplikácia sama beta.</string>
|
||||
<string name="channel_updates">Aktualizácie aplikácie</string>
|
||||
<string name="update_notice_title">LLeMbas pre Android %1$s</string>
|
||||
<string name="update_notice_text">Je dostupná novšia verzia. Ťuknutím otvoríte stránku vydania.</string>
|
||||
<string name="assist_hint">Spýtajte sa na čokoľvek</string>
|
||||
<string name="assist_signed_out">Najprv sa v aplikácii prihláste do inštancie LLeMbas.</string>
|
||||
<string name="assist_open_app">Otvoriť aplikáciu</string>
|
||||
|
||||
@@ -321,6 +321,16 @@
|
||||
<string name="update_allow_installs">Allow LLeMbas to install updates, then check again.</string>
|
||||
<string name="update_bad_file">The download did not match the release and was discarded.</string>
|
||||
<string name="update_installing">Installing %1$s…</string>
|
||||
<string name="update_checking">Checking…</string>
|
||||
<string name="update_available">%1$s is available. Tap to open its release page.</string>
|
||||
<string name="update_install">Install %1$s</string>
|
||||
<string name="update_auto">Look for new versions</string>
|
||||
<string name="update_auto_line">At most once a day, when the app starts, it reads the list of LLeMbas for Android releases from GitHub and tells you in a notification when there is a newer one. Nothing about you or your instance is sent. On by default in a beta, off otherwise.</string>
|
||||
<string name="update_betas">Include betas</string>
|
||||
<string name="update_betas_line">Offer test versions as well as releases. On by default when this app is itself a beta.</string>
|
||||
<string name="channel_updates">App updates</string>
|
||||
<string name="update_notice_title">LLeMbas for Android %1$s</string>
|
||||
<string name="update_notice_text">A newer version is available. Tap to open its release page.</string>
|
||||
<string name="assist_hint">Ask anything</string>
|
||||
<string name="assist_signed_out">Sign in to a LLeMbas instance in the app first.</string>
|
||||
<string name="assist_open_app">Open the app</string>
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package eu.llembas.android
|
||||
|
||||
import eu.llembas.android.api.LembasJson
|
||||
import eu.llembas.android.auth.Prefs
|
||||
import eu.llembas.android.update.AppVersion
|
||||
import eu.llembas.android.update.PublicRelease
|
||||
import eu.llembas.android.update.ReleaseCheck
|
||||
import eu.llembas.android.update.checksUpdates
|
||||
import eu.llembas.android.update.offersBetas
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class UpdateCheckTest {
|
||||
private fun v(text: String) = AppVersion.parse(text)!!
|
||||
|
||||
@Test
|
||||
fun versionsSortAsTheirCodesDo() {
|
||||
assertTrue(v("1.0.0-beta.2") > v("1.0.0-beta.1"))
|
||||
assertTrue(v("1.0.0-beta.10") > v("1.0.0-beta.9"))
|
||||
assertTrue(v("1.0.0") > v("1.0.0-beta.99"))
|
||||
assertTrue(v("1.0.1-beta.1") > v("1.0.0"))
|
||||
assertEquals(v("v1.2.3"), v("1.2.3"))
|
||||
// A test build's suffix is not part of the version.
|
||||
assertEquals(v("1.0.0-beta.5"), v("1.0.0-beta.5-debug.44"))
|
||||
assertNull(AppVersion.parse("1.0.0-rc.1"))
|
||||
assertNull(AppVersion.parse("latest"))
|
||||
}
|
||||
|
||||
// GitHub's answer, cut to what the check reads plus a field it does not.
|
||||
private val releases = LembasJson.decodeFromString(
|
||||
ListSerializer(PublicRelease.serializer()),
|
||||
"""
|
||||
[
|
||||
{"tag_name": "v1.1.0-beta.1", "prerelease": true, "draft": false, "html_url": "https://example.org/b1", "assets": []},
|
||||
{"tag_name": "v1.0.1", "prerelease": false, "draft": false, "html_url": "https://example.org/101"},
|
||||
{"tag_name": "v1.2.0", "prerelease": false, "draft": true, "html_url": "https://example.org/draft"},
|
||||
{"tag_name": "v1.0.0", "prerelease": false, "html_url": "https://example.org/100"},
|
||||
{"tag_name": "nightly", "prerelease": true}
|
||||
]
|
||||
""",
|
||||
)
|
||||
|
||||
@Test
|
||||
fun aReleaseIsOfferedTheNewestItMayHave() {
|
||||
// A release without betas: the newest release, never the draft.
|
||||
val stable = ReleaseCheck.newest(releases, v("1.0.0"), betas = false)!!
|
||||
assertEquals(v("1.0.1"), stable.version)
|
||||
assertEquals("https://example.org/101", stable.page)
|
||||
// With betas: the beta above it.
|
||||
assertEquals(v("1.1.0-beta.1"), ReleaseCheck.newest(releases, v("1.0.0"), betas = true)!!.version)
|
||||
// Nothing newer: nothing offered.
|
||||
assertNull(ReleaseCheck.newest(releases, v("1.1.0-beta.1"), betas = true))
|
||||
assertNull(ReleaseCheck.newest(releases, v("1.0.1"), betas = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theSettingsFollowTheInstalledChannelUntilChosen() {
|
||||
val unset = Prefs()
|
||||
assertTrue(unset.checksUpdates(installedIsBeta = true))
|
||||
assertFalse(unset.checksUpdates(installedIsBeta = false))
|
||||
assertTrue(unset.offersBetas(installedIsBeta = true))
|
||||
assertFalse(unset.offersBetas(installedIsBeta = false))
|
||||
assertFalse(Prefs(updateCheck = false).checksUpdates(installedIsBeta = true))
|
||||
assertTrue(Prefs(updateBetas = true).offersBetas(installedIsBeta = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun onceADayAtMost() {
|
||||
val day = 24L * 60 * 60 * 1000
|
||||
assertTrue(ReleaseCheck.due(0, 5))
|
||||
assertFalse(ReleaseCheck.due(1_000, 1_000 + day - 1))
|
||||
assertTrue(ReleaseCheck.due(1_000, 1_000 + day))
|
||||
// A clock set back is not a reason to wait a year.
|
||||
assertTrue(ReleaseCheck.due(10 * day, day))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user