Compare commits

..
11 changed files with 77 additions and 75 deletions

No files matched your search

@@ -2384,7 +2384,6 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
homeScreenEnabled = HomeApp.isHomeScreenEnabled(this)
homeAppSelected = homeScreenEnabled && HomeApp.isDefault(this)
defaultHomeLabel = HomeApp.defaultLabel(this)
com.droiddeck.launcher.ui.NavTabs.syncHomeApps(this, homeAppSelected)
refreshAndroidApps()
integrationState = readIntegration()
}
@@ -22,7 +22,7 @@ class RuntimeInstallService : Service() {
if (intent?.action == ACTION_PACKAGE) return holdPackage(startId)
val removal = intent?.action == ACTION_REMOVE
val release = intent?.let(::releaseFrom)
val foreground = enterForeground(notification(getString(if (LinuxRuntimeInstaller.isMaintaining()) R.string.desktop_removing else if (removal) R.string.rtinst_removing else R.string.user_apps_starting), -1))
startForeground(NOTIFICATION_ID, notification(getString(if (LinuxRuntimeInstaller.isMaintaining()) R.string.desktop_removing else if (removal) R.string.rtinst_removing else R.string.user_apps_starting), -1))
if (release == null && !removal) {
stopSelf(startId)
return START_NOT_STICKY
@@ -31,7 +31,7 @@ class RuntimeInstallService : Service() {
val manager = getSystemService(NotificationManager::class.java)
var shown = ""
val progress = LinuxRuntimeInstaller.ProgressListener { stage, percent ->
if (foreground && "$stage:$percent" != shown) {
if ("$stage:$percent" != shown) {
shown = "$stage:$percent"
manager?.notify(NOTIFICATION_ID, notification(stage, percent))
}
@@ -46,10 +46,7 @@ class RuntimeInstallService : Service() {
}
private fun holdPackage(startId: Int): Int {
if (!enterForeground(notification(packageStage, packagePercent, packageTitle))) {
stopSelf(startId)
return START_NOT_STICKY
}
startForeground(NOTIFICATION_ID, notification(packageStage, packagePercent, packageTitle))
Thread({
val manager = getSystemService(NotificationManager::class.java)
var shown = ""
@@ -68,15 +65,6 @@ class RuntimeInstallService : Service() {
return START_NOT_STICKY
}
/** Android 12+ refuses a foreground start while the app is in the background; the work then goes on without the notification. */
private fun enterForeground(notification: Notification): Boolean = try {
startForeground(NOTIFICATION_ID, notification)
true
} catch (e: IllegalStateException) {
android.util.Log.w("RuntimeInstallService", "running without a foreground service: $e")
false
}
private fun notification(stage: String, percent: Int, title: String? = null): Notification {
val manager = getSystemService(NotificationManager::class.java)
manager?.createNotificationChannel(NotificationChannel(CHANNEL_ID, getString(R.string.setup_runtime),
@@ -448,13 +448,6 @@ object SessionPrefs {
prefs(context).edit().putString("navTabHidden", keys.joinToString(",")).apply()
}
fun appsTabHomeSeen(context: Context): Boolean? =
prefs(context).takeIf { it.contains("appsTabHomeSeen") }?.getBoolean("appsTabHomeSeen", false)
fun setAppsTabHomeSeen(context: Context, seen: Boolean) {
prefs(context).edit().putBoolean("appsTabHomeSeen", seen).apply()
}
private fun idList(raw: String?): List<String> = raw.orEmpty().split(',').map { it.trim() }.filter { it.isNotEmpty() }
val STORES_SORTS = listOf("lastPlayed", "recentlyInstalled", "titleAsc", "titleDesc", "sizeDesc", "sizeAsc", "releaseDateDesc")
@@ -117,20 +117,19 @@ object EaApi {
return list to next
}
internal fun ownedVariables(next: String): JSONObject = JSONObject()
.put("isMac", false)
.put("limit", 100)
.put("next", next)
.put("type", JSONArray().put("DIGITAL_FULL_GAME").put("PACKAGED_FULL_GAME"))
.put("storefronts", JSONArray().put("EA").put("EPIC"))
.put("platforms", JSONArray().put("PC"))
fun owned(token: String): List<OwnedProduct> {
val out = ArrayList<OwnedProduct>()
var next: String? = "0"
var guard = 0
while (next != null && guard++ < 50) {
val (items, after) = parseOwned(call(token, "getPreloadedOwnedGames", ownedVariables(next)))
val variables = JSONObject()
.put("isMac", false)
.put("limit", 100)
.put("next", next)
.put("type", JSONArray().put("DIGITAL_FULL_GAME").put("PACKAGED_FULL_GAME"))
.put("storefronts", JSONArray().put("EA"))
.put("platforms", JSONArray().put("PC"))
val (items, after) = parseOwned(call(token, "getPreloadedOwnedGames", variables))
out += items
next = after?.takeIf { it != next && items.isNotEmpty() }
}
@@ -87,7 +87,8 @@ object Syncthing {
fun storageRoots(context: Context): List<File> =
listOf(context.dataDir) + context.getExternalFilesDirs(null).filterNotNull().mapNotNull { it.parentFile }
fun guard(context: Context) = SyncthingGuard(folderRoot(context), storageRoots(context), listOf(home(context)))
fun guard(context: Context, extraRoots: List<File> = emptyList()) =
SyncthingGuard(folderRoot(context), storageRoots(context) + extraRoots, listOf(home(context)))
fun init(application: Application) {
app = application.applicationContext
@@ -578,7 +578,7 @@ internal fun LibraryPage(s: FrontEndState, a: FrontEndActions, selected: String,
else GameDetail(key, s, a, lead, backLabel, hopRail = "games", onBack = back)
}
if (savedDialog) SavedDialog(emptyList(), onOpen = { id -> onSelect("sound:$id") }) { savedDialog = false }
if (addingSoundtrack) SyncFolderPicker(stringResource(R.string.soundtracks_add_title), null, onDismiss = { addingSoundtrack = false }) { dir ->
if (addingSoundtrack) SyncFolderPicker(stringResource(R.string.soundtracks_add_title), null, sharedStorage = true, onDismiss = { addingSoundtrack = false }) { dir ->
addingSoundtrack = false
a.onSoundtrackAdded(dir)
}
@@ -27,9 +27,9 @@ internal object DeveloperTools {
internal object NavTabs {
const val MORE = "more"
val ALL = listOf("steam", "desktop", "games", "downloads", "setup", "updates", "stores", "soundtracks", "components", "storage", "sync", "decky", "boot-movies", "android-apps", "agent")
val DEFAULT_SHELVED = setOf("soundtracks", "components", "storage", "sync", "decky", "boot-movies", "agent")
val DEFAULT_SHELVED = setOf("soundtracks", "components", "storage", "sync", "decky", "boot-movies", "android-apps", "agent")
val DEFAULT_HIDDEN = setOf("android-apps", "agent")
private val SHELVED_WHEN_NEW = setOf("storage", "sync", "decky", "boot-movies", "agent")
private val SHELVED_WHEN_NEW = setOf("storage", "sync", "decky", "boot-movies", "android-apps", "agent")
private val OLD_ORDER = listOf("steam", "games", "soundtracks", "stores", "downloads", "desktop", "agent", "components", "android-apps", "storage", "sync", "setup", "updates")
private val OLD_SHELVED = setOf("soundtracks", "agent", "storage", "sync")
private const val LAYOUT_VERSION = 2
@@ -95,15 +95,6 @@ internal object NavTabs {
else -> true
}
// Apps only has content when DroidDeck is the home app, so it follows that state on each change and
// otherwise stays wherever the user put it.
fun syncHomeApps(context: Context, homeSelected: Boolean) {
val seen = SessionPrefs.appsTabHomeSeen(context)
SessionPrefs.setAppsTabHomeSeen(context, homeSelected)
if (seen == homeSelected || (seen == null && !homeSelected)) return
setHidden(context, "android-apps", !homeSelected)
}
fun hideable(key: String) = key != "setup"
fun place(s: FrontEndState, key: String): TabPlace = when {
@@ -48,8 +48,11 @@ internal class SyncLocation(val root: File, val label: String, val icon: ImageVe
internal fun containerHome(context: Context) = File(LinuxRuntime.rootDir(context), "root")
internal fun syncLocations(context: Context): List<SyncLocation> {
internal fun syncLocations(context: Context, sharedStorage: Boolean = false): List<SyncLocation> {
val volumes = pickVolumes(context)
val storage = if (!sharedStorage) emptyList() else volumes.map {
SyncLocation(it.root, it.label, if (it.removable) Icons.Outlined.SdCard else Icons.Outlined.Smartphone)
}
val roots = Syncthing.storageRoots(context)
val shared = roots.drop(1).mapIndexed { i, root ->
val volume = volumes.firstOrNull { root.path.startsWith(it.root.path + "/") }
@@ -58,18 +61,23 @@ internal fun syncLocations(context: Context): List<SyncLocation> {
}
val home = containerHome(context).takeIf { it.isDirectory }?.let { SyncLocation(it, context.getString(R.string.sync_location_home), Icons.Outlined.Home) }
return listOfNotNull(home, SyncLocation(Syncthing.folderRoot(context), context.getString(R.string.sync_location_sync), Icons.Outlined.FolderSpecial)) +
shared + SyncLocation(roots.first(), context.getString(R.string.sync_location_app), Icons.Outlined.Folder)
storage + shared + SyncLocation(roots.first(), context.getString(R.string.sync_location_app), Icons.Outlined.Folder)
}
internal fun syncPickerGuard(context: Context, locations: List<SyncLocation>, sharedStorage: Boolean) =
Syncthing.guard(context, if (sharedStorage) locations.map { it.root } else emptyList())
@Composable
internal fun SyncFolderPicker(title: String, suggestedName: String?, onDismiss: () -> Unit, onPick: (File) -> Unit) {
internal fun SyncFolderPicker(
title: String, suggestedName: String?, sharedStorage: Boolean = false, onDismiss: () -> Unit, onPick: (File) -> Unit,
) {
val ctx = LocalContext.current
val colors = MaterialTheme.colorScheme
val density = LocalDensity.current
val shown = rememberShown(onDismiss)
val close = { shown.targetState = false }
val locations = remember { syncLocations(ctx) }
val guard = remember { Syncthing.guard(ctx) }
val locations = remember { syncLocations(ctx, sharedStorage) }
val guard = remember { syncPickerGuard(ctx, locations, sharedStorage) }
fun locationOf(d: File) = locations.filter { d.path == it.root.path || d.path.startsWith(it.root.path + "/") }.maxByOrNull { it.root.path.length }
var dir by remember { mutableStateOf<File?>(containerHome(ctx).takeIf { it.isDirectory } ?: Syncthing.folderRoot(ctx).also { it.mkdirs() }) }
var refresh by remember { mutableIntStateOf(0) }
@@ -298,14 +298,6 @@ class EaTest {
assertNotNull(EaApi.query("getPreloadedOwnedGames"))
}
@Test fun ownedGamesIncludeEpicCopiesTheEaAppInstallsButNotSteamCopies() {
val variables = EaApi.ownedVariables("0")
val storefronts = variables.getJSONArray("storefronts").let { a -> (0 until a.length()).map { a.getString(it) } }
assertEquals(listOf("EA", "EPIC"), storefronts)
assertEquals("0", variables.getString("next"))
assertEquals("PC", variables.getJSONArray("platforms").getString(0))
}
@Test fun launcherReadsTheSessionFileOnce() {
val text = StoreLaunch.launcherText(StoreGameSidecar(Store.EA, "Origin.OFR.1", "Game", exe = "bin/Game.exe", args = listOf("-dx12")))
assertTrue(text.contains("for /f \"usebackq tokens=1,* delims==\" %%a in (\"%~dp0.droiddeck-ea-env\") do set \"%%a=%%b\""))
@@ -48,21 +48,6 @@ class NavTabsTest {
assertTrue(NavTabs.isDefault())
}
@Test fun appsFollowsTheHomeAppOnEachChangeAndOtherwiseKeepsTheUsersChoice() {
NavTabs.syncHomeApps(ctx, false)
assertEquals(TabPlace.HIDDEN, NavTabs.place(state(), "android-apps"))
NavTabs.syncHomeApps(ctx, true)
assertEquals(TabPlace.BAR, NavTabs.place(state(), "android-apps"))
NavTabs.setHidden(ctx, "android-apps", true)
NavTabs.syncHomeApps(ctx, true)
assertEquals(TabPlace.HIDDEN, NavTabs.place(state(), "android-apps"))
NavTabs.syncHomeApps(ctx, false)
NavTabs.syncHomeApps(ctx, true)
assertEquals(TabPlace.BAR, NavTabs.place(state(), "android-apps"))
NavTabs.syncHomeApps(ctx, false)
assertEquals(TabPlace.HIDDEN, NavTabs.place(state(), "android-apps"))
}
@Test fun showingMusicOnceKeepsItShownAfterReload() {
place("soundtracks", TabPlace.BAR)
NavTabs.load(ctx)
@@ -234,12 +219,12 @@ class NavTabsTest {
}
}
}
val last = NavTabs.listed(state()).last { it !in NavTabs.shelved }
val last = navigationKeys(state()).last { it != NavTabs.MORE }
compose.onNodeWithTag("tab-row-$last").requestFocus()
compose.onNodeWithTag("tab-row-$last").performKeyPress(pad(android.view.KeyEvent.KEYCODE_BUTTON_Y))
compose.onNodeWithTag("tab-row-$last").performKeyPress(pad(android.view.KeyEvent.KEYCODE_DPAD_DOWN))
compose.onNodeWithTag("tab-row-$last").performKeyPress(pad(android.view.KeyEvent.KEYCODE_BUTTON_Y))
compose.runOnIdle { assertTrue(last in NavTabs.shelved) }
compose.runOnIdle { assertEquals(last, NavTabs.more(state()).first()) }
compose.onNodeWithTag("tab-shown-desktop").performClick()
compose.runOnIdle { assertFalse("desktop" in navigationKeys(state())) }
compose.onNodeWithTag("tab-shown-setup").performClick()
@@ -0,0 +1,46 @@
package com.droiddeck.launcher.ui
import android.os.Environment
import com.droiddeck.launcher.R
import com.droiddeck.launcher.sync.Syncthing
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
import java.io.File
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class SyncFolderPickerTest {
private val context = RuntimeEnvironment.getApplication()
private val internal = Environment.getExternalStorageDirectory()
private val music = File(internal, "Music")
@Test fun sharedStorageListsInternalStorageAndAllowsItsMusicFolder() {
val locations = syncLocations(context, sharedStorage = true)
val guard = syncPickerGuard(context, locations, sharedStorage = true)
assertTrue(locations.any { it.root.path == internal.path && it.label == context.getString(R.string.games_internal) })
assertTrue(guard.allows(music.path))
assertTrue(guard.browsable(music))
}
@Test fun sharedStorageKeepsTheSyncthingConfigBlocked() {
val guard = syncPickerGuard(context, syncLocations(context, sharedStorage = true), sharedStorage = true)
assertFalse(guard.allows(Syncthing.home(context).path))
assertFalse(guard.browsable(Syncthing.home(context)))
}
@Test fun theSyncthingPickerStaysInsideAppStorage() {
val locations = syncLocations(context)
val guard = syncPickerGuard(context, locations, sharedStorage = false)
assertFalse(locations.any { it.root.path == internal.path })
assertFalse(guard.allows(music.path))
assertTrue(guard.allows(Syncthing.folderRoot(context).path))
}
}