fix: Steam shows cached library art when it starts without reaching Steam (#1985)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-01 19:55:18 -05:00
1 parent e1d241d723
commit 84a04d9ead
2 files changed
+69

No files matched your search

@@ -18,6 +18,19 @@ COMPAT = runpy.run_path(os.path.join(HERE, "steam-compatibility"))
BINDING = "droiddeckCompatChanged"
BRIGHTNESS_BINDING = "droiddeckBrightnessChanged"
CONTROLS_DIR = "/etc/droiddeck-device-controls"
LIBRARY_ART_JS = r"""
(() => {
if (window.__droiddeckLibraryArt) return "present";
const store = typeof appStore === "object" ? appStore : null;
if (typeof store?.BHasCachedLibraryAsset !== "function") return "unavailable";
// The client reports which cached assets exist only after a logon that reaches Steam; before that every app reads as
// uncached and the UI asks the CDN, which is blank offline. The native check still runs, so misses are still reported.
const native = store.BHasCachedLibraryAsset.bind(store);
store.BHasCachedLibraryAsset = (appid, version, type) => native(appid, version, type) || !version;
window.__droiddeckLibraryArt = true;
return "installed";
})()
"""
BRIGHTNESS_JS = r"""
(() => {
if (window.__droiddeckBrightness) return "present";
@@ -851,6 +864,7 @@ class Helper:
if self.files_only:
page.call("Runtime.addBinding", {"name": FILE_BINDING})
page.evaluate(FILE_JS)
page.evaluate(LIBRARY_ART_JS)
self.page = page
self.controls_state = None
self.controls_installed = False
@@ -861,6 +875,7 @@ class Helper:
page.evaluate(VR_JS)
page.call("Runtime.addBinding", {"name": FILE_BINDING})
page.evaluate(FILE_JS)
page.evaluate(LIBRARY_ART_JS)
try:
page.evaluate(TOUR_JS)
except RuntimeError:
+54
View File
@@ -0,0 +1,54 @@
from pathlib import Path
import runpy
import shutil
import subprocess
import tempfile
import unittest
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
LIVE = runpy.run_path(str(BIN / "droiddeck-steam-compat"))
HARNESS = """
const reports = [];
global.appStore = {
BHasCachedLibraryAsset(appid, version, type) {
if ((version ?? 0) & (1 << type)) return true;
reports.push([appid, type]);
return false;
},
};
const first = eval(process.argv[2]);
const second = eval(process.argv[2]);
const check = (name, actual, expected) => { if (actual !== expected) throw new Error(name + ": " + actual); };
check("install", first, "installed");
check("reinstall", second, "present");
check("no logon", appStore.BHasCachedLibraryAsset(10, undefined, 3), true);
check("zero version", appStore.BHasCachedLibraryAsset(10, 0, 3), true);
check("reported", reports.length, 2);
check("bit set", appStore.BHasCachedLibraryAsset(10, 1 << 3, 3), true);
check("bit missing", appStore.BHasCachedLibraryAsset(10, 1 << 2, 3), false);
check("reported again", reports.length, 3);
"""
@unittest.skipUnless(shutil.which("node"), "node is not installed")
class LibraryArtTest(unittest.TestCase):
def run_node(self, harness):
with tempfile.TemporaryDirectory() as directory:
script = Path(directory, "harness.js")
script.write_text("global.window = {};\n" + harness)
return subprocess.run(["node", str(script), LIVE["LIBRARY_ART_JS"]], capture_output=True, text=True, timeout=20)
def test_apps_without_a_client_cache_report_read_from_the_local_library_cache(self):
result = self.run_node(HARNESS)
self.assertEqual(result.returncode, 0, result.stderr)
def test_a_page_without_the_app_store_is_left_alone(self):
result = self.run_node("""
if (eval(process.argv[2]) !== "unavailable") throw new Error("installed without an app store");
""")
self.assertEqual(result.returncode, 0, result.stderr)
if __name__ == "__main__":
unittest.main()