aboutsummaryrefslogtreecommitdiff
path: root/scripts/windows_input/Bootstrap.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/windows_input/Bootstrap.ps1')
-rw-r--r--scripts/windows_input/Bootstrap.ps151
1 files changed, 51 insertions, 0 deletions
diff --git a/scripts/windows_input/Bootstrap.ps1 b/scripts/windows_input/Bootstrap.ps1
new file mode 100644
index 00000000..4f6884fb
--- /dev/null
+++ b/scripts/windows_input/Bootstrap.ps1
@@ -0,0 +1,51 @@
+#Requires -Version 7.0
+param([Parameter(Mandatory)][string] $PlanPath)
+. "$PSScriptRoot/Common.ps1"
+$plan = Read-GauntletJson $PlanPath
+# Terminal activation can inherit another process's environment. Normalize here too.
+foreach ($item in @(Get-ChildItem Env:)) {
+ if ($item.Name -like 'HERDR_*' -or $item.Name -in @('SSH_CONNECTION', 'SSH_TTY')) { Remove-Item "Env:$($item.Name)" }
+}
+$env:HERDR_CONFIG_PATH = $plan.config
+$env:XDG_CONFIG_HOME = $plan.config_home
+$env:HERDR_SESSION = $plan.session
+if ($plan.profile -ne 'default') { $env:HERDR_WINDOWS_INPUT_PROBE = $plan.profile }
+Add-Type -Path "$PSScriptRoot/Native.cs"
+$before = [HerdrInputGauntlet.ConsoleProbe]::Geometry()
+$child = $null
+try {
+ if ($plan.path -eq 'herdr') {
+ $child = New-GauntletProcess $plan.exe @('--session', $plan.session) $plan
+ } else {
+ $child = New-GauntletProcess $plan.pwsh @('-NoProfile', '-File', "$PSScriptRoot/Probe.ps1", '-PlanPath', $PlanPath) $plan
+ }
+ $sequence = 0
+ while (-not $child.HasExited -and (Test-GauntletLease $plan.root) -and -not (Test-Path (Join-Path $plan.work 'stop'))) {
+ $sequence++
+ Write-GauntletJson (Join-Path $plan.work 'outer.json') @{
+ nonce = $plan.nonce; pid = $PID; child_pid = $child.Id; sequence = $sequence
+ geometry = [HerdrInputGauntlet.ConsoleProbe]::Geometry(); before = $before
+ }
+ Start-Sleep -Milliseconds 100
+ }
+} finally {
+ $cleanup = @()
+ if ($null -ne $child) {
+ # Allow normal detach / observer disposal before forcing this owned child down.
+ if (-not $child.WaitForExit(5000)) {
+ $cleanup += 'Child required forced termination; normal console restoration was not qualified'
+ $child.Kill($true)
+ if (-not $child.WaitForExit(5000)) { $cleanup += 'Child remained active after forced termination' }
+ }
+ $child.Dispose()
+ }
+ if ($plan.path -eq 'herdr') {
+ foreach ($verb in @('stop', 'delete')) {
+ try { $null = Invoke-GauntletProcess $plan.exe @('session', $verb, $plan.session) $plan }
+ catch { $cleanup += $_.ToString() }
+ }
+ }
+ Write-GauntletJson (Join-Path $plan.work 'bootstrap-exit.json') @{
+ nonce = $plan.nonce; before = $before; after = [HerdrInputGauntlet.ConsoleProbe]::Geometry(); cleanup_errors = $cleanup
+ }
+}