mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
fix: refresh repaired components and render Ubisoft Connect (#2090)
* fix: refresh repaired components and render Ubisoft Connect * fix: address component repair and Wine registry review * fix: repair manually enabled components and check registry writes * fix: serialize component repairs and use Proton runinprefix * fix: report queued component repair failures * fix: preserve newer component repair waits * Make component queue transitions atomic * Isolate component apply failures by game * Preserve pending repair when catalog is stale * Restore persisted component repair revisions * Update pending requirements atomically * Respect disabled pending components per game * Keep queue key state atomic while worker waits * Pass selected game to component repairs * Preserve pending repair when component is absent * Preserve pending revision on catalog failure * Test legacy pending repair revision recovery * Isolate fake worker Steam app info lookup * Merge queued Steam app info lookups * Persist launch component revisions before repair * Gate launch on component repair discovery * Expand and refresh launch repair discovery * Include new automatic picks in launch requirements * Log repair persistence failures and align repair keys * Use runtime key for Battle.net component repairs * Retain failed component reapplications for retry * Harden pending repairs and launch preparation * Isolate wait-cool sleep mocking * Allow launches without catalog when no repair is pending * Queue launch repairs even if persistence fails * Block launch when repair state cannot persist * Allow launch when no component repair is needed * Persist selected repairs when catalog is offline * Drain offline component repair in test
This commit is contained in:
1 parent
ab92033b90
commit
516e3862fa
14 files changed
+756
-83
No files matched your search
+5
-1
@@ -392,6 +392,10 @@ def thermal(adb: str, serial: str) -> dict:
|
||||
return {"ok": True, "command": "thermal", **summary}
|
||||
|
||||
|
||||
def wait_sleep(seconds: float) -> None:
|
||||
time.sleep(seconds)
|
||||
|
||||
|
||||
def wait_cool(adb: str, serial: str, below: float, timeout: float) -> dict:
|
||||
started = time.monotonic()
|
||||
while True:
|
||||
@@ -404,7 +408,7 @@ def wait_cool(adb: str, serial: str, below: float, timeout: float) -> dict:
|
||||
if remaining <= 0:
|
||||
raise ControlError(f"Battery still at {reading['batteryC']:g} °C after {timeout:g} s, wanted below {below:g}",
|
||||
"TIMEOUT")
|
||||
time.sleep(min(10.0, remaining))
|
||||
wait_sleep(min(10.0, remaining))
|
||||
|
||||
|
||||
def start_session(adb: str, serial: str, request: dict) -> dict:
|
||||
|
||||
@@ -243,6 +243,20 @@ def ubisoft_overlay_off(env):
|
||||
print("droiddeck-game-env: Ubisoft Connect overlay left as is (%s)" % error, file=sys.stderr)
|
||||
|
||||
|
||||
def ubisoft_composition_off(proton, env):
|
||||
prefix = Path(env.get("STEAM_COMPAT_DATA_PATH", "/nonexistent")) / "pfx"
|
||||
if not (prefix / UBISOFT_LAUNCHER).is_dir() or not (prefix / "user.reg").is_file():
|
||||
return
|
||||
try:
|
||||
for program in ("upc.exe", "UplayWebCore.exe"):
|
||||
key = r"HKCU\Software\Wine\AppDefaults\%s\DllOverrides" % program
|
||||
subprocess.run([proton, "runinprefix", "reg.exe", "add", key,
|
||||
"/v", "dcomp", "/t", "REG_SZ", "/d", "", "/f"], env=env, check=True)
|
||||
print("droiddeck-game-env: Ubisoft Connect uses CEF without DirectComposition", file=sys.stderr)
|
||||
except (OSError, ValueError, subprocess.CalledProcessError) as error:
|
||||
print("droiddeck-game-env: Ubisoft Connect composition configuration failed (%s)" % error, file=sys.stderr)
|
||||
|
||||
|
||||
PZ_JVM_FLAGS = ("-XX:+UseG1GC", "-XX:TieredStopAtLevel=1")
|
||||
|
||||
|
||||
@@ -973,6 +987,8 @@ def wait_forwarding_signals(process):
|
||||
|
||||
|
||||
def start(launch, launch_env, digest, after=None):
|
||||
if len(launch) > 1 and launch[1] == "waitforexitandrun":
|
||||
ubisoft_composition_off(launch[0], launch_env)
|
||||
if after:
|
||||
process = subprocess.Popen(launch, env=launch_env)
|
||||
try:
|
||||
|
||||
@@ -476,15 +476,30 @@ def save_state(compat, state):
|
||||
def pending_for(app_id, pending=PENDING):
|
||||
try:
|
||||
with open(pending, encoding="utf-8") as source:
|
||||
ids = json.load(source).get("games", {}).get(str(app_id), [])
|
||||
config = json.load(source)
|
||||
ids = config.get("games", {}).get(str(app_id), [])
|
||||
revisions = config.get("revisions", {})
|
||||
except (OSError, ValueError, AttributeError):
|
||||
return []
|
||||
return [i for i in ids if valid_id(i)] if isinstance(ids, list) else []
|
||||
return {}
|
||||
revisions = revisions if isinstance(revisions, dict) else {}
|
||||
return {i: max(0, revisions[i]) if type(revisions.get(i)) is int else 0
|
||||
for i in ids if valid_id(i)} if isinstance(ids, list) else {}
|
||||
|
||||
|
||||
def wait_for_pending(app_id, pending=PENDING, store=STORE, timeout=PENDING_WAIT, sleep=time.sleep, clock=time.monotonic):
|
||||
def missing():
|
||||
return [cid for cid in pending_for(app_id, pending) if component(store, cid) is None]
|
||||
left = []
|
||||
for cid, revision in pending_for(app_id, pending).items():
|
||||
try:
|
||||
with open(Path(store) / cid / "component.json", encoding="utf-8") as source:
|
||||
meta = json.load(source)
|
||||
installed = meta.get("revision", 0)
|
||||
ready = type(installed) is int and installed >= revision
|
||||
except (OSError, ValueError, AttributeError):
|
||||
ready = False
|
||||
if not ready:
|
||||
left.append(cid)
|
||||
return left
|
||||
left = missing()
|
||||
if not left:
|
||||
return None
|
||||
|
||||
@@ -490,7 +490,7 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
|
||||
def test_wait_cool_polls_until_the_battery_is_below(self):
|
||||
self.configure({}, battery=[battery(412), battery(395), battery(379)], thermalservice=THERMALSERVICE)
|
||||
with unittest.mock.patch.object(ctl.time, "sleep") as slept:
|
||||
with unittest.mock.patch.object(ctl, "wait_sleep") as slept:
|
||||
code, out = self.run_ctl("wait", "cool", "--below", "38", "--timeout", "600")
|
||||
self.assertEqual(0, code, out)
|
||||
self.assertEqual(["wait", 37.9], [out["command"], out["batteryC"]])
|
||||
|
||||
@@ -2190,6 +2190,66 @@ class UbisoftOverlayTest(unittest.TestCase):
|
||||
self.assertEqual(sorted(p.name for p in settings.parent.iterdir()), ["settings.yaml"])
|
||||
|
||||
|
||||
class UbisoftCompositionTest(unittest.TestCase):
|
||||
def test_writes_through_wine_without_replacing_a_live_servers_registry(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
prefix = Path(tmp) / "pfx"
|
||||
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
||||
registry = prefix / "user.reg"
|
||||
registry.write_text("registry last saved by Wine\n")
|
||||
env = {"STEAM_COMPAT_DATA_PATH": tmp, "WINESERVER": "/selected/wineserver"}
|
||||
keys = []
|
||||
|
||||
def write_registry(argv, **kwargs):
|
||||
self.assertEqual(argv[:4], ["/selected/proton", "runinprefix", "reg.exe", "add"])
|
||||
self.assertEqual(argv[5:], ["/v", "dcomp", "/t", "REG_SZ", "/d", "", "/f"])
|
||||
self.assertIs(kwargs["env"], env)
|
||||
self.assertTrue(kwargs["check"])
|
||||
keys.append(argv[4])
|
||||
registry.write_text("newer state saved by the active Wine server\n")
|
||||
return subprocess.CompletedProcess(argv, 0)
|
||||
|
||||
with mock.patch("subprocess.run", side_effect=write_registry) as run:
|
||||
MODULE["ubisoft_composition_off"]("/selected/proton", env)
|
||||
self.assertEqual(run.call_count, 2)
|
||||
self.assertEqual(registry.read_text(), "newer state saved by the active Wine server\n")
|
||||
self.assertEqual(keys, [r"HKCU\Software\Wine\AppDefaults\%s\DllOverrides" % program
|
||||
for program in ("upc.exe", "UplayWebCore.exe")])
|
||||
self.assertEqual(list(prefix.glob(".ubisoft-*.reg")), [])
|
||||
|
||||
def test_other_prefixes_and_uninitialized_registries_are_untouched(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
prefix = Path(tmp) / "pfx"
|
||||
prefix.mkdir()
|
||||
registry = prefix / "user.reg"
|
||||
registry.write_text("WINE REGISTRY Version 2\n")
|
||||
env = {"STEAM_COMPAT_DATA_PATH": tmp}
|
||||
with mock.patch("subprocess.run") as run:
|
||||
MODULE["ubisoft_composition_off"]("proton", env)
|
||||
self.assertEqual(registry.read_text(), "WINE REGISTRY Version 2\n")
|
||||
registry.unlink()
|
||||
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
||||
MODULE["ubisoft_composition_off"]("proton", env)
|
||||
self.assertFalse(registry.exists())
|
||||
run.assert_not_called()
|
||||
|
||||
def test_failed_registry_write_keeps_the_game_launch_available(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
prefix = Path(tmp) / "pfx"
|
||||
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
||||
(prefix / "user.reg").write_text("WINE REGISTRY Version 2\n")
|
||||
for failed_write in (0, 1):
|
||||
stderr = io.StringIO()
|
||||
results = [subprocess.CompletedProcess([], 0)] * failed_write
|
||||
results.append(subprocess.CalledProcessError(1, "proton"))
|
||||
with mock.patch("subprocess.run", side_effect=results) as run, mock.patch("sys.stderr", stderr):
|
||||
MODULE["ubisoft_composition_off"]("proton", {"STEAM_COMPAT_DATA_PATH": tmp})
|
||||
self.assertEqual(run.call_count, failed_write + 1)
|
||||
self.assertIn("configuration failed", stderr.getvalue())
|
||||
self.assertNotIn("uses CEF", stderr.getvalue())
|
||||
self.assertEqual(list(prefix.glob(".ubisoft-*.reg")), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
@@ -274,10 +274,13 @@ class PendingWaitTest(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def install(self, cid):
|
||||
def install(self, cid, revision=0):
|
||||
folder = self.store / cid
|
||||
folder.mkdir(parents=True, exist_ok=True)
|
||||
(folder / "component.json").write_text(json.dumps({"id": cid, "overrides": []}))
|
||||
metadata = {"id": cid, "overrides": []}
|
||||
if revision is not None:
|
||||
metadata["revision"] = revision
|
||||
(folder / "component.json").write_text(json.dumps(metadata))
|
||||
|
||||
def clock(self):
|
||||
return len(self.slept) * 0.5
|
||||
@@ -296,6 +299,8 @@ class PendingWaitTest(unittest.TestCase):
|
||||
self.install("d3dx9")
|
||||
self.pending.write_text(json.dumps({"games": {"1262580": ["d3dx9"]}}))
|
||||
self.assertIsNone(self.wait())
|
||||
self.install("d3dx9", revision=None)
|
||||
self.assertIsNone(self.wait())
|
||||
self.assertEqual([], self.slept)
|
||||
|
||||
def test_waits_until_the_component_lands(self):
|
||||
@@ -311,6 +316,21 @@ class PendingWaitTest(unittest.TestCase):
|
||||
self.assertEqual(4, len(self.slept))
|
||||
self.assertEqual("wincomp: 1262580 launched without vcredist2019_dll (not ready)", note)
|
||||
|
||||
def test_an_existing_old_revision_waits_until_the_repair_lands(self):
|
||||
self.install("vcredist2010_dll", revision=0)
|
||||
self.pending.write_text(json.dumps({"games": {"1262580": ["vcredist2010_dll"]},
|
||||
"revisions": {"vcredist2010_dll": 1}}))
|
||||
note = self.wait(on_sleep=lambda n: self.install("vcredist2010_dll", revision=1) if n == 3 else None)
|
||||
self.assertEqual(3, len(self.slept))
|
||||
self.assertEqual(note, "wincomp: 1262580 waited 1500ms for vcredist2010_dll")
|
||||
|
||||
def test_an_old_revision_does_not_satisfy_a_pending_repair(self):
|
||||
self.install("vcredist2010_dll", revision=1)
|
||||
self.pending.write_text(json.dumps({"games": {"1262580": ["vcredist2010_dll"]},
|
||||
"revisions": {"vcredist2010_dll": 2}}))
|
||||
self.assertEqual(self.wait(timeout=1.0), "wincomp: 1262580 launched without vcredist2010_dll (not ready)")
|
||||
self.assertEqual(2, len(self.slept))
|
||||
|
||||
def test_a_damaged_pending_file_is_no_wait(self):
|
||||
self.pending.write_text("{not json")
|
||||
self.assertIsNone(self.wait())
|
||||
|
||||
Reference in new issue
Block a user