mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-01 01:49:06 +08:00
Added theme awereness based on somil55s PR
This commit is contained in:
parent
835ffc38cb
commit
8edd3226be
@ -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");
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Callback when windows theme is changed.
|
||||
/// </summary>
|
||||
/// <param name="previousTheme">Previous Theme</param>
|
||||
/// <param name="currentTheme">Current Theme</param>
|
||||
private void OnThemeChanged(Theme previousTheme, Theme currentTheme)
|
||||
{
|
||||
_mainVM.Query();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// let exception throw as normal is better for Debug
|
||||
/// </summary>
|
||||
|
@ -57,7 +57,6 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
|
||||
<PackageReference Include="MahApps.Metro" Version="2.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="3.2.8" />
|
||||
<PackageReference Include="SharpZipLib" Version="1.2.0" />
|
||||
|
@ -57,6 +57,17 @@ namespace Wox.Plugin
|
||||
[Obsolete]
|
||||
void ShowApp();
|
||||
|
||||
/// <summary>
|
||||
/// Get current theme
|
||||
/// </summary>
|
||||
Theme GetCurrentTheme();
|
||||
|
||||
/// <summary>
|
||||
/// Theme change event
|
||||
/// </summary>
|
||||
event ThemeChangedHandler ThemeChanged;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Save all Wox settings
|
||||
/// </summary>
|
||||
|
@ -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,
|
@ -57,6 +57,8 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
|
||||
<PackageReference Include="MahApps.Metro" Version="2.1.0" />
|
||||
<PackageReference Include="ControlzEx" Version="4.3.0" />
|
||||
<PackageReference Include="Microsoft.Toolkit.Wpf.UI.XamlHost" Version="6.0.1" />
|
||||
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user