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'
}
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.Text = `$CatalogTitle
`$form.StartPosition = 'CenterScreen'
@@ -1494,7 +1533,53 @@ function Load-AppList {
`$stateRefreshTimer.Interval = 500
`$script:StateRefreshPending = `$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 {
param(
@@ -1586,22 +1671,23 @@ function Start-CatalogDaemonRunspaceRequest {
throw
}
[void]`$script:RunspaceJobs.Add(`$job)
`$script:RunspaceJobs = @(`$script:RunspaceJobs + `$job)
`$jobRef = `$job
`$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]@{
Context = `$job.Context
Context = `$jobRef.Context
Response = `$null
ErrorMessage = `$null
}
try {
`$result = @(`$job.PowerShell.EndInvoke(`$job.AsyncResult))
if (`$job.PowerShell.Streams.Error.Count -gt 0) {
`$firstError = `$job.PowerShell.Streams.Error[0]
if (`$firstError.Exception) {
`$result = @(`$jobRef.PowerShell.EndInvoke(`$jobRef.AsyncResult))
if (`$jobRef.PowerShell.Streams.Error.Count -gt 0) {
`$firstError = `$jobRef.PowerShell.Streams.Error[0]
if (`$null -ne `$firstError.Exception) {
`$completion.ErrorMessage = `$firstError.Exception.Message
}
else {
@@ -1613,19 +1699,25 @@ function Start-CatalogDaemonRunspaceRequest {
}
}
catch {
`$completion.ErrorMessage = `$_.Exception.Message
`$exception = `$_.Exception
while (`$exception.InnerException) {
`$exception = `$exception.InnerException
}
`$completion.ErrorMessage = `$exception.Message
}
try {
& `$job.OnCompleted `$completion
if (-not `$script:CatalogClosing) {
& `$jobRef.OnCompleted `$completion
}
}
catch {
try { `$status.Text = 'Fehler: ' + `$_.Exception.Message } catch { }
}
finally {
[void]`$script:RunspaceJobs.Remove(`$job)
`$job.Timer.Dispose()
`$job.PowerShell.Dispose()
`$job.Runspace.Dispose()
Remove-CatalogRunspaceJob -Job `$jobRef
}
})
}.GetNewClosure())
`$timer.Start()
}
@@ -1652,13 +1744,27 @@ function Start-AppRequestAsync {
}
try {
Start-CatalogDaemonRunspaceRequest -Command `$Action -Alias `$context.Alias -Context `$context -OnCompleted {
Start-CatalogDaemonRunspaceRequest -Command `$Action -Alias `$context.Alias -Context `$context -OnCompleted ({
param(`$completion)
try {
`$script:RequestWorkerBusy = `$false
`$btnRefresh.Enabled = `$true
if (`$completion.Context.Action -eq 'Uninstall') {
`$verb = 'Deinstallation'
}
else {
`$verb = 'Installation'
}
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
`$script:StateRefreshPending = `$true
[System.Windows.Forms.MessageBox]::Show(
@@ -1676,12 +1782,6 @@ function Start-AppRequestAsync {
DisplayName = `$completion.Context.DisplayName
Response = `$completion.Response
}
if (`$result.Action -eq 'Uninstall') {
`$verb = 'Deinstallation'
}
else {
`$verb = 'Installation'
}
if (`$result.Response.Message) {
`$status.Text = [string]`$result.Response.Message
}
@@ -1701,7 +1801,7 @@ function Start-AppRequestAsync {
finally {
Update-InstallButtonState
}
}
}.GetNewClosure())
}
catch {
`$script:RequestWorkerBusy = `$false
@@ -1724,7 +1824,7 @@ function Start-RefreshStatusAsync {
`$status.Text = 'Installationsdaten-Aktualisierung wird angefordert...'
try {
Start-CatalogDaemonRunspaceRequest -Command 'RefreshStatus' -OnCompleted {
Start-CatalogDaemonRunspaceRequest -Command 'RefreshStatus' -OnCompleted ({
param(`$completion)
try {
`$script:RequestWorkerBusy = `$false
@@ -1748,7 +1848,7 @@ function Start-RefreshStatusAsync {
finally {
Update-InstallButtonState
}
}
}.GetNewClosure())
}
catch {
`$script:RequestWorkerBusy = `$false
@@ -1861,6 +1961,7 @@ function Start-RefreshStatusAsync {
`$stateRefreshTimer.Add_Tick({
if (-not `$script:StateRefreshPending) { return }
if (`$script:RequestWorkerBusy) { return }
`$script:StateRefreshPending = `$false
try { Load-AppList }
catch { `$status.Text = "Fehler bei automatischer Aktualisierung: " + `$_.Exception.Message }
@@ -1931,36 +2032,15 @@ function Start-RefreshStatusAsync {
`$stateRefreshTimer.Start()
})
`$form.Add_FormClosing({
`$script:CatalogClosing = `$true
`$stateRefreshTimer.Stop()
`$stateRefreshTimer.Dispose()
if (`$script:StateWatcher) { `$script:StateWatcher.Dispose() }
if (`$script:SnapshotWatcher) { `$script:SnapshotWatcher.Dispose() }
if (`$null -ne `$script:StateWatcher) { `$script:StateWatcher.Dispose() }
if (`$null -ne `$script:SnapshotWatcher) { `$script:SnapshotWatcher.Dispose() }
foreach (`$job in @(`$script:RunspaceJobs)) {
try {
if (`$job.Timer) {
`$job.Timer.Stop()
`$job.Timer.Dispose()
Remove-CatalogRunspaceJob -Job `$job -Stop
}
}
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()
`$script:RunspaceJobs = @()
})
`$list.Add_SelectedIndexChanged({ Update-InstallButtonState })