mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
Preserve second-screen choices across partial selections and migration retries
Track explicit whole-profile choices, including Auto, separately from inherited profiles so physical and main-screen overrides do not suppress legacy panel migration. Persist this distinction in library version 8 and read older selection records compatibly. Keep saved Deck panels during unavailable-controller fallbacks and retain legacy preferences when migration fails. Add regressions for all three review findings, explicit Auto selection and older saved libraries. Validation: all 992 input/UI tests passed.
This commit is contained in:
1 parent
281c2aea1b
commit
aff9738748
5 files changed
+110
-13
No files matched your search
@@ -3317,17 +3317,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
if (pipUi || !started) return
|
||||
val mode = if (requested == SecondScreenMode.DECK_CONTROLS || requested == SecondScreenMode.KEYBOARD_TRACKPAD) {
|
||||
val remembered = SessionPrefs.secondScreenPanel(this)
|
||||
if (remembered == SecondScreenMode.DECK_CONTROLS.id || remembered == SecondScreenMode.KEYBOARD_TRACKPAD.id) {
|
||||
if (remembered == requested.id) {
|
||||
val desktop = SessionState.mode == SessionService.MODE_DESKTOP
|
||||
val library = com.droiddeck.launcher.input.InputLibraries.read(this)
|
||||
val key = if (desktop) InputProfile.DESKTOP else InputProfile.GAME
|
||||
if (key !in library.selections) {
|
||||
val preset = if (requested == SecondScreenMode.DECK_CONTROLS) com.droiddeck.launcher.input.InputStockLayouts.DECK else com.droiddeck.launcher.input.InputStockLayouts.TRACKPAD
|
||||
runCatching { com.droiddeck.launcher.input.InputLibraries.update(this) { it.selectPart(desktop, InputRole.SECONDARY, preset) } }
|
||||
.onSuccess { refreshInputProfile() }
|
||||
.onFailure { Log.w(TAG, "could not migrate the saved second-screen selection", it) }
|
||||
val preset = if (requested == SecondScreenMode.DECK_CONTROLS) com.droiddeck.launcher.input.InputStockLayouts.DECK else com.droiddeck.launcher.input.InputStockLayouts.TRACKPAD
|
||||
runCatching {
|
||||
com.droiddeck.launcher.input.InputLibraries.update(this) { library ->
|
||||
val selection = library.selections[key]
|
||||
if (selection?.profileSelected == true || selection?.parts?.containsKey(InputRole.SECONDARY) == true) library
|
||||
else library.selectPart(desktop, InputRole.SECONDARY, preset)
|
||||
}
|
||||
}.onSuccess {
|
||||
refreshInputProfile()
|
||||
SessionPrefs.setSecondScreenPanel(this, SecondScreenMode.CUSTOM_CONTROLS.id)
|
||||
}.onFailure {
|
||||
Log.w(TAG, "could not migrate the saved second-screen selection", it)
|
||||
}
|
||||
SessionPrefs.setSecondScreenPanel(this, SecondScreenMode.CUSTOM_CONTROLS.id)
|
||||
}
|
||||
SecondScreenMode.CUSTOM_CONTROLS
|
||||
} else requested
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.json.JSONObject
|
||||
import java.util.UUID
|
||||
|
||||
object InputLibraries {
|
||||
private const val VERSION = 7
|
||||
private const val VERSION = 8
|
||||
private const val KEY = "library"
|
||||
private const val RECOVERY = "library-recovery."
|
||||
const val OVERLAY = "builtin.overlay"
|
||||
@@ -231,7 +231,7 @@ object InputLibraries {
|
||||
for ((mode, selection) in library.selections) {
|
||||
val parts = JSONObject()
|
||||
selection.parts.forEach { (role, id) -> parts.put(role.name, id) }
|
||||
selections.put(mode, JSONObject().put("profile", selection.profile).put("parts", parts))
|
||||
selections.put(mode, JSONObject().put("profile", selection.profile).put("parts", parts).put("profileSelected", selection.profileSelected))
|
||||
}
|
||||
return JSONObject().put("selections", selections).put("version", VERSION).put("selected", library.selected).put("steam", library.steam).put("desktop", library.desktop)
|
||||
.put("profiles", profiles).put("layouts", layouts).put("bindings", bindings).toString()
|
||||
@@ -272,7 +272,9 @@ object InputLibraries {
|
||||
val value = saved.getJSONObject(mode)
|
||||
val parts = value.getJSONObject("parts")
|
||||
require(parts.length() <= InputRole.entries.size)
|
||||
InputSelection(value.getString("profile"), parts.keys().asSequence().associate { role -> InputRole.valueOf(role) to parts.getString(role) })
|
||||
val profile = value.getString("profile")
|
||||
InputSelection(profile, parts.keys().asSequence().associate { role -> InputRole.valueOf(role) to parts.getString(role) },
|
||||
value.optBoolean("profileSelected", profile != InputProfiles.AUTO || parts.length() == 0))
|
||||
}
|
||||
}.orEmpty()
|
||||
InputLibrary(profiles, layouts, bindings, doc.getString("selected"), doc.getString("steam"), doc.getString("desktop"), selections).validate()
|
||||
|
||||
@@ -44,7 +44,9 @@ data class SavedInputBindings(
|
||||
?: defaultElementClick(element, action(element)) { controls[it] ?: InputAction.Native() }
|
||||
}
|
||||
|
||||
data class InputSelection(val profile: String = InputProfiles.AUTO, val parts: Map<InputRole, String> = emptyMap())
|
||||
data class InputSelection(
|
||||
val profile: String = InputProfiles.AUTO, val parts: Map<InputRole, String> = emptyMap(), val profileSelected: Boolean = false,
|
||||
)
|
||||
|
||||
data class InputPart(val bindings: String, val layout: String? = null)
|
||||
|
||||
@@ -68,7 +70,7 @@ data class InputLibrary(
|
||||
val id = selection(isDesktop).profile
|
||||
return if (id == InputProfiles.AUTO) { if (isDesktop) desktop else steam } else id
|
||||
}
|
||||
fun selectProfile(isDesktop: Boolean, id: String) = copy(selections = selections + (mode(isDesktop) to InputSelection(id)))
|
||||
fun selectProfile(isDesktop: Boolean, id: String) = copy(selections = selections + (mode(isDesktop) to InputSelection(id, profileSelected = true)))
|
||||
fun selectPart(isDesktop: Boolean, role: InputRole, bindingsId: String): InputLibrary {
|
||||
val previous = selection(isDesktop)
|
||||
return copy(selections = selections + (mode(isDesktop) to previous.copy(parts = previous.parts + (role to bindingsId))))
|
||||
|
||||
Reference in new issue
Block a user