igneum/relay/playbooks/app-shot-light.ps1
2026-10-06 23:14:29 +00:00

29 lines
2.9 KiB
PowerShell

# Igneum playbook: two light-mode screenshots of the installed app (Overview, Cards) for the site's showcase card.
# Read-only: GETs the app's own URL and runs Edge headless, which renders prefers-color-scheme light by default.
# Never pauses, resumes or quits anything (the standing rule of 5 October 2026); the miners never notice.
# Queue: packaging/ota/publish-jobs.sh add --kind run --target 1ccfe586 --script relay/playbooks/app-shot-light.ps1 --title "app light-mode shots"
$ErrorActionPreference = 'Continue'
$urlFile = Join-Path $env:LOCALAPPDATA 'igneum\app\app.url'
if (-not (Test-Path $urlFile)) { Write-Host "ERROR: $urlFile missing (is the app running?)"; exit 2 }
$url = (Get-Content $urlFile -Raw).Trim()
$edge = @("$env:ProgramFiles (x86)\Microsoft\Edge\Application\msedge.exe", "$env:ProgramFiles\Microsoft\Edge\Application\msedge.exe") | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $edge) { Write-Host "ERROR: Edge not found"; exit 2 }
Write-Host ("edge " + (Get-Item $edge).VersionInfo.ProductVersion + " at " + $edge)
$out = Join-Path $env:TEMP 'igneum-shots'; New-Item -ItemType Directory -Force -Path $out | Out-Null
# a profile of its own, or the launcher hands the request to the user's running Edge and returns at once with no file
# (run-20261006-222112 on PC 2: both shots missing in 0 s); -Wait holds until the headless browser exits
$profile = Join-Path $out 'profile'; New-Item -ItemType Directory -Force -Path $profile | Out-Null
foreach ($page in @('overview', 'cards')) {
$png = Join-Path $out "igneum-$page-light-1440.png"
if (Test-Path $png) { Remove-Item $png -Force }
# take 3: the old headless mode (the new one wrote nothing on PC 2's Edge, exit 0 in 11 s); the screenshot path is
# passed bare, and the working directory is the output folder because old headless falls back to screenshot.png there
$args = @('--headless', '--disable-gpu', '--hide-scrollbars', '--no-first-run', '--no-sandbox', '--window-size=1440,1000', '--virtual-time-budget=8000', "--user-data-dir=$profile", "--screenshot=$png", "$url?page=$page&visible=1")
$errLog = Join-Path $out "edge-$page.log"
$p = Start-Process -FilePath $edge -ArgumentList $args -Wait -PassThru -WindowStyle Hidden -WorkingDirectory $out -RedirectStandardError $errLog
$tries = 0; while (-not (Test-Path $png) -and $tries -lt 20) { Start-Sleep -Milliseconds 500; $tries++ }
if (-not (Test-Path $png) -and (Test-Path (Join-Path $out 'screenshot.png'))) { Move-Item (Join-Path $out 'screenshot.png') $png -Force }
if (Test-Path $errLog) { Get-Content $errLog | Select-Object -First 5 | ForEach-Object { Write-Host "edge: $_" } }
if (Test-Path $png) { Write-Host "RESULT shot=$page bytes=$((Get-Item $png).Length) edge_exit=$($p.ExitCode)"; & $env:RELAY_SEND -TaskId ([long]$env:RELAY_TASK_ID) -Title "app $page light" $png } else { Write-Host "RESULT shot=$page missing edge_exit=$($p.ExitCode)" }
}
exit 0