fix: store background jobs log a failure instead of ending the app (#898)

* fix: store background jobs log a failure instead of ending the app

refresh, sign-out, uninstall and the EOS overlay cleanup ran on plain threads. An exception there reaches the crash handler, which ends the process. Run them through one helper that logs the failure; a failed uninstall also clears its row and calls onDone so the UI does not stay on uninstalling.

* ci: run the build again

The first run failed while installing packages (archive.debian.org returned 404 for libnsl-dev). Nothing in the change differs.

---------

Co-authored-by: ovurrsl <ovurrsl@users.noreply.github.com>
This commit is contained in:
Resul Övürandovurrsl authored and GitHub committed 2026-10-16 09:50:06 -04:00
1 parent c74a6b3888
commit 0d2e268dd5
1 file changed
+22 -7
@@ -71,7 +71,7 @@ object StoresState {
fun refresh(context: Context) {
val app = context.applicationContext
com.droiddeck.launcher.stores.download.SavedQueue.restore(app)
Thread({
background("stores-refresh") {
val found = Store.entries.mapNotNull { store -> StoreAccounts.signedInAs(app, store)?.let { store to it } }
val onDisk = StoreInstallRoot.gameFolders(app).mapNotNull { folder ->
StoreGameSidecar.read(folder)?.takeIf { it.isInstalled }?.let { InstalledStoreGame(it, folder) }
@@ -85,7 +85,7 @@ object StoresState {
unfinished = partial
engine = version
}
}, "stores-refresh").start()
}
}
fun isSignedIn(store: Store): Boolean = accounts.containsKey(store)
@@ -136,7 +136,7 @@ object StoresState {
fun signOut(context: Context, store: Store) {
val app = context.applicationContext
Thread({
background("stores-signout") {
backends[store]?.signOut(app)
if (store == Store.GOG) com.droiddeck.launcher.stores.gog.GogComet.replaceAccount { StoreAccounts.clear(app, store) }
else StoreAccounts.clear(app, store)
@@ -144,7 +144,7 @@ object StoresState {
accounts.remove(store); library.remove(store); status.remove(store); problems.remove(store)
logLine("${store.label}: signed out")
}
}, "stores-signout").start()
}
}
var openDownloads by mutableStateOf(false)
@@ -199,7 +199,7 @@ object StoresState {
val app = context.applicationContext
val key = "${game.sidecar.store.id}:${game.sidecar.id}"
uninstalling[key] = 0f
Thread({
background("stores-uninstall", onFailure = { main.post { uninstalling.remove(key); onDone() } }) {
runCatching { backends[game.sidecar.store]?.uninstall(app, game) }
StoreInstalls.uninstall(app, game, progress = { f -> main.post { if (key in uninstalling) uninstalling[key] = f } }, removed = {
main.post {
@@ -208,7 +208,7 @@ object StoresState {
}
})
main.post(onDone)
}, "stores-uninstall").start()
}
}
@Volatile var libraryListener: (() -> Unit)? = null
@@ -231,7 +231,7 @@ object StoresState {
appContext = context.applicationContext
StoreLogFiles.prune(context)
val overlay = java.io.File(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(context), "root/.local/share/droiddeck/epic-overlay")
if (overlay.exists()) Thread({ overlay.deleteRecursively(); Log.i(TAG, "removed the old EOS overlay download") }, "epic-overlay-cleanup").start()
if (overlay.exists()) background("epic-overlay-cleanup") { overlay.deleteRecursively(); Log.i(TAG, "removed the old EOS overlay download") }
val app = context.applicationContext
Thread({
runCatching { CloudSaves.uploadAllDirty(app, "recovery") }
@@ -241,6 +241,21 @@ object StoresState {
internal fun post(block: () -> Unit) = main.post(block)
/**
* A worker thread whose failure is logged. An uncaught exception on a plain Thread reaches the crash
* handler, which ends the whole app, and none of these jobs is worth that.
*/
private fun background(name: String, onFailure: () -> Unit = {}, block: () -> Unit) {
Thread({
try {
block()
} catch (e: Throwable) {
Log.w(TAG, "$name failed", e)
runCatching(onFailure)
}
}, name).start()
}
private val CLOCK = SimpleDateFormat("HH:mm:ss.SSS", Locale.US)
}