diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Calculator/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Calculator/Main.cs index 6e860f9c1c..016fa55e7d 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Calculator/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Calculator/Main.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Windows; using Mages.Core; using Wox.Plugin; +using System.Drawing; namespace Microsoft.Plugin.Calculator { @@ -22,6 +23,7 @@ namespace Microsoft.Plugin.Calculator private static readonly Regex RegBrackets = new Regex(@"[\(\)\[\]]", RegexOptions.Compiled); private static readonly Engine MagesEngine; private PluginInitContext Context { get; set; } + private string IconPath { get; set; } static Main() { @@ -52,7 +54,7 @@ namespace Microsoft.Plugin.Calculator new Result { Title = result.ToString(), - IcoPath = "Images/calculator.dark.png", + IcoPath = IconPath, Score = 300, SubTitle = Context.API.GetTranslation("wox_plugin_calculator_copy_number_to_clipboard"), Action = c => @@ -109,9 +111,27 @@ namespace Microsoft.Plugin.Calculator public void Init(PluginInitContext context) { Context = context; + Context.API.ThemeChanged += OnThemeChanged; + ResetCalculatorIconPath(Context.API.GetCurrentTheme()); } - public string GetTranslatedPluginTitle() + private void ResetCalculatorIconPath(Theme theme) + { + string ThemeString; + if (theme == Theme.Light || theme == Theme.HighContrastWhite) + ThemeString = "light"; + else + ThemeString = "dark"; + + IconPath = "Images/calculator." + ThemeString + ".png"; + } + + private void OnThemeChanged(Theme _, Theme newTheme) + { + ResetCalculatorIconPath(newTheme); + } + + public string GetTranslatedPluginTitle() { return Context.API.GetTranslation("wox_plugin_calculator_plugin_name"); } diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Main.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Main.cs index b397d92dd5..42b8f6cbb9 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Main.cs @@ -13,7 +13,7 @@ using Wox.Plugin; using Microsoft.Plugin.Program.Views; using Stopwatch = Wox.Infrastructure.Stopwatch; - +using Microsoft.Plugin.Program.Programs; namespace Microsoft.Plugin.Program { @@ -104,9 +104,25 @@ namespace Microsoft.Plugin.Program public void Init(PluginInitContext context) { _context = context; + _context.API.ThemeChanged += onThemeChanged; + ResetUWPIconPath(_context.API.GetCurrentTheme()); } - public static void IndexWin32Programs() + public void ResetUWPIconPath(Theme theme) + { + foreach (UWP.Application app in _uwps) + { + app.ResetPath(theme); + } + } + + public void onThemeChanged(Theme _, Theme currentTheme) + { + ResetUWPIconPath(currentTheme); + } + + + public static void IndexWin32Programs() { var win32S = Programs.Win32.All(_settings); lock (IndexLock) diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWP.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWP.cs index bd288cb9c9..3b78b3fc0e 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWP.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Program/Programs/UWP.cs @@ -405,7 +405,6 @@ namespace Microsoft.Plugin.Program.Programs DisplayName = ResourceFromPri(package.FullName, DisplayName); Description = ResourceFromPri(package.FullName, Description); LogoUri = LogoUriFromManifest(manifestApp); - LogoPath = LogoPathFromUri(LogoUri); Enabled = true; CanRunElevated = IfApplicationcanRunElevated(); @@ -515,9 +514,17 @@ namespace Microsoft.Plugin.Program.Programs { return string.Empty; } - } - - internal string LogoPathFromUri(string uri) + } + + public void ResetPath(Theme theme) + { + if (theme == Theme.Light || theme == Theme.HighContrastWhite) + LogoPath = LogoPathFromUri(LogoUri, "contrast-white"); + else + LogoPath = LogoPathFromUri(LogoUri, "contrast-black"); + } + + internal string LogoPathFromUri(string uri, string theme) { // all https://msdn.microsoft.com/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets // windows 10 https://msdn.microsoft.com/en-us/library/windows/apps/dn934817.aspx diff --git a/src/modules/launcher/PowerLauncher/App.xaml.cs b/src/modules/launcher/PowerLauncher/App.xaml.cs index 3028af9cf3..6a10db3636 100644 --- a/src/modules/launcher/PowerLauncher/App.xaml.cs +++ b/src/modules/launcher/PowerLauncher/App.xaml.cs @@ -2,6 +2,7 @@ using Microsoft.PowerLauncher.Telemetry; using Microsoft.PowerToys.Telemetry; using System; using System.Diagnostics; +using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Timers; using System.Windows; @@ -16,6 +17,7 @@ using Wox.Infrastructure.Image; using Wox.Infrastructure.Logger; using Wox.Infrastructure.UserSettings; using Wox.ViewModel; +using Wox.Plugin; using Stopwatch = Wox.Infrastructure.Stopwatch; namespace PowerLauncher @@ -29,6 +31,7 @@ namespace PowerLauncher private static bool _disposed; private Settings _settings; private MainViewModel _mainVM; + private ThemeManager _themeManager; private SettingWindowViewModel _settingsVM; private readonly Alphabet _alphabet = new Alphabet(); private StringMatcher _stringMatcher; @@ -67,12 +70,12 @@ namespace PowerLauncher _stringMatcher = new StringMatcher(_alphabet); 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); + _themeManager = new ThemeManager(this); + API = new PublicAPIInstance(_settingsVM, _mainVM, _alphabet, _themeManager); PluginManager.InitializePlugins(API); Current.MainWindow = window; @@ -93,6 +96,7 @@ namespace PowerLauncher _mainVM.MainWindowVisibility = Visibility.Visible; _mainVM.ColdStartFix(); + _themeManager.ThemeChanged += OnThemeChanged; Log.Info("|App.OnStartup|End Wox startup ---------------------------------------------------- "); bootTime.Stop(); @@ -113,6 +117,16 @@ namespace PowerLauncher Current.SessionEnding += (s, e) => Dispose(); } + /// + /// Callback when windows theme is changed. + /// + /// Previous Theme + /// Current Theme + private void OnThemeChanged(Theme previousTheme, Theme currentTheme) + { + _mainVM.Query(); + } + /// /// let exception throw as normal is better for Debug /// diff --git a/src/modules/launcher/Wox.Core/Wox.Core.csproj b/src/modules/launcher/Wox.Core/Wox.Core.csproj index 3edfdf995f..a4f2eb9c2b 100644 --- a/src/modules/launcher/Wox.Core/Wox.Core.csproj +++ b/src/modules/launcher/Wox.Core/Wox.Core.csproj @@ -57,7 +57,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/src/modules/launcher/Wox.Plugin/IPublicAPI.cs b/src/modules/launcher/Wox.Plugin/IPublicAPI.cs index 16fd768552..ddfec1f462 100644 --- a/src/modules/launcher/Wox.Plugin/IPublicAPI.cs +++ b/src/modules/launcher/Wox.Plugin/IPublicAPI.cs @@ -57,6 +57,17 @@ namespace Wox.Plugin [Obsolete] void ShowApp(); + /// + /// Get current theme + /// + Theme GetCurrentTheme(); + + /// + /// Theme change event + /// + event ThemeChangedHandler ThemeChanged; + + /// /// Save all Wox settings /// diff --git a/src/modules/launcher/PowerLauncher/ThemeManager.cs b/src/modules/launcher/Wox.Plugin/ThemeManager.cs similarity index 93% rename from src/modules/launcher/PowerLauncher/ThemeManager.cs rename to src/modules/launcher/Wox.Plugin/ThemeManager.cs index 4c39126546..969778a441 100644 --- a/src/modules/launcher/PowerLauncher/ThemeManager.cs +++ b/src/modules/launcher/Wox.Plugin/ThemeManager.cs @@ -6,7 +6,7 @@ using System.Diagnostics; using System.Linq; using System.Windows; -namespace Wox.Core.Resource +namespace Wox.Plugin { public class ThemeManager { @@ -19,6 +19,8 @@ namespace Wox.Core.Resource private readonly string HighContrastBlackTheme = "HighContrast.Accent4"; private readonly string HighContrastWhiteTheme = "HighContrast.Accent5"; + public event ThemeChangedHandler ThemeChanged; + public ThemeManager(Application app) { this.App = app; @@ -60,7 +62,11 @@ namespace Wox.Core.Resource } }; } - + + public Theme GetCurrentTheme() + { + return currentTheme; + } public Theme GetHighContrastBaseType() { @@ -80,7 +86,7 @@ namespace Wox.Core.Resource return Theme.None; } - public void ResetTheme() + private void ResetTheme() { if (SystemParameters.HighContrast) { @@ -96,6 +102,7 @@ namespace Wox.Core.Resource private void ChangeTheme(Theme theme) { + Theme previousTheme = currentTheme; if (theme == currentTheme) return; if (theme == Theme.HighContrastOne) @@ -132,7 +139,7 @@ namespace Wox.Core.Resource { currentTheme = Theme.None; } - Debug.WriteLine("Theme Changed to :" + currentTheme); + ThemeChanged?.Invoke(previousTheme, currentTheme); } private void Current_ThemeChanged(object sender, ThemeChangedEventArgs e) @@ -141,6 +148,8 @@ namespace Wox.Core.Resource } } + public delegate void ThemeChangedHandler(Theme previousTheme, Theme newTheme); + public enum Theme { None, diff --git a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj index 1845c2714b..edd2459dd8 100644 --- a/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj +++ b/src/modules/launcher/Wox.Plugin/Wox.Plugin.csproj @@ -57,6 +57,8 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/src/modules/launcher/Wox/PublicAPIInstance.cs b/src/modules/launcher/Wox/PublicAPIInstance.cs index a663dc8c37..4f357cd60c 100644 --- a/src/modules/launcher/Wox/PublicAPIInstance.cs +++ b/src/modules/launcher/Wox/PublicAPIInstance.cs @@ -20,14 +20,19 @@ namespace Wox private readonly SettingWindowViewModel _settingsVM; private readonly MainViewModel _mainVM; private readonly Alphabet _alphabet; + private readonly ThemeManager _themeManager; + + public event ThemeChangedHandler ThemeChanged; #region Constructor - public PublicAPIInstance(SettingWindowViewModel settingsVM, MainViewModel mainVM, Alphabet alphabet) + public PublicAPIInstance(SettingWindowViewModel settingsVM, MainViewModel mainVM, Alphabet alphabet, ThemeManager themeManager) { _settingsVM = settingsVM; _mainVM = mainVM; _alphabet = alphabet; + _themeManager = themeManager; + _themeManager.ThemeChanged += OnThemeChanged; GlobalHotkey.Instance.hookedKeyboardCallback += KListener_hookedKeyboardCallback; WebRequest.RegisterPrefix("data", new DataWebRequestFactory()); } @@ -141,9 +146,18 @@ namespace Wox }); } + public Theme GetCurrentTheme() + { + return _themeManager.GetCurrentTheme(); + } #endregion - #region Private Methods + #region Protected Methods + + protected void OnThemeChanged(Theme previousTheme, Theme currentTheme) + { + ThemeChanged?.Invoke(previousTheme, currentTheme); + } private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) {