Restore Xbox launches from Steam (#1170)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-20 00:46:35 +00:00
1 parent 7eae6ca3e7
commit 80a62cd0f0
6 files changed
+19 -36

No files matched your search

@@ -83,10 +83,6 @@ object StoreLaunch {
}
fun prepare(context: Context, store: Store, id: String, onReady: () -> Unit) {
if (store == Store.XBOX && !com.droiddeck.launcher.stores.xbox.XboxRuntime.authorize(context, id)) {
StoresState.problems[Store.XBOX] = "Xbox account is unavailable. Sign in again and retry."
return
}
if (store != Store.EPIC) { onReady(); return }
val app = context.applicationContext
Thread({
@@ -4,16 +4,11 @@ import java.io.Closeable
import java.util.UUID
internal class XboxLaunchLeases(private val now: () -> Long) {
private data class Permit(val account: String, val expires: Long)
private data class Lease(val id: String, val account: String, val session: String, var expires: Long, var child: Closeable? = null)
private val permits = HashMap<String, Permit>()
private val leases = HashMap<String, Lease>()
@Synchronized fun authorize(id: String, account: String) { permits[id] = Permit(account, now() + 180_000) }
@Synchronized fun active(id: String) = leases.values.any { it.id == id }
@Synchronized fun begin(id: String, account: String, session: String): String {
val permit = permits.remove(id)
check(permit != null && permit.account == account && permit.expires > now()) { "Start this Xbox game from DroidDeck." }
check(!active(id)) { "This Xbox game is already starting or running." }
val token = UUID.randomUUID().toString()
leases[token] = Lease(id, account, session, now() + 180_000)
@@ -38,7 +33,6 @@ internal class XboxLaunchLeases(private val now: () -> Long) {
return expired.mapNotNull { leases.remove(it)?.child }
}
@Synchronized fun clear(): List<Closeable> {
permits.clear()
return leases.values.mapNotNull { it.child }.also { leases.clear() }
}
}
@@ -16,13 +16,6 @@ internal object XboxRuntime {
private val views = XboxLaunchViews()
private val launches = XboxLaunchLeases { android.os.SystemClock.uptimeMillis() }
fun isActive(id: String): Boolean = launches.active(id)
fun authorize(app: Context, id: String): Boolean = runCatching {
XboxCredentials.lifecycle(app) {
val account = StoreAccounts.signedInAs(app, Store.XBOX) ?: return@lifecycle false
launches.authorize(id, account)
true
}
}.getOrDefault(false)
fun released(token: String) { runCatching { launches.release(token)?.close() } }
fun renew(app: Context, id: String, token: String): Boolean = launches.renew(token, id,
StoreAccounts.signedInAs(app, Store.XBOX), SessionState.sessionId.takeIf { SessionState.running })