mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-08-11 18:41:18 +10:00
Fix UI helper errors during headless -Preset and -Config runs (#4941)
* Make UI helpers no-op when no window exists The -Preset and -Config paths run Invoke-WinUtilAutoRun before the XAML form is created and before PresentationCore is loaded, so every call into Invoke-WPFUIThread failed with InvokeMethodOnNull and every call into Set-WinUtilTweaksProgressIndicator failed to resolve [Windows.Visibility]. The errors were non-terminating, so tweaks still applied, but each run filled the log with noise. Loading presentationframework earlier does not help: Visibility lives in PresentationCore, which only loads once a WPF object is instantiated, and the XAML-named progress controls do not exist in these paths either. Guarding the two helpers covers Invoke-WPFtweaksbutton, Invoke-WPFundoall and Invoke-WPFFeatureInstall, which the existing per-call-site $hasUI convention never reached. * Suppress stray console output from automation runs Invoke-WPFRunspace returns an IAsyncResult that no caller uses, and Set-WinUtilRegistry was the only New-PSDrive call site that did not suppress its output. A GUI click handler discards both, but the -Preset and -Config paths call the workflows directly, so an async handle dump and a PSDrive table landed in the user's log. The handle itself is kept because pester/runspace.Tests.ps1 asserts that Invoke-WPFRunspace returns a single IAsyncResult, so the suppression goes at the four call sites reachable from Invoke-WinUtilAutoRun. * Add project learning for window-free UI helpers
This commit is contained in:
@@ -96,5 +96,5 @@ function Invoke-WPFAppxRemoval {
|
||||
$sync.ProcessRunning = $false
|
||||
}
|
||||
|
||||
}
|
||||
} | Out-Null
|
||||
}
|
||||
|
||||
@@ -36,5 +36,5 @@ function Invoke-WPFFeatureInstall {
|
||||
Write-Host "--- Features are Installed ---"
|
||||
Write-Host "--- A Reboot may be required ---"
|
||||
Write-Host "==================================="
|
||||
}
|
||||
} | Out-Null
|
||||
}
|
||||
|
||||
@@ -110,5 +110,5 @@ function Invoke-WPFInstall {
|
||||
}
|
||||
$sync.ProcessRunning = $False
|
||||
}
|
||||
}
|
||||
} | Out-Null
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
function Invoke-WPFUIThread ($ScriptBlock) {
|
||||
if ($null -eq $sync.form -or $null -eq $sync.form.Dispatcher) {
|
||||
return
|
||||
}
|
||||
|
||||
$sync.form.Dispatcher.Invoke([action]$ScriptBlock)
|
||||
}
|
||||
|
||||
@@ -88,5 +88,5 @@ function Invoke-WPFtweaksbutton {
|
||||
Write-Host "-- Tweaks are Finished ---"
|
||||
Write-Host "================================="
|
||||
Write-WinUtilLog -Component "Tweaks" -Message "Tweaks workflow completed."
|
||||
}
|
||||
} | Out-Null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user