From 0251757fc07882a3a448068de0e0ab1c4a7b7a51 Mon Sep 17 00:00:00 2001 From: Martin Wiethan <47688561+Marterich@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:34:10 +0200 Subject: [PATCH] Add the option to change the UI Theme at runtime (#2693) * Setup for testing * Working Example for Background * Almost all MainBackgrounColor working * Random Color PoC * Fix DBorderColor * prevent old logic from replacing colors in memory at startup * Comment out resources in xaml * Finish new Button * Remove Pulse, Load Windows default Theme * Fix Colors * Fix Toggle Colors * working version, with shared still being mostly applied be replace instead of resouces * Load all entries in themes.json as Resource and reference them in inputXML.xaml * Rename File to match Function Name * Hotfix for Sync with main * Remove Static Set-WinUtilUITheme function/file * Rename File and Function * Cleanup and Stuff * Unify Button Theme with rest of UI * Refactor/Optimazation * Performance optimization * Add Comments * Rename Functions and Variables to be more concise and descriptive * Add persistence to the user Theme Preference across winutil restarts * Reimplement Theme Chagnes from #2722 * Add AUTO option to follow window theme and add dropdown instead toggle * Formatting and deleting temp file * Fix small display bug where Dropdown would remain open for settings and themes * Remove terniary operators because only PS7+ is supported --- config/themes.json | 265 ++++------- .../private/Invoke-WinutilThemeChange.ps1 | 180 +++++++ functions/private/Set-WinUtilUITheme.ps1 | 83 ---- functions/private/Show-CustomDialog.ps1 | 28 +- functions/public/Invoke-WPFButton.ps1 | 1 - functions/public/Invoke-WPFUIElements.ps1 | 10 +- scripts/main.ps1 | 97 ++-- xaml/inputXML.xaml | 442 +++++++++--------- 8 files changed, 575 insertions(+), 531 deletions(-) create mode 100644 functions/private/Invoke-WinutilThemeChange.ps1 delete mode 100644 functions/private/Set-WinUtilUITheme.ps1 diff --git a/config/themes.json b/config/themes.json index 27f3a45e13..abf7f5759d 100644 --- a/config/themes.json +++ b/config/themes.json @@ -1,169 +1,100 @@ { - "_default": { - "CustomDialogFontSize": "12", - "CustomDialogFontSizeHeader": "14", - "CustomDialogIconSize": "25", - "CustomDialogWidth": "400", - "CustomDialogHeight": "200", - - "FontSize": "12", - "FontFamily": "Arial", - "FontSizeHeading": "16", - "HeaderFontFamily": "Consolas, Monaco", - - "CheckBoxBulletDecoratorSize": "14", - "CheckBoxMargin": "15,0,0,2", - - "TabContentMargin": "5", - "TabButtonFontSize": "14", - "TabButtonWidth": "100", - "TabButtonHeight": "25", - "TabRowHeightInPixels": "50", - "IconFontSize": "14", - "IconButtonSize": "35", - "SettingsIconFontSize": "18", - "CloseIconFontSize": "18", - - "MicroWinLogoSize": "10", - "MicrowinCheckBoxMargin": "-10,5,0,0", - - "ProgressBarForegroundColor": "#2e77ff", - "ProgressBarBackgroundColor": "Transparent", - "ProgressBarTextColor": "#232629", - - "ComboBoxBackgroundColor": "#F7F7F7", - "LabelboxForegroundColor": "#232629", - "MainForegroundColor": "#232629", - "MainBackgroundColor": "#F7F7F7", - "LabelBackgroundColor": "#F7F7F7", - "LinkForegroundColor": "#232629", - "LinkHoverForegroundColor": "#232629", - "GroupBorderBackgroundColor": "#232629", - "ComboBoxForegroundColor": "#232629", - - "ButtonFontSize": "12", - "ButtonFontFamily": "Arial", - "ButtonWidth": "200", - "ButtonHeight": "25", - "ConfigTabButtonFontSize": "16", - - "SearchBarWidth": "200", - "SearchBarHeight": "25", - "SearchBarTextBoxFontSize": "12", - "SearchBarClearButtonFontSize": "14", - - "ButtonInstallBackgroundColor": "#F7F7F7", - "ButtonTweaksBackgroundColor": "#F7F7F7", - "ButtonConfigBackgroundColor": "#F7F7F7", - "ButtonUpdatesBackgroundColor": "#F7F7F7", - "ButtonInstallForegroundColor": "#232629", - "ButtonTweaksForegroundColor": "#232629", - "ButtonConfigForegroundColor": "#232629", - "ButtonUpdatesForegroundColor": "#232629", - "ButtonBackgroundColor": "#F5F5F5", - "ButtonBackgroundPressedColor": "#1A1A1A", - "CheckboxMouseOverColor": "#999999", - "ButtonBackgroundMouseoverColor": "#C2C2C2", - "ButtonBackgroundSelectedColor": "#F0F0F0", - "ButtonForegroundColor": "#232629", - "ToggleButtonOnColor": "#2e77ff", - - "ButtonBorderThickness": "1", - "ButtonMargin": "1", - "ButtonCornerRadius": "2", - "BorderColor": "#232629", - "BorderOpacity": "0.2", - "ShadowPulse": "Forever" - }, - "Classic": { - "ComboBoxBackgroundColor": "#F7F7F7", - "LabelboxForegroundColor": "#232629", - "MainForegroundColor": "#232629", - "MainBackgroundColor": "#F7F7F7", - "LabelBackgroundColor": "#F7F7F7", - "LinkForegroundColor": "#232629", - "LinkHoverForegroundColor": "#232629", - "GroupBorderBackgroundColor": "#232629", - "ComboBoxForegroundColor": "#232629", - - "ButtonInstallBackgroundColor": "#F7F7F7", - "ButtonTweaksBackgroundColor": "#F7F7F7", - "ButtonConfigBackgroundColor": "#F7F7F7", - "ButtonUpdatesBackgroundColor": "#F7F7F7", - "ButtonInstallForegroundColor": "#232629", - "ButtonTweaksForegroundColor": "#232629", - "ButtonConfigForegroundColor": "#232629", - "ButtonUpdatesForegroundColor": "#232629", - "ButtonBackgroundColor": "#F5F5F5", - "ButtonBackgroundPressedColor": "#1A1A1A", - "CheckboxMouseOverColor": "#999999", - "ButtonBackgroundMouseoverColor": "#C2C2C2", - "ButtonBackgroundSelectedColor": "#F0F0F0", - "ButtonForegroundColor": "#232629", - "ToggleButtonOnColor": "#2e77ff" - }, - "Matrix": { - "ComboBoxBackgroundColor": "#232629", - "LabelboxForegroundColor": "#f7f7f7", - "MainForegroundColor": "#F7F7F7", - "MainBackgroundColor": "#232629", - "LabelBackgroundColor": "#232629", - "LinkForegroundColor": "#add8e6", - "LinkHoverForegroundColor": "#F7F7F7", - "ComboBoxForegroundColor": "#81a1c1", - - "ProgressBarForegroundColor": "#222222", - "ProgressBarBackgroundColor": "Transparent", - "ProgressBarTextColor": "#cccccc", - - "ButtonInstallBackgroundColor": "#222222", - "ButtonTweaksBackgroundColor": "#333333", - "ButtonConfigBackgroundColor": "#444444", - "ButtonUpdatesBackgroundColor": "#555555", - "ButtonInstallForegroundColor": "#F7F7F7", - "ButtonTweaksForegroundColor": "#F7F7F7", - "ButtonConfigForegroundColor": "#F7F7F7", - "ButtonUpdatesForegroundColor": "#F7F7F7", - "ButtonBackgroundColor": "#1E3747", - "ButtonBackgroundPressedColor": "#F7F7F7", - "ButtonBackgroundMouseoverColor": "#3B4252", - "ButtonBackgroundSelectedColor": "#5E81AC", - "ButtonForegroundColor": "#F7F7F7", - "ToggleButtonOnColor": "#2e77ff", - - "BorderColor": "#0060CC", - "BorderOpacity": "0.2", - "ShadowPulse": "0:0:3" - }, - "Dark": { - "ComboBoxBackgroundColor": "#1e3747", - "LabelboxForegroundColor": "#0567ff", - "MainForegroundColor": "#F7F7F7", - "MainBackgroundColor": "#121212", - "LabelBackgroundColor": "#121212", - "LinkForegroundColor": "#add8e6", - "LinkHoverForegroundColor": "#F7F7F7", - "ComboBoxForegroundColor": "#f7f7f7", - - "ProgressBarForegroundColor": "#222222", - "ProgressBarBackgroundColor": "Transparent", - "ProgressBarTextColor": "#cccccc", - - "ButtonInstallBackgroundColor": "#222222", - "ButtonTweaksBackgroundColor": "#333333", - "ButtonConfigBackgroundColor": "#444444", - "ButtonUpdatesBackgroundColor": "#555555", - "ButtonInstallForegroundColor": "#F7F7F7", - "ButtonTweaksForegroundColor": "#F7F7F7", - "ButtonConfigForegroundColor": "#F7F7F7", - "ButtonUpdatesForegroundColor": "#F7F7F7", - "ButtonBackgroundColor": "#1E3747", - "ButtonBackgroundPressedColor": "#00CFFF", - "ButtonBackgroundMouseoverColor": "#5E81AC", - "ButtonBackgroundSelectedColor": "#5E81AC", - "ButtonForegroundColor": "#F7F7F7", - "ToggleButtonOnColor": "#2e77ff", - - "BorderColor": "#2F373D" - } + "shared":{ + "CustomDialogFontSize": "12", + "CustomDialogFontSizeHeader": "14", + "CustomDialogIconSize": "25", + "CustomDialogWidth": "400", + "CustomDialogHeight": "200", + "FontSize": "12", + "FontFamily": "Arial", + "FontSizeHeading": "16", + "HeaderFontFamily": "Consolas, Monaco", + "CheckBoxBulletDecoratorSize": "14", + "CheckBoxMargin": "15,0,0,2", + "TabContentMargin": "5", + "TabButtonFontSize": "14", + "TabButtonWidth": "100", + "TabButtonHeight": "25", + "TabRowHeightInPixels": "50", + "IconFontSize": "14", + "IconButtonSize": "35", + "SettingsIconFontSize": "18", + "CloseIconFontSize": "18", + "MicroWinLogoSize": "10", + "MicrowinCheckBoxMargin": "-10,5,0,0", + "GroupBorderBackgroundColor": "#232629", + "ButtonFontSize": "12", + "ButtonFontFamily": "Arial", + "ButtonWidth": "200", + "ButtonHeight": "25", + "ConfigTabButtonFontSize": "16", + "SearchBarWidth": "200", + "SearchBarHeight": "25", + "SearchBarTextBoxFontSize": "12", + "SearchBarClearButtonFontSize": "14", + "CheckboxMouseOverColor": "#999999", + "ButtonBorderThickness": "1", + "ButtonMargin": "1", + "ButtonCornerRadius": "2" + }, + "Light": { + "ComboBoxForegroundColor": "#232629", + "ComboBoxBackgroundColor": "#F7F7F7", + "LabelboxForegroundColor": "#232629", + "MainForegroundColor": "#232629", + "MainBackgroundColor": "#F7F7F7", + "LabelBackgroundColor": "#F7F7F7", + "LinkForegroundColor": "#232629", + "LinkHoverForegroundColor": "#232629", + + "ProgressBarForegroundColor": "#2e77ff", + "ProgressBarBackgroundColor": "Transparent", + "ProgressBarTextColor": "#232629", + "ButtonInstallBackgroundColor": "#F7F7F7", + "ButtonTweaksBackgroundColor": "#F7F7F7", + "ButtonConfigBackgroundColor": "#F7F7F7", + "ButtonUpdatesBackgroundColor": "#F7F7F7", + "ButtonInstallForegroundColor": "#232629", + "ButtonTweaksForegroundColor": "#232629", + "ButtonConfigForegroundColor": "#232629", + "ButtonUpdatesForegroundColor": "#232629", + "ButtonBackgroundColor": "#F5F5F5", + "ButtonBackgroundPressedColor": "#1A1A1A", + "ButtonBackgroundMouseoverColor": "#C2C2C2", + "ButtonBackgroundSelectedColor": "#F0F0F0", + "ButtonForegroundColor": "#232629", + "ToggleButtonOnColor": "#2e77ff", + "BorderColor": "#232629", + "BorderOpacity": "0.2" + + }, + "Dark": { + "ComboBoxForegroundColor": "#1e3747", + "ComboBoxBackgroundColor": "#232629", + "LabelboxForegroundColor": "#0567ff", + "MainForegroundColor": "#F7F7F7", + "MainBackgroundColor": "#121212", + "LabelBackgroundColor": "#121212", + "LinkForegroundColor": "#add8e6", + "LinkHoverForegroundColor": "#F7F7F7", + "ProgressBarForegroundColor": "#222222", + "ProgressBarBackgroundColor": "Transparent", + "ProgressBarTextColor": "#cccccc", + "ButtonInstallBackgroundColor": "#222222", + "ButtonTweaksBackgroundColor": "#333333", + "ButtonConfigBackgroundColor": "#444444", + "ButtonUpdatesBackgroundColor": "#555555", + "ButtonInstallForegroundColor": "#F7F7F7", + "ButtonTweaksForegroundColor": "#F7F7F7", + "ButtonConfigForegroundColor": "#F7F7F7", + "ButtonUpdatesForegroundColor": "#F7F7F7", + "ButtonBackgroundColor": "#1E3747", + "ButtonBackgroundPressedColor": "#F7F7F7", + "ButtonBackgroundMouseoverColor": "#3B4252", + "ButtonBackgroundSelectedColor": "#5E81AC", + "ButtonForegroundColor": "#F7F7F7", + "ToggleButtonOnColor": "#2e77ff", + "BorderColor": "#2F373D", + "BorderOpacity": "0.2" + } } diff --git a/functions/private/Invoke-WinutilThemeChange.ps1 b/functions/private/Invoke-WinutilThemeChange.ps1 new file mode 100644 index 0000000000..fc1bbe18ed --- /dev/null +++ b/functions/private/Invoke-WinutilThemeChange.ps1 @@ -0,0 +1,180 @@ +function Invoke-WinutilThemeChange { + <# + .SYNOPSIS + Toggles between light and dark themes for a Windows utility application. + + .DESCRIPTION + This function toggles the theme of the user interface between 'Light' and 'Dark' modes, + modifying various UI elements such as colors, margins, corner radii, font families, etc. + If the '-init' switch is used, it initializes the theme based on the system's current dark mode setting. + + .PARAMETER init + A switch parameter. If set to $true, the function initializes the theme based on the system’s current dark mode setting. + + .EXAMPLE + Invoke-WinutilThemeChange + # Toggles the theme between 'Light' and 'Dark'. + + .EXAMPLE + Invoke-WinutilThemeChange -init + # Initializes the theme based on the system's dark mode and applies the shared theme. + #> + param ( + [switch]$init = $false, + [string]$theme + ) + + function Set-WinutilTheme { + <# + .SYNOPSIS + Applies the specified theme to the application's user interface. + + .DESCRIPTION + This internal function applies the given theme by setting the relevant properties + like colors, font families, corner radii, etc., in the UI. It uses the + 'Set-ThemeResourceProperty' helper function to modify the application's resources. + + .PARAMETER currentTheme + The name of the theme to be applied. Common values are "Light", "Dark", or "shared". + #> + param ( + [string]$currentTheme + ) + + function Set-ThemeResourceProperty { + <# + .SYNOPSIS + Sets a specific UI property in the application's resources. + + .DESCRIPTION + This helper function sets a property (e.g., color, margin, corner radius) in the + application's resources, based on the provided type and value. It includes + error handling to manage potential issues while setting a property. + + .PARAMETER Name + The name of the resource property to modify (e.g., "MainBackgroundColor", "ButtonBackgroundMouseoverColor"). + + .PARAMETER Value + The value to assign to the resource property (e.g., "#FFFFFF" for a color). + + .PARAMETER Type + The type of the resource, such as "ColorBrush", "CornerRadius", "GridLength", or "FontFamily". + #> + param($Name, $Value, $Type) + try { + # Set the resource property based on its type + $sync.Form.Resources[$Name] = switch ($Type) { + "ColorBrush" { [Windows.Media.SolidColorBrush]::new($Value) } + "Color" { + # Convert hex string to RGB values + $hexColor = $Value.TrimStart("#") + $r = [Convert]::ToInt32($hexColor.Substring(0,2), 16) + $g = [Convert]::ToInt32($hexColor.Substring(2,2), 16) + $b = [Convert]::ToInt32($hexColor.Substring(4,2), 16) + [Windows.Media.Color]::FromRgb($r, $g, $b) + } + "CornerRadius" { [System.Windows.CornerRadius]::new($Value) } + "GridLength" { [System.Windows.GridLength]::new($Value) } + "Thickness" { + # Parse the Thickness value (supports 1, 2, or 4 inputs) + $values = $Value -split "," + switch ($values.Count) { + 1 { [System.Windows.Thickness]::new([double]$values[0]) } + 2 { [System.Windows.Thickness]::new([double]$values[0], [double]$values[1]) } + 4 { [System.Windows.Thickness]::new([double]$values[0], [double]$values[1], [double]$values[2], [double]$values[3]) } + } + } + "FontFamily" { [Windows.Media.FontFamily]::new($Value) } + "Double" { [double]$Value } + default { $Value } + } + } + catch { + # Log a warning if there's an issue setting the property + Write-Warning "Failed to set property $($Name): $_" + } + } + + # Retrieve all theme properties from the theme configuration + $themeProperties = $sync.configs.themes.$currentTheme.PSObject.Properties + foreach ($_ in $themeProperties) { + # Apply properties that deal with colors + if ($_.Name -like "*color*") { + Set-ThemeResourceProperty -Name $_.Name -Value $_.Value -Type "ColorBrush" + # For certain color properties, also set complementary values (e.g., BorderColor -> CBorderColor) This is required because e.g DropShadowEffect requires a and not a object + if ($_.Name -in @("BorderColor", "ButtonBackgroundMouseoverColor")) { + Set-ThemeResourceProperty -Name "C$($_.Name)" -Value $_.Value -Type "Color" + } + } + # Apply corner radius properties + elseif ($_.Name -like "*Radius*") { + Set-ThemeResourceProperty -Name $_.Name -Value $_.Value -Type "CornerRadius" + } + # Apply row height properties + elseif ($_.Name -like "*RowHeight*") { + Set-ThemeResourceProperty -Name $_.Name -Value $_.Value -Type "GridLength" + } + # Apply thickness or margin properties + elseif (($_.Name -like "*Thickness*") -or ($_.Name -like "*margin")) { + Set-ThemeResourceProperty -Name $_.Name -Value $_.Value -Type "Thickness" + } + # Apply font family properties + elseif ($_.Name -like "*FontFamily*") { + Set-ThemeResourceProperty -Name $_.Name -Value $_.Value -Type "FontFamily" + } + # Apply any other properties as doubles (numerical values) + else { + Set-ThemeResourceProperty -Name $_.Name -Value $_.Value -Type "Double" + } + } + } + + $LightPreferencePath = "$env:LOCALAPPDATA\winutil\LightTheme.ini" + $DarkPreferencePath = "$env:LOCALAPPDATA\winutil\DarkTheme.ini" + + if ($init) { + Set-WinutilTheme -currentTheme "shared" + if (Test-Path $LightPreferencePath) { + $theme = "Light" + } + elseif (Test-Path $DarkPreferencePath) { + $theme = "Dark" + } + else { + $theme = "Auto" + } + } + + switch ($theme) { + "Auto" { + $systemUsesDarkMode = Get-WinUtilToggleStatus WPFToggleDarkMode + if ($systemUsesDarkMode){ + Set-WinutilTheme -currentTheme "Dark" + } + else{ + Set-WinutilTheme -currentTheme "Light" + } + + + $themeButtonIcon = [char]0xF08C + Remove-Item $LightPreferencePath -Force -ErrorAction SilentlyContinue + Remove-Item $DarkPreferencePath -Force -ErrorAction SilentlyContinue + } + "Dark" { + Set-WinutilTheme -currentTheme $theme + $themeButtonIcon = [char]0xE708 + $null = New-Item $DarkPreferencePath -Force + Remove-Item $LightPreferencePath -Force -ErrorAction SilentlyContinue + } + "Light" { + Set-WinutilTheme -currentTheme $theme + $themeButtonIcon = [char]0xE706 + $null = New-Item $LightPreferencePath -Force + Remove-Item $DarkPreferencePath -Force -ErrorAction SilentlyContinue + } + } + + # Update the theme selector button with the appropriate icon + $ThemeButton = $sync.Form.FindName("ThemeButton") + $ThemeButton.Content = [string]$themeButtonIcon +} diff --git a/functions/private/Set-WinUtilUITheme.ps1 b/functions/private/Set-WinUtilUITheme.ps1 deleted file mode 100644 index c71ae88c88..0000000000 --- a/functions/private/Set-WinUtilUITheme.ps1 +++ /dev/null @@ -1,83 +0,0 @@ -function Set-WinUtilUITheme { - <# - .SYNOPSIS - Sets the theme of the XAML file - - .PARAMETER inputXML - A string representing the XAML object to modify - - .PARAMETER customThemeName - The name of the custom theme to set the XAML to. Defaults to 'matrix' - - .PARAMETER defaultThemeName - The name of the default theme to use when setting the XAML. Defaults to '_default' - - .EXAMPLE - $returnVal = Set-WinUtilUITheme -inputXAML $inputXAML - if ($returnVal[0] -eq "") { - Write-Host "Failed to process inputXML" - } else { - $inputXML = $returnVal[0] - } - # to know which theme this function has used, access the second item in returned value. - Write-Host "Theme used in processing: $($returnVal[1])" - #> - - param ( - [Parameter(Mandatory, position=0)] - [string]$inputXML, - - [Parameter(position=1)] - [string]$customThemeName = 'matrix', - - [Parameter(position=2)] - [string]$defaultThemeName = '_default' - ) - - try { - # Note: - # Reason behind not caching the '$sync.configs.themes` object into a variable, - # because this code can modify the themes object.. meaning it's better to access it - # using the more verbose way, rather than introduce possible bugs into the code, just for the sake of readability. - # - if (-NOT $sync.configs.themes) { - throw [GenericException]::new("[Set-WinUtilTheme] Did not find 'config.themes' inside `$sync variable.") - } - - if (-NOT $sync.configs.themes.$defaultThemeName) { - throw [GenericException]::new("[Set-WinUtilTheme] Did not find '$defaultThemeName' theme in the themes config file.") - } - - $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.$themeToUse.$optionName) { - $sync.configs.themes.$themeToUse | Add-Member -MemberType NoteProperty -Name $optionName -Value $optionValue - } - } - } else { - Write-Debug "[Set-WinUtilTheme] Theme '$customThemeName' was not found, using '$defaultThemeName' instead." - $themeToUse = $defaultThemeName - } - - foreach ($property in $sync.configs.themes.$themeToUse.PSObject.Properties) { - $key = $property.Name - $value = $property.Value - # Add curly braces around the key - $formattedKey = "{$key}" - # Replace the key with the value in the input XML - $inputXML = $inputXML.Replace($formattedKey, $value) - } - } - catch { - Write-Host "[Set-WinUtilTheme] Unable to apply theme" -ForegroundColor Red - Write-Host "$($psitem.Exception.Message)" -ForegroundColor Red - $inputXML = "" # Make inputXML equal an empty string, indicating something went wrong to the function caller. - } - - return @($inputXML, $themeToUse); -} diff --git a/functions/private/Show-CustomDialog.ps1 b/functions/private/Show-CustomDialog.ps1 index d2bbe08998..654cb41ec5 100644 --- a/functions/private/Show-CustomDialog.ps1 +++ b/functions/private/Show-CustomDialog.ps1 @@ -33,25 +33,25 @@ function Show-CustomDialog { #> param( [string]$Message, - [int]$Width = 300, - [int]$Height = 200, - [int]$FontSize = 10, - [int]$HeaderFontSize = 14, - [int]$IconSize = 25, + [int]$Width = $sync.Form.Resources.CustomDialogWidth, + [int]$Height = $sync.Form.Resources.CustomDialogHeight, + [int]$FontSize = $sync.Form.Resources.CustomDialogFontSize, + [int]$HeaderFontSize = $sync.Form.Resources.CustomDialogFontSizeHeader, + [int]$IconSize = $sync.Form.Resources.CustomDialogLogoSize, [bool]$EnableScroll = $false ) Add-Type -AssemblyName PresentationFramework # Define theme colors - $foregroundColor = $sync.configs.themes.$ctttheme.MainForegroundColor - $backgroundColor = $sync.configs.themes.$ctttheme.MainBackgroundColor + $foregroundColor = $sync.Form.Resources.MainForegroundColor + $backgroundColor = $sync.Form.Resources.MainBackgroundColor $font = New-Object Windows.Media.FontFamily("Consolas") - $borderColor = $sync.configs.themes.$ctttheme.BorderColor # ButtonInstallBackgroundColor - $buttonBackgroundColor = $sync.configs.themes.$ctttheme.ButtonInstallBackgroundColor - $buttonForegroundColor = $sync.configs.themes.$ctttheme.ButtonInstallForegroundColor + $borderColor = $sync.Form.Resources.BorderColor # ButtonInstallBackgroundColor + $buttonBackgroundColor = $sync.Form.Resources.ButtonInstallBackgroundColor + $buttonForegroundColor = $sync.Form.Resources.ButtonInstallForegroundColor $shadowColor = [Windows.Media.ColorConverter]::ConvertFromString("#AAAAAAAA") - $logocolor = $sync.configs.themes.$ctttheme.LabelboxForegroundColor + $logocolor = $sync.Form.Resources.LabelboxForegroundColor # Create a custom dialog window $dialog = New-Object Windows.Window @@ -162,7 +162,7 @@ function Show-CustomDialog { $hyperlink.NavigateUri = New-Object System.Uri($match.Groups[1].Value) $hyperlink.Inlines.Add($match.Groups[2].Value) $hyperlink.TextDecorations = [Windows.TextDecorations]::None # Remove underline - $hyperlink.Foreground = $sync.configs.themes.$ctttheme.LinkForegroundColor + $hyperlink.Foreground = $sync.Form.Resources.LinkForegroundColor $hyperlink.Add_Click({ param($sender, $args) @@ -170,11 +170,11 @@ function Show-CustomDialog { }) $hyperlink.Add_MouseEnter({ param($sender, $args) - $sender.Foreground = $sync.configs.themes.$ctttheme.LinkHoverForegroundColor + $sender.Foreground = $sync.Form.Resources.LinkHoverForegroundColor }) $hyperlink.Add_MouseLeave({ param($sender, $args) - $sender.Foreground = $sync.configs.themes.$ctttheme.LinkForegroundColor + $sender.Foreground = $sync.Form.Resources.LinkForegroundColor }) $messageTextBlock.Inlines.Add($hyperlink) diff --git a/functions/public/Invoke-WPFButton.ps1 b/functions/public/Invoke-WPFButton.ps1 index 9f768fd8b6..2773ccb571 100644 --- a/functions/public/Invoke-WPFButton.ps1 +++ b/functions/public/Invoke-WPFButton.ps1 @@ -19,7 +19,6 @@ function Invoke-WPFButton { } Switch -Wildcard ($Button) { - "WPFTab?BT" {Invoke-WPFTab $Button} "WPFInstall" {Invoke-WPFInstall} "WPFUninstall" {Invoke-WPFUnInstall} diff --git a/functions/public/Invoke-WPFUIElements.ps1 b/functions/public/Invoke-WPFUIElements.ps1 index a1ed85684c..f4c2d73be3 100644 --- a/functions/public/Invoke-WPFUIElements.ps1 +++ b/functions/public/Invoke-WPFUIElements.ps1 @@ -27,7 +27,7 @@ function Invoke-WPFUIElements { $window = $sync["Form"] - $theme = $sync.configs.themes.$ctttheme + $theme = $sync.Form.Resources $borderstyle = $window.FindResource("BorderStyle") $HoverTextBlockStyle = $window.FindResource("HoverTextBlockStyle") $ColorfulToggleSwitchStyle = $window.FindResource("ColorfulToggleSwitchStyle") @@ -186,7 +186,7 @@ function Invoke-WPFUIElements { $label.ToolTip = $entryInfo.Description $label.HorizontalAlignment = "Left" $label.FontSize = $theme.FontSize - $label.Foreground = $theme.MainForegroundColor + $label.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor") $dockPanel.Children.Add($label) | Out-Null $stackPanel.Children.Add($dockPanel) | Out-Null @@ -207,14 +207,14 @@ function Invoke-WPFUIElements { $toggleButton.HorizontalAlignment = "Left" $toggleButton.Height = $theme.TabButtonHeight $toggleButton.Width = $theme.TabButtonWidth - $toggleButton.Background = $theme.ButtonInstallBackgroundColor - $toggleButton.Foreground = [Windows.Media.Brushes]::White + $toggleButton.SetResourceReference([Windows.Controls.Control]::BackgroundProperty, "ButtonInstallBackgroundColor") + $toggleButton.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "MainForegroundColor") $toggleButton.FontWeight = [Windows.FontWeights]::Bold $textBlock = New-Object Windows.Controls.TextBlock $textBlock.FontSize = $theme.TabButtonFontSize $textBlock.Background = [Windows.Media.Brushes]::Transparent - $textBlock.Foreground = $theme.ButtonInstallForegroundColor + $textBlock.SetResourceReference([Windows.Controls.Control]::ForegroundProperty, "ButtonInstallForegroundColor") $underline = New-Object Windows.Documents.Underline $underline.Inlines.Add($entryInfo.name -replace "(.).*", "`$1") diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 0a0c566b07..ed81cd6913 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -52,29 +52,6 @@ $sync.runspace.Open() $inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^@KonTy GitHub : ChrisTitusTech/winutil Version : $($sync.version) "@ - $FontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSize - $HeaderFontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSizeHeader - $LogoSize = $sync.configs.themes.$ctttheme.CustomDialogLogoSize - $Width = $sync.configs.themes.$ctttheme.CustomDialogWidth - $Height = $sync.configs.themes.$ctttheme.CustomDialogHeight - Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -LogoSize $LogoSize + + Show-CustomDialog -Message $authorInfo -LogoSize $LogoSize }) $sync["SponsorMenuItem"].Add_Click({ @@ -548,12 +559,8 @@ $sync["SponsorMenuItem"].Add_Click({ $authorInfo += "An error occurred while fetching or processing the sponsors: $_`n" } - $FontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSize - $HeaderFontSize = $sync.configs.themes.$ctttheme.CustomDialogFontSizeHeader - $LogoSize = $sync.configs.themes.$ctttheme.CustomDialogLogoSize - $Width = $sync.configs.themes.$ctttheme.CustomDialogWidth - $Height = $sync.configs.themes.$ctttheme.CustomDialogHeight - Show-CustomDialog -Message $authorInfo -Width $Width -Height $Height -FontSize $FontSize -HeaderFontSize $HeaderFontSize -LogoSize $LogoSize -EnableScroll $true + Show-CustomDialog -Message $authorInfo -EnableScroll $true }) + $sync["Form"].ShowDialog() | out-null Stop-Transcript diff --git a/xaml/inputXML.xaml b/xaml/inputXML.xaml index cf4b2010d1..2ab4441398 100644 --- a/xaml/inputXML.xaml +++ b/xaml/inputXML.xaml @@ -5,7 +5,6 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WinUtility" mc:Ignorable="d" - Background="{MainBackgroundColor}" WindowStartupLocation="CenterScreen" UseLayoutRounding="True" WindowStyle="None" @@ -39,11 +38,11 @@ @@ -640,62 +611,63 @@ - + - + - - + + - + - + Install - + - + Tweaks - + - + Config - + - + Updates - + - + MicroWin - + - - + + + @@ -710,13 +682,13 @@ --> @@ -725,7 +697,7 @@ Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Segoe MDL2 Assets" - FontSize="{IconFontSize}" + FontSize="{DynamicResource DynamicResource IconFontSize}" Margin="180,0,0,0"> - + Foreground="{DynamicResource LabelboxForegroundColor}"> -