Contract at server dev e0c2332; the update check asks the instance first (GET /api/v2/apps)
CI / check (push) Canceled after 0s

Re-pinned at e0c2332 (after 2a2b24f /apps, 57d06ee schedules on a computer, e0c2332
force_tool on POST /chats): apps.json, apps_stable.json, schedule_on_device.json; `runs_on`
on schedules (parsed by the rest, not drawn yet); the schedules frame's version hash.

ReleaseCheck: the instance's recommendation first (it knows which release speaks its
/api/v2); a beta only with Include betas; a null android means no offer. A server without the
route, none signed in or none reachable falls back to GitHub's list as before. The About line
says so (8 translations). UpdateCheckTest reads both fixtures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 14:05:38 +00:00
1 parent 9b1bf688a1
commit a5c4fdc128
26 files changed
+237 -27

No files matched your search

@@ -171,6 +171,9 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
/** The folder and the folders inside it; their chats fall back to no folder. */
suspend fun deleteFolder(id: String) = empty(authed("$v2/folders/${segment(id)}").delete().build())
/** The app releases this server recommends; 404 from a server older than the route. */
suspend fun apps(): AppsInfo = get("/apps")
/** The web's search in JSON: chats by their words (and meaning, where indexed), files, memories. */
suspend fun search(q: String, within: String = "all", limit: Int = 20): SearchResults = get("/search?q=${segment(q)}&in=${segment(within)}&limit=$limit")
@@ -220,6 +220,22 @@ data class SearchResults(
fun hits(kind: String): List<SearchHit> = results.firstOrNull { it.kind == kind }?.hits.orEmpty()
}
/** One app release the server recommends (`GET /api/v2/apps`), with the page its files are on. */
@Serializable
data class AppRelease(val version: String = "", val tag: String = "", val channel: String = "", val page: String = "")
@Serializable
data class ServerChannel(val version: String = "", val channel: String = "")
/**
* Which release of each app goes with this server: a stable server names only a stable app, a
* beta server the newer of the app's stable and beta. Null for an app it recommends none of.
*/
@Serializable
data class AppsInfo(val server: ServerChannel = ServerChannel(), val apps: Map<String, AppRelease?> = emptyMap()) {
val android: AppRelease? get() = apps["android"]
}
/** A data group: whose records a memory is kept among. */
@Serializable
data class DataGroup(val id: String = "", val name: String = "")
@@ -13,6 +13,7 @@ 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.AppsInfo
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.SharedHttp
import eu.llembas.android.api.await
@@ -79,7 +80,9 @@ sealed interface UpdateResult {
}
/**
* The update check: the public releases of the app on GitHub, read over plain HTTPS -- no
* The update check: the release the instance recommends (`GET /api/v2/apps`), which knows what
* speaks its API; from a server without that, 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
@@ -92,6 +95,13 @@ 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
// The instance first: it knows which release speaks its /api/v2. Only a server without
// the route (or none signed in, or none reachable) leaves it to GitHub's list.
val server = runCatching { context.lembas.instances.client()?.apps() }.getOrNull()
if (server != null) {
return@withContext recommended(server, installed, prefs.offersBetas(installed.isBeta))
?.let { UpdateResult.Newer(it) } ?: UpdateResult.Current
}
try {
val releases = SharedHttp.newCall(
Request.Builder().url(RELEASES).header("Accept", "application/vnd.github+json").build(),
@@ -161,6 +171,20 @@ class ReleaseCheck(private val context: Context) {
.maxByOrNull { (v, _) -> v }
?.let { (v, r) -> UpdateOffer(v, r.page.ifBlank { "$REPOSITORY/releases/tag/${r.tag}" }) }
/**
* The server's recommendation, when it is newer than [installed] and may be offered: a
* beta only with [betas]. None recommended (null) is no offer -- the server knows no
* Android release that speaks its API, so none is pushed.
*/
fun recommended(info: AppsInfo, installed: AppVersion, betas: Boolean): UpdateOffer? {
val app = info.android ?: return null
val version = AppVersion.parse(app.version) ?: return null
if (version.isBeta && !betas) return null
if (version <= installed) return null
val tag = app.tag.ifBlank { "v$version" }
return UpdateOffer(version, app.page.takeIf { it.startsWith("https://") } ?: "$REPOSITORY/releases/tag/$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)