mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-12-22 05:51:30 -06:00
1d0e3bfd5c
* move logic to json template - 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 * add reg params for toggles into tweaks.json - add all reg keys to tweaks.json into existing toggle entry - remove unneeded scripts * fix HKU - load HKU if needed (for tweaks & GetToggleStatus) - remove unneeded Invoke-WinUtilNumLock - has loaded HKU does not load/not stay loaded * add a lot of error handling * 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 * globally fix HKU error & minimize console feedback - fix HKU issue globally - remove some console logs, change some others to write-debug * update Explorerrefresh - change Invoke-WinUtilExplorerRefresh to handle refresh and restart - add restart logic to window snapping Flyout & Suggestions - rename Invoke-WinUtilExplorerRefresh to Invoke-WinUtilExplorerUpdate * add explorer restart where needed to take effect add explorer restart logic for hidden files + Fileextension toggles * fix missing theme change logic in darkmode toggle * fix window snapping - fix issue defining WindowArrangementActive as dword instead of string * fix bing search - switch bing search enabled/disabled values * add a little bit of error handling - add error handling for Get-WinUtilToggleStatus --------- Co-authored-by: Marterich <47688561+Marterich@users.noreply.github.com>
61 lines
2.0 KiB
PowerShell
61 lines
2.0 KiB
PowerShell
Function Get-WinUtilToggleStatus {
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
Pulls the registry keys for the given toggle switch and checks whether the toggle should be checked or unchecked
|
|
|
|
.PARAMETER ToggleSwitch
|
|
The name of the toggle to check
|
|
|
|
.OUTPUTS
|
|
Boolean to set the toggle's status to
|
|
|
|
#>
|
|
|
|
Param($ToggleSwitch)
|
|
|
|
$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry
|
|
|
|
try {
|
|
if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
|
|
$null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS)
|
|
if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) {
|
|
Write-Debug "HKU drive created successfully"
|
|
} else {
|
|
Write-Debug "Failed to create HKU drive"
|
|
}
|
|
}
|
|
} catch {
|
|
Write-Error "An error occurred regarding the HKU Drive: $_"
|
|
return $false
|
|
}
|
|
|
|
if ($ToggleSwitchReg) {
|
|
$count = 0
|
|
|
|
foreach ($regentry in $ToggleSwitchReg) {
|
|
try {
|
|
$regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name)
|
|
if ($regstate -eq $regentry.Value) {
|
|
$count += 1
|
|
Write-Debug "$($regentry.Name) is true (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
|
|
} else {
|
|
Write-Debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
|
|
}
|
|
} catch {
|
|
Write-Error "An error occurred while accessing registry entry $($regentry.Path): $_"
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|