From 4fc14b7ac64789f8dac567003f46482114192f58 Mon Sep 17 00:00:00 2001 From: "Mr.k" Date: Wed, 28 Aug 2024 15:14:26 +0300 Subject: [PATCH] Support the fallback to default theme (if it exists) --- functions/private/Set-WinUtilUITheme.ps1 | 14 ++++++++------ scripts/main.ps1 | 7 +++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/functions/private/Set-WinUtilUITheme.ps1 b/functions/private/Set-WinUtilUITheme.ps1 index bd89aa5c..57570ed1 100644 --- a/functions/private/Set-WinUtilUITheme.ps1 +++ b/functions/private/Set-WinUtilUITheme.ps1 @@ -41,21 +41,23 @@ function Set-WinUtilUITheme { throw [GenericException]::new("[Set-WinUtilTheme] Did not find '$defaultThemeName' theme in the themes config file.") } - if ($sync.configs.themes.$customThemeName) { + $themeToUse = $customThemeName + if ($sync.configs.themes.$themeToUse) { # Loop through every default theme option, and modify the custom theme in $sync variable, # so that it has full options available for other functions to use. foreach ($option in $sync.configs.themes.$defaultThemeName.PSObject.Properties) { $optionName = $option.Name $optionValue = $option.Value - if (-NOT $sync.configs.themes.$customThemeName.$optionName) { - $sync.configs.themes.$customThemeName | Add-Member -MemberType NoteProperty -Name $optionName -Value $optionValue + if (-NOT $sync.configs.themes.$themeToUse.$optionName) { + $sync.configs.themes.$themeToUse | Add-Member -MemberType NoteProperty -Name $optionName -Value $optionValue } } } else { - Write-Debug "[Set-WinUtilTheme] Theme '$customThemeName' was not found." + Write-Debug "[Set-WinUtilTheme] Theme '$customThemeName' was not found, using '$defaultThemeName' instead." + $themeToUse = $defaultThemeName } - foreach ($property in $sync.configs.themes.$customThemeName.PSObject.Properties) { + foreach ($property in $sync.configs.themes.$themeToUse.PSObject.Properties) { $key = $property.Name $value = $property.Value # Add curly braces around the key @@ -70,5 +72,5 @@ function Set-WinUtilUITheme { $inputXML = "" # Make inputXML equal an empty string, indicating something went wrong to the function caller. } - return $inputXML; + return @($inputXML, $themeToUse); } diff --git a/scripts/main.ps1 b/scripts/main.ps1 index b1e436aa..412f218f 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -52,6 +52,7 @@ $sync.runspace.Open() $inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^