mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-06-11 11:06:27 +00:00
Add DisableWhenApplied property to features and update UI control states accordingly
This commit is contained in:
@@ -863,7 +863,8 @@
|
|||||||
"ApplyText": null,
|
"ApplyText": null,
|
||||||
"RegistryUndoKey": null,
|
"RegistryUndoKey": null,
|
||||||
"MinVersion": null,
|
"MinVersion": null,
|
||||||
"MaxVersion": null
|
"MaxVersion": null,
|
||||||
|
"DisableWhenApplied": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"FeatureId": "HideChat",
|
"FeatureId": "HideChat",
|
||||||
|
|||||||
@@ -28,6 +28,23 @@ function Test-FeatureApplied {
|
|||||||
$feature = $script:Features[$FeatureId]
|
$feature = $script:Features[$FeatureId]
|
||||||
|
|
||||||
switch ($FeatureId) {
|
switch ($FeatureId) {
|
||||||
|
'DisableWidgets' {
|
||||||
|
# Widgets packages cannot be reinstalled automatically, so we treat their
|
||||||
|
# absence as the applied state (checked) and presence as not-yet-applied.
|
||||||
|
$widgetAppIds = @(
|
||||||
|
'Microsoft.StartExperiencesApp',
|
||||||
|
'MicrosoftWindows.Client.WebExperience',
|
||||||
|
'Microsoft.WidgetsPlatformRuntime'
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach ($appId in $widgetAppIds) {
|
||||||
|
if (Get-AppxPackage -Name $appId -AllUsers -ErrorAction SilentlyContinue) {
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $true
|
||||||
|
}
|
||||||
'DisableStoreSearchSuggestions' {
|
'DisableStoreSearchSuggestions' {
|
||||||
if ($script:Params.ContainsKey('Sysprep')) {
|
if ($script:Params.ContainsKey('Sysprep')) {
|
||||||
return (Test-StoreSearchSuggestionsDisabledForAllUsers)
|
return (Test-StoreSearchSuggestionsDisabledForAllUsers)
|
||||||
|
|||||||
@@ -391,6 +391,7 @@ function Show-MainWindow {
|
|||||||
$control = $window.FindName($controlName)
|
$control = $window.FindName($controlName)
|
||||||
if ($control -is [System.Windows.Controls.CheckBox]) {
|
if ($control -is [System.Windows.Controls.CheckBox]) {
|
||||||
$control.IsChecked = $false
|
$control.IsChecked = $false
|
||||||
|
$control.IsEnabled = $true
|
||||||
}
|
}
|
||||||
elseif ($control -is [System.Windows.Controls.ComboBox]) {
|
elseif ($control -is [System.Windows.Controls.ComboBox]) {
|
||||||
$control.SelectedIndex = 0
|
$control.SelectedIndex = 0
|
||||||
@@ -890,13 +891,19 @@ function Show-MainWindow {
|
|||||||
$items = @('No Change', $opt)
|
$items = @('No Change', $opt)
|
||||||
$comboName = ("Feature_{0}_Combo" -f $feature.FeatureId) -replace '[^a-zA-Z0-9_]',''
|
$comboName = ("Feature_{0}_Combo" -f $feature.FeatureId) -replace '[^a-zA-Z0-9_]',''
|
||||||
$combo = CreateLabeledCombo -parent $panel -labelText $feature.Label -comboName $comboName -items $items
|
$combo = CreateLabeledCombo -parent $panel -labelText $feature.Label -comboName $comboName -items $items
|
||||||
# attach tooltip from Features.json if present
|
# attach tooltip from Features.json if present, and include the disabled-state reason
|
||||||
if ($feature.ToolTip) {
|
if ($feature.ToolTip -or $feature.DisableWhenApplied -eq $true) {
|
||||||
|
$tooltipText = $feature.ToolTip
|
||||||
|
if ($feature.DisableWhenApplied -eq $true) {
|
||||||
|
$tooltipText = "This tweak is already applied and cannot be undone automatically. Visit the Win11Debloat wiki for instructions on how to manually revert this change."
|
||||||
|
}
|
||||||
|
|
||||||
$tipBlock = New-Object System.Windows.Controls.TextBlock
|
$tipBlock = New-Object System.Windows.Controls.TextBlock
|
||||||
$tipBlock.Text = $feature.ToolTip
|
$tipBlock.Text = $tooltipText
|
||||||
$tipBlock.TextWrapping = 'Wrap'
|
$tipBlock.TextWrapping = 'Wrap'
|
||||||
$tipBlock.MaxWidth = 420
|
$tipBlock.MaxWidth = 420
|
||||||
$combo.ToolTip = $tipBlock
|
$combo.ToolTip = $tipBlock
|
||||||
|
[System.Windows.Controls.ToolTipService]::SetShowOnDisabled($combo, $true)
|
||||||
$lblBorderObj = $null
|
$lblBorderObj = $null
|
||||||
try { $lblBorderObj = $window.FindName("$comboName`_LabelBorder") } catch {}
|
try { $lblBorderObj = $window.FindName("$comboName`_LabelBorder") } catch {}
|
||||||
if ($lblBorderObj) { $lblBorderObj.ToolTip = $tipBlock }
|
if ($lblBorderObj) { $lblBorderObj.ToolTip = $tipBlock }
|
||||||
@@ -937,10 +944,14 @@ function Show-MainWindow {
|
|||||||
if ($control -is [System.Windows.Controls.CheckBox] -and $mapping.Type -eq 'feature') {
|
if ($control -is [System.Windows.Controls.CheckBox] -and $mapping.Type -eq 'feature') {
|
||||||
$applied = $false
|
$applied = $false
|
||||||
try { $applied = [bool](Test-FeatureApplied -FeatureId $mapping.FeatureId) } catch {}
|
try { $applied = [bool](Test-FeatureApplied -FeatureId $mapping.FeatureId) } catch {}
|
||||||
Add-Member -InputObject $control -MemberType NoteProperty -Name 'SystemState' -Value $applied -Force
|
$featureObj = $script:Features[$mapping.FeatureId]
|
||||||
|
$disableWhenApplied = $featureObj -and $featureObj.DisableWhenApplied -eq $true
|
||||||
|
Add-Member -InputObject $control -MemberType NoteProperty -Name 'SystemState' -Value $applied -Force
|
||||||
|
Add-Member -InputObject $control -MemberType NoteProperty -Name 'DisableWhenApplied' -Value $disableWhenApplied -Force
|
||||||
|
|
||||||
if ($ApplyToUi) {
|
if ($ApplyToUi) {
|
||||||
$control.IsChecked = $applied
|
$control.IsChecked = $applied
|
||||||
|
$control.IsEnabled = -not ($applied -and $disableWhenApplied)
|
||||||
Add-Member -InputObject $control -MemberType NoteProperty -Name 'InitialState' -Value $applied -Force
|
Add-Member -InputObject $control -MemberType NoteProperty -Name 'InitialState' -Value $applied -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1379,11 +1390,14 @@ function Show-MainWindow {
|
|||||||
if ($loadSystemState) {
|
if ($loadSystemState) {
|
||||||
# Set checkbox to the currently applied state from registry
|
# Set checkbox to the currently applied state from registry
|
||||||
$applied = if ($null -ne $control.PSObject.Properties['SystemState']) { [bool]$control.SystemState } else { $false }
|
$applied = if ($null -ne $control.PSObject.Properties['SystemState']) { [bool]$control.SystemState } else { $false }
|
||||||
|
$disableWhenApplied = $null -ne $control.PSObject.Properties['DisableWhenApplied'] -and [bool]$control.DisableWhenApplied
|
||||||
$control.IsChecked = $applied
|
$control.IsChecked = $applied
|
||||||
|
$control.IsEnabled = -not ($applied -and $disableWhenApplied)
|
||||||
Add-Member -InputObject $control -MemberType NoteProperty -Name 'InitialState' -Value $applied -Force
|
Add-Member -InputObject $control -MemberType NoteProperty -Name 'InitialState' -Value $applied -Force
|
||||||
} else {
|
} else {
|
||||||
# Clear the checkbox
|
# Clear the checkbox
|
||||||
$control.IsChecked = $false
|
$control.IsChecked = $false
|
||||||
|
$control.IsEnabled = $true
|
||||||
Add-Member -InputObject $control -MemberType NoteProperty -Name 'InitialState' -Value $false -Force
|
Add-Member -InputObject $control -MemberType NoteProperty -Name 'InitialState' -Value $false -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user