fix(runtime): fetch the KDE language-pack index directly from GitHub (#2845)

The index carries the sha256 of every language pack, so loading it through a download mirror let the mirror pick both the hash and the pack that gets extracted into the Linux runtime. The index now always comes straight from GitHub; pack bodies can still use mirrors since their hash is trusted.

Co-authored-by: Tapuuk <177422350+Tapuuk@users.noreply.github.com>
This commit is contained in:
TapuukandTapuuk authored and GitHub committed 2026-11-24 16:18:15 -05:00
1 parent 31c475d5e1
commit 8f0e124b5d
2 files changed
+66 -1

No files matched your search

@@ -32,6 +32,9 @@ object DesktopLanguage {
internal fun baseUrl(desktopUrl: String) = desktopUrl.substringBeforeLast('/') + "/"
/** The index carries every pack's sha256, so it never goes through a download mirror. */
internal fun fetchIndex(base: String): Map<String, Pack>? = Downloader.downloadDirect(base + INDEX)?.let(::parseIndex)
private fun marker(root: File, tag: String, name: String) = File(root, ".droiddeck-i18n-$tag-$name")
/** Installs the desktop's translations for [locale]; false when a download failed and is worth retrying. */
@@ -44,7 +47,7 @@ object DesktopLanguage {
val pending = candidates(locale).filterNot { marker(root, tag, it).isFile }
if (pending.isEmpty()) return true
val base = baseUrl(BuildConfig.DESKTOP_KDE_URL)
val index = parseIndex(Downloader.downloadString(base + INDEX) ?: return false)
val index = fetchIndex(base) ?: return false
var complete = true
for (name in pending) {
val pack = index[name]
@@ -0,0 +1,62 @@
package com.droiddeck.launcher.runtime
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import com.droiddeck.launcher.core.DownloadSource
import com.droiddeck.launcher.core.Downloader
import java.net.ServerSocket
import java.util.concurrent.CopyOnWriteArrayList
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class DesktopLanguageIndexSourceTest {
private val base = "https://github.com/Droid-Deck/desktop/releases/download/t/"
private val tunnels = CopyOnWriteArrayList<String>()
private lateinit var context: Context
private lateinit var proxy: ServerSocket
@Before fun setUp() {
proxy = ServerSocket(0)
Thread {
try {
while (!proxy.isClosed) {
proxy.accept().use { socket ->
val line = socket.getInputStream().bufferedReader().readLine() ?: return@use
tunnels += line.removePrefix("CONNECT ").substringBefore(':')
socket.getOutputStream().write("HTTP/1.1 403 Forbidden\r\nContent-Length: 0\r\n\r\n".toByteArray())
}
}
} catch (_: Exception) {
}
}.apply { isDaemon = true }.start()
context = ApplicationProvider.getApplicationContext()
DownloadSource.init(context)
DownloadSource.setMode(context, DownloadSource.MODE_MIRROR)
DownloadSource.setProxy(context, "127.0.0.1:${proxy.localPort}")
}
@After fun tearDown() {
DownloadSource.setMode(context, DownloadSource.MODE_AUTO)
DownloadSource.setProxy(context, "")
proxy.close()
}
@Test fun mirrorModeWouldOtherwiseSendTheIndexThroughAMirror() {
Downloader.downloadString(base + "desktop-kde.i18n.txt")
assertTrue(tunnels.toString(), tunnels.any { host -> DownloadSource.MIRRORS.any { it.host == host } })
}
@Test fun indexIsFetchedOnlyFromGithubInMirrorMode() {
assertNull(DesktopLanguage.fetchIndex(base))
assertEquals(listOf("github.com"), tunnels.toList())
}
}