mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
fix: leave published component choices alone when state.json cannot be read
This commit is contained in:
1 parent
c781cfd525
commit
c25d54aced
2 files changed
+16
No files matched your search
@@ -175,6 +175,9 @@ object ComponentsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun republish(context: Context): Boolean = synchronized(lock) {
|
fun republish(context: Context): Boolean = synchronized(lock) {
|
||||||
|
recoverState(context)
|
||||||
|
val saved = stateFile(context)
|
||||||
|
if (saved.exists() && runCatching { JSONObject(saved.readText()) }.isFailure) return false
|
||||||
val state = loadState(context)
|
val state = loadState(context)
|
||||||
val prepared = prepareLaunchState(context, state)
|
val prepared = prepareLaunchState(context, state)
|
||||||
if ((FileUtils.readString(File(launchDir(context), "desired.tsv")) ?: "") == prepared.text) return false
|
if ((FileUtils.readString(File(launchDir(context), "desired.tsv")) ?: "") == prepared.text) return false
|
||||||
|
|||||||
@@ -60,6 +60,19 @@ class ComponentsRepublishTest {
|
|||||||
assertEquals(modified, launchState().lastModified())
|
assertEquals(modified, launchState().lastModified())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test fun anUnreadableStateLeavesThePublishedSelectionsAlone() {
|
||||||
|
proton("DroidDeck-Proton 11-11.7", "DroidDeck-Proton-11-11.7")
|
||||||
|
packageFile()
|
||||||
|
ComponentsManager.setGameComponent(context, scope, "fex", fex)
|
||||||
|
val published = launchState().readText()
|
||||||
|
val state = File(context.filesDir, "components/state.json").apply { writeText("{\"active\": ") }
|
||||||
|
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
|
||||||
|
|
||||||
|
assertFalse(ComponentsManager.republish(context))
|
||||||
|
assertEquals(published, launchState().readText())
|
||||||
|
assertEquals("{\"active\": ", state.readText())
|
||||||
|
}
|
||||||
|
|
||||||
@Test fun withNoSelectionsNothingIsPublished() {
|
@Test fun withNoSelectionsNothingIsPublished() {
|
||||||
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
|
proton("DroidDeck-Proton 11-11.8", "DroidDeck-Proton-11-11.8")
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user