From e66ec18c47c58de94fdaef65fa6201b6b88b2f04 Mon Sep 17 00:00:00 2001 From: Divyansh Srivastava Date: Tue, 2 Jun 2020 11:36:54 -0700 Subject: [PATCH 1/7] Removed Wox Theme Manager --- src/modules/launcher/PowerLauncher/App.xaml | 1 - .../launcher/PowerLauncher/App.xaml.cs | 2 - .../PowerLauncher/PowerLauncher.csproj | 8 +- .../launcher/PowerLauncher/Themes/Base.xaml | 141 ---------- .../PowerLauncher/Themes/BlackAndWhite.xaml | 1 - .../PowerLauncher/Themes/BlurBlack.xaml | 58 ---- .../PowerLauncher/Themes/BlurWhite.xaml | 58 ---- .../launcher/PowerLauncher/Themes/Dark.xaml | 40 --- .../launcher/PowerLauncher/Themes/Gray.xaml | 49 ---- .../launcher/PowerLauncher/Themes/Light.xaml | 50 ---- .../PowerLauncher/Themes/Metro Server.xaml | 33 --- .../launcher/PowerLauncher/Themes/Pink.xaml | 30 -- .../Themes/ThemeBuilder/Template.xaml | 52 ---- .../Themes/ThemeBuilder/ThemeConvertor.py | 26 -- .../launcher/Wox.Core/Resource/Theme.cs | 266 +----------------- .../Wox.Core/Resource/ThemeManager.cs | 26 -- src/modules/launcher/Wox.Core/Wox.Core.csproj | 1 + src/modules/launcher/Wox/App.xaml | 14 - src/modules/launcher/Wox/App.xaml.cs | 131 --------- src/modules/launcher/Wox/MainWindow.xaml.cs | 1 - .../Wox/ViewModel/SettingWindowViewModel.cs | 8 - src/modules/launcher/Wox/Wox.csproj | 8 - 22 files changed, 18 insertions(+), 986 deletions(-) delete mode 100644 src/modules/launcher/PowerLauncher/Themes/Base.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/BlackAndWhite.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/BlurBlack.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/BlurWhite.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/Dark.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/Gray.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/Light.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/Metro Server.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/Pink.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/ThemeBuilder/Template.xaml delete mode 100644 src/modules/launcher/PowerLauncher/Themes/ThemeBuilder/ThemeConvertor.py delete mode 100644 src/modules/launcher/Wox.Core/Resource/ThemeManager.cs delete mode 100644 src/modules/launcher/Wox/App.xaml delete mode 100644 src/modules/launcher/Wox/App.xaml.cs diff --git a/src/modules/launcher/PowerLauncher/App.xaml b/src/modules/launcher/PowerLauncher/App.xaml index ec92b631a489..11740e71365c 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml +++ b/src/modules/launcher/PowerLauncher/App.xaml @@ -6,7 +6,6 @@ - diff --git a/src/modules/launcher/PowerLauncher/App.xaml.cs b/src/modules/launcher/PowerLauncher/App.xaml.cs index 17974072e776..9d12ea19c667 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml.cs +++ b/src/modules/launcher/PowerLauncher/App.xaml.cs @@ -83,8 +83,6 @@ private void OnStartup(object sender, StartupEventArgs e) InternationalizationManager.Instance.ChangeLanguage(_settings.Language); // main windows needs initialized before theme change because of blur settings - ThemeManager.Instance.Settings = _settings; - ThemeManager.Instance.ChangeTheme(_settings.Theme); Http.Proxy = _settings.Proxy; diff --git a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj index 12586fccb0c1..1256ed74b9b3 100644 --- a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj +++ b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj @@ -48,10 +48,6 @@ - - - - @@ -189,4 +185,8 @@ + + + + \ No newline at end of file diff --git a/src/modules/launcher/PowerLauncher/Themes/Base.xaml b/src/modules/launcher/PowerLauncher/Themes/Base.xaml deleted file mode 100644 index 2955c7e624e8..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/Base.xaml +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/modules/launcher/PowerLauncher/Themes/BlackAndWhite.xaml b/src/modules/launcher/PowerLauncher/Themes/BlackAndWhite.xaml deleted file mode 100644 index 8c3f0cbd45e9..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/BlackAndWhite.xaml +++ /dev/null @@ -1 +0,0 @@ - #4F6180 \ No newline at end of file diff --git a/src/modules/launcher/PowerLauncher/Themes/BlurBlack.xaml b/src/modules/launcher/PowerLauncher/Themes/BlurBlack.xaml deleted file mode 100644 index 488048cf44dd..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/BlurBlack.xaml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - True - - - - - - - - - - - - - - - #356ef3 - - - - - - diff --git a/src/modules/launcher/PowerLauncher/Themes/BlurWhite.xaml b/src/modules/launcher/PowerLauncher/Themes/BlurWhite.xaml deleted file mode 100644 index 2fe9e3185f13..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/BlurWhite.xaml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - True - - - - - - - - - - - - - - - #356ef3 - - - - - - diff --git a/src/modules/launcher/PowerLauncher/Themes/Dark.xaml b/src/modules/launcher/PowerLauncher/Themes/Dark.xaml deleted file mode 100644 index 5bd54b0edaa6..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/Dark.xaml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - #4F6180 - - - - - - diff --git a/src/modules/launcher/PowerLauncher/Themes/Gray.xaml b/src/modules/launcher/PowerLauncher/Themes/Gray.xaml deleted file mode 100644 index e52d4201beb5..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/Gray.xaml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - #00AAF6 - - - - diff --git a/src/modules/launcher/PowerLauncher/Themes/Light.xaml b/src/modules/launcher/PowerLauncher/Themes/Light.xaml deleted file mode 100644 index 6c373ef6024c..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/Light.xaml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - #3875D7 - - - - - - \ No newline at end of file diff --git a/src/modules/launcher/PowerLauncher/Themes/Metro Server.xaml b/src/modules/launcher/PowerLauncher/Themes/Metro Server.xaml deleted file mode 100644 index 9648203946b2..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/Metro Server.xaml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - #006ac1 - - - \ No newline at end of file diff --git a/src/modules/launcher/PowerLauncher/Themes/Pink.xaml b/src/modules/launcher/PowerLauncher/Themes/Pink.xaml deleted file mode 100644 index 93f2dee6e3a5..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/Pink.xaml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - #cc1081 - - - \ No newline at end of file diff --git a/src/modules/launcher/PowerLauncher/Themes/ThemeBuilder/Template.xaml b/src/modules/launcher/PowerLauncher/Themes/ThemeBuilder/Template.xaml deleted file mode 100644 index 8d1c4845a4e9..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/ThemeBuilder/Template.xaml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - {%selectedResultBackgroundColor%} - - - - - - diff --git a/src/modules/launcher/PowerLauncher/Themes/ThemeBuilder/ThemeConvertor.py b/src/modules/launcher/PowerLauncher/Themes/ThemeBuilder/ThemeConvertor.py deleted file mode 100644 index 674728ec3d80..000000000000 --- a/src/modules/launcher/PowerLauncher/Themes/ThemeBuilder/ThemeConvertor.py +++ /dev/null @@ -1,26 +0,0 @@ -import os,plistlib - -def convert(path,templatePath): - pl = plistlib.readPlist(path) - with open(templatePath, 'r') as content_file: - template = content_file.read() - for key in pl: - if "rgba" in pl[key]: - template = template.replace("{%"+key+"%}",tohex(pl[key].replace("rgba","rgb"))) - f = open(path.replace(".alfredtheme",".xaml"),'w') - f.write(template) - f.close() - - -def tohex(string): - string = string[4:] - split = string.split(",") - split[2] = ''.join(split[2].split(")")[0]) - r = int(split[0]) - g = int(split[1]) - b = int(split[2]) - tu = (r, g, b) - return '#%02x%02x%02x' % tu - -#print tohex("rgb(255,255,255,0.50)") -print convert("Night.alfredtheme","Light.xaml") diff --git a/src/modules/launcher/Wox.Core/Resource/Theme.cs b/src/modules/launcher/Wox.Core/Resource/Theme.cs index 05d176089222..bbc03409908c 100644 --- a/src/modules/launcher/Wox.Core/Resource/Theme.cs +++ b/src/modules/launcher/Wox.Core/Resource/Theme.cs @@ -1,263 +1,23 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Interop; -using System.Windows.Markup; -using System.Windows.Media; -using Wox.Infrastructure; -using Wox.Infrastructure.Logger; -using Wox.Infrastructure.UserSettings; +using ControlzEx.Theming; +using MahApps.Metro.Theming; +using System; namespace Wox.Core.Resource { public class Theme { - private readonly List _themeDirectories = new List(); - private ResourceDictionary _oldResource; - private string _oldTheme; - public Settings Settings { get; set; } - private const string Folder = "Themes"; - private const string Extension = ".xaml"; - private string DirectoryPath => Path.Combine(Constant.ProgramDirectory, Folder); - private string UserDirectoryPath => Path.Combine(Constant.DataDirectory, Folder); + readonly Uri LightTheme = new Uri("pack://application:,,,/Light.xaml"); + readonly Uri DarkTheme = new Uri("pack://application:,,,/Dark.xaml"); + readonly Uri HighContrastTheme = new Uri("pack://application:,,,/HighContrast.xaml"); - public Theme() + Theme() { - _themeDirectories.Add(DirectoryPath); - _themeDirectories.Add(UserDirectoryPath); - MakeSureThemeDirectoriesExist(); - - var dicts = Application.Current.Resources.MergedDictionaries; - _oldResource = dicts.First(d => - { - var p = d.Source.AbsolutePath; - var dir = Path.GetDirectoryName(p).NonNull(); - var info = new DirectoryInfo(dir); - var f = info.Name; - var e = Path.GetExtension(p); - var found = f == Folder && e == Extension; - return found; - }); - _oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath); - } - - private void MakeSureThemeDirectoriesExist() - { - foreach (string dir in _themeDirectories) - { - if (!Directory.Exists(dir)) - { - try - { - Directory.CreateDirectory(dir); - } - catch (Exception e) - { - Log.Exception($"|Theme.MakeSureThemeDirectoriesExist|Exception when create directory <{dir}>", e); - } - } - } - } - - public bool ChangeTheme(string theme) - { - const string defaultTheme = "Dark"; - - string path = GetThemePath(theme); - try - { - if (string.IsNullOrEmpty(path)) - throw new DirectoryNotFoundException("Theme path can't be found <{path}>"); - - Settings.Theme = theme; - - var dicts = Application.Current.Resources.MergedDictionaries; - //always allow re-loading default theme, in case of failure of switching to a new theme from default theme - if (_oldTheme != theme || theme == defaultTheme) - { - dicts.Remove(_oldResource); - var newResource = GetResourceDictionary(); - dicts.Add(newResource); - _oldResource = newResource; - _oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath); - } - } - catch (DirectoryNotFoundException e) - { - Log.Error($"|Theme.ChangeTheme|Theme <{theme}> path can't be found"); - if (theme != defaultTheme) - { - MessageBox.Show(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_path_not_exists"), theme)); - ChangeTheme(defaultTheme); - } - return false; - } - catch (XamlParseException e) - { - Log.Error($"|Theme.ChangeTheme|Theme <{theme}> fail to parse"); - if (theme != defaultTheme) - { - MessageBox.Show(string.Format(InternationalizationManager.Instance.GetTranslation("theme_load_failure_parse_error"), theme)); - ChangeTheme(defaultTheme); - } - return false; - } - return true; - } - - public ResourceDictionary GetResourceDictionary() - { - var uri = GetThemePath(Settings.Theme); - var dict = new ResourceDictionary - { - Source = new Uri(uri, UriKind.Absolute) - }; - - Style queryBoxStyle = dict["QueryBoxStyle"] as Style; - if (queryBoxStyle != null) - { - queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(Settings.QueryBoxFont))); - queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle))); - queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight))); - queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch))); - } - - Style resultItemStyle = dict["ItemTitleStyle"] as Style; - Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style; - Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style; - Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style; - if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) - { - Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(Settings.ResultFont)); - Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.ResultFontStyle)); - Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.ResultFontWeight)); - Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.ResultFontStretch)); - - Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch }; - Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p))); - } - return dict; - } - - public List LoadAvailableThemes() - { - List themes = new List(); - foreach (var themeDirectory in _themeDirectories) - { - themes.AddRange( - Directory.GetFiles(themeDirectory) - .Where(filePath => filePath.EndsWith(Extension) && !filePath.EndsWith("Base.xaml")) - .ToList()); - } - return themes.OrderBy(o => o).ToList(); - } - - private string GetThemePath(string themeName) - { - foreach (string themeDirectory in _themeDirectories) - { - string path = Path.Combine(themeDirectory, themeName + Extension); - if (File.Exists(path)) - { - return path; - } - } - - return string.Empty; - } - - #region Blur Handling - /* - Found on https://github.com/riverar/sample-win10-aeroglass - */ - private enum AccentState - { - ACCENT_DISABLED = 0, - ACCENT_ENABLE_GRADIENT = 1, - ACCENT_ENABLE_TRANSPARENTGRADIENT = 2, - ACCENT_ENABLE_BLURBEHIND = 3, - ACCENT_INVALID_STATE = 4 - } - - [StructLayout(LayoutKind.Sequential)] - private struct AccentPolicy - { - public AccentState AccentState; - public int AccentFlags; - public int GradientColor; - public int AnimationId; - } - - [StructLayout(LayoutKind.Sequential)] - private struct WindowCompositionAttributeData - { - public WindowCompositionAttribute Attribute; - public IntPtr Data; - public int SizeOfData; - } - - private enum WindowCompositionAttribute - { - WCA_ACCENT_POLICY = 19 - } - [DllImport("user32.dll")] - private static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data); - - /// - /// Sets the blur for a window via SetWindowCompositionAttribute - /// - public void SetBlurForWindow() - { - - // Exception of FindResource can't be caught if global exception handle is set - if (Environment.OSVersion.Version >= new Version(6, 2)) - { - var resource = Application.Current.TryFindResource("ThemeBlurEnabled"); - bool blur; - if (resource is bool) - { - blur = (bool)resource; - } - else - { - blur = false; - } - - if (blur) - { - SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_ENABLE_BLURBEHIND); - } - else - { - SetWindowAccent(Application.Current.MainWindow, AccentState.ACCENT_DISABLED); - } - } - } - - private void SetWindowAccent(Window w, AccentState state) - { - var windowHelper = new WindowInteropHelper(w); - var accent = new AccentPolicy { AccentState = state }; - var accentStructSize = Marshal.SizeOf(accent); - - var accentPtr = Marshal.AllocHGlobal(accentStructSize); - Marshal.StructureToPtr(accent, accentPtr, false); - - var data = new WindowCompositionAttributeData - { - Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY, - SizeOfData = accentStructSize, - Data = accentPtr - }; - - SetWindowCompositionAttribute(windowHelper.Handle, ref data); - - Marshal.FreeHGlobal(accentPtr); + ThemeManager.Current.AddLibraryTheme(new LibraryTheme(LightTheme, + MahAppsLibraryThemeProvider.DefaultInstance)); + ThemeManager.Current.AddLibraryTheme(new LibraryTheme(DarkTheme, + MahAppsLibraryThemeProvider.DefaultInstance)); + ThemeManager.Current.AddLibraryTheme(new LibraryTheme(HighContrastTheme, + MahAppsLibraryThemeProvider.DefaultInstance)); } - #endregion } } diff --git a/src/modules/launcher/Wox.Core/Resource/ThemeManager.cs b/src/modules/launcher/Wox.Core/Resource/ThemeManager.cs deleted file mode 100644 index 193b0bd534b0..000000000000 --- a/src/modules/launcher/Wox.Core/Resource/ThemeManager.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace Wox.Core.Resource -{ - public class ThemeManager - { - private static Theme instance; - private static object syncObject = new object(); - - public static Theme Instance - { - get - { - if (instance == null) - { - lock (syncObject) - { - if (instance == null) - { - instance = new Theme(); - } - } - } - return instance; - } - } - } -} diff --git a/src/modules/launcher/Wox.Core/Wox.Core.csproj b/src/modules/launcher/Wox.Core/Wox.Core.csproj index a4f2eb9c2b5b..3edfdf995fa3 100644 --- a/src/modules/launcher/Wox.Core/Wox.Core.csproj +++ b/src/modules/launcher/Wox.Core/Wox.Core.csproj @@ -57,6 +57,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/src/modules/launcher/Wox/App.xaml b/src/modules/launcher/Wox/App.xaml deleted file mode 100644 index 53341c629c00..000000000000 --- a/src/modules/launcher/Wox/App.xaml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/src/modules/launcher/Wox/App.xaml.cs b/src/modules/launcher/Wox/App.xaml.cs deleted file mode 100644 index 4ee71d675993..000000000000 --- a/src/modules/launcher/Wox/App.xaml.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System; -using System.Diagnostics; -using System.Threading.Tasks; -using System.Timers; -using System.Windows; -using Wox.Core; -using Wox.Core.Plugin; -using Wox.Core.Resource; -using Wox.Helper; -using Wox.Infrastructure; -using Wox.Infrastructure.Http; -using Wox.Infrastructure.Image; -using Wox.Infrastructure.Logger; -using Wox.Infrastructure.UserSettings; -using Wox.ViewModel; -using Stopwatch = Wox.Infrastructure.Stopwatch; - -namespace Wox -{ - public partial class App : IDisposable, ISingleInstanceApp - { - public static PublicAPIInstance API { get; private set; } - private const string Unique = "Wox_Unique_Application_Mutex"; - private static bool _disposed; - private Settings _settings; - private MainViewModel _mainVM; - private SettingWindowViewModel _settingsVM; - private readonly Alphabet _alphabet = new Alphabet(); - private StringMatcher _stringMatcher; - - [STAThread] - public static void Main() - { - if (SingleInstance.InitializeAsFirstInstance(Unique)) - { - using (var application = new App()) - { - application.InitializeComponent(); - application.Run(); - } - } - } - - private void OnStartup(object sender, StartupEventArgs e) - { - Stopwatch.Normal("|App.OnStartup|Startup cost", () => - { - Log.Info("|App.OnStartup|Begin Wox startup ----------------------------------------------------"); - Log.Info($"|App.OnStartup|Runtime info:{ErrorReporting.RuntimeInfo()}"); - RegisterAppDomainExceptions(); - RegisterDispatcherUnhandledException(); - - ImageLoader.Initialize(); - - _settingsVM = new SettingWindowViewModel(); - _settings = _settingsVM.Settings; - - _alphabet.Initialize(_settings); - _stringMatcher = new StringMatcher(_alphabet); - StringMatcher.Instance = _stringMatcher; - _stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision; - - PluginManager.LoadPlugins(_settings.PluginSettings); - _mainVM = new MainViewModel(_settings); - var window = new MainWindow(_settings, _mainVM); - API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet); - PluginManager.InitializePlugins(API); - - Current.MainWindow = window; - Current.MainWindow.Title = Constant.ExeFileName; - - // happlebao todo temp fix for instance code logic - // load plugin before change language, because plugin language also needs be changed - InternationalizationManager.Instance.Settings = _settings; - InternationalizationManager.Instance.ChangeLanguage(_settings.Language); - // main windows needs initialized before theme change because of blur settings - ThemeManager.Instance.Settings = _settings; - ThemeManager.Instance.ChangeTheme(_settings.Theme); - - Http.Proxy = _settings.Proxy; - - RegisterExitEvents(); - - _mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible; - Log.Info("|App.OnStartup|End Wox startup ---------------------------------------------------- "); - }); - } - - private void RegisterExitEvents() - { - AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose(); - Current.Exit += (s, e) => Dispose(); - Current.SessionEnding += (s, e) => Dispose(); - } - - /// - /// let exception throw as normal is better for Debug - /// - [Conditional("RELEASE")] - private void RegisterDispatcherUnhandledException() - { - DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException; - } - - - /// - /// let exception throw as normal is better for Debug - /// - [Conditional("RELEASE")] - private static void RegisterAppDomainExceptions() - { - AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle; - } - - public void Dispose() - { - // if sessionending is called, exit proverbially be called when log off / shutdown - // but if sessionending is not called, exit won't be called when log off / shutdown - if (!_disposed) - { - API.SaveAppAllSettings(); - _disposed = true; - } - } - - public void OnSecondAppStarted() - { - Current.MainWindow.Visibility = Visibility.Visible; - } - } -} \ No newline at end of file diff --git a/src/modules/launcher/Wox/MainWindow.xaml.cs b/src/modules/launcher/Wox/MainWindow.xaml.cs index b56904f8a433..bc2b098da5c0 100644 --- a/src/modules/launcher/Wox/MainWindow.xaml.cs +++ b/src/modules/launcher/Wox/MainWindow.xaml.cs @@ -54,7 +54,6 @@ private void OnInitialized(object sender, EventArgs e) private void OnLoaded(object sender, RoutedEventArgs _) { // todo is there a way to set blur only once? - ThemeManager.Instance.SetBlurForWindow(); WindowsInteropHelper.DisableControlBox(this); InitProgressbarAnimation(); InitializePosition(); diff --git a/src/modules/launcher/Wox/ViewModel/SettingWindowViewModel.cs b/src/modules/launcher/Wox/ViewModel/SettingWindowViewModel.cs index f3b9e14b8e10..80523756367d 100644 --- a/src/modules/launcher/Wox/ViewModel/SettingWindowViewModel.cs +++ b/src/modules/launcher/Wox/ViewModel/SettingWindowViewModel.cs @@ -168,13 +168,9 @@ public string SelectedTheme set { Settings.Theme = value; - ThemeManager.Instance.ChangeTheme(value); } } - public List Themes - => ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension).ToList(); - public Brush PreviewBackground { get @@ -257,7 +253,6 @@ public FontFamily SelectedQueryBoxFont set { Settings.QueryBoxFont = value.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); } } @@ -278,7 +273,6 @@ public FamilyTypeface SelectedQueryBoxFontFaces Settings.QueryBoxFontStretch = value.Stretch.ToString(); Settings.QueryBoxFontWeight = value.Weight.ToString(); Settings.QueryBoxFontStyle = value.Style.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); } } @@ -302,7 +296,6 @@ public FontFamily SelectedResultFont set { Settings.ResultFont = value.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); } } @@ -323,7 +316,6 @@ public FamilyTypeface SelectedResultFontFaces Settings.ResultFontStretch = value.Stretch.ToString(); Settings.ResultFontWeight = value.Weight.ToString(); Settings.ResultFontStyle = value.Style.ToString(); - ThemeManager.Instance.ChangeTheme(Settings.Theme); } } diff --git a/src/modules/launcher/Wox/Wox.csproj b/src/modules/launcher/Wox/Wox.csproj index e988e96684d7..c5db45087a3e 100644 --- a/src/modules/launcher/Wox/Wox.csproj +++ b/src/modules/launcher/Wox/Wox.csproj @@ -37,14 +37,6 @@ MinimumRecommendedRules.ruleset 4 - - - - - - - - From a376f2517f10ce6fc0aa3ca43734a460bdc7426c Mon Sep 17 00:00:00 2001 From: Divyansh Srivastava Date: Tue, 2 Jun 2020 13:55:26 -0700 Subject: [PATCH 2/7] Added Light and dark theme and template for high contrast theme --- src/modules/launcher/PowerLauncher/App.xaml | 1 + .../launcher/PowerLauncher/App.xaml.cs | 3 +- .../PowerLauncher/LauncherControl.xaml | 20 +---- .../launcher/PowerLauncher/MainWindow.xaml | 6 -- .../PowerLauncher/PowerLauncher.csproj | 7 +- .../launcher/PowerLauncher/ResultList.xaml | 22 +---- .../launcher/PowerLauncher/ThemeManager.cs | 80 +++++++++++++++++++ .../launcher/PowerLauncher/Themes/Dark.xaml | 31 +++++++ .../PowerLauncher/Themes/HighContrast.xaml | 18 +++++ .../launcher/PowerLauncher/Themes/Light.xaml | 31 +++++++ .../launcher/Wox.Core/Resource/Theme.cs | 23 ------ 11 files changed, 175 insertions(+), 67 deletions(-) create mode 100644 src/modules/launcher/PowerLauncher/ThemeManager.cs create mode 100644 src/modules/launcher/PowerLauncher/Themes/Dark.xaml create mode 100644 src/modules/launcher/PowerLauncher/Themes/HighContrast.xaml create mode 100644 src/modules/launcher/PowerLauncher/Themes/Light.xaml delete mode 100644 src/modules/launcher/Wox.Core/Resource/Theme.cs diff --git a/src/modules/launcher/PowerLauncher/App.xaml b/src/modules/launcher/PowerLauncher/App.xaml index 11740e71365c..379c8ed700a0 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml +++ b/src/modules/launcher/PowerLauncher/App.xaml @@ -7,6 +7,7 @@ + diff --git a/src/modules/launcher/PowerLauncher/App.xaml.cs b/src/modules/launcher/PowerLauncher/App.xaml.cs index 9d12ea19c667..7d0b30cb4a58 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml.cs +++ b/src/modules/launcher/PowerLauncher/App.xaml.cs @@ -68,12 +68,13 @@ private void OnStartup(object sender, StartupEventArgs e) StringMatcher.Instance = _stringMatcher; _stringMatcher.UserSettingSearchPrecision = _settings.QuerySearchPrecision; + ThemeManager themeManager = new ThemeManager(this); + PluginManager.LoadPlugins(_settings.PluginSettings); _mainVM = new MainViewModel(_settings); var window = new MainWindow(_settings, _mainVM); API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet); PluginManager.InitializePlugins(API); - Current.MainWindow = window; Current.MainWindow.Title = Constant.ExeFileName; diff --git a/src/modules/launcher/PowerLauncher/LauncherControl.xaml b/src/modules/launcher/PowerLauncher/LauncherControl.xaml index b08c34722e52..814257c24b50 100644 --- a/src/modules/launcher/PowerLauncher/LauncherControl.xaml +++ b/src/modules/launcher/PowerLauncher/LauncherControl.xaml @@ -9,25 +9,11 @@ d:DesignHeight="300" d:DesignWidth="720"> - #66000000 - - - - - - - diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml b/src/modules/launcher/PowerLauncher/MainWindow.xaml index 46c87742eba7..3973e9b5547c 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml @@ -24,12 +24,6 @@ Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" d:DataContext="{d:DesignInstance vm:MainViewModel}"> - - - diff --git a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj index 1256ed74b9b3..9178a4bfd8ca 100644 --- a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj +++ b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj @@ -186,7 +186,12 @@ - + + Designer + + + Designer + \ No newline at end of file diff --git a/src/modules/launcher/PowerLauncher/ResultList.xaml b/src/modules/launcher/PowerLauncher/ResultList.xaml index e2480cd1d2f4..0443a3417215 100644 --- a/src/modules/launcher/PowerLauncher/ResultList.xaml +++ b/src/modules/launcher/PowerLauncher/ResultList.xaml @@ -15,23 +15,6 @@ --> - - - - - - - - - - - - - + Dark.Accent1 + PowerToysRun + Accent1 (Dark) + Dark + Accent1 + Black + + #66FFFFFF + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/modules/launcher/PowerLauncher/Themes/HighContrast.xaml b/src/modules/launcher/PowerLauncher/Themes/HighContrast.xaml new file mode 100644 index 000000000000..232efea95f77 --- /dev/null +++ b/src/modules/launcher/PowerLauncher/Themes/HighContrast.xaml @@ -0,0 +1,18 @@ + + + + HighContrast.Accent1 + PowerToysRun + Accent1 (HighContrast) + HighContrast + Accent1 + White + + + \ No newline at end of file diff --git a/src/modules/launcher/PowerLauncher/Themes/Light.xaml b/src/modules/launcher/PowerLauncher/Themes/Light.xaml new file mode 100644 index 000000000000..09e9da014e44 --- /dev/null +++ b/src/modules/launcher/PowerLauncher/Themes/Light.xaml @@ -0,0 +1,31 @@ + + + + Light.Accent1 + PowerToysRun + Accent1 (Light) + Light + Accent1 + White + + #66000000 + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/modules/launcher/Wox.Core/Resource/Theme.cs b/src/modules/launcher/Wox.Core/Resource/Theme.cs deleted file mode 100644 index bbc03409908c..000000000000 --- a/src/modules/launcher/Wox.Core/Resource/Theme.cs +++ /dev/null @@ -1,23 +0,0 @@ -using ControlzEx.Theming; -using MahApps.Metro.Theming; -using System; - -namespace Wox.Core.Resource -{ - public class Theme - { - readonly Uri LightTheme = new Uri("pack://application:,,,/Light.xaml"); - readonly Uri DarkTheme = new Uri("pack://application:,,,/Dark.xaml"); - readonly Uri HighContrastTheme = new Uri("pack://application:,,,/HighContrast.xaml"); - - Theme() - { - ThemeManager.Current.AddLibraryTheme(new LibraryTheme(LightTheme, - MahAppsLibraryThemeProvider.DefaultInstance)); - ThemeManager.Current.AddLibraryTheme(new LibraryTheme(DarkTheme, - MahAppsLibraryThemeProvider.DefaultInstance)); - ThemeManager.Current.AddLibraryTheme(new LibraryTheme(HighContrastTheme, - MahAppsLibraryThemeProvider.DefaultInstance)); - } - } -} From 45c474b3a41b40463e1813926265be0824ad82e8 Mon Sep 17 00:00:00 2001 From: Divyansh Srivastava Date: Tue, 2 Jun 2020 16:05:47 -0700 Subject: [PATCH 3/7] Updated themeManager to remove strings --- .../launcher/PowerLauncher/ResultList.xaml | 7 --- .../launcher/PowerLauncher/ThemeManager.cs | 51 +++++++++++-------- .../PowerLauncher/Themes/HighContrast.xaml | 14 ++++- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/modules/launcher/PowerLauncher/ResultList.xaml b/src/modules/launcher/PowerLauncher/ResultList.xaml index 0443a3417215..ff0515d84940 100644 --- a/src/modules/launcher/PowerLauncher/ResultList.xaml +++ b/src/modules/launcher/PowerLauncher/ResultList.xaml @@ -15,13 +15,6 @@ --> - - - -