"""Restore the recorded personal display/focus/workspace settings after lab work.""" from . import background from . import support from . import workspace from .diagnostics import DiagnosticError def launch(): """Every devkit launch establishes lab mode before Steam starts the game.""" from . import lifecycle support.manage.ensure_game_closed() lifecycle.verify() # Catch known conflicts before enabling either feature. In particular an # already-installed background adapter must still own the display preset. background.prepare_disable() background.viewport(background.SETTINGS.read_bytes()) workspace.prepare_pin() step='background-enable' completed={} try: completed[step]=background.enable() step='workspace-pin' completed[step]=workspace.pin() step='steam-launch' support.run('steam','-applaunch','292030','--launcher-skip','-dx12','-net','-debugscripts') except Exception as error: # Steam delivery can be uncertain. reset() refuses to remove an adapter # from a live game; retain the original error and cleanup evidence. try: cleanup=reset() except Exception as cleanup_error: cleanup=dict(ok=False,detail=str(cleanup_error), recovery='Close the game, then run reset-game-settings.') raise DiagnosticError('E9001',f'Lab launch failed during {step}: {error}', evidence=dict(completed=completed,failed_step=step,settings_cleanup=cleanup)) from error return dict(ok=True,state='launch_requested',lab_mode=completed, next='Wait for the real game window, then attach. stop restores personal settings after exit.') def reset(): support.manage.ensure_game_closed() # Validate both restorations before either mutates disk. Each operation also # rechecks its ownership immediately before making changes. background.prepare_disable() pin=workspace.prepare_unpin() if pin is not None: workspace.script(workspace.QUERY) # Check the compositor is reachable first. completed={} step='background-disable' try: completed[step]=background.disable() step='workspace-unpin' completed[step]=workspace.unpin() step='verify' if background.verify() or workspace.prepare_unpin() is not None: raise RuntimeError('Lab background mode or workspace pin remains enabled') except Exception as error: raise DiagnosticError('E9001', f'reset-game-settings failed during {step}: {error}. ' 'Completed steps are retained; the failing step may have changed files. ' 'Inspect background-status, workspace-status and their ownership receipts before retrying.', evidence=dict(completed=completed,failed_step=step, background_receipt=str(background.RECEIPT), workspace_receipt=str(workspace.RECEIPT))) from error return dict(ok=True,background_enabled=False,workspace_pinned=False, steps=completed, note='Recorded display settings restored when background mode was enabled. ' 'Steam Play uses personal settings; lab launch automatically enables lab mode again. ' 'Saves, combat mods, the devkit bridge and unrelated settings are preserved.')