diff --git a/app/src/main/java/com/droiddeck/launcher/store/StoreState.kt b/app/src/main/java/com/droiddeck/launcher/store/StoreState.kt index b2c35911a..cd47019d8 100644 --- a/app/src/main/java/com/droiddeck/launcher/store/StoreState.kt +++ b/app/src/main/java/com/droiddeck/launcher/store/StoreState.kt @@ -48,6 +48,9 @@ object StoreState { private set var searching by mutableStateOf(false) private set + + /** An app whose Flathub page was asked for from outside the store (its card on Desktop), once. */ + var openRequest by mutableStateOf(null) private var searchSeq = 0 val SECTIONS = listOf("popular" to R.string.store_section_popular, "trending" to R.string.store_section_trending, "recently-added" to R.string.store_section_new, "recently-updated" to R.string.store_section_updated) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/DesktopPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/DesktopPage.kt index 3a5a114b7..0b6f03507 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/DesktopPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/DesktopPage.kt @@ -97,6 +97,11 @@ import kotlinx.coroutines.withContext // Files). Under the hero the page scrolls to two shelves - the apps that run in the desktop, and // what can be added - and the hero folds into a slim header as it goes. +/** What Desktop remembers between visits: how far down it was scrolled. */ +internal object DesktopMemory { + var scroll = 0 +} + /** The desktop's own chips: its session settings, then Files. */ private val DESKTOP_TABS = modeSheetTabs(steam = false) + SheetTab.FILES @@ -108,12 +113,17 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie val colors = MaterialTheme.colorScheme val pal = LocalPalette.current LaunchedEffect(Unit) { UserAppsState.refresh(ctx) } + // Flathub's installed apps sit with the others in Your apps. + LaunchedEffect(s.ready, s.storeEnabled) { if (s.storeEnabled) com.droiddeck.launcher.store.StoreState.refresh(ctx) } val installed = s.emulators.filter { it.installed } val available = s.emulators.filter { !it.installed } val apps = UserAppsState.items var adding by rememberSaveable { mutableStateOf(false) } var sheetOpen by remember { mutableStateOf(false) } - val scroll = rememberScrollState() + // Where the page was scrolled, kept while one of its own pages (an emulator's, Flathub) is + // open: back on Desktop the page draws into its card where the card still is. + val scroll = rememberScrollState(DesktopMemory.scroll) + LaunchedEffect(scroll) { androidx.compose.runtime.snapshotFlow { scroll.value }.collect { DesktopMemory.scroll = it } } val scope = androidx.compose.runtime.rememberCoroutineScope() // Where the Your apps shelf ends, for a new emulator's dot to land. var yourAppsAt by remember { mutableStateOf(null) } @@ -171,7 +181,8 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().onGloballyPositioned { yourAppsAt = it.boundsInRoot() }.horizontalScroll(rememberScrollState()).padding(vertical = 2.dp), ) { - val keys = installed.map { "emu:${it.id}" } + apps.map { "user:${it.key}" } + val flatpaks = if (s.storeEnabled) com.droiddeck.launcher.store.StoreState.installed else emptyList() + val keys = installed.map { "emu:${it.id}" } + apps.map { "user:${it.key}" } + flatpaks.map { "flatpak:${it.id}" } keys.forEachIndexed { i, k -> key(k) { // A card that arrives after the shelf is up (an emulator just installed) opens in. @@ -181,6 +192,7 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie val last = Modifier.then(if (i == keys.lastIndex) Modifier.onGloballyPositioned { lastCardAt = it.boundsInRoot() } else Modifier) Box(last) { val e = installed.firstOrNull { "emu:${it.id}" == k } + val flatpak = flatpaks.firstOrNull { "flatpak:${it.id}" == k } val app = apps.firstOrNull { "user:${it.key}" == k } if (e != null) { val system = if (e.systemRes != 0) stringResource(e.systemRes) else e.system.replaceFirstChar { c -> c.uppercase() } @@ -189,6 +201,13 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie if (e.id == "retroarch") system else "$system · " + pluralStringResource(R.plurals.mode_added_count, e.games.size, e.games.size), art = e.iconRes, first = i == 0, ) { at -> openFrom(k, at, e.iconRes, k) } + } else if (flatpak != null) DesktopCard( + k, flatpak.name, flatpak.summary ?: stringResource(R.string.flathub_name), + art = flatpak.icon ?: com.droiddeck.launcher.store.FlathubApi.iconUrl(flatpak.id), first = i == 0, + ) { at -> + // Its page on Flathub: open, update or remove it there. + com.droiddeck.launcher.store.StoreState.openRequest = flatpak.id + openFrom(k, at, flatpak.icon, "store") } else if (app != null) DesktopCard(k, app.name, stringResource(app.kind.label()), art = app.icon, fallback = if (app.kind == UserApps.Kind.SCRIPT) Icons.Outlined.Terminal else Icons.Outlined.Apps, first = i == 0) { at -> openFrom(k, at, app.icon, k) } @@ -232,12 +251,10 @@ internal fun DesktopPage(s: FrontEndState, a: FrontEndActions, modifier: Modifie } DesktopCard("add", stringResource(R.string.user_apps_add), stringResource(R.string.user_apps_add_detail), art = null, fallback = Icons.Filled.Add, accent = true) { if (!s.busy) adding = true } if (s.storeEnabled) { - val back = stringResource(R.string.rail_desktop) - val show = LocalShowSection.current + // Flathub's apps run in the desktop: its storefront is a page of Desktop's, + // flooding out of this card as an emulator's does. DesktopCard("flathub", stringResource(R.string.flathub_name), stringResource(R.string.flathub_line), art = null, fallback = Icons.Outlined.Storefront, tint = FlathubTeal) { at -> - // Flathub is its own section: the card hops there, and B on it comes back here. - if (at == null) show("store") - else Hops.go(HopOrigin("desktop", HOP_SURFACE_DESKTOP, null, "tile:desktop:flathub", at, back, dest = "store", page = "store")) { show("store") } + openFrom("flathub", at, null, "store") } } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndRail.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndRail.kt index 80f23780f..2ed5dcd5c 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndRail.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndRail.kt @@ -106,7 +106,7 @@ internal fun SideRail( modifier = modifier.width(if (iconOnly) 64.dp else 92.dp).background(colors.surface).padding(vertical = if (compact) 8.dp else 12.dp), ) { // Every section on screen at once: items shrink (to 44dp, still a touch target) before the rail scrolls. - val count = 6 + (if (s.storeEnabled) 1 else 0) + (if (s.gameStoresEnabled) 1 else 0) + (if (s.isHomeApp) 1 else 0) + val count = 6 + (if (s.gameStoresEnabled) 1 else 0) + (if (s.isHomeApp) 1 else 0) BoxWithConstraints(Modifier.weight(1f).fillMaxWidth()) { val fit = (maxHeight / count - 4.dp).coerceIn(44.dp, if (iconOnly) 48.dp else if (compact) 52.dp else 60.dp) // A hop in flight moves the selection ahead of the page it is bringing. @@ -115,7 +115,6 @@ internal fun SideRail( add("steam"); add("games") if (s.gameStoresEnabled) add("stores") add("desktop") - if (s.storeEnabled) add("store") add("components") if (s.isHomeApp) add("android-apps") add("setup"); add("updates") @@ -148,7 +147,6 @@ internal fun SideRail( // A section switched on in Setup comes in as the rail's own entrance; off, it folds away. RailEntrance(s.gameStoresEnabled) { RailItem(stringResource(R.string.rail_stores), Icons.Outlined.LocalMall, "stores", shown == "stores", compact, iconOnly, fit, count = s.storeDownloadsActive, place = place, onFocus = { onFocusSelect("stores") }) { onSelect("stores") } } RailItem(stringResource(R.string.rail_desktop), Icons.Outlined.DesktopWindows, "desktop", shown == "desktop", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("desktop") }) { onSelect("desktop") } - RailEntrance(s.storeEnabled) { RailItem(stringResource(R.string.rail_store), Icons.Outlined.Storefront, "store", shown == "store", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("store") }) { onSelect("store") } } RailItem(stringResource(R.string.rail_components), Icons.Outlined.Layers, "components", shown == "components", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("components") }) { onSelect("components") } // Home mode's extra section goes last, so it shifts nothing above it. if (s.isHomeApp) RailItem(stringResource(R.string.rail_apps), Icons.Outlined.Apps, "android-apps", shown == "android-apps", compact, iconOnly, fit, place = place, onFocus = { onFocusSelect("android-apps") }) { onSelect("android-apps") } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index 05c4d5335..215f8d2ba 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -443,17 +443,17 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com } val density = androidx.compose.ui.platform.LocalDensity.current.density remember(density) { Hops.density = density; true } - // Back (and B) from a ROM, an emulator or an added app steps out one level, as its "‹" link - // does, instead of leaving the app: a ROM -> its emulator, the others -> Desktop. + // Back (and B) from a ROM, an emulator, an added app or Flathub steps out one level instead + // of leaving the app: a ROM -> its emulator, the others -> Desktop. BackHandler( enabled = !processSettingsPageVisible && (s.pageKey == null || page == null) && - (selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:")), + (selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:") || selected == "store"), ) { selected = if (selected.startsWith("rom:")) "emu:" + selected.removePrefix("rom:").substringBefore(':') else "desktop" } LaunchedEffect(s.isHomeApp) { if (!s.isHomeApp && selected == "android-apps") selected = "steam" } // The Store turned off in Setup takes its page with it; so does Stores. - LaunchedEffect(s.storeEnabled) { if (!s.storeEnabled && selected == "store") selected = "steam" } + LaunchedEffect(s.storeEnabled) { if (!s.storeEnabled && selected == "store") selected = "desktop" } LaunchedEffect(s.gameStoresEnabled) { if (!s.gameStoresEnabled && selected == "stores") selected = "games" } // The last game uninstalled leaves the Games tab on its empty state. LaunchedEffect(s.steamGames.isEmpty()) { @@ -468,7 +468,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com s.pageKey == "performance" -> "steam" s.pageKey == "controller-mapping" -> "setup" selected.startsWith("app:") -> "games" - selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:") -> "desktop" + // Flathub is a page of Desktop's, as an emulator's is. + selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:") || selected == "store" -> "desktop" else -> s.pageKey ?: selected } // Bumped each time a rail item is picked, so a controller moves on into the new page. @@ -482,6 +483,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com // Another section: no way back to keep, and no sheet to put back. Hops.origin = null Hops.restore = null + // Picked from the rail, Desktop starts at its hero; back from one of its pages it is where it was. + if (key == "desktop" && selected != "desktop") DesktopMemory.scroll = 0 selected = key } } @@ -645,7 +648,7 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com // A section reached by a hop goes back to where it came from, not to the rail. (s.pageKey == null && Hops.origin?.page == selected) || ((s.pageKey == null || page == null) && - (selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:"))) + (selected.startsWith("emu:") || selected.startsWith("rom:") || selected.startsWith("user:") || selected == "store")) // At the top of a section, Back goes to the rail - the launcher itself is never backed out of. BackHandler(enabled = !processSettingsPageVisible && !hasBackTarget) { if (inputModeManager.inputMode != InputMode.Keyboard) inputModeManager.requestInputMode(InputMode.Keyboard) diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 895d69643..593adeaaa 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -392,10 +392,11 @@ internal fun SetupPanel( } val rail: @Composable () -> Unit = { SettingsGroup(stringResource(R.string.setup_group_rail)) { - RailToggle( - "store", host, "store-enabled", stringResource(R.string.setup_store), + // Flathub is a page of Desktop's, not a rail item: this shows its card there. + ToggleRow( + host, "store-enabled", stringResource(R.string.setup_store), if (s.storeEnabled) stringResource(R.string.setup_store_on) else stringResource(R.string.setup_store_off), - s.storeEnabled, a.onStoreEnabled, + s.storeEnabled, onChange = a.onStoreEnabled, ) RailToggle("stores", host, "stores-enabled", stringResource(R.string.setup_stores_show), null, s.gameStoresEnabled, a.onGameStoresEnabled) } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StorePage.kt b/app/src/main/java/com/droiddeck/launcher/ui/StorePage.kt index c64a3d87c..f29ce1b25 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StorePage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StorePage.kt @@ -319,6 +319,8 @@ private fun Storefront(s: FrontEndState, a: FrontEndActions) { ff.items["tile:store:$id"]?.let { req -> focusWithinFrames({ false }) { req } } } BackHandler(enabled = openApp != null) { openApp = null } + // An app's card on Desktop asked for its page. + LaunchedEffect(StoreState.openRequest) { StoreState.openRequest?.let { openApp = it; StoreState.openRequest = null } } val covering = detail != null && !leaving val sink by animateFloatAsState(if (covering) 0.95f else 1f, if (covering) Motion.tw(480) else Motion.tw(460, 40), label = "flathubSink") val fade by animateFloatAsState(if (covering) 0f else 1f, if (covering) Motion.tw(320, 80) else Motion.tw(300, 100), label = "flathubFade") @@ -333,10 +335,10 @@ private fun Storefront(s: FrontEndState, a: FrontEndActions) { ) { Rise(0) { Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) { - Box(Modifier.weight(1f)) { FlathubChips(mode, modes, StoreState.installed.size, updates.size) { mode = it } } - // Reached by a hop from Desktop: the way back. + // A page of Desktop's: the way back to it, for a finger (B does the same). val show = LocalShowSection.current - HopBackChip { Hops.origin?.let { o -> Hops.back { show(o.rail) } } } + BackLink(stringResource(R.string.rail_desktop), compact = true) { show("desktop") } + Box(Modifier.weight(1f)) { FlathubChips(mode, modes, StoreState.installed.size, updates.size) { mode = it } } } } Spacer(Modifier.height(8.dp)) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6841d8730..fc67746d0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -646,8 +646,8 @@ Choose a Home app Choose Linux apps (beta) - Flathub Store - In the menu. Some apps may not start; logs are in Download/DroidDeck. + Flathub on Desktop + Under Get more on Desktop. Some apps may not start; logs are in Download/DroidDeck. Install Linux apps and games from Flathub Files Browse and manage files @@ -2207,7 +2207,7 @@ When something needs you Look This device - Sections on the rail + Sections Library art LINUX APPS