From f492c4efdb7590a997079fce3807fda744116ca6 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Fri, 26 Jun 2020 13:54:56 +0200 Subject: [PATCH] Added theming to Shell and WindowWalker --- .../Plugins/Microsoft.Plugin.Shell/Main.cs | 29 +++++++++++++++---- .../Microsoft.Plugin.WindowWalker/Main.cs | 26 ++++++++++++++--- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs index d6d4ff331b..5554a80bfa 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Shell/Main.cs @@ -25,7 +25,8 @@ namespace Microsoft.Plugin.Shell { public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, ISavable { - private const string Image = "Images/shell.dark.png"; + private string IconPath { get; set; } + private PluginInitContext _context; private bool _winRStroked; private readonly KeyboardSimulator _keyboardSimulator = new KeyboardSimulator(new InputSimulator()); @@ -88,7 +89,7 @@ namespace Microsoft.Plugin.Shell results.AddRange(autocomplete.ConvertAll(m => new Result { Title = m, - IcoPath = Image, + IcoPath = IconPath, Action = c => { Execute(Process.Start, PrepareProcessStartInfo(m)); @@ -121,7 +122,7 @@ namespace Microsoft.Plugin.Shell { Title = m.Key, SubTitle = "Shell: " + string.Format(_context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value), - IcoPath = Image, + IcoPath = IconPath, Action = c => { Execute(Process.Start, PrepareProcessStartInfo(m.Key)); @@ -140,7 +141,7 @@ namespace Microsoft.Plugin.Shell Title = cmd, Score = 5000, SubTitle = "Shell: " + _context.API.GetTranslation("wox_plugin_cmd_execute_through_shell"), - IcoPath = Image, + IcoPath = IconPath, Action = c => { Execute(Process.Start, PrepareProcessStartInfo(cmd)); @@ -158,7 +159,7 @@ namespace Microsoft.Plugin.Shell { Title = m.Key, SubTitle = "Shell: " + string.Format(_context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value), - IcoPath = Image, + IcoPath = IconPath, Action = c => { Execute(Process.Start, PrepareProcessStartInfo(m.Key)); @@ -290,6 +291,24 @@ namespace Microsoft.Plugin.Shell { this._context = context; context.API.GlobalKeyboardEvent += API_GlobalKeyboardEvent; + context.API.ThemeChanged += OnThemeChanged; + ResetCalculatorIconPath(context.API.GetCurrentTheme()); + } + + private void ResetCalculatorIconPath(Theme theme) + { + string ThemeString; + if (theme == Theme.Light || theme == Theme.HighContrastWhite) + ThemeString = "light"; + else + ThemeString = "dark"; + + IconPath = "Images/shell." + ThemeString + ".png"; + } + + private void OnThemeChanged(Theme _, Theme newTheme) + { + ResetCalculatorIconPath(newTheme); } bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Main.cs index a301d3118f..295eb02464 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Main.cs @@ -7,8 +7,8 @@ namespace Microsoft.Plugin.WindowWalker { public class Main : IPlugin, IPluginI18n { - private static List _results = new List(); - private static string IcoPath = "Images/windowwalker.dark.png"; + private static List _results = new List(); + private string IconPath { get; set; } private PluginInitContext Context { get; set; } static Main() @@ -24,7 +24,7 @@ namespace Microsoft.Plugin.WindowWalker return _results.Select(x => new Result() { Title = x.Result.Title, - IcoPath = IcoPath, + IcoPath = IconPath, SubTitle = "Running: " + x.Result.ProcessName, Action = c => { @@ -37,7 +37,25 @@ namespace Microsoft.Plugin.WindowWalker public void Init(PluginInitContext context) { - Context = context; + Context = context; + Context.API.ThemeChanged += OnThemeChanged; + ResetCalculatorIconPath(context.API.GetCurrentTheme()); + } + + private void ResetCalculatorIconPath(Theme theme) + { + string ThemeString; + if (theme == Theme.Light || theme == Theme.HighContrastWhite) + ThemeString = "light"; + else + ThemeString = "dark"; + + IconPath = "Images/windowwalker." + ThemeString + ".png"; + } + + private void OnThemeChanged(Theme _, Theme newTheme) + { + ResetCalculatorIconPath(newTheme); } public string GetTranslatedPluginTitle()