$ErrorActionPreference = 'Stop' $taskName = 'Chimera Remote Play Worker' $target = Join-Path $env:LOCALAPPDATA 'Chimera\RemotePlayWorker' $node = Get-Command node.exe -ErrorAction SilentlyContinue if (-not $node) { $winget = Get-Command winget.exe -ErrorAction SilentlyContinue if (-not $winget) { throw 'Node.js ontbreekt en Windows Package Manager is niet beschikbaar om het automatisch te installeren.' } Write-Host 'Node.js LTS ontbreekt; Chimera installeert het nu via Windows Package Manager.' -ForegroundColor Yellow & $winget.Source install --id OpenJS.NodeJS.LTS -e --accept-package-agreements --accept-source-agreements --disable-interactivity if ($LASTEXITCODE -ne 0) { throw "Node.js-installatie mislukte met exitcode $LASTEXITCODE." } $nodePath = Join-Path $env:ProgramFiles 'nodejs\node.exe' if (Test-Path -LiteralPath $nodePath) { $node = Get-Command $nodePath -ErrorAction SilentlyContinue } else { $node = Get-Command node.exe -ErrorAction SilentlyContinue } } if (-not $node) { throw 'Node.js LTS kon na installatie niet worden gevonden.' } if (-not (Test-Path -LiteralPath (Join-Path $PSScriptRoot 'pairing.json'))) { throw 'pairing.json ontbreekt. Download een nieuw workerpakket vanuit Chimera.' } New-Item -ItemType Directory -Force -Path $target | Out-Null Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'worker.js') -Destination (Join-Path $target 'worker.js') -Force Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'pairing.json') -Destination (Join-Path $target 'pairing.json') -Force Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'uninstall.ps1') -Destination (Join-Path $target 'uninstall.ps1') -Force $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name & icacls.exe (Join-Path $target 'pairing.json') /inheritance:r /grant:r "${identity}:(M)" | Out-Null $arguments = '"' + (Join-Path $target 'worker.js') + '" --config "' + (Join-Path $target 'pairing.json') + '"' $action = New-ScheduledTaskAction -Execute $node.Source -Argument $arguments -WorkingDirectory $target $trigger = New-ScheduledTaskTrigger -AtLogOn -User $identity $principal = New-ScheduledTaskPrincipal -UserId $identity -LogonType Interactive -RunLevel Limited $settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit ([TimeSpan]::Zero) -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1) -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null Start-ScheduledTask -TaskName $taskName Remove-Item -LiteralPath (Join-Path $PSScriptRoot 'pairing.json') -Force Write-Host '' Write-Host 'Chimera Remote Play Worker is geinstalleerd en gestart.' -ForegroundColor Green Write-Host "Installatiemap: $target" Write-Host 'Ga terug naar Chimera en klik op Vernieuwen of Diagnose.'