mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9cf0a7e43f | ||
|
|
4df3f775e1 | ||
|
|
6b570c573b |
No files matched your search
@@ -2384,6 +2384,7 @@ 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()
|
||||
}
|
||||
|
||||
@@ -329,8 +329,8 @@ object BwrapSpawner {
|
||||
|
||||
private fun zypakShims(binds: List<Bind>, root: File, dir: File): List<Bind> {
|
||||
val wrappers = listOf("/app/bin/zypak-wrapper.sh", "/app/bin/zypak-wrapper").filter { guest ->
|
||||
val host = File(hostPath(binds, root.path, guest))
|
||||
host.isFile && !Files.isSymbolicLink(host.toPath())
|
||||
val host = File(hostPath(binds, root.path, guest)).toPath()
|
||||
Files.isRegularFile(host, java.nio.file.LinkOption.NOFOLLOW_LINKS) || Files.isSymbolicLink(host)
|
||||
}
|
||||
if (wrappers.isEmpty()) return emptyList()
|
||||
val shim = File(dir, "zypak-wrapper")
|
||||
|
||||
@@ -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)
|
||||
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))
|
||||
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))
|
||||
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 ("$stage:$percent" != shown) {
|
||||
if (foreground && "$stage:$percent" != shown) {
|
||||
shown = "$stage:$percent"
|
||||
manager?.notify(NOTIFICATION_ID, notification(stage, percent))
|
||||
}
|
||||
@@ -46,7 +46,10 @@ class RuntimeInstallService : Service() {
|
||||
}
|
||||
|
||||
private fun holdPackage(startId: Int): Int {
|
||||
startForeground(NOTIFICATION_ID, notification(packageStage, packagePercent, packageTitle))
|
||||
if (!enterForeground(notification(packageStage, packagePercent, packageTitle))) {
|
||||
stopSelf(startId)
|
||||
return START_NOT_STICKY
|
||||
}
|
||||
Thread({
|
||||
val manager = getSystemService(NotificationManager::class.java)
|
||||
var shown = ""
|
||||
@@ -65,6 +68,15 @@ 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,6 +448,13 @@ 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")
|
||||
|
||||
@@ -87,8 +87,7 @@ object Syncthing {
|
||||
fun storageRoots(context: Context): List<File> =
|
||||
listOf(context.dataDir) + context.getExternalFilesDirs(null).filterNotNull().mapNotNull { it.parentFile }
|
||||
|
||||
fun guard(context: Context, extraRoots: List<File> = emptyList()) =
|
||||
SyncthingGuard(folderRoot(context), storageRoots(context) + extraRoots, listOf(home(context)))
|
||||
fun guard(context: Context) = SyncthingGuard(folderRoot(context), storageRoots(context), 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, sharedStorage = true, onDismiss = { addingSoundtrack = false }) { dir ->
|
||||
if (addingSoundtrack) SyncFolderPicker(stringResource(R.string.soundtracks_add_title), null, 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", "android-apps", "agent")
|
||||
val DEFAULT_SHELVED = setOf("soundtracks", "components", "storage", "sync", "decky", "boot-movies", "agent")
|
||||
val DEFAULT_HIDDEN = setOf("android-apps", "agent")
|
||||
private val SHELVED_WHEN_NEW = setOf("storage", "sync", "decky", "boot-movies", "android-apps", "agent")
|
||||
private val SHELVED_WHEN_NEW = setOf("storage", "sync", "decky", "boot-movies", "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,6 +95,15 @@ 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,11 +48,8 @@ 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, sharedStorage: Boolean = false): List<SyncLocation> {
|
||||
internal fun syncLocations(context: Context): 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 + "/") }
|
||||
@@ -61,23 +58,18 @@ internal fun syncLocations(context: Context, sharedStorage: Boolean = false): Li
|
||||
}
|
||||
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)) +
|
||||
storage + shared + SyncLocation(roots.first(), context.getString(R.string.sync_location_app), Icons.Outlined.Folder)
|
||||
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?, sharedStorage: Boolean = false, onDismiss: () -> Unit, onPick: (File) -> Unit,
|
||||
) {
|
||||
internal fun SyncFolderPicker(title: String, suggestedName: String?, 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, sharedStorage) }
|
||||
val guard = remember { syncPickerGuard(ctx, locations, sharedStorage) }
|
||||
val locations = remember { syncLocations(ctx) }
|
||||
val guard = remember { Syncthing.guard(ctx) }
|
||||
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) }
|
||||
|
||||
@@ -263,8 +263,26 @@ class BwrapSpawnerPlanTest {
|
||||
val shim = plan.binds.single { it.guest == "/app/bin/zypak-wrapper.sh" }
|
||||
assertTrue(shim.host.startsWith(dir.path))
|
||||
assertTrue(File(shim.host).readText().contains("exec \"\$program\" --no-sandbox \"\$@\""))
|
||||
assertFalse(plan.binds.any { it.guest == "/app/bin/zypak-wrapper" })
|
||||
assertEquals(shim.host, plan.binds.single { it.guest == "/app/bin/zypak-wrapper" }.host)
|
||||
assertTrue(File(app, "bin/zypak-wrapper.sh").readText().contains("zypak-helper"))
|
||||
assertEquals("/app/bin/zypak-wrapper.sh", Files.readSymbolicLink(File(app, "bin/zypak-wrapper").toPath()).toString())
|
||||
}
|
||||
|
||||
@Test fun zypakWrapperLinkThatDoesNotResolveOnTheHostGetsTheShim() {
|
||||
val context = RuntimeEnvironment.getApplication()
|
||||
val app = File(runtime, "app").apply { File(this, "bin").mkdirs() }
|
||||
File(app, "bin/zypak-wrapper.sh").writeText("#!/usr/bin/bash\nexec zypak-helper host - \"\$@\"\n")
|
||||
val dangling = java.nio.file.Paths.get(LinuxRuntime.rootDir(context).path, "app/bin/zypak-wrapper.sh")
|
||||
Files.createSymbolicLink(File(app, "bin/zypak-wrapper").toPath(), dangling)
|
||||
val plan = BwrapSpawner.plan(context, request(
|
||||
op("t" to "bind", "src" to "/runtime-files/app", "dest" to "/app", "ro" to true),
|
||||
), dir)
|
||||
|
||||
assertFalse(Files.exists(dangling))
|
||||
val shim = plan.binds.single { it.guest == "/app/bin/zypak-wrapper" }
|
||||
assertTrue(shim.host.startsWith(dir.path))
|
||||
assertTrue(File(shim.host).readText().contains("exec \"\$program\" --no-sandbox \"\$@\""))
|
||||
assertEquals(shim.host, plan.binds.single { it.guest == "/app/bin/zypak-wrapper.sh" }.host)
|
||||
}
|
||||
|
||||
@Test fun appsWithoutZypakKeepTheirFiles() {
|
||||
|
||||
@@ -48,6 +48,21 @@ 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)
|
||||
@@ -219,12 +234,12 @@ class NavTabsTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
val last = navigationKeys(state()).last { it != NavTabs.MORE }
|
||||
val last = NavTabs.listed(state()).last { it !in NavTabs.shelved }
|
||||
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 { assertEquals(last, NavTabs.more(state()).first()) }
|
||||
compose.runOnIdle { assertTrue(last in NavTabs.shelved) }
|
||||
compose.onNodeWithTag("tab-shown-desktop").performClick()
|
||||
compose.runOnIdle { assertFalse("desktop" in navigationKeys(state())) }
|
||||
compose.onNodeWithTag("tab-shown-setup").performClick()
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
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))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user