feat: Battle.net on the desktop with its games and store, plus memory options (#979)

This commit is contained in:
Charles DuBose authored and GitHub committed 2026-10-25 12:49:27 -04:00
1 parent 6918fd9308
commit c4df7e9b3d
82 files changed
+4750 -53

No files matched your search

@@ -100,6 +100,10 @@ class FrontEndState(
val logsEnabled: Boolean,
val vacDiagnostics: Boolean = false,
val agentCommands: Boolean = false,
val clearCachedApps: Boolean = false,
val adbPaired: Boolean = false,
val backgroundAppLimit: Int = -1,
val memoryHud: String = "off",
val steamGames: List<Library.SteamGame>,
val steamGamesX64: Boolean = false,
val emulators: List<Library.Emulator>,
@@ -124,6 +128,7 @@ class FrontEndState(
val packageStage: String? = null,
val packagePercent: Int = -1,
val sessionRunning: Boolean = false,
val battleNetInstalled: Boolean = false,
val removalPending: Boolean = false,
val runtimeActionsBlocked: Boolean = false,
val backActionsInverted: Boolean = false,
@@ -176,6 +181,7 @@ class FrontEndActions(
val onEmulator: (Library.Emulator) -> Unit,
val onFlatpakApp: (String, String) -> Unit = { _, _ -> },
val onUserApp: (com.droiddeck.launcher.runtime.UserApps.App) -> Unit = {},
val onBattleNet: () -> Unit = {},
val onRom: (Library.Rom) -> Unit,
val onResume: () -> Unit,
val onSteamSettings: () -> Unit,
@@ -200,6 +206,9 @@ class FrontEndActions(
val onLogs: () -> Unit,
val onVacDiagnostics: () -> Unit = {},
val onAgentCommands: () -> Unit = {},
val onClearCachedApps: (Boolean) -> Unit = {},
val onMemoryHud: (String) -> Unit = {},
val onBackgroundAppLimit: (Int) -> Unit = {},
val onShareLogs: () -> Unit = {},
val onClearLogs: () -> Unit = {},
val onResetSettings: () -> Unit = {},
@@ -470,6 +470,38 @@ internal fun SetupPanel(
ActionRow(stringResource(R.string.setup_reset_settings), stringResource(R.string.setup_reset_settings_hint),
stringResource(R.string.setup_reset_settings_button), a.onResetSettings)
}
SettingsGroup(stringResource(R.string.setup_group_memory)) {
ToggleRow(
host, "clear-cached-apps", stringResource(R.string.setup_clear_cached),
stringResource(if (s.adbPaired) R.string.setup_clear_cached_hint else R.string.setup_clear_cached_unpaired),
s.clearCachedApps, enabled = s.adbPaired || s.clearCachedApps,
) { a.onClearCachedApps(it) }
ChoiceRow(
host, "background-app-limit", stringResource(R.string.setup_bg_limit),
stringResource(if (s.adbPaired) R.string.setup_bg_limit_hint else R.string.setup_clear_cached_unpaired),
listOf(
com.droiddeck.launcher.core.BackgroundAppLimit.OFF to stringResource(R.string.game_env_off),
4 to stringResource(R.string.setup_bg_limit_4),
1 to stringResource(R.string.setup_bg_limit_1),
0 to stringResource(R.string.setup_bg_limit_0),
),
s.backgroundAppLimit, enabled = s.adbPaired || s.backgroundAppLimit != com.droiddeck.launcher.core.BackgroundAppLimit.OFF,
onPick = a.onBackgroundAppLimit,
)
ChoiceRow(
host, "memory-hud", stringResource(R.string.setup_memory_hud), stringResource(R.string.setup_memory_hud_hint),
listOf(
com.droiddeck.launcher.session.SessionPrefs.MEMORY_HUD_OFF to stringResource(R.string.game_env_off),
com.droiddeck.launcher.session.SessionPrefs.MEMORY_HUD_SIMPLE to stringResource(R.string.setup_memory_hud_simple),
com.droiddeck.launcher.session.SessionPrefs.MEMORY_HUD_ADVANCED to stringResource(R.string.setup_memory_hud_advanced),
),
s.memoryHud, onPick = a.onMemoryHud,
)
if (!s.adbPaired) ActionRow(
stringResource(R.string.setup_adb_pair), stringResource(R.string.setup_adb_pair_hint),
stringResource(R.string.setup_adb_pair_button), { onRequestWirelessAdb(false) },
)
}
}
GLASSES_TAB -> GlassesSetupPanel()
}
@@ -364,6 +364,7 @@ private fun GameActions(
}
SecondaryButton(stringResource(R.string.stores_xbox_manage), enabled = download == null) { XboxContent.manage(ctx, installed) }
}
if (store == Store.BATTLENET) SecondaryButton(stringResource(R.string.bnet_open)) { a.onBattleNet() }
}
download != null -> {
ActionChip(downloadLabel(download), ok = false)
@@ -378,6 +379,7 @@ private fun GameActions(
}
ConfirmButton(stringResource(R.string.stores_dl_clear), stringResource(R.string.stores_dl_cancel_confirm), compact = true) { DownloadQueue.clear(ctx, failed.key) }
}
store == Store.BATTLENET && item != null -> InstallButton(stringResource(R.string.stores_install), leadOn) { StoresState.requestInstall(ctx, item) }
store == Store.XBOX && item != null && !item.xboxPc && item.xboxCloud -> {
XboxStreamButton(item.id, item.title, main = true, modifier = leadOn)
XboxLibraryButton(item.id, item)
@@ -521,6 +523,7 @@ private fun IconAction(icon: androidx.compose.ui.graphics.vector.ImageVector, la
private fun RemoveButton(title: String, game: Library.SteamGame?, installed: InstalledStoreGame?, a: FrontEndActions) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
if ((installed?.sidecar?.store?.id ?: game?.source) == Store.BATTLENET.id) return
if (installed != null) {
val key = installed.key
val gone = StoresState.uninstalling[key]
@@ -101,7 +101,8 @@ internal fun GameEnvironmentEditor(byPad: Boolean, initialScope: String = "", on
LaunchedEffect(Unit) {
runCatching {
withContext(Dispatchers.IO) {
GameEnvironmentStore.read(context) to Library.steamGames(context).map { it.appId.toString() to it.name }
GameEnvironmentStore.read(context) to Library.steamGames(context).map { it.appId.toString() to it.name } +
listOfNotNull(com.droiddeck.launcher.runtime.BattleNet.profile(context))
}
}.onSuccess { (settings, installed) -> config = settings; games = installed }
.onFailure { error = true }
@@ -31,6 +31,7 @@ internal fun sourceColours(source: String): SourceColours = when (source) {
Store.AMAZON.id -> SourceColours(Color(0xFF3A2A0A), Color(0xFFFFC266), Color(0xFFFF9900))
Store.XBOX.id -> SourceColours(Color(0xFF17381B), Color(0xFFC6EDC2), Color(0xFF70C850))
Store.ITCH.id -> SourceColours(Color(0xFF3A1A1E), Color(0xFFFFB3B3), Color(0xFFFF5C5C))
Store.BATTLENET.id -> SourceColours(Color(0xFF0A2440), Color(0xFF9DD1FF), Color(0xFF148EFF))
Library.SOURCE_STEAM -> SourceColours(Color(0xFF16293D), Color(0xFF7CC4FF), Color(0xFF1A9FFF))
FLATHUB -> SourceColours(Color(0xFF0B2E2B), Color(0xFF9FE3DD), FlathubTeal)
else -> SourceColours(Color(0xFF1A1D22), Color(0xFF9AA3AF), Color(0xFF9AA3AF))
@@ -44,6 +45,7 @@ internal fun sourceLabel(source: String): String = when (source) {
Store.AMAZON.id -> Store.AMAZON.label
Store.XBOX.id -> Store.XBOX.label
Store.ITCH.id -> Store.ITCH.label
Store.BATTLENET.id -> Store.BATTLENET.label
else -> stringResource(R.string.source_added)
}
@@ -221,7 +221,7 @@ private fun FinishedRow(d: DownloadEntry, s: FrontEndState, a: FrontEndActions,
ArtStrip(d.cover, d.name) {
StripLabel(d.name, d.store.id, stringResource(if (d.state == DownloadState.INSTALLED) R.string.stores_installed_chip else R.string.stores_dl_cancelled), Color.White.copy(alpha = 0.72f))
if (d.state == DownloadState.INSTALLED) Box(Modifier.bloomIn(bloom, GATHER_HOLD_MS + 150)) {
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else launchStoreGame(ctx, d.store, d.id, s, a) }
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else if (d.key == com.droiddeck.launcher.stores.battlenet.BattleNetClient.DOWNLOAD_KEY) a.onBattleNet() else launchStoreGame(ctx, d.store, d.id, s, a) }
}
}
}
@@ -372,7 +372,7 @@ private fun DownloadCard(d: DownloadEntry, s: FrontEndState, a: FrontEndActions)
CancelAction { DownloadQueue.clear(ctx, d.key) }
}
DownloadState.INSTALLED -> Box(Modifier.bloomIn(true, 420)) {
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else launchStoreGame(ctx, d.store, d.id, s, a) }
RoundAction(Icons.Filled.PlayArrow, stringResource(R.string.stores_play), primary = true) { if (d.key == EpicClient.DOWNLOAD_KEY) a.onEpicLauncher() else if (d.key == com.droiddeck.launcher.stores.battlenet.BattleNetClient.DOWNLOAD_KEY) a.onBattleNet() else launchStoreGame(ctx, d.store, d.id, s, a) }
}
DownloadState.CANCELLED -> {}
}
@@ -235,6 +235,12 @@ internal fun StoresPage(s: FrontEndState, a: FrontEndActions, modifier: Modifier
LaunchedEffect(Unit) { StoresState.refresh(ctx) }
val lifecycle = androidx.compose.ui.platform.LocalLifecycleOwner.current.lifecycle
LaunchedEffect(chip) {
if (chip == Store.BATTLENET.id) {
while (true) {
if (lifecycle.currentState.isAtLeast(androidx.lifecycle.Lifecycle.State.RESUMED)) com.droiddeck.launcher.stores.battlenet.BattleNetClient.refresh(ctx)
delay(5_000)
}
}
if (chip == Store.EPIC.id) {
EpicClient.ensure(ctx)
while (true) {
@@ -919,7 +925,7 @@ private fun Storefront(
Shelf(stringResource(R.string.stores_shelf_new), shelf(shelves?.whatsNew), card)
Shelf(stringResource(R.string.stores_shelf_deals), shelf(shelves?.deals), card)
Shelf(stringResource(R.string.stores_shelf_free), shelf(shelves?.free), card)
Shelf(stringResource(R.string.stores_shelf_trending), shelf(shelves?.trending), card)
Shelf(stringResource(if (store == Store.BATTLENET) R.string.bnet_store else R.string.stores_shelf_trending), shelf(shelves?.trending), card)
if (shelves == null) Rise(4) { Box(Modifier.padding(top = 8.dp)) { Note(stringResource(R.string.stores_shelves_loading)) } }
else if (shelves.isEmpty && store == Store.AMAZON) Rise(4) { Box(Modifier.padding(top = 8.dp)) { Note(stringResource(R.string.stores_amazon_no_catalog)) } }
}
@@ -965,6 +971,39 @@ private fun ProfileStrip(store: Store, owned: Int, loaded: Boolean, s: FrontEndS
}
}
if (store == Store.EPIC) EpicLauncherRow(s, a)
if (store == Store.BATTLENET) BattleNetLauncherRow(s, a)
}
}
@Composable
private fun BattleNetLauncherRow(s: FrontEndState, a: FrontEndActions) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
val title = stringResource(R.string.bnet_name)
Box(Modifier.fillMaxWidth().height(1.dp).background(pal.line))
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.fillMaxWidth().testTag("stores-battlenet-launcher")) {
val icon by androidx.compose.runtime.produceState<java.io.File?>(null, s.battleNetInstalled) {
value = if (!s.battleNetInstalled) null
else kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { com.droiddeck.launcher.runtime.BattleNet.icon(ctx) }
}
if (icon != null) AsyncImage(model = icon, contentDescription = null, contentScale = ContentScale.Fit, modifier = Modifier.size(36.dp).clip(RoundedCornerShape(8.dp)))
Text(title, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f))
Actions {
SecondaryButton(stringResource(R.string.bnet_open), enabled = !s.busy, compact = true) { a.onBattleNet() }
val entry = remember(s.battleNetInstalled) { com.droiddeck.launcher.runtime.BattleNet.launcherEntry(s.battleNetInstalled) }
val scope = entry?.let { com.droiddeck.launcher.session.NoSteamLaunch.scope(it) }
if (entry != null && scope != null) {
val host = rememberMenuHost()
val settings = rememberGameSettings(scope)
Box {
SecondaryButton(stringResource(R.string.game_settings_card), compact = true) {
host.open = if (host.open == GAME_SETTINGS_MENU) null else GAME_SETTINGS_MENU
}
GameSettingsMenus(host, entry, settings)
}
}
}
}
}
@@ -1066,6 +1105,7 @@ internal fun storePalette(base: Palette, store: Store?): Palette {
Store.AMAZON -> Color(0xFFFF9900) to Color(0xFFE07800)
Store.XBOX -> Color(0xFF70C850) to Color(0xFF107C10)
Store.ITCH -> Color(0xFFFF5C5C) to Color(0xFFD93B3B)
Store.BATTLENET -> Color(0xFF148EFF) to Color(0xFF0B6BD3)
null -> return base
}
val on = if (accent.luminance() > 0.18f) Color(0xFF0B0B0D) else Color.White