feat: add persistent per-game compatibility profiles (#449)

* feat(profiles): add persistent per-game compatibility profiles

* fix(profiles): show Windows component overrides

Include per-game Windows component selections in the resolved profile summary so the session overlay marks those games as custom and shows the selected components.

* fix(session): detect Proton games across runtime paths

* fix(profiles): select the active Gamescope game

* fix(profiles): improve per-game reset feedback

* fix(profiles): align session components with game overrides

* fix(session): prefer selected Steam game during refresh

* fix(session): resume profile following when reopening games

* chore: keep local dev testing outside the repository

* test(session): remove local dev package path

* fix(session): preserve profiles when refresh fails

* fix(session): reject empty game profile reset scope

* perf(session): cache drawer inventory by refresh revision

* fix(profiles): align game presets and profile reset behavior

* fix(profiles): preserve originals and normalize shortcut ids

* fix(profiles): keep editor scope stable after rebase

* fix(tests): host Compose tests in both build variants

* fix(profiles): recover interrupted component selection saves

---------

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
Juan MartíandKurt Himebauch authored and GitHub committed 2026-10-11 17:00:28 -04:00
1 parent 78fcb60fd5
commit 435beb7f19
46 files changed
+3501 -150

No files matched your search

@@ -40,6 +40,7 @@ import com.droiddeck.launcher.core.FileUtils
import com.droiddeck.launcher.core.TextureFiltering
import com.droiddeck.launcher.files.InAppFilePicker
import com.droiddeck.launcher.frontend.Library
import com.droiddeck.launcher.agent.AgentGuest
import com.droiddeck.launcher.gpu.FrameGen
import com.droiddeck.launcher.gpu.ScreenEffectLooks
import com.droiddeck.launcher.gpu.ScreenEffects
@@ -64,6 +65,9 @@ import com.droiddeck.launcher.session.PerfHud
import com.droiddeck.launcher.session.PerfMode
import com.droiddeck.launcher.session.SteamRepair
import com.droiddeck.launcher.session.GameEnvironmentStore
import com.droiddeck.launcher.session.GameProfileFollowState
import com.droiddeck.launcher.session.GameProfileInventoryCache
import com.droiddeck.launcher.session.GameProfileRefreshState
import com.droiddeck.launcher.session.SessionPrefs
import com.droiddeck.launcher.session.SessionEvents
import com.droiddeck.launcher.session.SessionArtifacts
@@ -73,6 +77,9 @@ import com.droiddeck.launcher.session.SessionPaths
import com.droiddeck.launcher.wayland.HdrSupport
import com.droiddeck.launcher.session.SessionService
import com.droiddeck.launcher.session.SessionState
import com.droiddeck.launcher.session.ProtonDefault
import com.droiddeck.launcher.session.SelectedGameProfile
import com.droiddeck.launcher.session.WinComponents
import com.droiddeck.launcher.ui.CursorOverlay
import androidx.compose.ui.graphics.asImageBitmap
import com.droiddeck.launcher.ui.DrawerActions
@@ -86,6 +93,7 @@ import com.droiddeck.launcher.wayland.CompositorHost
import com.droiddeck.launcher.wayland.WaylandCompositor
import java.io.File
import com.droiddeck.launcher.session.ComponentsManager
import com.droiddeck.launcher.session.LatestRequestCoordinator
import com.droiddeck.launcher.ui.SessionDrawerPage
import com.droiddeck.launcher.ui.sessionDrawerPages
import com.droiddeck.launcher.ui.step
@@ -247,6 +255,24 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private var closeAtOnce = false
/** The drawer's Components tab: the Protons as last read (ComponentsManager). */
private var drawerComponents by mutableStateOf<ComponentsManager.Snapshot?>(null)
private var drawerGameProfileId by mutableStateOf<Long?>(null)
private val drawerGameInventory = GameProfileInventoryCache<Library.SteamGame>()
private var drawerGameInventoryRevision = 0L
private var drawerGameFexPresetSaving by mutableStateOf(false)
private val drawerGameProfileFollowState = GameProfileFollowState()
private data class DrawerGameProfileRefresh(
val followsSteam: Boolean,
val requestedAppId: Long?,
val inventoryRevision: Long,
)
private data class DrawerGameProfileResult(
val profiles: List<Pair<Long, String>>,
val selectedAppId: Long?,
val profile: SelectedGameProfile?,
val error: Exception? = null,
)
private var drawerGameProfileRefresh by mutableStateOf(GameProfileRefreshState<DrawerGameProfileResult>())
private val drawerGameProfileRefreshes = LatestRequestCoordinator<DrawerGameProfileRefresh>()
private var drawerPage by mutableStateOf(SessionDrawerPage.CONTROLLER)
private var drawerControllerActive by mutableStateOf(false)
private var backActionsInverted by mutableStateOf(false)
@@ -260,6 +286,8 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
private var effects by mutableStateOf(ScreenEffects.OFF)
private var textureAnisotropy by mutableStateOf(0)
private var textureLodBias by mutableStateOf(TextureFiltering.LOD_BIAS_OFF)
private var drawerTextureAnisotropy by mutableStateOf<Int?>(null)
private var drawerTextureLodBias by mutableStateOf<String?>(null)
private var lossless by mutableStateOf(Lossless.State.NONE)
private val pickLossless = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedFile(r.data)?.let { importLossless(it) }
@@ -544,7 +572,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
androidApps = androidApps,
hudOn = hudOn,
upscaler = upscaler, upscaleSharpness = upscaleSharpness,
effects = effects, textureAnisotropy = textureAnisotropy, textureLodBias = textureLodBias,
effects = effects,
textureAnisotropy = if (drawerGameProfileId == null) textureAnisotropy else drawerTextureAnisotropy,
textureLodBias = if (drawerGameProfileId == null) textureLodBias else drawerTextureLodBias,
frameGen = frameGen,
lossless = lossless,
oscMode = oscMode, onScreenButtonsVisible = onScreenButtonsVisible, suspendPolicy = suspendPolicy,
@@ -569,8 +599,24 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
SessionPrefs.setScreenEffects(this@SessionActivity, e); effects = e
e.push(upscaler)
},
onTextureAnisotropy = { v -> SessionPrefs.setTextureAnisotropy(this@SessionActivity, v); textureAnisotropy = v },
onTextureLodBias = { v -> SessionPrefs.setTextureLodBias(this@SessionActivity, v); textureLodBias = v },
onTextureAnisotropy = { value ->
drawerGameProfileId?.let { appId ->
SessionPrefs.setGameTextureAnisotropy(this@SessionActivity, appId.toString(), value)
drawerTextureAnisotropy = value
} ?: value?.let {
SessionPrefs.setTextureAnisotropy(this@SessionActivity, it)
textureAnisotropy = it
}
},
onTextureLodBias = { value ->
drawerGameProfileId?.let { appId ->
SessionPrefs.setGameTextureLodBias(this@SessionActivity, appId.toString(), value)
drawerTextureLodBias = value
} ?: value?.let {
SessionPrefs.setTextureLodBias(this@SessionActivity, it)
textureLodBias = it
}
},
onFrameGenPick = { mode ->
FrameGen.set(this@SessionActivity, mode)
readPrefs()
@@ -666,7 +712,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
onClose = { drawerOpen = false },
components = drawerComponents,
onComponentsRefresh = { refreshDrawerComponents() },
gameProfiles = drawerGameProfileRefresh.data?.profiles.orEmpty(),
selectedGameProfileId = drawerGameProfileId,
selectedGameProfile = drawerGameProfileRefresh.data
?.takeIf { it.selectedAppId == drawerGameProfileId }?.profile,
gameProfilesLoaded = drawerGameProfileRefresh.loaded,
gameProfileRefreshFailed = drawerGameProfileRefresh.failed,
onSelectedGameProfile = ::selectDrawerGameProfile,
onGameProfilesPageOpened = {
drawerGameProfileFollowState.resumeFollowingSteam()
drawerGameInventoryRevision++
},
onSelectedGameProfileRefresh = ::refreshDrawerGameProfile,
gameFexPresetSaving = drawerGameFexPresetSaving,
onGameFexPreset = ::setDrawerGameFexPreset,
onComponentSwap = { pid, comp, value -> swapDrawerComponent(pid, comp, value) },
onGameComponent = ::setDrawerGameComponent,
))
if (SessionState.suspended) SessionPausedOverlay(
title = pausedTitle(),
@@ -763,6 +824,107 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}, "drawer-components").start()
}
private fun selectDrawerGameProfile(appId: Long?) {
drawerGameProfileFollowState.selectManually()
drawerGameProfileId = appId
drawerGameProfileRefresh = drawerGameProfileRefresh.retrying()
readDrawerTextureFiltering(appId)
refreshDrawerGameProfile()
}
private fun readDrawerTextureFiltering(appId: Long?) {
val choice = appId?.let { SessionPrefs.gameTextureFiltering(this, it.toString()) }
drawerTextureAnisotropy = choice?.anisotropy
drawerTextureLodBias = choice?.lodBias
}
private fun refreshDrawerGameProfile() {
val refresh = DrawerGameProfileRefresh(
drawerGameProfileFollowState.followsSteam,
drawerGameProfileId,
drawerGameInventoryRevision,
)
if (!drawerGameProfileRefreshes.submit(refresh)) return
Thread({
var request = drawerGameProfileRefreshes.takeLatest()
while (request != null) {
val current = request
val result = resolveDrawerGameProfileRefresh(current.value)
uiHandler.post {
if (!drawerGameProfileRefreshes.isLatest(current)) return@post
applyDrawerGameProfileRefresh(current.value, result)
}
request = drawerGameProfileRefreshes.takeLatest()
}
}, "drawer-game-profile").start()
}
private fun resolveDrawerGameProfileRefresh(
refresh: DrawerGameProfileRefresh,
): DrawerGameProfileResult {
return try {
val games = drawerGameInventory.get(refresh.inventoryRevision) { Library.launchableGames(this) }
val options = games.mapNotNull { game ->
game.profileKey.toLongOrNull()?.let { it to game.name }
}.sortedBy { it.second.lowercase() }
val installedAppIds = options.mapTo(mutableSetOf()) { it.first }
val selectedAppId = if (refresh.followsSteam) {
val activeAppId = AgentGuest.activeSteamAppId(this, installedAppIds)
val selectedSteamAppId = runCatching { AgentGuest.selectedSteamAppId(this) }
AgentGuest.selectedOrActiveInstalledSteamAppId(selectedSteamAppId, activeAppId, installedAppIds)
?: refresh.requestedAppId
} else {
refresh.requestedAppId
}
val profile = selectedAppId?.let { resolveDrawerGameProfile(it, games) }
DrawerGameProfileResult(options, selectedAppId, profile)
} catch (error: Exception) {
DrawerGameProfileResult(emptyList(), refresh.requestedAppId, null, error)
}
}
private fun applyDrawerGameProfileRefresh(
refresh: DrawerGameProfileRefresh,
result: DrawerGameProfileResult,
) {
if (result.error != null) {
if (!drawerGameProfileRefresh.failed) {
Log.w(TAG, "Could not refresh the selected game profile", result.error)
}
drawerGameProfileRefresh = drawerGameProfileRefresh.failed()
return
}
drawerGameProfileRefresh = drawerGameProfileRefresh.succeeded(result)
if (refresh.followsSteam) {
if (drawerGameProfileFollowState.followsSteam) {
drawerGameProfileId = result.selectedAppId
readDrawerTextureFiltering(result.selectedAppId)
}
}
}
private fun resolveDrawerGameProfile(
selectedAppId: Long,
games: List<Library.SteamGame>,
): SelectedGameProfile? {
val game = games.firstOrNull { it.profileKey == selectedAppId.toString() } ?: return null
val snapshot = drawerComponents ?: ComponentsManager.snapshot(this)
val protons = snapshot.protons.map { it.proton }
val gameChoice = ProtonDefault.gameChoice(this, game.profileKey)
return SelectedGameProfile.resolve(
selectedAppId = selectedAppId,
games = games,
generalFexPreset = SessionPrefs.fexPreset(this),
environment = GameEnvironmentStore.read(this),
snapshot = snapshot,
generalProtonId = ProtonDefault.selectedId(this, protons),
gameProtonChoice = gameChoice,
gameProtonId = ProtonDefault.gameSelectedId(this, game.profileKey, protons),
gameComponents = ComponentsManager.gameComponents(this, game.profileKey),
gameWindowsComponents = WinComponents.picks(this, game.profileKey),
)
}
private fun swapDrawerComponent(protonId: String, comp: String, value: String) {
Thread({
val message = runCatching {
@@ -784,6 +946,43 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
}, "drawer-components-swap").start()
}
private fun setDrawerGameComponent(appId: Long, comp: String, file: String?) {
val name = drawerGameProfileRefresh.data?.profiles?.firstOrNull { it.first == appId }?.second ?: appId.toString()
Thread({
val message = runCatching {
ComponentsManager.setGameComponent(this, appId.toString(), comp, file)
getString(R.string.comp_game_saved_next, name)
}.getOrElse { e ->
getString(R.string.session_profile_save_failed, e.message ?: e.javaClass.simpleName)
}
uiHandler.post {
android.widget.Toast.makeText(this, message, android.widget.Toast.LENGTH_LONG).show()
refreshDrawerComponents()
refreshDrawerGameProfile()
}
}, "drawer-game-component").start()
}
private fun setDrawerGameFexPreset(appId: Long, preset: String?) {
if (drawerGameFexPresetSaving) return
drawerGameFexPresetSaving = true
val name = drawerGameProfileRefresh.data?.profiles?.firstOrNull { it.first == appId }?.second ?: appId.toString()
Thread({
val message = try {
GameEnvironmentStore.setGameFexPreset(this, appId.toString(), preset)
getString(R.string.comp_game_saved_next, name)
} catch (error: Exception) {
Log.w(TAG, "Could not save the game FEX preset for $appId", error)
getString(R.string.session_profile_save_failed, error.message ?: error.javaClass.simpleName)
}
uiHandler.post {
drawerGameFexPresetSaving = false
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
refreshDrawerGameProfile()
}
}, "drawer-game-fex-preset").start()
}
/** The session this screen is bringing up: the live one when re-attached, else the intent's. */
private fun loadingMode(): String =
if (SessionState.running) SessionState.mode