From be8d20d47836b84f6eca040fcb2c2755c9bd0b5e Mon Sep 17 00:00:00 2001 From: Eren Date: Thu, 12 Feb 2026 23:34:28 +0300 Subject: [PATCH] export and import toggle switch states in config JSON (#4037) * feat: add support for importing and exporting WPFToggle checkbox states. * feat: add export and import * remove unnecessary buttons from tweaks tab * Merge branch 'main' into feature/import-export * Merge branch 'main' into feature/import-export --- functions/private/Get-WinUtilCheckBoxes.ps1 | 9 +++++++++ functions/public/Invoke-WPFImpex.ps1 | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/functions/private/Get-WinUtilCheckBoxes.ps1 b/functions/private/Get-WinUtilCheckBoxes.ps1 index 2f331836..36f0c40f 100644 --- a/functions/private/Get-WinUtilCheckBoxes.ps1 +++ b/functions/private/Get-WinUtilCheckBoxes.ps1 @@ -25,10 +25,19 @@ Function Get-WinUtilCheckBoxes { WPFTweaks = @() WPFFeature = @() WPFInstall = @() + WPFToggle = @() } $CheckBoxes = $sync.GetEnumerator() | Where-Object { $_.Value -is [System.Windows.Controls.CheckBox] } + # Collect toggle switch states + foreach ($CheckBox in $CheckBoxes) { + if ($CheckBox.Key -like "WPFToggle*" -and $CheckBox.Value.IsChecked -eq $true) { + $Output["WPFToggle"] += $CheckBox.Key + Write-Debug "Adding toggle: $($CheckBox.Key)" + } + } + # First check and add WPFTweaksRestorePoint if checked $RestorePoint = $CheckBoxes | Where-Object { $_.Key -eq 'WPFTweaksRestorePoint' -and $_.Value.IsChecked -eq $true } if ($RestorePoint) { diff --git a/functions/public/Invoke-WPFImpex.ps1 b/functions/public/Invoke-WPFImpex.ps1 index 94bd9f17..db98f2ce 100644 --- a/functions/public/Invoke-WPFImpex.ps1 +++ b/functions/public/Invoke-WPFImpex.ps1 @@ -66,8 +66,21 @@ function Invoke-WPFImpex { Write-Error "Failed to load the JSON file from the specified path or URL: $_" return } - $flattenedJson = $jsonFile.PSObject.Properties.Where({ $_.Name -ne "Install" }).ForEach({ $_.Value }) + $flattenedJson = $jsonFile.PSObject.Properties.Where({ $_.Name -ne "Install" -and $_.Name -ne "WPFToggle" }).ForEach({ $_.Value }) Invoke-WPFPresets -preset $flattenedJson -imported $true + + # Restore toggle switch states + $importedToggles = if ($jsonFile.WPFToggle) { $jsonFile.WPFToggle } else { @() } + $allToggles = $sync.GetEnumerator() | Where-Object { $_.Key -like "WPFToggle*" -and $_.Value -is [System.Windows.Controls.CheckBox] } + foreach ($toggle in $allToggles) { + if ($importedToggles -contains $toggle.Key) { + $sync[$toggle.Key].IsChecked = $true + Write-Debug "Restoring toggle: $($toggle.Key) = checked" + } else { + $sync[$toggle.Key].IsChecked = $false + Write-Debug "Restoring toggle: $($toggle.Key) = unchecked" + } + } } } catch { Write-Error "An error occurred while importing: $_"