Merge branch 'master' into undo-tweaks

This commit is contained in:
Raphire
2026-03-27 20:34:41 +01:00
21 changed files with 811 additions and 81 deletions

View File

@@ -27,6 +27,8 @@ function Show-MainWindow {
$menuReportBug = $window.FindName('MenuReportBug')
$menuLogs = $window.FindName('MenuLogs')
$menuAbout = $window.FindName('MenuAbout')
$importConfigBtn = $window.FindName('ImportConfigBtn')
$exportConfigBtn = $window.FindName('ExportConfigBtn')
# Title bar event handlers
$titleBar.Add_MouseLeftButtonDown({
@@ -67,6 +69,22 @@ function Show-MainWindow {
Show-AboutDialog -Owner $window
})
# --- Import/Export Configuration ---
$exportConfigBtn.Add_Click({
Export-Configuration -Owner $window -UsesDarkMode $usesDarkMode -AppsPanel $appsPanel -UiControlMappings $script:UiControlMappings -UserSelectionCombo $userSelectionCombo -OtherUsernameTextBox $otherUsernameTextBox
})
$importConfigBtn.Add_Click({
Import-Configuration -Owner $window -UsesDarkMode $usesDarkMode -AppsPanel $appsPanel -UiControlMappings $script:UiControlMappings -UserSelectionCombo $userSelectionCombo -OtherUsernameTextBox $otherUsernameTextBox -OnAppsImported { UpdateAppSelectionStatus; UpdatePresetStates } -OnImportCompleted {
$tabControl.SelectedIndex = 3
UpdateNavigationButtons
$window.Dispatcher.BeginInvoke([System.Windows.Threading.DispatcherPriority]::Loaded, [action]{
Show-Bubble -TargetControl $reviewChangesBtn -Message 'View the selected changes here'
}) | Out-Null
}
})
$closeBtn.Add_Click({
$window.Close()
})
@@ -241,7 +259,7 @@ function Show-MainWindow {
$check = ($this.IsChecked -eq $true)
if ($this.IsChecked -eq $null) { $this.IsChecked = $false; $check = $false }
$presetIds = $this.PresetAppIds
ApplyPresetToApps -MatchFilter { param($c) $presetIds -contains $c.Tag }.GetNewClosure() -Check $check
ApplyPresetToApps -MatchFilter { param($c) (@($c.AppIds) | Where-Object { $presetIds -contains $_ }).Count -gt 0 }.GetNewClosure() -Check $check
})
}
@@ -254,6 +272,11 @@ function Show-MainWindow {
$script:PendingDefaultMode = $false
# Holds apps data preloaded before ShowDialog() so the first load skips the background job
$script:PreloadedAppData = $null
# Prevent app import until the apps list has finished initial population.
if ($importConfigBtn) {
$importConfigBtn.IsEnabled = $false
}
# Set script-level variable for GUI window reference
$script:GuiWindow = $window
@@ -317,7 +340,7 @@ function Show-MainWindow {
$key = switch ($script:SortColumn) {
'Name' { { $_.AppName } }
'Description' { { $_.AppDescription } }
'AppId' { { $_.Tag } }
'AppId' { { $_.AppIdDisplay } }
}
$sorted = $children | Sort-Object $key -Descending:(-not $script:SortAscending)
$appsPanel.Children.Clear()
@@ -379,14 +402,6 @@ function Show-MainWindow {
function UpdatePresetStates {
$script:UpdatingPresets = $true
try {
# Build a set of currently checked app tags for fast lookup
$checkedTags = @{}
foreach ($child in $appsPanel.Children) {
if ($child -is [System.Windows.Controls.CheckBox] -and $child.IsChecked) {
$checkedTags[$child.Tag] = $true
}
}
# Helper: count matching and checked apps, set checkbox state
function SetPresetState($checkbox, [scriptblock]$MatchFilter) {
$total = 0; $checked = 0
@@ -394,7 +409,7 @@ function Show-MainWindow {
if ($child -is [System.Windows.Controls.CheckBox]) {
if (& $MatchFilter $child) {
$total++
if ($checkedTags.ContainsKey($child.Tag)) { $checked++ }
if ($child.IsChecked) { $checked++ }
}
}
}
@@ -416,12 +431,12 @@ function Show-MainWindow {
SetPresetState $presetDefaultApps { param($c) $c.SelectedByDefault -eq $true }
foreach ($jsonCb in $script:JsonPresetCheckboxes) {
$localIds = $jsonCb.PresetAppIds
SetPresetState $jsonCb { param($c) $localIds -contains $c.Tag }.GetNewClosure()
SetPresetState $jsonCb { param($c) (@($c.AppIds) | Where-Object { $localIds -contains $_ }).Count -gt 0 }.GetNewClosure()
}
# Last used preset: only update if it's visible (has saved apps)
if ($presetLastUsed.Visibility -ne 'Collapsed' -and $script:SavedAppIds) {
SetPresetState $presetLastUsed { param($c) $script:SavedAppIds -contains $c.Tag }
SetPresetState $presetLastUsed { param($c) (@($c.AppIds) | Where-Object { $script:SavedAppIds -contains $_ }).Count -gt 0 }
}
}
finally {
@@ -746,6 +761,9 @@ function Show-MainWindow {
if ($appsToAdd.Count -eq 0) {
$window.FindName('DeploymentApplyBtn').IsEnabled = $true
if ($importConfigBtn) {
$importConfigBtn.IsEnabled = $true
}
return
}
@@ -760,9 +778,9 @@ function Show-MainWindow {
$app = $appsToAdd[$i]
$checkbox = New-Object System.Windows.Controls.CheckBox
$automationName = if ($app.FriendlyName) { $app.FriendlyName } elseif ($app.AppId) { $app.AppId } else { $null }
$automationName = if ($app.FriendlyName) { $app.FriendlyName } elseif ($app.AppIdDisplay) { $app.AppIdDisplay } else { $null }
if ($automationName) { $checkbox.SetValue([System.Windows.Automation.AutomationProperties]::NameProperty, $automationName) }
$checkbox.Tag = $app.AppId
$checkbox.Tag = $app.AppIdDisplay
$checkbox.IsChecked = $app.IsChecked
$checkbox.Style = $window.Resources['AppsPanelCheckBoxStyle']
@@ -798,9 +816,9 @@ function Show-MainWindow {
[System.Windows.Controls.Grid]::SetColumn($tbDesc, 2)
$tbId = New-Object System.Windows.Controls.TextBlock
$tbId.Text = $app.AppId
$tbId.Style = $window.Resources['AppIdTextStyle']
$tbId.ToolTip = $app.AppId
$tbId.Text = $app.AppIdDisplay
$tbId.Style = $window.Resources["AppIdTextStyle"]
$tbId.ToolTip = $app.AppIdDisplay
[System.Windows.Controls.Grid]::SetColumn($tbId, 3)
$row.Children.Add($dot) | Out-Null
@@ -812,6 +830,8 @@ function Show-MainWindow {
Add-Member -InputObject $checkbox -MemberType NoteProperty -Name 'AppName' -Value $app.FriendlyName
Add-Member -InputObject $checkbox -MemberType NoteProperty -Name 'AppDescription' -Value $app.Description
Add-Member -InputObject $checkbox -MemberType NoteProperty -Name 'SelectedByDefault' -Value $app.SelectedByDefault
Add-Member -InputObject $checkbox -MemberType NoteProperty -Name 'AppIds' -Value @($app.AppId)
Add-Member -InputObject $checkbox -MemberType NoteProperty -Name 'AppIdDisplay' -Value $app.AppIdDisplay
$checkbox.Add_Checked({ UpdateAppSelectionStatus })
$checkbox.Add_Unchecked({ UpdateAppSelectionStatus })
@@ -836,6 +856,9 @@ function Show-MainWindow {
# Re-enable Apply button now that the full, correctly-checked app list is ready
$window.FindName('DeploymentApplyBtn').IsEnabled = $true
if ($importConfigBtn) {
$importConfigBtn.IsEnabled = $true
}
}
# Loads apps into the UI
@@ -844,6 +867,10 @@ function Show-MainWindow {
if ($script:IsLoadingApps) { return }
$script:IsLoadingApps = $true
if ($importConfigBtn) {
$importConfigBtn.IsEnabled = $false
}
# Show loading indicator and clear existing apps
$loadingAppsIndicator.Visibility = 'Visible'
$appsPanel.Children.Clear()
@@ -1575,9 +1602,10 @@ function Show-MainWindow {
$selectedApps = @()
foreach ($child in $appsPanel.Children) {
if ($child -is [System.Windows.Controls.CheckBox] -and $child.IsChecked) {
$selectedApps += $child.Tag
$selectedApps += @($child.AppIds)
}
}
$selectedApps = @($selectedApps | Where-Object { $_ } | Select-Object -Unique)
if ($selectedApps.Count -gt 0) {
# Check if Microsoft Store is selected
@@ -1798,7 +1826,7 @@ function Show-MainWindow {
if ($script:UpdatingPresets) { return }
$check = ($this.IsChecked -eq $true)
if ($this.IsChecked -eq $null) { $this.IsChecked = $false; $check = $false }
ApplyPresetToApps -MatchFilter { param($c) $script:SavedAppIds -contains $c.Tag } -Check $check
ApplyPresetToApps -MatchFilter { param($c) (@($c.AppIds) | Where-Object { $script:SavedAppIds -contains $_ }).Count -gt 0 } -Check $check
})
}
else {