mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-01-16 01:40:35 -06:00
Support the fallback to default theme (if it exists)
This commit is contained in:
parent
591675e832
commit
4fc14b7ac6
@ -41,21 +41,23 @@ function Set-WinUtilUITheme {
|
|||||||
throw [GenericException]::new("[Set-WinUtilTheme] Did not find '$defaultThemeName' theme in the themes config file.")
|
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,
|
# 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.
|
# so that it has full options available for other functions to use.
|
||||||
foreach ($option in $sync.configs.themes.$defaultThemeName.PSObject.Properties) {
|
foreach ($option in $sync.configs.themes.$defaultThemeName.PSObject.Properties) {
|
||||||
$optionName = $option.Name
|
$optionName = $option.Name
|
||||||
$optionValue = $option.Value
|
$optionValue = $option.Value
|
||||||
if (-NOT $sync.configs.themes.$customThemeName.$optionName) {
|
if (-NOT $sync.configs.themes.$themeToUse.$optionName) {
|
||||||
$sync.configs.themes.$customThemeName | Add-Member -MemberType NoteProperty -Name $optionName -Value $optionValue
|
$sync.configs.themes.$themeToUse | Add-Member -MemberType NoteProperty -Name $optionName -Value $optionValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
$key = $property.Name
|
||||||
$value = $property.Value
|
$value = $property.Value
|
||||||
# Add curly braces around the key
|
# 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.
|
$inputXML = "" # Make inputXML equal an empty string, indicating something went wrong to the function caller.
|
||||||
}
|
}
|
||||||
|
|
||||||
return $inputXML;
|
return @($inputXML, $themeToUse);
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ $sync.runspace.Open()
|
|||||||
|
|
||||||
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
|
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
|
||||||
|
|
||||||
|
$defaulttheme = '_default'
|
||||||
if ((Get-WinUtilToggleStatus WPFToggleDarkMode) -eq $True) {
|
if ((Get-WinUtilToggleStatus WPFToggleDarkMode) -eq $True) {
|
||||||
if (Invoke-WinUtilGPU -eq $True) {
|
if (Invoke-WinUtilGPU -eq $True) {
|
||||||
$ctttheme = 'Matrix'
|
$ctttheme = 'Matrix'
|
||||||
@ -62,8 +63,8 @@ if ((Get-WinUtilToggleStatus WPFToggleDarkMode) -eq $True) {
|
|||||||
$ctttheme = 'Classic'
|
$ctttheme = 'Classic'
|
||||||
}
|
}
|
||||||
|
|
||||||
$inputXML = Set-WinUtilUITheme -inputXML $inputXML -customThemeName $ctttheme
|
$returnVal = Set-WinUtilUITheme -inputXML $inputXML -customThemeName $ctttheme -defaultThemeName $defaulttheme
|
||||||
if ($inputXML -eq "") {
|
if ($returnVal[0] -eq "") {
|
||||||
Write-Host "Failed to statically apply theming to xaml content using Set-WinUtilTheme, please check previous Error/Warning messages." -ForegroundColor Red
|
Write-Host "Failed to statically apply theming to xaml content using Set-WinUtilTheme, please check previous Error/Warning messages." -ForegroundColor Red
|
||||||
Write-Host "Quitting winutil..." -ForegroundColor Red
|
Write-Host "Quitting winutil..." -ForegroundColor Red
|
||||||
$sync.runspace.Dispose()
|
$sync.runspace.Dispose()
|
||||||
@ -71,6 +72,8 @@ if ($inputXML -eq "") {
|
|||||||
[System.GC]::Collect()
|
[System.GC]::Collect()
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
$inputXML = $returnVal[0]
|
||||||
|
$ctttheme = $returnVal[1]
|
||||||
|
|
||||||
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
|
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
|
||||||
[xml]$XAML = $inputXML
|
[xml]$XAML = $inputXML
|
||||||
|
Loading…
Reference in New Issue
Block a user