From facaf8612a2dec46ed1f3e33351aa7be69a6a646 Mon Sep 17 00:00:00 2001 From: MyDrift Date: Tue, 6 Aug 2024 12:32:56 +0200 Subject: [PATCH] enhance toggle logics - cleanup Invoke-WPFToggle.ps1 - add attributes member to tweaks - add "eprestart" for restart explorer to attributes. - removed restart explorer logics from existing toggles. - add restart explorer logics to Invoke-WPFToggle.ps1 depending on attribute content --- config/tweaks.json | 4 ++ .../private/Invoke-WinUtilSnapFlyout.ps1 | 4 +- .../private/Invoke-WinUtilSnapSuggestion.ps1 | 2 - functions/public/Invoke-WPFToggle.ps1 | 38 +++++++++++-------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/config/tweaks.json b/config/tweaks.json index f15bbf72..4098987a 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -3052,6 +3052,7 @@ "Content": "Dark Theme for Windows", "Description": "Enable/Disable Dark Mode.", "category": "Customize Preferences", + "attributes": "epRestart", "panel": "2", "Order": "a100_", "Type": "Toggle" @@ -3084,6 +3085,7 @@ "Content": "Snap Window", "Description": "If enabled you can align windows by dragging them. | Relogin Required", "category": "Customize Preferences", + "attributes": "epRestart", "panel": "2", "Order": "a104_", "Type": "Toggle" @@ -3092,6 +3094,7 @@ "Content": "Snap Assist Flyout", "Description": "If enabled then Snap preview is disabled when maximize button is hovered.", "category": "Customize Preferences", + "attributes": "epRestart", "panel": "2", "Order": "a105_", "Type": "Toggle" @@ -3100,6 +3103,7 @@ "Content": "Snap Assist Suggestion", "Description": "If enabled then you will get suggestions to snap other applications in the left over spaces.", "category": "Customize Preferences", + "attributes": "epRestart", "panel": "2", "Order": "a106_", "Type": "Toggle" diff --git a/functions/private/Invoke-WinUtilSnapFlyout.ps1 b/functions/private/Invoke-WinUtilSnapFlyout.ps1 index fb317ec9..aef378cb 100644 --- a/functions/private/Invoke-WinUtilSnapFlyout.ps1 +++ b/functions/private/Invoke-WinUtilSnapFlyout.ps1 @@ -15,11 +15,9 @@ function Invoke-WinUtilSnapFlyout { Write-Host "Disabling Snap Assist Flyout On startup" $value = 0 } - # taskkill.exe /F /IM "explorer.exe" + $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" - taskkill.exe /F /IM "explorer.exe" Set-ItemProperty -Path $Path -Name EnableSnapAssistFlyout -Value $value - Start-Process "explorer.exe" } Catch [System.Security.SecurityException] { Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" diff --git a/functions/private/Invoke-WinUtilSnapSuggestion.ps1 b/functions/private/Invoke-WinUtilSnapSuggestion.ps1 index 6fd35a14..d1567567 100644 --- a/functions/private/Invoke-WinUtilSnapSuggestion.ps1 +++ b/functions/private/Invoke-WinUtilSnapSuggestion.ps1 @@ -17,9 +17,7 @@ function Invoke-WinUtilSnapSuggestion { } # taskkill.exe /F /IM "explorer.exe" $Path = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced" - taskkill.exe /F /IM "explorer.exe" Set-ItemProperty -Path $Path -Name SnapAssist -Value $value - Start-Process "explorer.exe" } Catch [System.Security.SecurityException] { Write-Warning "Unable to set $Path\$Name to $Value due to a Security Exception" diff --git a/functions/public/Invoke-WPFToggle.ps1 b/functions/public/Invoke-WPFToggle.ps1 index fa1868f2..38855c3f 100644 --- a/functions/public/Invoke-WPFToggle.ps1 +++ b/functions/public/Invoke-WPFToggle.ps1 @@ -15,23 +15,29 @@ function Invoke-WPFToggle { # Use this to get the name of the button #[System.Windows.MessageBox]::Show("$Button","Chris Titus Tech's Windows Utility","OK","Info") + $ToggleStatus = (Get-WinUtilToggleStatus $Button) + Switch -Wildcard ($Button){ - "WPFToggleDarkMode" {Invoke-WinUtilDarkMode -DarkMoveEnabled $(Get-WinUtilToggleStatus WPFToggleDarkMode)} - "WPFToggleBingSearch" {Invoke-WinUtilBingSearch $(Get-WinUtilToggleStatus WPFToggleBingSearch)} - "WPFToggleNumLock" {Invoke-WinUtilNumLock $(Get-WinUtilToggleStatus WPFToggleNumLock)} - "WPFToggleVerboseLogon" {Invoke-WinUtilVerboseLogon $(Get-WinUtilToggleStatus WPFToggleVerboseLogon)} - "WPFToggleShowExt" {Invoke-WinUtilShowExt $(Get-WinUtilToggleStatus WPFToggleShowExt)} - "WPFToggleSnapWindow" {Invoke-WinUtilSnapWindow $(Get-WinUtilToggleStatus WPFToggleSnapWindow)} - "WPFToggleSnapFlyout" {Invoke-WinUtilSnapFlyout $(Get-WinUtilToggleStatus WPFToggleSnapFlyout)} - "WPFToggleSnapSuggestion" {Invoke-WinUtilSnapSuggestion $(Get-WinUtilToggleStatus WPFToggleSnapSuggestion)} - "WPFToggleMouseAcceleration" {Invoke-WinUtilMouseAcceleration $(Get-WinUtilToggleStatus WPFToggleMouseAcceleration)} - "WPFToggleStickyKeys" {Invoke-WinUtilStickyKeys $(Get-WinUtilToggleStatus WPFToggleStickyKeys)} - "WPFToggleTaskbarWidgets" {Invoke-WinUtilTaskbarWidgets $(Get-WinUtilToggleStatus WPFToggleTaskbarWidgets)} - "WPFToggleTaskbarSearch" {Invoke-WinUtilTaskbarSearch $(Get-WinUtilToggleStatus WPFToggleTaskbarSearch)} - "WPFToggleTaskView" {Invoke-WinUtilTaskView $(Get-WinUtilToggleStatus WPFToggleTaskView)} - "WPFToggleHiddenFiles" {Invoke-WinUtilHiddenFiles $(Get-WinUtilToggleStatus WPFToggleHiddenFiles)} - "WPFToggleTaskbarAlignment" {Invoke-WinUtilTaskbarAlignment $(Get-WinUtilToggleStatus WPFToggleTaskbarAlignment)} - "WPFToggleDetailedBSoD" {Invoke-WinUtilDetailedBSoD $(Get-WinUtilToggleStatus WPFToggleDetailedBSoD)} + "WPFToggleDarkMode" {Invoke-WinUtilDarkMode $ToggleStatus} + "WPFToggleBingSearch" {Invoke-WinUtilBingSearch $ToggleStatus} + "WPFToggleNumLock" {Invoke-WinUtilNumLock $ToggleStatus} + "WPFToggleVerboseLogon" {Invoke-WinUtilVerboseLogon $ToggleStatus} + "WPFToggleShowExt" {Invoke-WinUtilShowExt $ToggleStatus} + "WPFToggleSnapWindow" {Invoke-WinUtilSnapWindow $ToggleStatus} + "WPFToggleSnapFlyout" {Invoke-WinUtilSnapFlyout $ToggleStatus} + "WPFToggleSnapSuggestion" {Invoke-WinUtilSnapSuggestion $ToggleStatus} + "WPFToggleMouseAcceleration" {Invoke-WinUtilMouseAcceleration $ToggleStatus} + "WPFToggleStickyKeys" {Invoke-WinUtilStickyKeys $ToggleStatus} + "WPFToggleTaskbarWidgets" {Invoke-WinUtilTaskbarWidgets $ToggleStatus} + "WPFToggleTaskbarSearch" {Invoke-WinUtilTaskbarSearch $ToggleStatus} + "WPFToggleTaskView" {Invoke-WinUtilTaskView $ToggleStatus} + "WPFToggleHiddenFiles" {Invoke-WinUtilHiddenFiles $ToggleStatus} + "WPFToggleTaskbarAlignment" {Invoke-WinUtilTaskbarAlignment $ToggleStatus} + "WPFToggleDetailedBSoD" {Invoke-WinUtilDetailedBSoD $ToggleStatus} + } + if ($sync.configs.tweaks.$($button).attributes -contains "epRestart") { + taskkill.exe /F /IM "explorer.exe" + Start-Process "explorer.exe" } }