Skip to content

Commit

Permalink
move logic to json template
Browse files Browse the repository at this point in the history
- remove Invoke-WPFToggle.ps1
- generalize Get-WinUtilToggleStatus
- add bingsearch reg key for testing
- use Invoke-WinUtilTweaks for actions
- replace Add-Click with checked & unchecked to make undo work
  • Loading branch information
MyDrift-user committed Nov 5, 2024
1 parent ce1ef2a commit f0afb67
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 111 deletions.
9 changes: 9 additions & 0 deletions config/tweaks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3302,6 +3302,15 @@
"panel": "2",
"Order": "a101_",
"Type": "Toggle",
"registry": [
{
"Path": "HKCU:\\Software\\Microsoft\\Windows\\CurrentVersion\\Search",
"Name": "BingSearchEnabled",
"Value": "0",
"OriginalValue": "1",
"Type": "DWord"
}
],
"link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/BingSearch"
},
"WPFToggleNumLock": {
Expand Down
92 changes: 23 additions & 69 deletions functions/private/Get-WinUtilToggleStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,75 +13,29 @@ Function Get-WinUtilToggleStatus {
#>

Param($ToggleSwitch)
if($ToggleSwitch -eq "WPFToggleDarkMode") {
$app = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').AppsUseLightTheme
$system = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').SystemUsesLightTheme
return $app -eq 0 -and $system -eq 0
}
if($ToggleSwitch -eq "WPFToggleBingSearch") {
$bingsearch = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Search').BingSearchEnabled
return $bingsearch -ne 0
}
if($ToggleSwitch -eq "WPFToggleNumLock") {
$numlockvalue = (Get-ItemProperty -path 'HKCU:\Control Panel\Keyboard').InitialKeyboardIndicators
return $numlockvalue -eq 2
}
if($ToggleSwitch -eq "WPFToggleVerboseLogon") {
$VerboseStatusvalue = (Get-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System').VerboseStatus
return $VerboseStatusvalue -eq 1
}
if($ToggleSwitch -eq "WPFToggleShowExt") {
$hideextvalue = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').HideFileExt
return $hideextvalue -eq 0
}
if($ToggleSwitch -eq "WPFToggleSnapWindow") {
$hidesnap = (Get-ItemProperty -path 'HKCU:\Control Panel\Desktop').WindowArrangementActive
return $hidesnap -ne 0
}
if($ToggleSwitch -eq "WPFToggleSnapFlyout") {
$hidesnap = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').EnableSnapAssistFlyout
return $hidesnap -ne 0
}
if($ToggleSwitch -eq "WPFToggleSnapSuggestion") {
$hidesnap = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').SnapAssist
return $hidesnap -ne 0
}
if($ToggleSwitch -eq "WPFToggleMouseAcceleration") {
$MouseSpeed = (Get-ItemProperty -path 'HKCU:\Control Panel\Mouse').MouseSpeed
$MouseThreshold1 = (Get-ItemProperty -path 'HKCU:\Control Panel\Mouse').MouseThreshold1
$MouseThreshold2 = (Get-ItemProperty -path 'HKCU:\Control Panel\Mouse').MouseThreshold2

return $MouseSpeed -eq 1 -and $MouseThreshold1 -eq 6 -and $MouseThreshold2 -eq 10
}
if($ToggleSwitch -eq "WPFToggleTaskbarSearch") {
$SearchButton = (Get-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search").SearchboxTaskbarMode
return $SearchButton -ne 0
}
if ($ToggleSwitch -eq "WPFToggleStickyKeys") {
$StickyKeys = (Get-ItemProperty -path 'HKCU:\Control Panel\Accessibility\StickyKeys').Flags
return $StickyKeys -ne 58
}
if ($ToggleSwitch -eq "WPFToggleTaskView") {
$TaskView = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').ShowTaskViewButton
return $TaskView -ne 0
}

if ($ToggleSwitch -eq "WPFToggleHiddenFiles") {
$HiddenFiles = (Get-ItemProperty -path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced').Hidden
return $HiddenFiles -ne 0
}

if ($ToggleSwitch -eq "WPFToggleTaskbarWidgets") {
$TaskbarWidgets = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced").TaskBarDa
return $TaskbarWidgets -ne 0
}
if ($ToggleSwitch -eq "WPFToggleTaskbarAlignment") {
$TaskbarAlignment = (Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced").TaskbarAl
return $TaskbarAlignment -ne 0
}
if ($ToggleSwitch -eq "WPFToggleDetailedBSoD") {
$DetailedBSoD1 = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl').DisplayParameters
$DetailedBSoD2 = (Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\CrashControl').DisableEmoticon
return !(($DetailedBSoD1 -eq 0) -or ($DetailedBSoD2 -eq 0) -or !$DetailedBSoD1 -or !$DetailedBSoD2)
$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry

if ($ToggleSwitchReg) {
$count = 0

foreach ($regentry in $ToggleSwitchReg) {
$regstate = (Get-ItemProperty -path $($regentry.Path)).$($regentry.Name)
if ($regstate -eq $regentry.Value) {
$count += 1
} else {
write-debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
}
}

if ($count -eq $ToggleSwitchReg.Count) {
write-debug "$($ToggleSwitchReg.Name) is true (count: $count)"
return $true
} else {
write-debug "$($ToggleSwitchReg.Name) is false (count: $count)"
return $false
}
} else {
return $false
}
}
4 changes: 4 additions & 0 deletions functions/private/Invoke-WinUtilTweaks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function Invoke-WinUtilTweaks {
$KeepServiceStartup = $true
)

if ($Checkbox -contains "Toggle") {
$CheckBox = $sync.configs.tweaks.$CheckBox
}

Write-Debug "Tweaks: $($CheckBox)"
if($undo) {
$Values = @{
Expand Down
39 changes: 0 additions & 39 deletions functions/public/Invoke-WPFToggle.ps1

This file was deleted.

11 changes: 8 additions & 3 deletions functions/public/Invoke-WPFUIElements.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,16 @@ function Invoke-WPFUIElements {

$sync[$entryInfo.Name] = $checkBox

$sync[$entryInfo.Name].IsChecked = Get-WinUtilToggleStatus $sync[$entryInfo.Name].Name
$sync[$entryInfo.Name].IsChecked = Get-WinUtilToggleStatus $entryInfo.Name

$sync[$entryInfo.Name].Add_Click({
$sync[$entryInfo.Name].Add_Checked({
[System.Object]$Sender = $args[0]
Invoke-WPFToggle $Sender.name
Invoke-WinUtilTweaks $sender.name
})

$sync[$entryInfo.Name].Add_Unchecked({
[System.Object]$Sender = $args[0]
Invoke-WinUtiltweaks $sender.name -undo $true
})
}

Expand Down

0 comments on commit f0afb67

Please sign in to comment.