mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[PT Run] Option for override theme (#7355)
* option for override PT Run theme * fix startup theme detection and moved strings in resources * xaml fixed * fix title spacing * launcher theme fix moved theme enum removed settings direct access * missing files * theme manager dispose removed Co-authored-by: Clint Rutkas <clint@rutkas.com>
This commit is contained in:
committed by
GitHub
parent
6424667396
commit
146e7866a6
@@ -5,6 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using ManagedCommon;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Controls;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Plugin.Folder.Sources;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Wox.Infrastructure.Storage;
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Collections.Immutable;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Plugin.Folder.Sources.Result;
|
||||
using Wox.Plugin;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Controls;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Plugin.Indexer.DriveDetection;
|
||||
using Microsoft.Plugin.Indexer.SearchHelper;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Plugin.Program.ProgramArgumentParser;
|
||||
using Microsoft.Plugin.Program.Programs;
|
||||
using Microsoft.Plugin.Program.Storage;
|
||||
|
||||
@@ -16,6 +16,7 @@ using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Plugin.Program.Logger;
|
||||
using Microsoft.Plugin.Program.Win32;
|
||||
using Wox.Infrastructure;
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Input;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Plugin.Uri.UriHelper;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Plugin.WindowWalker.Components;
|
||||
using Wox.Plugin;
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace PowerLauncher
|
||||
|
||||
RegisterExitEvents();
|
||||
|
||||
_settingsWatcher = new SettingsWatcher(_settings);
|
||||
_settingsWatcher = new SettingsWatcher(_settings, _themeManager);
|
||||
|
||||
_mainVM.MainWindowVisibility = Visibility.Visible;
|
||||
_mainVM.ColdStartFix();
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Windows;
|
||||
using ManagedCommon;
|
||||
using PowerLauncher.Helper;
|
||||
using PowerLauncher.ViewModel;
|
||||
using Wox.Core.Plugin;
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows.Input;
|
||||
using ManagedCommon;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using PowerLauncher.Helper;
|
||||
@@ -27,11 +28,13 @@ namespace PowerLauncher
|
||||
private static readonly object _watcherSyncObject = new object();
|
||||
private readonly FileSystemWatcher _watcher;
|
||||
private readonly Settings _settings;
|
||||
private readonly ThemeManager _themeManager;
|
||||
|
||||
public SettingsWatcher(Settings settings)
|
||||
public SettingsWatcher(Settings settings, ThemeManager themeManager)
|
||||
{
|
||||
_settingsUtils = new SettingsUtils(new SystemIOProvider());
|
||||
_settings = settings;
|
||||
_themeManager = themeManager;
|
||||
|
||||
// Set up watcher
|
||||
_watcher = Microsoft.PowerToys.Settings.UI.Library.Utilities.Helper.GetFileWatcher(PowerLauncherSettings.ModuleName, "settings.json", OverloadSettings);
|
||||
@@ -100,6 +103,12 @@ namespace PowerLauncher
|
||||
_settings.ClearInputOnLaunch = overloadSettings.Properties.ClearInputOnLaunch;
|
||||
}
|
||||
|
||||
if (_settings.Theme != overloadSettings.Properties.Theme)
|
||||
{
|
||||
_settings.Theme = overloadSettings.Properties.Theme;
|
||||
_themeManager.ChangeTheme(_settings.Theme, _settings.Theme == Theme.System);
|
||||
}
|
||||
|
||||
retry = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using ManagedCommon;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using ManagedCommon;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Wox.Plugin;
|
||||
@@ -44,7 +45,7 @@ namespace Wox.Infrastructure.UserSettings
|
||||
|
||||
public string Language { get; set; } = "en";
|
||||
|
||||
public string Theme { get; set; } = "Dark";
|
||||
public Theme Theme { get; set; } = Theme.System;
|
||||
|
||||
public string QueryBoxFont { get; set; } = FontFamily.GenericSansSerif.Name;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ManagedCommon;
|
||||
|
||||
namespace Wox.Plugin
|
||||
{
|
||||
@@ -71,7 +72,6 @@ namespace Wox.Plugin
|
||||
/// <summary>
|
||||
/// Get all loaded plugins
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<PluginPair> GetAllPlugins();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using ControlzEx.Theming;
|
||||
using MahApps.Metro.Theming;
|
||||
using ManagedCommon;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Wox.Plugin
|
||||
@@ -39,32 +38,32 @@ namespace Wox.Plugin
|
||||
Uri darkThemeUri = new Uri("pack://application:,,,/Themes/Dark.xaml");
|
||||
|
||||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
|
||||
new LibraryTheme(
|
||||
new ControlzEx.Theming.LibraryTheme(
|
||||
highContrastOneThemeUri,
|
||||
MahAppsLibraryThemeProvider.DefaultInstance));
|
||||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
|
||||
new LibraryTheme(
|
||||
new ControlzEx.Theming.LibraryTheme(
|
||||
highContrastTwoThemeUri,
|
||||
MahAppsLibraryThemeProvider.DefaultInstance));
|
||||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
|
||||
new LibraryTheme(
|
||||
new ControlzEx.Theming.LibraryTheme(
|
||||
highContrastBlackThemeUri,
|
||||
MahAppsLibraryThemeProvider.DefaultInstance));
|
||||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
|
||||
new LibraryTheme(
|
||||
new ControlzEx.Theming.LibraryTheme(
|
||||
highContrastWhiteThemeUri,
|
||||
MahAppsLibraryThemeProvider.DefaultInstance));
|
||||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
|
||||
new LibraryTheme(
|
||||
new ControlzEx.Theming.LibraryTheme(
|
||||
lightThemeUri,
|
||||
MahAppsLibraryThemeProvider.DefaultInstance));
|
||||
ControlzEx.Theming.ThemeManager.Current.AddLibraryTheme(
|
||||
new LibraryTheme(
|
||||
new ControlzEx.Theming.LibraryTheme(
|
||||
darkThemeUri,
|
||||
MahAppsLibraryThemeProvider.DefaultInstance));
|
||||
|
||||
ResetTheme();
|
||||
ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ThemeSyncMode.SyncAll;
|
||||
ControlzEx.Theming.ThemeManager.Current.ThemeSyncMode = ControlzEx.Theming.ThemeSyncMode.SyncAll;
|
||||
ControlzEx.Theming.ThemeManager.Current.ThemeChanged += Current_ThemeChanged;
|
||||
}
|
||||
|
||||
@@ -90,67 +89,73 @@ namespace Wox.Plugin
|
||||
case "hcblack":
|
||||
return Theme.HighContrastBlack;
|
||||
default:
|
||||
return Theme.None;
|
||||
return Theme.HighContrastOne;
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetTheme()
|
||||
{
|
||||
if (WindowsThemeHelper.IsHighContrastEnabled())
|
||||
{
|
||||
Theme highContrastBaseType = GetHighContrastBaseType();
|
||||
ChangeTheme(highContrastBaseType);
|
||||
}
|
||||
else
|
||||
{
|
||||
string baseColor = WindowsThemeHelper.GetWindowsBaseColor();
|
||||
ChangeTheme((Theme)Enum.Parse(typeof(Theme), baseColor));
|
||||
}
|
||||
ChangeTheme(currentTheme, false);
|
||||
}
|
||||
|
||||
private void ChangeTheme(Theme theme)
|
||||
public void ChangeTheme(Theme theme, bool forceSystem)
|
||||
{
|
||||
Theme oldTheme = currentTheme;
|
||||
|
||||
if (theme == Theme.HighContrastOne)
|
||||
if (theme == Theme.System)
|
||||
{
|
||||
currentTheme = Theme.System;
|
||||
if (ControlzEx.Theming.WindowsThemeHelper.IsHighContrastEnabled())
|
||||
{
|
||||
Theme highContrastBaseType = GetHighContrastBaseType();
|
||||
ChangeTheme(highContrastBaseType, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
string baseColor = ControlzEx.Theming.WindowsThemeHelper.GetWindowsBaseColor();
|
||||
ChangeTheme((Theme)Enum.Parse(typeof(Theme), baseColor), true);
|
||||
}
|
||||
}
|
||||
else if (theme == Theme.HighContrastOne)
|
||||
{
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastOneTheme);
|
||||
currentTheme = Theme.HighContrastOne;
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastOneTheme);
|
||||
}
|
||||
else if (theme == Theme.HighContrastTwo)
|
||||
{
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastTwoTheme);
|
||||
currentTheme = Theme.HighContrastTwo;
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastTwoTheme);
|
||||
}
|
||||
else if (theme == Theme.HighContrastWhite)
|
||||
{
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastWhiteTheme);
|
||||
currentTheme = Theme.HighContrastWhite;
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastWhiteTheme);
|
||||
}
|
||||
else if (theme == Theme.HighContrastBlack)
|
||||
{
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastBlackTheme);
|
||||
currentTheme = Theme.HighContrastBlack;
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, HighContrastBlackTheme);
|
||||
}
|
||||
else if (theme == Theme.Light)
|
||||
{
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, LightTheme);
|
||||
currentTheme = Theme.Light;
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, LightTheme);
|
||||
}
|
||||
else if (theme == Theme.Dark)
|
||||
{
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, DarkTheme);
|
||||
currentTheme = Theme.Dark;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentTheme = Theme.None;
|
||||
ControlzEx.Theming.ThemeManager.Current.ChangeTheme(_app, DarkTheme);
|
||||
}
|
||||
|
||||
ThemeChanged?.Invoke(oldTheme, currentTheme);
|
||||
|
||||
if (forceSystem)
|
||||
{
|
||||
currentTheme = Theme.System;
|
||||
}
|
||||
}
|
||||
|
||||
private void Current_ThemeChanged(object sender, ThemeChangedEventArgs e)
|
||||
private void Current_ThemeChanged(object sender, ControlzEx.Theming.ThemeChangedEventArgs e)
|
||||
{
|
||||
ResetTheme();
|
||||
}
|
||||
@@ -175,15 +180,4 @@ namespace Wox.Plugin
|
||||
}
|
||||
|
||||
public delegate void ThemeChangedHandler(Theme oldTheme, Theme newTheme);
|
||||
|
||||
public enum Theme
|
||||
{
|
||||
None,
|
||||
Light,
|
||||
Dark,
|
||||
HighContrastOne,
|
||||
HighContrastTwo,
|
||||
HighContrastBlack,
|
||||
HighContrastWhite,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\common\ManagedCommon\ManagedCommon.csproj" />
|
||||
<ProjectReference Include="..\..\..\core\Microsoft.PowerToys.Settings.UI.Library\Microsoft.PowerToys.Settings.UI.Library.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user