Compare commits

...

3 Commits

Author SHA1 Message Date
feff1078d8 Bugfix: New-PSDrive seems to return the "hku" itself so weirdly gets prepended to the return value so the result becomes ("hku", $false). In powershell pretty much every variable that exists is interpreted as $true so the toggle for numlock got incorrectly checked 2024-11-06 22:58:41 +01:00
a4fccd3c85 add a lot of error handling 2024-11-06 22:16:01 +01:00
5c2d5fae1e fix HKU
- load HKU if needed (for tweaks & GetToggleStatus)
- remove unneeded Invoke-WinUtilNumLock
- has loaded HKU does not load/not stay loaded
2024-11-06 19:13:32 +01:00
5 changed files with 38 additions and 38 deletions

View File

@ -3310,10 +3310,14 @@
}
],
"InvokeScript": [
"Invoke-WinUtilExplorerRefresh"
"
Invoke-WinUtilExplorerRefresh
"
],
"UndoScript": [
"Invoke-WinUtilExplorerRefresh"
"
Invoke-WinUtilExplorerRefresh
"
],
"link": "https://christitustech.github.io/winutil/dev/tweaks/Customize-Preferences/DarkMode"
},

View File

@ -16,23 +16,35 @@ Function Get-WinUtilToggleStatus {
$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry
if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
$null = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
write-host "Created HKU drive"
if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) {
Write-Host "HKU drive created successfully" -ForegroundColor Green
} else {
Write-Host "Failed to create HKU drive"
}
}
if ($ToggleSwitchReg) {
$count = 0
foreach ($regentry in $ToggleSwitchReg) {
$regstate = (Get-ItemProperty -path $($regentry.Path)).$($regentry.Name)
write-host "Checking $($regentry.path)"
$regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name)
if ($regstate -eq $regentry.Value) {
$count += 1
write-host "$($regentry.Name) is true (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))" -ForegroundColor Green
} else {
write-debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
write-host "$($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)"
write-host "$($ToggleSwitchReg.Name) is true (count: $count)" -ForegroundColor Green
return $true
} else {
write-debug "$($ToggleSwitchReg.Name) is false (count: $count)"
write-host "$($ToggleSwitchReg.Name) is false (count: $count)"
return $false
}
} else {

View File

@ -1,31 +0,0 @@
function Invoke-WinUtilNumLock {
<#
.SYNOPSIS
Disables/Enables NumLock on startup
.PARAMETER Enabled
Indicates whether to enable or disable Numlock on startup
#>
Param($Enabled)
try {
if ($Enabled -eq $false) {
Write-Host "Enabling Numlock on startup"
$value = 2
} else {
Write-Host "Disabling Numlock on startup"
$value = 0
}
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
$HKUPath = "HKU:\.Default\Control Panel\Keyboard"
$HKCUPath = "HKCU:\Control Panel\Keyboard"
Set-ItemProperty -Path $HKUPath -Name InitialKeyboardIndicators -Value $value
Set-ItemProperty -Path $HKCUPath -Name InitialKeyboardIndicators -Value $value
}
Catch [System.Security.SecurityException] {
Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception"
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Warning $psitem.Exception.ErrorRecord
} catch {
Write-Warning "Unable to set $Name due to unhandled exception"
Write-Warning $psitem.Exception.StackTrace
}
}

View File

@ -77,6 +77,15 @@ function Invoke-WinUtilTweaks {
if($sync.configs.tweaks.$CheckBox.registry) {
$sync.configs.tweaks.$CheckBox.registry | ForEach-Object {
Write-Debug "$($psitem.Name) and state is $($psitem.$($values.registry))"
if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
write-host "Created HKU drive"
if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) {
Write-Host "HKU drive created successfully"
} else {
Write-Host "Failed to create HKU drive"
}
}
Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry)
}
}

View File

@ -192,7 +192,13 @@ function Invoke-WPFUIElements {
$sync[$entryInfo.Name] = $checkBox
$sync[$entryInfo.Name].IsChecked = Get-WinUtilToggleStatus $entryInfo.Name
$sync[$entryInfo.Name].IsChecked = (Get-WinUtilToggleStatus $entryInfo.Name)
if ($sync[$entryInfo.Name].IsChecked) {
write-host "$($entryInfo.Name) is checked" -ForegroundColor Blue
} else {
write-host "$($entryInfo.Name) is not checked" -ForegroundColor Red
}
$sync[$entryInfo.Name].Add_Checked({
[System.Object]$Sender = $args[0]