use Dispatcher.Invoke

This commit is contained in:
MyDrift 2024-07-13 12:54:59 +02:00
parent 790e0b22a5
commit 27792dc8a3
10 changed files with 23 additions and 20 deletions

View File

@ -14,19 +14,19 @@ function Install-WinUtilChoco {
return
}
Set-WinUtilTaskbaritem -state "Indeterminate"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
Write-Host "Seems Chocolatey is not installed, installing now."
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop
powershell choco feature enable -n allowGlobalConfirmation
Set-WinUtilTaskbaritem -state "None"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
}
Catch {
Write-Host "===========================================" -Foregroundcolor Red
Write-Host "-- Chocolatey failed to install ---" -Foregroundcolor Red
Write-Host "===========================================" -Foregroundcolor Red
Set-WinUtilTaskbaritem -state "Error"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
}
}

View File

@ -80,7 +80,7 @@ function Install-WinUtilProgramChoco {
}
}
$x++
# Set-WinUtilTaskbaritem -state "Normal" -value $x/$count
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value $using:x/$using:count })
}
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed

View File

@ -97,7 +97,7 @@ Function Install-WinUtilProgramWinget {
}
}
$X++
# Set-WinUtilTaskbaritem -state "Normal" -value $x/$count
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value $using:x/$using:count })
}
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
return $failedPackages;

View File

@ -19,7 +19,7 @@ function Install-WinUtilWinget {
Write-Host "`nWinget is not Installed. Continuing with install.`r" -ForegroundColor Red
}
Set-WinUtilTaskbaritem -state "Indeterminate"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
# Gets the computer's information
if ($null -eq $sync.ComputerInfo){
@ -65,6 +65,6 @@ function Install-WinUtilWinget {
throw [WingetFailedInstall]::new('Failed to install!')
}
}
Set-WinUtilTaskbaritem -state "None"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
}

View File

@ -10,7 +10,7 @@ function Invoke-WinUtilFeatureInstall {
$CheckBox
)
Set-WinUtilTaskbaritem -state "Normal" -value 1
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$using:CheckBox.Count })
$CheckBox | ForEach-Object {
if($sync.configs.feature.$psitem.feature){
@ -39,6 +39,7 @@ function Invoke-WinUtilFeatureInstall {
Write-Host "Running Script for $psitem"
Invoke-Command $scriptblock -ErrorAction stop
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
}
Catch{
if ($psitem.Exception.Message -like "*requires elevation*"){
@ -46,7 +47,7 @@ function Invoke-WinUtilFeatureInstall {
}
else{
Set-WinUtilTaskbaritem -state "Error"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
Write-Warning "Unable to Install $feature due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
@ -54,7 +55,4 @@ function Invoke-WinUtilFeatureInstall {
}
}
}
if ($sync["Form"].taskbarItemInfo.ProgressState -ne "Error"){
Set-WinUtilTaskbaritem -state "None"
}
}

View File

@ -24,7 +24,7 @@ function Invoke-WPFGetInstalled {
param($checkbox, $DebugPreference)
$sync.ProcessRunning = $true
Set-WinUtilTaskbaritem -state "Indeterminate"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
if($checkbox -eq "winget"){
Write-Host "Getting Installed Programs..."
@ -43,6 +43,6 @@ function Invoke-WPFGetInstalled {
Write-Host "Done..."
$sync.ProcessRunning = $false
Set-WinUtilTaskbaritem -state "None"
$sync.form.Dispatcher.Invoke([action] { Set-WinUtilTaskbaritem -state "None" })
}
}

View File

@ -23,7 +23,7 @@ function Invoke-WPFInstall {
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
param($PackagesToInstall, $DebugPreference)
Set-WinUtilTaskbaritem -state "Normal" -value 1/$PackagesToInstall.Count
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$using:PackagesToInstall.Count })
$packagesWinget, $packagesChoco = {
$packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new()
$packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new()
@ -54,13 +54,13 @@ function Invoke-WPFInstall {
Write-Host "==========================================="
Write-Host "-- Installs have finished ---"
Write-Host "==========================================="
# Set-WinUtilTaskbaritem -state "None"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
}
Catch {
Write-Host "==========================================="
Write-Host "Error: $_"
Write-Host "==========================================="
# Set-WinUtilTaskbaritem -state "Error"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
}
Start-Sleep -Seconds 5
$sync.ProcessRunning = $False

View File

@ -29,10 +29,10 @@ function Invoke-WPFUnInstall {
if($confirm -eq "No"){return}
Set-WinUtilTaskbaritem -state "Normal" -value 1/$PackagesToInstall.Count
Invoke-WPFRunspace -ArgumentList $PackagesToInstall -DebugPreference $DebugPreference -ScriptBlock {
param($PackagesToInstall, $DebugPreference)
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$using:PackagesToInstall.Count })
$packagesWinget, $packagesChoco = {
$packagesWinget = [System.Collections.Generic.List`1[System.Object]]::new()
$packagesChoco = [System.Collections.Generic.List`1[System.Object]]::new()
@ -68,13 +68,13 @@ function Invoke-WPFUnInstall {
Write-Host "==========================================="
Write-Host "-- Uninstalls have finished ---"
Write-Host "==========================================="
# Set-WinUtilTaskbaritem -state "None"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
}
Catch {
Write-Host "==========================================="
Write-Host "Error: $_"
Write-Host "==========================================="
# Set-WinUtilTaskbaritem -state "Error"
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
}
$sync.ProcessRunning = $False
}

View File

@ -30,15 +30,18 @@ function Invoke-WPFtweaksbutton {
$sync.ProcessRunning = $true
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value 1/$Tweaks.Count })
$cnt = 0
# Execute other selected tweaks
foreach ($tweak in $Tweaks) {
Write-Debug "This is a tweak to run $tweak count: $cnt"
Invoke-WinUtilTweaks $tweak
$cnt += 1
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -value ($using:cnt/$using:Tweaks.Count)})
}
$sync.ProcessRunning = $false
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
Write-Host "================================="
Write-Host "-- Tweaks are Finished ---"
Write-Host "================================="

View File

@ -24,12 +24,14 @@ function Invoke-WPFundoall {
param($Tweaks, $DebugPreference)
$sync.ProcessRunning = $true
# $sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Normal" -value $using:Tweaks.Count })
Foreach ($tweak in $tweaks){
Invoke-WinUtilTweaks $tweak -undo $true
}
$sync.ProcessRunning = $false
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
Write-Host "=================================="
Write-Host "--- Undo Tweaks are Finished ---"
Write-Host "=================================="