Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion functions/private/Invoke-WinutilThemeChange.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ function Invoke-WinutilThemeChange {
}

$sync.preferences.theme = $theme
Set-Preferences -save
Set-WinutilTheme -currentTheme "shared"

switch ($sync.preferences.theme) {
Expand Down
73 changes: 0 additions & 73 deletions functions/private/Set-Preferences.ps1

This file was deleted.

84 changes: 2 additions & 82 deletions pester/preferences-theme.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ namespace System.Windows
"@
}

. (Join-Path $script:repoRoot "functions\private\Set-Preferences.ps1")
. (Join-Path $script:repoRoot "functions\private\Invoke-WinutilThemeChange.ps1")

function Get-WinUtilToggleStatus {
Expand Down Expand Up @@ -186,84 +185,6 @@ namespace System.Windows
}
}

Describe "Set-Preferences" {
AfterEach {
if ($script:testRoot -and (Test-Path $script:testRoot)) {
Remove-Item -Path $script:testRoot -Recurse -Force -ErrorAction SilentlyContinue
}
$script:testRoot = $null
Remove-WinUtilPreferenceGlobals
}

It "loads default preferences when no preferences file exists" {
$script:testRoot = New-WinUtilPreferencesTestRoot
$global:winutildir = $script:testRoot
New-WinUtilPreferenceSync

Set-Preferences

$script:sync.preferences.theme | Should -Be "Auto"
$script:sync.preferences.packagemanager | Should -Be "Winget"
}

It "loads saved preferences and keeps the package manager as a string" {
$script:testRoot = New-WinUtilPreferencesTestRoot
$global:winutildir = $script:testRoot
New-WinUtilPreferenceSync
Set-Content -Path (Join-Path $script:testRoot "preferences.ini") -Value @(
"theme = Dark"
"packagemanager = Choco"
)

Set-Preferences

$script:sync.preferences.theme | Should -Be "Dark"
$script:sync.preferences.packagemanager | Should -Be "Choco"
}

It "saves current preferences to preferences.ini" {
$script:testRoot = New-WinUtilPreferencesTestRoot
$global:winutildir = $script:testRoot
New-WinUtilPreferenceSync -Preferences @{
theme = "Light"
packagemanager = "Winget"
}

Set-Preferences -save

$preferencesText = Get-Content -Path (Join-Path $script:testRoot "preferences.ini") -Raw
$preferencesText | Should -Match "theme=Light"
$preferencesText | Should -Match "packagemanager=Winget"
}

It "absorbs legacy preference files and removes old markers" {
$script:testRoot = New-WinUtilPreferencesTestRoot
$global:winutildir = $script:testRoot
New-WinUtilPreferenceSync
Set-Content -Path (Join-Path $script:testRoot "LightTheme.ini") -Value ""
Set-Content -Path (Join-Path $script:testRoot "preferChocolatey.ini") -Value ""

Set-Preferences

$script:sync.preferences.theme | Should -Be "Light"
$script:sync.preferences.packagemanager | Should -Be "Choco"
Test-Path (Join-Path $script:testRoot "LightTheme.ini") | Should -BeFalse
Test-Path (Join-Path $script:testRoot "preferChocolatey.ini") | Should -BeFalse
}

It "absorbs old package manager preferences stored without a key" {
$script:testRoot = New-WinUtilPreferencesTestRoot
$global:winutildir = $script:testRoot
New-WinUtilPreferenceSync
Set-Content -Path (Join-Path $script:testRoot "preferences.ini") -Value "Choco"

Set-Preferences

$script:sync.preferences.theme | Should -Be "Auto"
$script:sync.preferences.packagemanager | Should -Be "Choco"
}
}

Describe "Invoke-WinutilThemeChange" {
AfterEach {
if ($script:testRoot -and (Test-Path $script:testRoot)) {
Expand All @@ -273,7 +194,7 @@ Describe "Invoke-WinutilThemeChange" {
Remove-WinUtilPreferenceGlobals
}

It "applies shared and selected theme resources, saves the preference, and updates the theme button" {
It "applies shared and selected theme resources, keeps the preference in memory, and updates the theme button" {
$script:testRoot = New-WinUtilPreferencesTestRoot
$global:winutildir = $script:testRoot
New-WinUtilPreferenceSync
Expand All @@ -287,8 +208,7 @@ Describe "Invoke-WinutilThemeChange" {
$script:sync.Form.Resources.ContainsKey("CBorderColor") | Should -BeTrue
$script:sync.Form.ThemeButton.Content | Should -Be ([string][char]0xE708)

$preferencesText = Get-Content -Path (Join-Path $script:testRoot "preferences.ini") -Raw
$preferencesText | Should -Match "theme=Dark"
Test-Path -Path (Join-Path $script:testRoot "preferences.ini") | Should -BeFalse
}

It "uses the system dark-mode toggle when Auto theme is selected" {
Expand Down
7 changes: 2 additions & 5 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ $sync.configs.appxHashtable = @{}
$sync.configs.appx.PSObject.Properties | ForEach-Object {
$sync.configs.appxHashtable[$_.Name] = $_.Value
}

Set-Preferences
$sync.preferences.theme = "Auto"
$sync.preferences.packagemanager = "Winget"

if ($Preset) {
Initialize-WinUtilRunspacePool | Out-Null
Expand Down Expand Up @@ -137,14 +137,11 @@ Initialize-WinUtilTabContent -TabName "Install"

$xaml.SelectNodes("//*[@Name]") | ForEach-Object {$sync["$("$($psitem.Name)")"] = $sync["Form"].FindName($psitem.Name)}

#Persist Package Manager preference across winutil restarts
$sync.ChocoRadioButton.Add_Checked({
$sync.preferences.packagemanager = "Choco"
Set-Preferences -save
})
$sync.WingetRadioButton.Add_Checked({
$sync.preferences.packagemanager = "Winget"
Set-Preferences -save
})

switch ($sync.preferences.packagemanager) {
Expand Down
Loading