Disable the 'Scan for Updates' Button when the task is running (#13)

Co-authored-by: MyDrift <personal@mdiana.ch>
This commit is contained in:
Mr.k 2025-03-07 20:06:35 +03:00 committed by GitHub
parent 8fabebedf4
commit f9878a3472
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,8 +1,9 @@
function Invoke-WPFUpdatesScan { function Invoke-WPFUpdatesScan {
$sync["WPFScanUpdates"].IsEnabled = $false
$sync["WPFUpdateSelectedInstall"].IsEnabled = $false
$sync["WPFUpdateAllInstall"].IsEnabled = $false
Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo"
Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock { Invoke-WPFRunspace -DebugPreference $DebugPreference -ScriptBlock {
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" -value 0.01 -overlay "logo" })
# Check if the PSWindowsUpdate module is installed # Check if the PSWindowsUpdate module is installed
if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) { if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
try { try {
@ -12,6 +13,7 @@ function Invoke-WPFUpdatesScan {
} }
catch { catch {
Write-Error "Failed to install PSWindowsUpdate module: $_" Write-Error "Failed to install PSWindowsUpdate module: $_"
$sync.form.Dispatcher.Invoke([action] { $sync["WPFScanUpdates"].IsEnabled = $true })
return return
} }
} }
@ -23,6 +25,7 @@ function Invoke-WPFUpdatesScan {
} }
catch { catch {
Write-Error "Failed to import PSWindowsUpdate module: $_" Write-Error "Failed to import PSWindowsUpdate module: $_"
$sync.form.Dispatcher.Invoke([action] { $sync["WPFScanUpdates"].IsEnabled = $true })
return return
} }
@ -58,4 +61,7 @@ function Invoke-WPFUpdatesScan {
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -overlay "warning" }) $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" -overlay "warning" })
} }
} }
$sync["WPFScanUpdates"].IsEnabled = $false
$sync["WPFUpdateSelectedInstall"].IsEnabled = $false
$sync["WPFUpdateAllInstall"].IsEnabled = $false
} }