2 Commits

Author SHA1 Message Date
Ludwig Lehnert
526c40403b fix gui timeout; ignore dist
All checks were successful
Release / build-release (push) Successful in 4s
2026-07-01 13:20:24 +00:00
Ludwig Lehnert
7fc0602818 fix gui runspace cleanup
All checks were successful
Release / build-release (push) Successful in 3s
2026-07-01 13:02:48 +00:00
3 changed files with 133 additions and 87 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
dist/

35
dist/setup.ps1 vendored

File diff suppressed because one or more lines are too long

184
setup.ps1
View File

@@ -1194,6 +1194,45 @@ function Get-AppStatus {
return 'Installierbar' return 'Installierbar'
} }
function Test-RequestQueuedInState {
param(
[Parameter(Mandatory=`$true)][string]`$Alias,
[Parameter(Mandatory=`$true)][string]`$Action
)
if (-not (Test-Path -LiteralPath `$QueueStatePath)) {
return `$false
}
try {
`$raw = Get-Content -LiteralPath `$QueueStatePath -Raw -Encoding UTF8
if ([string]::IsNullOrWhiteSpace(`$raw)) {
return `$false
}
`$queueState = `$raw | ConvertFrom-Json
foreach (`$item in @(`$queueState.Queue)) {
if (-not `$item) { continue }
if (`$item.CreatedAt) {
try {
`$createdAt = [DateTime]::Parse([string]`$item.CreatedAt)
if (`$createdAt -lt (Get-Date).AddMinutes(-10)) { continue }
}
catch {
}
}
if (`$item.State -notin @('Queued','Running','Succeeded')) { continue }
if (-not [string]::Equals([string]`$item.Alias, `$Alias, [System.StringComparison]::OrdinalIgnoreCase)) { continue }
if (-not [string]::Equals([string]`$item.Action, `$Action, [System.StringComparison]::OrdinalIgnoreCase)) { continue }
return `$true
}
}
catch {
}
return `$false
}
`$form = New-Object System.Windows.Forms.Form `$form = New-Object System.Windows.Forms.Form
`$form.Text = `$CatalogTitle `$form.Text = `$CatalogTitle
`$form.StartPosition = 'CenterScreen' `$form.StartPosition = 'CenterScreen'
@@ -1494,7 +1533,53 @@ function Load-AppList {
`$stateRefreshTimer.Interval = 500 `$stateRefreshTimer.Interval = 500
`$script:StateRefreshPending = `$false `$script:StateRefreshPending = `$false
`$script:RequestWorkerBusy = `$false `$script:RequestWorkerBusy = `$false
`$script:RunspaceJobs = New-Object 'System.Collections.Generic.List[object]' `$script:RunspaceJobs = @()
`$script:CatalogClosing = `$false
function Remove-CatalogRunspaceJob {
param(
[Parameter(Mandatory=`$true)]`$Job,
[switch]`$Stop
)
try {
if (`$null -ne `$Job.Timer) {
`$Job.Timer.Stop()
`$Job.Timer.Dispose()
}
}
catch {
}
try {
if (`$Stop -and `$null -ne `$Job.PowerShell -and `$null -ne `$Job.AsyncResult -and -not `$Job.AsyncResult.IsCompleted) {
`$null = `$Job.PowerShell.BeginStop(`$null, `$null)
}
}
catch {
try { `$Job.PowerShell.Stop() } catch { }
}
try {
if (`$null -ne `$Job.PowerShell) { `$Job.PowerShell.Dispose() }
}
catch {
}
try {
if (`$null -ne `$Job.Runspace) { `$Job.Runspace.Dispose() }
}
catch {
}
`$remainingJobs = @()
foreach (`$existingJob in @(`$script:RunspaceJobs)) {
if (-not [object]::ReferenceEquals(`$existingJob, `$Job)) {
`$remainingJobs += `$existingJob
}
}
`$script:RunspaceJobs = `$remainingJobs
}
function Start-CatalogDaemonRunspaceRequest { function Start-CatalogDaemonRunspaceRequest {
param( param(
@@ -1586,22 +1671,23 @@ function Start-CatalogDaemonRunspaceRequest {
throw throw
} }
[void]`$script:RunspaceJobs.Add(`$job) `$script:RunspaceJobs = @(`$script:RunspaceJobs + `$job)
`$jobRef = `$job
`$timer.Add_Tick({ `$timer.Add_Tick({
if (-not `$job.AsyncResult.IsCompleted) { return } if (`$null -eq `$jobRef.AsyncResult -or -not `$jobRef.AsyncResult.IsCompleted) { return }
`$job.Timer.Stop() `$jobRef.Timer.Stop()
`$completion = [pscustomobject]@{ `$completion = [pscustomobject]@{
Context = `$job.Context Context = `$jobRef.Context
Response = `$null Response = `$null
ErrorMessage = `$null ErrorMessage = `$null
} }
try { try {
`$result = @(`$job.PowerShell.EndInvoke(`$job.AsyncResult)) `$result = @(`$jobRef.PowerShell.EndInvoke(`$jobRef.AsyncResult))
if (`$job.PowerShell.Streams.Error.Count -gt 0) { if (`$jobRef.PowerShell.Streams.Error.Count -gt 0) {
`$firstError = `$job.PowerShell.Streams.Error[0] `$firstError = `$jobRef.PowerShell.Streams.Error[0]
if (`$firstError.Exception) { if (`$null -ne `$firstError.Exception) {
`$completion.ErrorMessage = `$firstError.Exception.Message `$completion.ErrorMessage = `$firstError.Exception.Message
} }
else { else {
@@ -1613,19 +1699,25 @@ function Start-CatalogDaemonRunspaceRequest {
} }
} }
catch { catch {
`$completion.ErrorMessage = `$_.Exception.Message `$exception = `$_.Exception
while (`$exception.InnerException) {
`$exception = `$exception.InnerException
}
`$completion.ErrorMessage = `$exception.Message
} }
try { try {
& `$job.OnCompleted `$completion if (-not `$script:CatalogClosing) {
& `$jobRef.OnCompleted `$completion
}
}
catch {
try { `$status.Text = 'Fehler: ' + `$_.Exception.Message } catch { }
} }
finally { finally {
[void]`$script:RunspaceJobs.Remove(`$job) Remove-CatalogRunspaceJob -Job `$jobRef
`$job.Timer.Dispose()
`$job.PowerShell.Dispose()
`$job.Runspace.Dispose()
} }
}) }.GetNewClosure())
`$timer.Start() `$timer.Start()
} }
@@ -1652,13 +1744,27 @@ function Start-AppRequestAsync {
} }
try { try {
Start-CatalogDaemonRunspaceRequest -Command `$Action -Alias `$context.Alias -Context `$context -OnCompleted { Start-CatalogDaemonRunspaceRequest -Command `$Action -Alias `$context.Alias -Context `$context -OnCompleted ({
param(`$completion) param(`$completion)
try { try {
`$script:RequestWorkerBusy = `$false `$script:RequestWorkerBusy = `$false
`$btnRefresh.Enabled = `$true `$btnRefresh.Enabled = `$true
if (`$completion.Context.Action -eq 'Uninstall') {
`$verb = 'Deinstallation'
}
else {
`$verb = 'Installation'
}
if (`$completion.ErrorMessage) { if (`$completion.ErrorMessage) {
`$requestReachedQueue = (`$completion.ErrorMessage -like '*Zeitüberschreitung beim Warten auf Antwort*' -and (Test-RequestQueuedInState -Alias `$completion.Context.Alias -Action `$completion.Context.Action))
if (`$requestReachedQueue) {
`$status.Text = "`$verb eingereiht: {0}" -f `$completion.Context.DisplayName
`$script:StateRefreshPending = `$true
return
}
`$status.Text = 'Fehler: ' + `$completion.ErrorMessage `$status.Text = 'Fehler: ' + `$completion.ErrorMessage
`$script:StateRefreshPending = `$true `$script:StateRefreshPending = `$true
[System.Windows.Forms.MessageBox]::Show( [System.Windows.Forms.MessageBox]::Show(
@@ -1676,12 +1782,6 @@ function Start-AppRequestAsync {
DisplayName = `$completion.Context.DisplayName DisplayName = `$completion.Context.DisplayName
Response = `$completion.Response Response = `$completion.Response
} }
if (`$result.Action -eq 'Uninstall') {
`$verb = 'Deinstallation'
}
else {
`$verb = 'Installation'
}
if (`$result.Response.Message) { if (`$result.Response.Message) {
`$status.Text = [string]`$result.Response.Message `$status.Text = [string]`$result.Response.Message
} }
@@ -1701,7 +1801,7 @@ function Start-AppRequestAsync {
finally { finally {
Update-InstallButtonState Update-InstallButtonState
} }
} }.GetNewClosure())
} }
catch { catch {
`$script:RequestWorkerBusy = `$false `$script:RequestWorkerBusy = `$false
@@ -1724,7 +1824,7 @@ function Start-RefreshStatusAsync {
`$status.Text = 'Installationsdaten-Aktualisierung wird angefordert...' `$status.Text = 'Installationsdaten-Aktualisierung wird angefordert...'
try { try {
Start-CatalogDaemonRunspaceRequest -Command 'RefreshStatus' -OnCompleted { Start-CatalogDaemonRunspaceRequest -Command 'RefreshStatus' -OnCompleted ({
param(`$completion) param(`$completion)
try { try {
`$script:RequestWorkerBusy = `$false `$script:RequestWorkerBusy = `$false
@@ -1748,7 +1848,7 @@ function Start-RefreshStatusAsync {
finally { finally {
Update-InstallButtonState Update-InstallButtonState
} }
} }.GetNewClosure())
} }
catch { catch {
`$script:RequestWorkerBusy = `$false `$script:RequestWorkerBusy = `$false
@@ -1861,6 +1961,7 @@ function Start-RefreshStatusAsync {
`$stateRefreshTimer.Add_Tick({ `$stateRefreshTimer.Add_Tick({
if (-not `$script:StateRefreshPending) { return } if (-not `$script:StateRefreshPending) { return }
if (`$script:RequestWorkerBusy) { return }
`$script:StateRefreshPending = `$false `$script:StateRefreshPending = `$false
try { Load-AppList } try { Load-AppList }
catch { `$status.Text = "Fehler bei automatischer Aktualisierung: " + `$_.Exception.Message } catch { `$status.Text = "Fehler bei automatischer Aktualisierung: " + `$_.Exception.Message }
@@ -1931,36 +2032,15 @@ function Start-RefreshStatusAsync {
`$stateRefreshTimer.Start() `$stateRefreshTimer.Start()
}) })
`$form.Add_FormClosing({ `$form.Add_FormClosing({
`$script:CatalogClosing = `$true
`$stateRefreshTimer.Stop() `$stateRefreshTimer.Stop()
`$stateRefreshTimer.Dispose() `$stateRefreshTimer.Dispose()
if (`$script:StateWatcher) { `$script:StateWatcher.Dispose() } if (`$null -ne `$script:StateWatcher) { `$script:StateWatcher.Dispose() }
if (`$script:SnapshotWatcher) { `$script:SnapshotWatcher.Dispose() } if (`$null -ne `$script:SnapshotWatcher) { `$script:SnapshotWatcher.Dispose() }
foreach (`$job in @(`$script:RunspaceJobs)) { foreach (`$job in @(`$script:RunspaceJobs)) {
try { Remove-CatalogRunspaceJob -Job `$job -Stop
if (`$job.Timer) {
`$job.Timer.Stop()
`$job.Timer.Dispose()
} }
} `$script:RunspaceJobs = @()
catch {
}
try {
if (`$job.PowerShell -and `$job.AsyncResult -and -not `$job.AsyncResult.IsCompleted) {
`$job.PowerShell.Stop()
}
}
catch {
}
try {
if (`$job.PowerShell) { `$job.PowerShell.Dispose() }
if (`$job.Runspace) { `$job.Runspace.Dispose() }
}
catch {
}
}
`$script:RunspaceJobs.Clear()
}) })
`$list.Add_SelectedIndexChanged({ Update-InstallButtonState }) `$list.Add_SelectedIndexChanged({ Update-InstallButtonState })