mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-08-09 09:31:15 +10:00
Add window-level progress indicator for Run Tweaks and Undo (#4830)
* feat(tweaks): add window-level progress indicator for Run Tweaks and Undo * Hide completed tweaks progress on next action --------- Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
function Set-WinUtilTweaksProgressIndicator {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Shows, updates, or hides the window-level progress indicator used by the
|
||||
Tweaks and Undo workflows. It lives outside the TabControl, so unlike the
|
||||
Install tab's progress bar it stays visible no matter which tab is active.
|
||||
.PARAMETER Visible
|
||||
Whether the indicator should be shown or hidden.
|
||||
.PARAMETER Label
|
||||
The text to display above the progress bar.
|
||||
.PARAMETER Percent
|
||||
The percentage of the progress bar that should be filled (0-100).
|
||||
#>
|
||||
param(
|
||||
[bool]$Visible,
|
||||
[string]$Label,
|
||||
[ValidateRange(0,100)]
|
||||
[int]$Percent
|
||||
)
|
||||
|
||||
$indicatorVisible = if ($Visible) { [Windows.Visibility]::Visible } else { [Windows.Visibility]::Collapsed }
|
||||
$indicatorLabel = $Label
|
||||
$hasLabel = $PSBoundParameters.ContainsKey('Label')
|
||||
$hasPercent = $PSBoundParameters.ContainsKey('Percent')
|
||||
|
||||
Invoke-WPFUIThread -ScriptBlock {
|
||||
$sync.WPFTweaksProgressBar.Visibility = $indicatorVisible
|
||||
if ($hasLabel) {
|
||||
$sync.WPFTweaksProgressLabel.Text = $indicatorLabel
|
||||
}
|
||||
if ($hasPercent) {
|
||||
$sync.WPFTweaksProgressValue.Value = $Percent
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ function Invoke-WPFButton {
|
||||
#[System.Windows.MessageBox]::Show("$Button","Chris Titus Tech's Windows Utility","OK","Info")
|
||||
if (-not $sync.ProcessRunning) {
|
||||
Set-WinUtilProgressBar -label "" -percent 0
|
||||
Set-WinUtilTweaksProgressIndicator -Visible $false
|
||||
}
|
||||
|
||||
# Check if button is defined in feature config with function or InvokeScript
|
||||
|
||||
@@ -40,12 +40,14 @@ function Invoke-WPFtweaksbutton {
|
||||
}
|
||||
|
||||
Set-WinUtilProgressBar -Label "Creating restore point" -Percent 0
|
||||
Set-WinUtilTweaksProgressIndicator -Visible $true -Label "Creating restore point" -Percent 0
|
||||
Write-WinUtilLog -Component "Tweaks" -Message "Creating restore point before applying selected tweaks."
|
||||
Invoke-WinUtilTweaks $restorePointTweak
|
||||
$completedSteps = 1
|
||||
|
||||
if ($tweaksToRun.Count -eq 0 -and $dnsProvider -eq "Default") {
|
||||
Set-WinUtilProgressBar -Label "Tweaks finished" -Percent 100
|
||||
Set-WinUtilTweaksProgressIndicator -Visible $true -Label "Tweaks finished" -Percent 100
|
||||
$sync.ProcessRunning = $false
|
||||
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" }
|
||||
Write-Host "================================="
|
||||
@@ -76,12 +78,14 @@ function Invoke-WPFtweaksbutton {
|
||||
|
||||
for ($i = 0; $i -lt $tweaks.Count; $i++) {
|
||||
Set-WinUtilProgressBar -Label "Applying $($tweaks[$i])" -Percent ($completedSteps / $totalSteps * 100)
|
||||
Set-WinUtilTweaksProgressIndicator -Visible $true -Label "Applying $($tweaks[$i]) ($($completedSteps + 1)/$totalSteps)" -Percent ($completedSteps / $totalSteps * 100)
|
||||
Invoke-WinUtilTweaks $tweaks[$i]
|
||||
$completedSteps++
|
||||
$progress = $completedSteps / $totalSteps
|
||||
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -value $progress }
|
||||
}
|
||||
Set-WinUtilProgressBar -Label "Tweaks finished" -Percent 100
|
||||
Set-WinUtilTweaksProgressIndicator -Visible $true -Label "Tweaks finished" -Percent 100
|
||||
$sync.ProcessRunning = $false
|
||||
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" }
|
||||
Write-Host "================================="
|
||||
|
||||
@@ -34,11 +34,13 @@ function Invoke-WPFundoall {
|
||||
|
||||
for ($i = 0; $i -lt $tweaks.Count; $i++) {
|
||||
Set-WinUtilProgressBar -Label "Undoing $($tweaks[$i])" -Percent ($i / $tweaks.Count * 100)
|
||||
Set-WinUtilTweaksProgressIndicator -Visible $true -Label "Undoing $($tweaks[$i]) ($($i + 1)/$($tweaks.Count))" -Percent ($i / $tweaks.Count * 100)
|
||||
Invoke-WinUtiltweaks $tweaks[$i] -undo $true
|
||||
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -value ($i/$tweaks.Count) }
|
||||
}
|
||||
|
||||
Set-WinUtilProgressBar -Label "Undo Tweaks Finished" -Percent 100
|
||||
Set-WinUtilTweaksProgressIndicator -Visible $true -Label "Undo Tweaks Finished" -Percent 100
|
||||
$sync.ProcessRunning = $false
|
||||
Invoke-WPFUIThread -ScriptBlock { Set-WinUtilTaskbaritem -state "None" -overlay "checkmark" }
|
||||
Write-Host "=================================="
|
||||
|
||||
Reference in New Issue
Block a user