feat: toggle Steam shader pre-caching from DroidDeck's Steam settings

This commit is contained in:
Kurt Himebauch committed 2026-10-23 13:05:04 -04:00
1 parent f683ca1dea
commit f88227ed74
12 files changed
+216 -5

No files matched your search

@@ -531,6 +531,10 @@ case $mode in
fi
droiddeck-seed-redists "$steam_root" || true
fi
if [ -n "${BL_SHADER_PRECACHE:-}" ]; then
droiddeck-steam-shaders "$BL_SHADER_PRECACHE" "$XDG_DATA_HOME/Steam" \
"${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam" || true
fi
if [ "$steam_x64" = 0 ] && [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then
step "asking the client to fetch the ARM64 Proton"
set -- "$@" steam://install/4427310
@@ -0,0 +1,61 @@
#!/usr/bin/python3
"""Sets the Steam client's shader pre-caching (Settings > Downloads), before the client starts.
droiddeck-steam-shaders <0|1> <steam root>...
The client stores the toggle as InstallConfigStore/Software/Valve/Steam/ShaderCacheManager/
DisableShaderCache in config/config.vdf: "1" when off, "0" when on. It keeps the setting in memory
and writes config.vdf back on exit, so this runs only while the client is stopped. The launcher
passes a value only after its own toggle changes; otherwise the client's toggle stays the user's."""
from pathlib import Path
import runpy
import sys
VDF = runpy.run_path(str(Path(__file__).with_name("droiddeck-steam-ui-scale")))
PATH = ("Software", "Valve", "Steam", "ShaderCacheManager", "DisableShaderCache")
def set_text(text, enabled):
value = "0" if enabled else "1"
updated, changed = VDF["seed_value"](text, PATH, value)
if changed:
return updated, True
block = VDF["parse"](text).get("InstallConfigStore")
for section in PATH[:-1]:
block = block.get(section)
current = block.get(PATH[-1])
if isinstance(current, VDF["Block"]):
raise ValueError("invalid DisableShaderCache setting")
if current == value:
return text, False
at = block.offset(PATH[-1])
end = VDF["TOKEN"].match(text, at).end()
return text[:at] + f'"{value}"' + text[end:], True
def apply(steam_root, enabled):
config = Path(steam_root) / "config/config.vdf"
text = config.read_text() if config.exists() else '"InstallConfigStore"\n{\n}\n'
updated, changed = set_text(text, enabled)
if changed:
VDF["atomic_write"](config, updated)
return changed
if __name__ == "__main__":
if len(sys.argv) < 3 or sys.argv[1] not in ("0", "1"):
print("usage: droiddeck-steam-shaders <0|1> <steam root>...", file=sys.stderr)
sys.exit(2)
enabled = sys.argv[1] == "1"
status = 0
for root in sys.argv[2:]:
if not Path(root).is_dir():
continue
try:
if apply(root, enabled):
print(f"== steam: shader pre-caching {'on' if enabled else 'off'} in {root}")
except (OSError, ValueError, RecursionError) as error:
print(f"== steam: left shader pre-caching unchanged in {root}: {error}", file=sys.stderr)
status = 1
sys.exit(status)
@@ -26,9 +26,10 @@ TOKEN = re.compile(r'\s+|//[^\n]*|"(?:\\.|[^"\\])*"|[{}]')
class Block:
def __init__(self, pairs, end):
def __init__(self, pairs, end, offsets=()):
self.pairs = pairs
self.end = end
self.offsets = offsets
def get(self, name):
matches = [value for key, value in self.pairs if key.lower() == name.lower()]
@@ -36,6 +37,9 @@ class Block:
raise ValueError("duplicate UI setting")
return matches[0] if matches else None
def offset(self, name):
return next(at for (key, _), at in zip(self.pairs, self.offsets) if key.lower() == name.lower())
def parse(text):
tokens = []
@@ -51,17 +55,17 @@ def parse(text):
raise ValueError("invalid config.vdf")
def block(index, nested=False):
pairs = []
pairs, offsets = [], []
while index < len(tokens):
token, offset = tokens[index]
if token == '}':
if not nested:
raise ValueError("unexpected closing brace")
return Block(pairs, offset), index + 1
return Block(pairs, offset, offsets), index + 1
if not token.startswith('"') or index + 1 == len(tokens):
raise ValueError("missing config value")
key = token[1:-1]
value = tokens[index + 1][0]
value, at = tokens[index + 1]
index += 2
if value == '{':
value, index = block(index, True)
@@ -70,9 +74,10 @@ def parse(text):
else:
raise ValueError("invalid config value")
pairs.append((key, value))
offsets.append(at)
if nested:
raise ValueError("unclosed config block")
return Block(pairs, len(text)), index
return Block(pairs, len(text), offsets), index
return block(0)[0]
+88
View File
@@ -0,0 +1,88 @@
from pathlib import Path
import runpy
import tempfile
import unittest
BIN = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin'
MODULE = runpy.run_path(str(BIN / 'droiddeck-steam-shaders'))
apply = MODULE['apply']
set_text = MODULE['set_text']
parse = runpy.run_path(str(BIN / 'droiddeck-steam-ui-scale'))['parse']
THOR = '''"InstallConfigStore"
{
\t"Software"
\t{
\t\t"Valve"
\t\t{
\t\t\t"Steam"
\t\t\t{
\t\t\t\t"ShaderCacheManager"
\t\t\t\t{
\t\t\t\t\t"HasCurrentBucket"\t\t"1"
\t\t\t\t\t"ProcessingQueue"\t\t"207140;848350;"
\t\t\t\t\t"App"
\t\t\t\t\t{
\t\t\t\t\t}
\t\t\t\t}
\t\t\t}
\t\t}
\t}
}
'''
def disabled(text):
steam = parse(text).get('InstallConfigStore').get('Software').get('Valve').get('Steam')
return steam.get('ShaderCacheManager').get('DisableShaderCache')
class SteamShadersTest(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.config = self.root / 'config/config.vdf'
self.config.parent.mkdir()
def test_off_adds_the_key_the_client_writes(self):
text, changed = set_text(THOR, False)
self.assertTrue(changed)
self.assertEqual('1', disabled(text))
self.assertIn('\t\t\t\t\t"DisableShaderCache"\t\t"1"\n\t\t\t\t}', text)
self.assertIn('"ProcessingQueue"\t\t"207140;848350;"', text)
def test_existing_value_is_replaced_in_place(self):
off, _ = set_text(THOR, False)
on, changed = set_text(off, True)
self.assertTrue(changed)
self.assertEqual('0', disabled(on))
self.assertEqual(off.replace('"DisableShaderCache"\t\t"1"', '"DisableShaderCache"\t\t"0"'), on)
def test_matching_value_leaves_the_file_alone(self):
off, _ = set_text(THOR, False)
self.assertEqual((off, False), set_text(off, False))
def test_missing_sections_are_created(self):
text, changed = set_text('"InstallConfigStore"\n{\n}\n', False)
self.assertTrue(changed)
self.assertEqual('1', disabled(text))
def test_apply_writes_config_and_creates_a_fresh_one(self):
self.config.write_text(THOR)
self.assertTrue(apply(self.root, False))
self.assertEqual('1', disabled(self.config.read_text()))
self.assertFalse(apply(self.root, False))
fresh = Path(self.temp.name) / 'fresh'
fresh.mkdir()
self.assertTrue(apply(fresh, True))
self.assertEqual('0', disabled((fresh / 'config/config.vdf').read_text()))
def test_invalid_config_is_rejected(self):
with self.assertRaises(ValueError):
set_text('"InstallConfigStore" {', False)
if __name__ == '__main__':
unittest.main()