From 227babe0e8765f93b2fcc9df139a77459b48286d Mon Sep 17 00:00:00 2001 From: Justawildwolf <62820836+blusewill@users.noreply.github.com> Date: Fri, 28 Jun 2024 15:02:32 +0000 Subject: [PATCH] Toggle Search Button in the taskbar (#2162) --- config/tweaks.json | 12 +++++-- functions/private/Get-WinUtilToggleStatus.ps1 | 9 +++++ .../private/Invoke-WinUtilTaskbarSearch.ps1 | 34 +++++++++++++++++++ functions/public/Invoke-WPFToggle.ps1 | 1 + 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 functions/private/Invoke-WinUtilTaskbarSearch.ps1 diff --git a/config/tweaks.json b/config/tweaks.json index e15fb8b6..65334024 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -3068,7 +3068,15 @@ "Description": "If Enabled then Sticky Keys is activated - Sticky keys is an accessibility feature of some graphical user interfaces which assists users who have physical disabilities or help users reduce repetitive strain injury.", "category": "Customize Preferences", "panel": "2", - "Order": "a069_", + "Order": "a070_", + "Type": "Toggle" + }, + "WPFToggleTaskbarSearch": { + "Content": "Taskbar Search", + "Description": "If Enabled Search Button will be on the taskbar.", + "category": "Customize Preferences", + "panel": "2", + "Order": "a068_", "Type": "Toggle" }, "WPFOOSUbutton": { @@ -3083,7 +3091,7 @@ "Description": "If Enabled then Widgets Icon in Taskbar will be shown.", "category": "Customize Preferences", "panel": "2", - "Order": "a068_", + "Order": "a069_", "Type": "Toggle" }, "WPFchangedns": { diff --git a/functions/private/Get-WinUtilToggleStatus.ps1 b/functions/private/Get-WinUtilToggleStatus.ps1 index 95499ef1..d3469c94 100644 --- a/functions/private/Get-WinUtilToggleStatus.ps1 +++ b/functions/private/Get-WinUtilToggleStatus.ps1 @@ -98,6 +98,15 @@ Function Get-WinUtilToggleStatus { return $false } } + if($ToggleSwitch -eq "WPFToggleTaskbarSearch"){ + $SearchButton = (Get-ItemProperty -path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search").SearchboxTaskbarMode + if($SearchButton -eq 0){ + return $false + } + else{ + return $true + } + } if ($ToggleSwitch -eq "WPFToggleStickyKeys") { $StickyKeys = (Get-ItemProperty -path 'HKCU:\Control Panel\Accessibility\StickyKeys').Flags if($StickyKeys -eq 58){ diff --git a/functions/private/Invoke-WinUtilTaskbarSearch.ps1 b/functions/private/Invoke-WinUtilTaskbarSearch.ps1 new file mode 100644 index 00000000..e022cf89 --- /dev/null +++ b/functions/private/Invoke-WinUtilTaskbarSearch.ps1 @@ -0,0 +1,34 @@ +function Invoke-WinUtilTaskbarSearch { + <# + + .SYNOPSIS + Enable/Disable Taskbar Widgets + + .PARAMETER Enabled + Indicates whether to enable or disable Taskbar Widgets + + #> + Param($Enabled) + Try{ + if ($Enabled -eq $false){ + Write-Host "Enabling Search Button" + $value = 1 + } + else { + Write-Host "Disabling Search Button" + $value = 0 + } + $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Search\" + Set-ItemProperty -Path $Path -Name SearchboxTaskbarMode -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 + } +} diff --git a/functions/public/Invoke-WPFToggle.ps1 b/functions/public/Invoke-WPFToggle.ps1 index a3c94875..5e65f86e 100644 --- a/functions/public/Invoke-WPFToggle.ps1 +++ b/functions/public/Invoke-WPFToggle.ps1 @@ -28,5 +28,6 @@ function Invoke-WPFToggle { "WPFToggleMouseAcceleration" {Invoke-WinUtilMouseAcceleration $(Get-WinUtilToggleStatus WPFToggleMouseAcceleration)} "WPFToggleStickyKeys" {Invoke-WinUtilStickyKeys $(Get-WinUtilToggleStatus WPFToggleStickyKeys)} "WPFToggleTaskbarWidgets" {Invoke-WinUtilTaskbarWidgets $(Get-WinUtilToggleStatus WPFToggleTaskbarWidgets)} + "WPFToggleTaskbarSearch" {Invoke-WinUtilTaskbarSearch $(Get-WinUtilToggleStatus WPFToggleTaskbarSearch)} } }