Remove -NoUi (#4572)

* Made -NoUi not exit the window

* Update start.ps1

* Update main.ps1

* Update main.ps1

* Update Set-WinUtilProgressbar.ps1

* Update Invoke-WPFImpex.ps1

* Update Invoke-WPFUIThread.ps1

* Update start.ps1

* Update Invoke-WPFUIThread.ps1

* Update main.ps1

* Update main.ps1
This commit is contained in:
Gabi
2026-06-08 18:02:35 +03:00
committed by GitHub
parent 7dfebba70f
commit 01ef78915a
5 changed files with 18 additions and 86 deletions
@@ -14,10 +14,6 @@ function Set-WinUtilProgressbar{
[int]$Percent
)
if($PARAM_NOUI) {
return;
}
Invoke-WPFUIThread -ScriptBlock {$sync.progressBarTextBlock.Text = $label}
Invoke-WPFUIThread -ScriptBlock {$sync.progressBarTextBlock.ToolTip = $label}
if ($percent -lt 5 ) {
-11
View File
@@ -92,17 +92,6 @@ function Invoke-WPFImpex {
$sync.selectedFeatures = [System.Collections.Generic.List[string]]::new()
Update-WinUtilSelections -flatJson $flattenedJson
if (!$PARAM_NOUI) {
# Set flag so toggle Checked/Unchecked events don't trigger registry writes
# while we're programmatically restoring UI state from the imported config
$sync.ImportInProgress = $true
try {
Reset-WPFCheckBoxes -doToggles $true
} finally {
$sync.ImportInProgress = $false
}
}
}
} catch {
Write-Error "An error occurred while importing: $_"
+1 -19
View File
@@ -1,21 +1,3 @@
function Invoke-WPFUIThread {
<#
.SYNOPSIS
Creates and runs a task on Winutil's WPF Forms thread.
.PARAMETER ScriptBlock
The scriptblock to invoke in the thread
#>
[CmdletBinding()]
Param (
$ScriptBlock
)
if ($PARAM_NOUI) {
return;
}
function Invoke-WPFUIThread ($ScriptBlock) {
$sync.form.Dispatcher.Invoke([action]$ScriptBlock)
}
+17 -42
View File
@@ -35,13 +35,11 @@ $maxthreads = [int]$env:NUMBER_OF_PROCESSORS
# Create a new session state for parsing variables into our runspace
$hashVars = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'sync',$sync,$Null
$uiVar = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'PARAM_NOUI',$PARAM_NOUI,$Null
$offlineVar = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'PARAM_OFFLINE',$PARAM_OFFLINE,$Null
$InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
# Add the variable to the session state
$InitialSessionState.Variables.Add($hashVars)
$InitialSessionState.Variables.Add($uiVar)
$InitialSessionState.Variables.Add($offlineVar)
# Get every private function and add them to the session state
@@ -91,8 +89,6 @@ $sync.configs.applications.PSObject.Properties | ForEach-Object {
Set-Preferences
if ($Preset) {
Show-CTTLogo
# Selects the tweaks from $Preset varible
Update-WinUtilSelections -flatJson $sync.configs.preset.$Preset
@@ -107,27 +103,17 @@ if ($Preset) {
return
}
if ($PARAM_NOUI) {
Show-CTTLogo
if ($PARAM_CONFIG -and -not [string]::IsNullOrWhiteSpace($PARAM_CONFIG)) {
Write-Host "Running config file tasks..."
Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG
Invoke-WinUtilAutoRun
if ($Config) {
Invoke-WPFImpex -type "import" -Config $Config
$sync.runspace.Dispose()
$sync.runspace.Close()
[System.GC]::Collect()
Stop-Transcript
exit 1
}
else {
Write-Host "Cannot automatically run without a config file provided."
$sync.runspace.Dispose()
$sync.runspace.Close()
[System.GC]::Collect()
Stop-Transcript
exit 1
}
Invoke-WinUtilAutoRun
# Cleanup and exit
$sync.runspace.Dispose()
$sync.runspace.Close()
[System.GC]::Collect()
Stop-Transcript
return
}
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
@@ -400,27 +386,16 @@ $sync["Form"].Add_ContentRendered({
Invoke-WPFTab "WPFTab1BT" # Default to install tab
}
if (-not $PARAM_CONFIG -and (Test-Path "$winutildir\lastrun.json")) {
try {
$drifted = @(Get-Content "$winutildir\lastrun.json" | ConvertFrom-Json | Where-Object { $_ -notin (Invoke-WinUtilCurrentSystem -CheckBox "tweaks") })
if ($drifted.Count -gt 0 -and [System.Windows.MessageBox]::Show("$($drifted.Count) tweak(s) were reverted since last run. Re-select them?", "Winutil", "YesNo", "Question") -eq "Yes") {
Update-WinUtilSelections -flatJson $drifted
Reset-WPFCheckBoxes -doToggles $false
Invoke-WPFTab "WPFTab2BT"
}
} catch {}
}
$sync["Form"].Focus()
if ($PARAM_CONFIG -and -not [string]::IsNullOrWhiteSpace($PARAM_CONFIG)) {
Write-Host "Running config file tasks..."
Invoke-WPFImpex -type "import" -Config $PARAM_CONFIG
Invoke-WPFRunspace -ScriptBlock {
Invoke-WinUtilAutoRun
if (-not $Config -and (Test-Path "$winutildir\lastrun.json")) {
$drifted = @(Get-Content "$winutildir\lastrun.json" | ConvertFrom-Json | Where-Object { $_ -notin (Invoke-WinUtilCurrentSystem -CheckBox "tweaks") })
if ($drifted.Count -gt 0 -and [System.Windows.MessageBox]::Show("$($drifted.Count) tweak(s) were reverted since last run. Re-select them?", "Winutil", "YesNo", "Question") -eq "Yes") {
Update-WinUtilSelections -flatJson $drifted
Reset-WPFCheckBoxes -doToggles $false
Invoke-WPFTab "WPFTab2BT"
}
}
$sync["Form"].Focus()
})
# The SearchBarTimer is used to delay the search operation until the user has stopped typing for a short period
-10
View File
@@ -10,19 +10,9 @@ param (
[string]$Config,
[ValidateSet("Standard", "Minimal", "Advanced", "")]
[string]$Preset,
[switch]$Noui,
[switch]$Offline
)
if ($Config) {
$PARAM_CONFIG = $Config
}
$PARAM_NOUI = $false
if ($Noui) {
$PARAM_NOUI = $true
}
$PARAM_OFFLINE = $false
if ($Offline) {
$PARAM_OFFLINE = $true