mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
feat(steam): first-run defaults for big art and the bouncing logo screensaver (#3087)
* feat(steam): first-run defaults for big art on Library home and the bouncing logo screensaver * fix(steam): seeded keys land in the root store when nested stores close on its last line
This commit is contained in:
1 parent
86ad1544a6
commit
e3b1b60914
4 files changed
+55
-4
No files matched your search
@@ -660,6 +660,7 @@ object SessionFiles {
|
||||
private const val UI_STATE = "UIStoreLocalSteamUIState"
|
||||
private const val SORT_RECENT_OFF = "\\\"bSortedByRecent\\\":false"
|
||||
private const val SORT_RECENT_ON = "\\\"bSortedByRecent\\\":true"
|
||||
private const val LIBRARY_BIG_ART = "LibraryHomeBigArt"
|
||||
private const val BATTERY_PERCENT_ON = "{\\\"bShowBatteryPercentage\\\":true}"
|
||||
|
||||
/**
|
||||
@@ -709,7 +710,12 @@ object SessionFiles {
|
||||
val block = out.substring(web.keyStart, web.close + 1)
|
||||
out = out.replaceRange(web.keyStart, web.close + 1, setScalar(block, BATTERY_PREFERENCES, BATTERY_PERCENT_ON, newline))
|
||||
}
|
||||
return seedRecentSort(out, newline)
|
||||
out = seedRecentSort(out, newline)
|
||||
val last = findObject(out, "UserLocalConfigStore", 0, out.length) ?: return out
|
||||
if (!hasKey(out.substring(last.open + 1, last.close), LIBRARY_BIG_ART)) {
|
||||
out = insertInto(out, last, listOf("\"$LIBRARY_BIG_ART\"\t\t\"1\""), newline)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// The library sort lives inside a JSON string; Steam writes bSortedByRecent:false until the player picks a sort,
|
||||
@@ -729,9 +735,11 @@ object SessionFiles {
|
||||
|
||||
private fun insertInto(text: String, parent: VdfBlock, lines: List<String>, newline: String): String {
|
||||
val lineStart = text.lastIndexOf('\n', parent.close).let { if (it < 0) 0 else it + 1 }
|
||||
val indent = text.substring(lineStart, parent.close).takeWhile { it == '\t' || it == ' ' } + "\t"
|
||||
val before = text.substring(lineStart, parent.close)
|
||||
val indent = before.takeWhile { it == '\t' || it == ' ' } + "\t"
|
||||
val section = lines.joinToString(newline) { indent + it } + newline
|
||||
return text.substring(0, lineStart) + section + text.substring(lineStart)
|
||||
if (before.isBlank()) return text.substring(0, lineStart) + section + text.substring(lineStart)
|
||||
return text.substring(0, parent.close) + newline + section + text.substring(parent.close)
|
||||
}
|
||||
|
||||
private val IDLE_SLEEP_TIMERS = listOf("IdleSuspendBatterySeconds", "IdleSuspendACSeconds")
|
||||
|
||||
@@ -59,6 +59,27 @@ class SteamUserDefaultsTest {
|
||||
assertFalse(File(home, "userdata/123/config/droiddeck-user-defaults-initialized").exists())
|
||||
}
|
||||
|
||||
@Test fun libraryHomeUsesBigArtUnlessChosenOtherwise() {
|
||||
val fresh = home("")
|
||||
SessionFiles.seedUserDefaults(fresh)
|
||||
assertTrue(text(fresh).contains("\"LibraryHomeBigArt\"\t\t\"1\""))
|
||||
val chosen = home("\t\"LibraryHomeBigArt\"\t\t\"0\"\n")
|
||||
SessionFiles.seedUserDefaults(chosen)
|
||||
assertTrue(text(chosen).contains("\"LibraryHomeBigArt\"\t\t\"0\""))
|
||||
assertEquals(1, Regex("LibraryHomeBigArt").findAll(text(chosen)).count())
|
||||
}
|
||||
|
||||
@Test fun bigArtLandsInTheRootWhenNestedStoresCloseOnItsLastLine() {
|
||||
val home = home("")
|
||||
File(home, "userdata/123/config/localconfig.vdf").writeText(
|
||||
"\"UserLocalConfigStore\"\n{\n\t\"WebStorage\"\n\t{\n\t\t\"Other\"\t\t\"x\"\n\t}}\n")
|
||||
SessionFiles.seedUserDefaults(home)
|
||||
val t = text(home)
|
||||
val beforeBigArt = t.substring(0, t.indexOf("\"LibraryHomeBigArt\""))
|
||||
assertEquals(beforeBigArt.count { it == '{' }, beforeBigArt.count { it == '}' } + 1)
|
||||
assertTrue(t.indexOf("\"CachedBatteryPreferences\"") < t.indexOf("\"LibraryHomeBigArt\""))
|
||||
}
|
||||
|
||||
@Test fun librarySortsByRecentlyPlayed() {
|
||||
val fresh = home("")
|
||||
SessionFiles.seedUserDefaults(fresh)
|
||||
|
||||
@@ -10,6 +10,7 @@ import tempfile
|
||||
DISPLAY = "External: gamescope|||Windowed"
|
||||
NATIVE_RESOLUTION = "EnableSteamNativeExternalResolution"
|
||||
SCREENSAVER_IN_GAME = ("Customization", "Screensaver", "WhileInGame")
|
||||
SCREENSAVER_CURRENT = ("Customization", "Screensaver", "CurrentScreensaver")
|
||||
TOKEN = re.compile(r'\s+|//[^\n]*|"(?:\\.|[^"\\])*"|[{}]')
|
||||
|
||||
|
||||
@@ -137,6 +138,10 @@ def seed_no_screensaver_in_game(text):
|
||||
return seed_value(text, SCREENSAVER_IN_GAME, '0')
|
||||
|
||||
|
||||
def seed_bouncing_logo(text):
|
||||
return seed_value(text, SCREENSAVER_CURRENT, 'steam-bouncinglogo')
|
||||
|
||||
|
||||
def atomic_write(path, text):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
fd, temporary = tempfile.mkstemp(prefix='.' + path.name, dir=path.parent)
|
||||
@@ -179,6 +184,11 @@ def initialize_screensaver(steam_root):
|
||||
'== steam: no screensaver over a running game')
|
||||
|
||||
|
||||
def initialize_screensaver_choice(steam_root):
|
||||
return seed_once(steam_root, 'droiddeck-screensaver-choice-initialized', seed_bouncing_logo,
|
||||
'== steam: bouncing logo screensaver')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
status = 0
|
||||
try:
|
||||
@@ -186,7 +196,7 @@ if __name__ == '__main__':
|
||||
except (OSError, ValueError, RecursionError) as error:
|
||||
print('== steam: left UI scale unchanged: ' + str(error), file=sys.stderr)
|
||||
status = 1
|
||||
for what, step in (('native resolution', initialize_native_resolution), ('screensaver', initialize_screensaver)):
|
||||
for what, step in (('native resolution', initialize_native_resolution), ('screensaver', initialize_screensaver), ('screensaver choice', initialize_screensaver_choice)):
|
||||
try:
|
||||
step(sys.argv[1])
|
||||
except (OSError, ValueError, RecursionError) as error:
|
||||
|
||||
@@ -16,6 +16,8 @@ initialize_native_resolution = MODULE['initialize_native_resolution']
|
||||
NATIVE_RESOLUTION = MODULE['NATIVE_RESOLUTION']
|
||||
seed_no_screensaver_in_game = MODULE['seed_no_screensaver_in_game']
|
||||
initialize_screensaver = MODULE['initialize_screensaver']
|
||||
seed_bouncing_logo = MODULE['seed_bouncing_logo']
|
||||
initialize_screensaver_choice = MODULE['initialize_screensaver_choice']
|
||||
|
||||
|
||||
class SteamUiScaleTest(unittest.TestCase):
|
||||
@@ -182,6 +184,16 @@ class SteamScreensaverTest(unittest.TestCase):
|
||||
self.assertEqual('0', screensaver.get('WhileInGame'))
|
||||
self.assertIn('\t\t\t"WhileInGame"\t\t"0"\n\t\t}\n', updated)
|
||||
|
||||
def test_fresh_client_gets_the_bouncing_logo(self):
|
||||
self.assertTrue(initialize_screensaver_choice(self.root))
|
||||
screensaver = parse(self.config.read_text()).get('InstallConfigStore').get('Customization').get('Screensaver')
|
||||
self.assertEqual('steam-bouncinglogo', screensaver.get('CurrentScreensaver'))
|
||||
self.assertTrue(self.config.with_name('droiddeck-screensaver-choice-initialized').exists())
|
||||
|
||||
def test_a_screensaver_already_picked_is_kept(self):
|
||||
text = '"InstallConfigStore" { "Customization" { "Screensaver" { "CurrentScreensaver" "other" } } }'
|
||||
self.assertEqual((text, False), seed_bouncing_logo(text))
|
||||
|
||||
def test_users_choice_is_kept(self):
|
||||
text = '"InstallConfigStore" { "Customization" { "Screensaver" { "WhileInGame" "1" } } }'
|
||||
self.assertEqual((text, False), seed_no_screensaver_in_game(text))
|
||||
|
||||
Reference in new issue
Block a user