From b590437ca1f377d39874627ca7b6ab8fe0269a14 Mon Sep 17 00:00:00 2001 From: Davide Giacometti Date: Tue, 5 Jan 2021 15:54:32 +0100 Subject: [PATCH] Moved ThemeManager in common project (#8835) * moved theme manager in common project * added analyzers * renamed CommonUI project --- .pipelines/pipeline.user.windows.yml | 5 + PowerToys.sln | 7 + installer/PowerToysSetup/Product.wxs | 9 +- .../CustomLibraryThemeProvider.cs | 2 +- .../Microsoft.PowerToys.Common.UI.csproj | 45 ++++ .../ThemeManager.cs | 17 +- .../colorPicker/ColorPickerUI/App.xaml.cs | 3 +- .../ColorPickerUI/ColorPickerUI.csproj | 2 +- .../colorPicker/ColorPickerUI/ThemeManager.cs | 201 ------------------ src/modules/imageresizer/ui/App.xaml.cs | 1 + .../imageresizer/ui/ImageResizerUI.csproj | 2 +- .../Utilities/CustomLibraryThemeProvider.cs | 24 --- .../imageresizer/ui/Utilities/ThemeManager.cs | 201 ------------------ src/modules/launcher/PowerLauncher/App.xaml | 2 +- .../launcher/PowerLauncher/App.xaml.cs | 1 + .../PowerLauncher/PowerLauncher.csproj | 1 + .../PowerLauncher/PublicAPIInstance.cs | 2 +- .../launcher/PowerLauncher/SettingsWatcher.cs | 1 + .../Wox.Plugin/CustomLibraryThemeProvider.cs | 24 --- src/modules/launcher/Wox.Plugin/IPublicAPI.cs | 1 + .../launcher/Wox.Plugin/Wox.Plugin.csproj | 2 +- 21 files changed, 86 insertions(+), 467 deletions(-) rename src/{modules/colorPicker/ColorPickerUI/Helpers => common/Microsoft.PowerToys.Common.UI}/CustomLibraryThemeProvider.cs (94%) create mode 100644 src/common/Microsoft.PowerToys.Common.UI/Microsoft.PowerToys.Common.UI.csproj rename src/{modules/launcher/Wox.Plugin => common/Microsoft.PowerToys.Common.UI}/ThemeManager.cs (93%) delete mode 100644 src/modules/colorPicker/ColorPickerUI/ThemeManager.cs delete mode 100644 src/modules/imageresizer/ui/Utilities/CustomLibraryThemeProvider.cs delete mode 100644 src/modules/imageresizer/ui/Utilities/ThemeManager.cs delete mode 100644 src/modules/launcher/Wox.Plugin/CustomLibraryThemeProvider.cs diff --git a/.pipelines/pipeline.user.windows.yml b/.pipelines/pipeline.user.windows.yml index db3db46c0f..b16f511d15 100644 --- a/.pipelines/pipeline.user.windows.yml +++ b/.pipelines/pipeline.user.windows.yml @@ -72,6 +72,7 @@ build: - 'modules\ColorPicker\ColorPickerUI.dll' - 'modules\ColorPicker\ColorPickerUI.exe' - 'modules\ColorPicker\ManagedCommon.dll' + - 'modules\ColorPicker\Microsoft.PowerToys.Common.UI.dll' - 'modules\ColorPicker\Microsoft.PowerToys.Settings.UI.Lib.dll' - 'modules\ColorPicker\PowerToysInterop.dll' - 'modules\ColorPicker\Telemetry.dll' @@ -94,9 +95,13 @@ build: - 'modules\ImageResizer\ImageResizer.dll' - 'modules\ImageResizer\ImageResizerExt.dll' - 'modules\ImageResizer\PowerToysInterop.dll' + - 'modules\ImageResizer\ManagedCommon.dll' + - 'modules\ImageResizer\ManagedTelemetry.dll' + - 'modules\ImageResizer\Microsoft.PowerToys.Common.UI.dll' - 'modules\KeyboardManager\KeyboardManager.dll' - 'modules\launcher\Microsoft.PowerToys.Settings.UI.Lib.dll' - 'modules\launcher\ManagedCommon.dll' + - 'modules\launcher\Microsoft.PowerToys.Common.UI.dll' - 'modules\launcher\Microsoft.Launcher.dll' - 'modules\launcher\Plugins\Microsoft.Plugin.Calculator\Microsoft.Plugin.Calculator.dll' - 'modules\launcher\Plugins\Microsoft.Plugin.Calculator\Wox.Infrastructure.dll' diff --git a/PowerToys.sln b/PowerToys.sln index ff635c030a..6e0ab38f2b 100644 --- a/PowerToys.sln +++ b/PowerToys.sln @@ -300,6 +300,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Telemetry", "Telemetry", "{ src\common\Telemetry\TraceLoggingDefines.h = src\common\Telemetry\TraceLoggingDefines.h EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.PowerToys.Common.UI", "src\common\Microsoft.PowerToys.Common.UI\Microsoft.PowerToys.Common.UI.csproj", "{C3A17DCA-217B-462C-BB0C-BE086AF80081}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -606,6 +608,10 @@ Global {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Debug|x64.Build.0 = Debug|x64 {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Release|x64.ActiveCfg = Release|x64 {07C389E3-6BC8-41CF-923E-307B1265FA2D}.Release|x64.Build.0 = Release|x64 + {C3A17DCA-217B-462C-BB0C-BE086AF80081}.Debug|x64.ActiveCfg = Debug|x64 + {C3A17DCA-217B-462C-BB0C-BE086AF80081}.Debug|x64.Build.0 = Debug|x64 + {C3A17DCA-217B-462C-BB0C-BE086AF80081}.Release|x64.ActiveCfg = Release|x64 + {C3A17DCA-217B-462C-BB0C-BE086AF80081}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -696,6 +702,7 @@ Global {98537082-0FDB-40DE-ABD8-0DC5A4269BAB} = {1AFB6476-670D-4E80-A464-657E01DFF482} {B39DC643-4663-475E-B329-03F0C9918D48} = {1AFB6476-670D-4E80-A464-657E01DFF482} {8F62026A-294B-41C6-8839-87463613F216} = {1AFB6476-670D-4E80-A464-657E01DFF482} + {C3A17DCA-217B-462C-BB0C-BE086AF80081} = {1AFB6476-670D-4E80-A464-657E01DFF482} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {C3A2F9D1-7930-4EF4-A6FC-7EE0A99821D0} diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs index ed4f6254a6..c6664efe05 100644 --- a/installer/PowerToysSetup/Product.wxs +++ b/installer/PowerToysSetup/Product.wxs @@ -367,7 +367,7 @@ - + @@ -467,6 +467,9 @@ + + + @@ -575,7 +578,7 @@ - + @@ -875,7 +878,7 @@ - + diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/CustomLibraryThemeProvider.cs b/src/common/Microsoft.PowerToys.Common.UI/CustomLibraryThemeProvider.cs similarity index 94% rename from src/modules/colorPicker/ColorPickerUI/Helpers/CustomLibraryThemeProvider.cs rename to src/common/Microsoft.PowerToys.Common.UI/CustomLibraryThemeProvider.cs index 7929280fd0..b667c6d0bf 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/CustomLibraryThemeProvider.cs +++ b/src/common/Microsoft.PowerToys.Common.UI/CustomLibraryThemeProvider.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using ControlzEx.Theming; -namespace ColorPicker.Helpers +namespace Microsoft.PowerToys.Common.UI { public class CustomLibraryThemeProvider : LibraryThemeProvider { diff --git a/src/common/Microsoft.PowerToys.Common.UI/Microsoft.PowerToys.Common.UI.csproj b/src/common/Microsoft.PowerToys.Common.UI/Microsoft.PowerToys.Common.UI.csproj new file mode 100644 index 0000000000..4cc402447d --- /dev/null +++ b/src/common/Microsoft.PowerToys.Common.UI/Microsoft.PowerToys.Common.UI.csproj @@ -0,0 +1,45 @@ + + + + netcoreapp3.1 + true + x64 + x64 + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + 1.1.118 + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + StyleCop.json + + + + + + GlobalSuppressions.cs + + + + + + + + diff --git a/src/modules/launcher/Wox.Plugin/ThemeManager.cs b/src/common/Microsoft.PowerToys.Common.UI/ThemeManager.cs similarity index 93% rename from src/modules/launcher/Wox.Plugin/ThemeManager.cs rename to src/common/Microsoft.PowerToys.Common.UI/ThemeManager.cs index a8c19bba7c..ced98e92bc 100644 --- a/src/modules/launcher/Wox.Plugin/ThemeManager.cs +++ b/src/common/Microsoft.PowerToys.Common.UI/ThemeManager.cs @@ -8,7 +8,7 @@ using System.Windows; using ManagedCommon; using Microsoft.Win32; -namespace Wox.Plugin +namespace Microsoft.PowerToys.Common.UI { public class ThemeManager : IDisposable { @@ -61,13 +61,18 @@ namespace Wox.Plugin darkThemeUri, CustomLibraryThemeProvider.DefaultInstance)); + ResetTheme(); + ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ControlzEx.Theming.ThemeSyncMode.SyncWithAppMode; ControlzEx.Theming.ThemeManager.Current.ThemeChanged += Current_ThemeChanged; + SystemParameters.StaticPropertyChanged += SystemParameters_StaticPropertyChanged; + } - // Currently there is an issue in ControlzEx, so we must use SyncAll to sync also HighContrast themes. - // We can change this after using next release. - ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ControlzEx.Theming.ThemeSyncMode.SyncAll; - - ControlzEx.Theming.ThemeManager.Current.SyncTheme(); + private void SystemParameters_StaticPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + if (e.PropertyName == nameof(SystemParameters.HighContrast)) + { + ResetTheme(); + } } public Theme GetCurrentTheme() diff --git a/src/modules/colorPicker/ColorPickerUI/App.xaml.cs b/src/modules/colorPicker/ColorPickerUI/App.xaml.cs index a03476a8c9..98ba5fc9f7 100644 --- a/src/modules/colorPicker/ColorPickerUI/App.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/App.xaml.cs @@ -5,10 +5,9 @@ using System; using System.Threading; using System.Windows; -using ColorPicker; -using ColorPicker.Helpers; using ColorPicker.Mouse; using ManagedCommon; +using Microsoft.PowerToys.Common.UI; namespace ColorPickerUI { diff --git a/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj b/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj index 77a769846a..5868f3ff33 100644 --- a/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj +++ b/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj @@ -49,7 +49,6 @@ - runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -77,6 +76,7 @@ + diff --git a/src/modules/colorPicker/ColorPickerUI/ThemeManager.cs b/src/modules/colorPicker/ColorPickerUI/ThemeManager.cs deleted file mode 100644 index 6792684dec..0000000000 --- a/src/modules/colorPicker/ColorPickerUI/ThemeManager.cs +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. -using System; -using System.Linq; -using System.Windows; -using ColorPicker.Helpers; -using ControlzEx.Theming; -using Microsoft.Win32; - -namespace ColorPicker -{ - public class ThemeManager : IDisposable - { - private readonly Application _app; - private const string LightTheme = "Light.Accent1"; - private const string DarkTheme = "Dark.Accent1"; - private const string HighContrastOneTheme = "HighContrast.Accent2"; - private const string HighContrastTwoTheme = "HighContrast.Accent3"; - private const string HighContrastBlackTheme = "HighContrast.Accent4"; - private const string HighContrastWhiteTheme = "HighContrast.Accent5"; - - private Theme currentTheme; - private bool _disposed; - - public event ThemeChangedHandler ThemeChanged; - - public ThemeManager(Application app) - { - _app = app; - - Uri highContrastOneThemeUri = new Uri("pack://application:,,,/Themes/HighContrast1.xaml"); - Uri highContrastTwoThemeUri = new Uri("pack://application:,,,/Themes/HighContrast2.xaml"); - Uri highContrastBlackThemeUri = new Uri("pack://application:,,,/Themes/HighContrastWhite.xaml"); - Uri highContrastWhiteThemeUri = new Uri("pack://application:,,,/Themes/HighContrastBlack.xaml"); - Uri lightThemeUri = new Uri("pack://application:,,,/Themes/Light.xaml"); - Uri darkThemeUri = new Uri("pack://application:,,,/Themes/Dark.xaml"); - - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - highContrastOneThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - highContrastTwoThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - highContrastBlackThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - highContrastWhiteThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - lightThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - darkThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - - ResetTheme(); - ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode; - ControlzEx.Theming.ThemeManager.Current.ThemeChanged += Current_ThemeChanged; - SystemParameters.StaticPropertyChanged += SystemParameters_StaticPropertyChanged; - } - - private void SystemParameters_StaticPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) - { - if (e.PropertyName == nameof(SystemParameters.HighContrast)) - { - ResetTheme(); - } - } - - public Theme GetCurrentTheme() - { - return currentTheme; - } - - private static Theme GetHighContrastBaseType() - { - string registryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes"; - string theme = (string)Registry.GetValue(registryKey, "CurrentTheme", string.Empty); - theme = theme.Split('\\').Last().Split('.').First().ToString(); - - switch (theme) - { - case "hc1": - return Theme.HighContrastOne; - case "hc2": - return Theme.HighContrastTwo; - case "hcwhite": - return Theme.HighContrastWhite; - case "hcblack": - return Theme.HighContrastBlack; - default: - return Theme.None; - } - } - - private void ResetTheme() - { - if (SystemParameters.HighContrast) - { - Theme highContrastBaseType = GetHighContrastBaseType(); - ChangeTheme(highContrastBaseType); - } - else - { - string baseColor = WindowsThemeHelper.GetWindowsBaseColor(); - ChangeTheme((Theme)Enum.Parse(typeof(Theme), baseColor)); - } - } - - private void ChangeTheme(Theme theme) - { - Theme oldTheme = currentTheme; - if (theme == currentTheme) - { - return; - } - - if (theme == Theme.HighContrastOne) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastOneTheme); - currentTheme = Theme.HighContrastOne; - } - else if (theme == Theme.HighContrastTwo) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastTwoTheme); - currentTheme = Theme.HighContrastTwo; - } - else if (theme == Theme.HighContrastWhite) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastWhiteTheme); - currentTheme = Theme.HighContrastWhite; - } - else if (theme == Theme.HighContrastBlack) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastBlackTheme); - currentTheme = Theme.HighContrastBlack; - } - else if (theme == Theme.Light) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, LightTheme); - currentTheme = Theme.Light; - } - else if (theme == Theme.Dark) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, DarkTheme); - currentTheme = Theme.Dark; - } - else - { - currentTheme = Theme.None; - } - - ThemeChanged?.Invoke(oldTheme, currentTheme); - } - - private void Current_ThemeChanged(object sender, ThemeChangedEventArgs e) - { - ResetTheme(); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposed) - { - if (disposing) - { - ControlzEx.Theming.ThemeManager.Current.ThemeChanged -= Current_ThemeChanged; - SystemParameters.StaticPropertyChanged -= SystemParameters_StaticPropertyChanged; - _disposed = true; - } - } - } - - public void Dispose() - { - Dispose(disposing: true); - GC.SuppressFinalize(this); - } - } - - public delegate void ThemeChangedHandler(Theme oldTheme, Theme newTheme); - - public enum Theme - { - None, - Light, - Dark, - HighContrastOne, - HighContrastTwo, - HighContrastBlack, - HighContrastWhite, - } -} diff --git a/src/modules/imageresizer/ui/App.xaml.cs b/src/modules/imageresizer/ui/App.xaml.cs index ccd0993557..5d1148150f 100644 --- a/src/modules/imageresizer/ui/App.xaml.cs +++ b/src/modules/imageresizer/ui/App.xaml.cs @@ -10,6 +10,7 @@ using ImageResizer.Properties; using ImageResizer.Utilities; using ImageResizer.ViewModels; using ImageResizer.Views; +using Microsoft.PowerToys.Common.UI; namespace ImageResizer { diff --git a/src/modules/imageresizer/ui/ImageResizerUI.csproj b/src/modules/imageresizer/ui/ImageResizerUI.csproj index a6f631cfcc..a6c0f7a8db 100644 --- a/src/modules/imageresizer/ui/ImageResizerUI.csproj +++ b/src/modules/imageresizer/ui/ImageResizerUI.csproj @@ -61,7 +61,6 @@ - all @@ -77,6 +76,7 @@ + diff --git a/src/modules/imageresizer/ui/Utilities/CustomLibraryThemeProvider.cs b/src/modules/imageresizer/ui/Utilities/CustomLibraryThemeProvider.cs deleted file mode 100644 index ab2fc3a7f5..0000000000 --- a/src/modules/imageresizer/ui/Utilities/CustomLibraryThemeProvider.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Collections.Generic; -using ControlzEx.Theming; - -namespace ImageResizer.Utilities -{ - public class CustomLibraryThemeProvider : LibraryThemeProvider - { - public static readonly CustomLibraryThemeProvider DefaultInstance = new CustomLibraryThemeProvider(); - - public CustomLibraryThemeProvider() - : base(true) - { - } - - /// - public override void FillColorSchemeValues(Dictionary values, RuntimeThemeColorValues colorValues) - { - } - } -} diff --git a/src/modules/imageresizer/ui/Utilities/ThemeManager.cs b/src/modules/imageresizer/ui/Utilities/ThemeManager.cs deleted file mode 100644 index 03efb9688a..0000000000 --- a/src/modules/imageresizer/ui/Utilities/ThemeManager.cs +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Linq; -using System.Windows; -using ControlzEx.Theming; -using Microsoft.Win32; - -namespace ImageResizer.Utilities -{ - public class ThemeManager : IDisposable - { - private readonly Application _app; - private const string LightTheme = "Light.Accent1"; - private const string DarkTheme = "Dark.Accent1"; - private const string HighContrastOneTheme = "HighContrast.Accent2"; - private const string HighContrastTwoTheme = "HighContrast.Accent3"; - private const string HighContrastBlackTheme = "HighContrast.Accent4"; - private const string HighContrastWhiteTheme = "HighContrast.Accent5"; - - private Theme currentTheme; - private bool _disposed; - - public event ThemeChangedHandler ThemeChanged; - - public ThemeManager(Application app) - { - _app = app; - - Uri highContrastOneThemeUri = new Uri("pack://application:,,,/Themes/HighContrast1.xaml"); - Uri highContrastTwoThemeUri = new Uri("pack://application:,,,/Themes/HighContrast2.xaml"); - Uri highContrastBlackThemeUri = new Uri("pack://application:,,,/Themes/HighContrastWhite.xaml"); - Uri highContrastWhiteThemeUri = new Uri("pack://application:,,,/Themes/HighContrastBlack.xaml"); - Uri lightThemeUri = new Uri("pack://application:,,,/Themes/Light.xaml"); - Uri darkThemeUri = new Uri("pack://application:,,,/Themes/Dark.xaml"); - - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - highContrastOneThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - highContrastTwoThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - highContrastBlackThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - highContrastWhiteThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - lightThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme( - new LibraryTheme( - darkThemeUri, - CustomLibraryThemeProvider.DefaultInstance)); - - ResetTheme(); - ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncWithAppMode; - ControlzEx.Theming.ThemeManager.Current.ThemeChanged += Current_ThemeChanged; - SystemParameters.StaticPropertyChanged += SystemParameters_StaticPropertyChanged; - } - - private void SystemParameters_StaticPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) - { - if (e.PropertyName == nameof(SystemParameters.HighContrast)) - { - ResetTheme(); - } - } - - public Theme GetCurrentTheme() - { - return currentTheme; - } - - private static Theme GetHighContrastBaseType() - { - string registryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes"; - string theme = (string)Registry.GetValue(registryKey, "CurrentTheme", string.Empty); - theme = theme.Split('\\').Last().Split('.').First().ToString(); - - switch (theme) - { - case "hc1": - return Theme.HighContrastOne; - case "hc2": - return Theme.HighContrastTwo; - case "hcwhite": - return Theme.HighContrastWhite; - case "hcblack": - return Theme.HighContrastBlack; - default: - return Theme.None; - } - } - - private void ResetTheme() - { - if (SystemParameters.HighContrast) - { - Theme highContrastBaseType = GetHighContrastBaseType(); - ChangeTheme(highContrastBaseType); - } - else - { - string baseColor = WindowsThemeHelper.GetWindowsBaseColor(); - ChangeTheme((Theme)Enum.Parse(typeof(Theme), baseColor)); - } - } - - private void ChangeTheme(Theme theme) - { - Theme oldTheme = currentTheme; - if (theme == currentTheme) - { - return; - } - - if (theme == Theme.HighContrastOne) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastOneTheme); - currentTheme = Theme.HighContrastOne; - } - else if (theme == Theme.HighContrastTwo) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastTwoTheme); - currentTheme = Theme.HighContrastTwo; - } - else if (theme == Theme.HighContrastWhite) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastWhiteTheme); - currentTheme = Theme.HighContrastWhite; - } - else if (theme == Theme.HighContrastBlack) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastBlackTheme); - currentTheme = Theme.HighContrastBlack; - } - else if (theme == Theme.Light) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, LightTheme); - currentTheme = Theme.Light; - } - else if (theme == Theme.Dark) - { - ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, DarkTheme); - currentTheme = Theme.Dark; - } - else - { - currentTheme = Theme.None; - } - - ThemeChanged?.Invoke(oldTheme, currentTheme); - } - - private void Current_ThemeChanged(object sender, ThemeChangedEventArgs e) - { - ResetTheme(); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposed) - { - if (disposing) - { - ControlzEx.Theming.ThemeManager.Current.ThemeChanged -= Current_ThemeChanged; - SystemParameters.StaticPropertyChanged -= SystemParameters_StaticPropertyChanged; - _disposed = true; - } - } - } - - public void Dispose() - { - Dispose(disposing: true); - GC.SuppressFinalize(this); - } - } - - public delegate void ThemeChangedHandler(Theme oldTheme, Theme newTheme); - - public enum Theme - { - None, - Light, - Dark, - HighContrastOne, - HighContrastTwo, - HighContrastBlack, - HighContrastWhite, - } -} diff --git a/src/modules/launcher/PowerLauncher/App.xaml b/src/modules/launcher/PowerLauncher/App.xaml index 2e322001f8..22cbfd0b10 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml +++ b/src/modules/launcher/PowerLauncher/App.xaml @@ -1,7 +1,7 @@  diff --git a/src/modules/launcher/PowerLauncher/App.xaml.cs b/src/modules/launcher/PowerLauncher/App.xaml.cs index 59025bf5dc..7791870156 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml.cs +++ b/src/modules/launcher/PowerLauncher/App.xaml.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Windows; using ManagedCommon; using Microsoft.PowerLauncher.Telemetry; +using Microsoft.PowerToys.Common.UI; using Microsoft.PowerToys.Telemetry; using PowerLauncher.Helper; using PowerLauncher.Plugin; diff --git a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj index 173ffb8b88..5f7baa5ac5 100644 --- a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj +++ b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj @@ -121,6 +121,7 @@ + diff --git a/src/modules/launcher/PowerLauncher/PublicAPIInstance.cs b/src/modules/launcher/PowerLauncher/PublicAPIInstance.cs index 0081167894..4184da631e 100644 --- a/src/modules/launcher/PowerLauncher/PublicAPIInstance.cs +++ b/src/modules/launcher/PowerLauncher/PublicAPIInstance.cs @@ -8,10 +8,10 @@ using System.Linq; using System.Net; using System.Windows; using ManagedCommon; +using Microsoft.PowerToys.Common.UI; using PowerLauncher.Helper; using PowerLauncher.Plugin; using PowerLauncher.ViewModel; -using Wox.Infrastructure; using Wox.Infrastructure.Image; using Wox.Plugin; diff --git a/src/modules/launcher/PowerLauncher/SettingsWatcher.cs b/src/modules/launcher/PowerLauncher/SettingsWatcher.cs index 6358b8003d..ed9116d2e1 100644 --- a/src/modules/launcher/PowerLauncher/SettingsWatcher.cs +++ b/src/modules/launcher/PowerLauncher/SettingsWatcher.cs @@ -8,6 +8,7 @@ using System.IO.Abstractions; using System.Threading; using System.Windows.Input; using ManagedCommon; +using Microsoft.PowerToys.Common.UI; using Microsoft.PowerToys.Settings.UI.Library; using PowerLauncher.Helper; using PowerLauncher.Plugin; diff --git a/src/modules/launcher/Wox.Plugin/CustomLibraryThemeProvider.cs b/src/modules/launcher/Wox.Plugin/CustomLibraryThemeProvider.cs deleted file mode 100644 index 640890c9cc..0000000000 --- a/src/modules/launcher/Wox.Plugin/CustomLibraryThemeProvider.cs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation -// The Microsoft Corporation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Collections.Generic; -using ControlzEx.Theming; - -namespace Wox.Plugin -{ - public class CustomLibraryThemeProvider : LibraryThemeProvider - { - public static readonly CustomLibraryThemeProvider DefaultInstance = new CustomLibraryThemeProvider(); - - public CustomLibraryThemeProvider() - : base(true) - { - } - - /// - public override void FillColorSchemeValues(Dictionary values, RuntimeThemeColorValues colorValues) - { - } - } -} diff --git a/src/modules/launcher/Wox.Plugin/IPublicAPI.cs b/src/modules/launcher/Wox.Plugin/IPublicAPI.cs index 6237af9a06..2f8d90efef 100644 --- a/src/modules/launcher/Wox.Plugin/IPublicAPI.cs +++ b/src/modules/launcher/Wox.Plugin/IPublicAPI.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using ManagedCommon; +using Microsoft.PowerToys.Common.UI; namespace Wox.Plugin { diff --git a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj index d9ad836ea8..acbc0b2442 100644 --- a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj +++ b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj @@ -76,7 +76,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -92,6 +91,7 @@ +