mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-04-05 22:28:31 +00:00
Decoupled UI and data (#4051)
* Decoupled UI and data * Fix bad variable naming * Fix mistype * Fix mistype v2 Editing from mobile is hard
This commit is contained in:
@@ -44,7 +44,8 @@ function Invoke-WPFImpex {
|
||||
try {
|
||||
$Config = ConfigDialog
|
||||
if ($Config) {
|
||||
$jsonFile = Get-WinUtilCheckBoxes -unCheck $false | ConvertTo-Json
|
||||
$allConfs = $sync.selectedApps + $sync.selectedTweaks + $sync.selectedToggles + $sync.selectedFeatures
|
||||
$jsonFile = $allConfs | ConvertTo-Json
|
||||
$jsonFile | Out-File $Config -Force
|
||||
"iex ""& { `$(irm https://christitus.com/win) } -Config '$Config'""" | Set-Clipboard
|
||||
}
|
||||
@@ -66,21 +67,12 @@ 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" -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"
|
||||
}
|
||||
}
|
||||
# TODO how to handle old style? detected json type then flatten it in a func?
|
||||
# $flattenedJson = $jsonFile.PSObject.Properties.Where({ $_.Name -ne "Install" }).ForEach({ $_.Value })
|
||||
$flattenedJson = $jsonFile
|
||||
Update-WinUtilSelections -flatJson $flattenedJson
|
||||
# TODO test with toggles
|
||||
Reset-WPFCheckBoxes -doToggles $true
|
||||
}
|
||||
} catch {
|
||||
Write-Error "An error occurred while importing: $_"
|
||||
|
||||
Reference in New Issue
Block a user