mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
This PR introduces user settings for app mode themes (dark, light, or
system) and background customization options, including custom colors,
system accent colors, or custom images.
- Adds a new page to the Settings window with new appearance settings
and moves some existing settings there as well.
- Introduces a new core-level service abstraction, `IThemeService`, that
holds the state for the current theme.
- Uses the helper class `ResourceSwapper` to update application-level
XAML resources. The way WinUI / XAML handles these is painful, and XAML
Hot Reload is pain². Initialization must be lazy, as XAML resources can
only be accessed after the window is activated.
- `ThemeService` takes app and system settings and selects one of the
registered `IThemeProvider`s to calculate visuals and choose the
appropriate XAML resources.
- At the moment, there are two:
- `NormalThemeProvider`
- Provides the current uncolorized light and dark styles
- `ms-appx:///Styles/Theme.Normal.xaml`
- `ColorfulThemeProvider`
- Style that matches the Windows 11 visual style (based on the Start
menu) and colors
- `ms-appx:///Styles/Theme.Colorful.xaml`
- Applied when the background is colorized or a background image is
selected
- The app theme is applied only on the main window
(`WindowThemeSynchronizer` helper class can be used to synchronize other
windows if needed).
- Adds a new dependency on `Microsoft.Graphics.Win2D`.
- Adds a custom color picker popup; the one from the Community Toolkit
occasionally loses the selected color.
- Flyby: separates the keyword tag and localizable label for pages in
the Settings window navigation.
## Pictures? Pictures!
<img width="2027" height="1276" alt="image"
src="https://github.com/user-attachments/assets/e3485c71-7faa-495b-b455-b313ea6046ee"
/>
<img width="3776" height="2025" alt="image"
src="https://github.com/user-attachments/assets/820fa823-34d4-426d-b066-b1049dc3266f"
/>
Matching Windows accent color and tint:
<img width="3840" height="2160" alt="image"
src="https://github.com/user-attachments/assets/65f3b608-e282-4894-b7c8-e014a194f11f"
/>
<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
- [x] Closes: #38444
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx
<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
---------
Co-authored-by: Niels Laute <niels.laute@live.nl>
212 lines
5.4 KiB
C#
212 lines
5.4 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using Microsoft.CmdPal.Core.Common.Services;
|
|
using Microsoft.CmdPal.UI.ViewModels.Services;
|
|
using Microsoft.CmdPal.UI.ViewModels.Settings;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Microsoft.CmdPal.UI.ViewModels;
|
|
|
|
public partial class SettingsViewModel : INotifyPropertyChanged
|
|
{
|
|
private static readonly List<TimeSpan> AutoGoHomeIntervals =
|
|
[
|
|
Timeout.InfiniteTimeSpan,
|
|
TimeSpan.Zero,
|
|
TimeSpan.FromSeconds(10),
|
|
TimeSpan.FromSeconds(20),
|
|
TimeSpan.FromSeconds(30),
|
|
TimeSpan.FromSeconds(60),
|
|
TimeSpan.FromSeconds(90),
|
|
TimeSpan.FromSeconds(120),
|
|
TimeSpan.FromSeconds(180),
|
|
];
|
|
|
|
private readonly SettingsModel _settings;
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
public AppearanceSettingsViewModel Appearance { get; }
|
|
|
|
public HotkeySettings? Hotkey
|
|
{
|
|
get => _settings.Hotkey;
|
|
set
|
|
{
|
|
_settings.Hotkey = value ?? SettingsModel.DefaultActivationShortcut;
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Hotkey)));
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public bool UseLowLevelGlobalHotkey
|
|
{
|
|
get => _settings.UseLowLevelGlobalHotkey;
|
|
set
|
|
{
|
|
_settings.UseLowLevelGlobalHotkey = value;
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Hotkey)));
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public bool AllowExternalReload
|
|
{
|
|
get => _settings.AllowExternalReload;
|
|
set
|
|
{
|
|
_settings.AllowExternalReload = value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public bool ShowAppDetails
|
|
{
|
|
get => _settings.ShowAppDetails;
|
|
set
|
|
{
|
|
_settings.ShowAppDetails = value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public bool BackspaceGoesBack
|
|
{
|
|
get => _settings.BackspaceGoesBack;
|
|
set
|
|
{
|
|
_settings.BackspaceGoesBack = value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public bool SingleClickActivates
|
|
{
|
|
get => _settings.SingleClickActivates;
|
|
set
|
|
{
|
|
_settings.SingleClickActivates = value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public bool HighlightSearchOnActivate
|
|
{
|
|
get => _settings.HighlightSearchOnActivate;
|
|
set
|
|
{
|
|
_settings.HighlightSearchOnActivate = value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public int MonitorPositionIndex
|
|
{
|
|
get => (int)_settings.SummonOn;
|
|
set
|
|
{
|
|
_settings.SummonOn = (MonitorBehavior)value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public bool ShowSystemTrayIcon
|
|
{
|
|
get => _settings.ShowSystemTrayIcon;
|
|
set
|
|
{
|
|
_settings.ShowSystemTrayIcon = value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public bool IgnoreShortcutWhenFullscreen
|
|
{
|
|
get => _settings.IgnoreShortcutWhenFullscreen;
|
|
set
|
|
{
|
|
_settings.IgnoreShortcutWhenFullscreen = value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public bool DisableAnimations
|
|
{
|
|
get => _settings.DisableAnimations;
|
|
set
|
|
{
|
|
_settings.DisableAnimations = value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public int AutoGoBackIntervalIndex
|
|
{
|
|
get
|
|
{
|
|
var index = AutoGoHomeIntervals.IndexOf(_settings.AutoGoHomeInterval);
|
|
return index >= 0 ? index : 0;
|
|
}
|
|
|
|
set
|
|
{
|
|
if (value >= 0 && value < AutoGoHomeIntervals.Count)
|
|
{
|
|
_settings.AutoGoHomeInterval = AutoGoHomeIntervals[value];
|
|
}
|
|
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public int EscapeKeyBehaviorIndex
|
|
{
|
|
get => (int)_settings.EscapeKeyBehaviorSetting;
|
|
set
|
|
{
|
|
_settings.EscapeKeyBehaviorSetting = (EscapeKeyBehavior)value;
|
|
Save();
|
|
}
|
|
}
|
|
|
|
public ObservableCollection<ProviderSettingsViewModel> CommandProviders { get; } = [];
|
|
|
|
public SettingsExtensionsViewModel Extensions { get; }
|
|
|
|
public SettingsViewModel(SettingsModel settings, IServiceProvider serviceProvider, TaskScheduler scheduler)
|
|
{
|
|
_settings = settings;
|
|
_serviceProvider = serviceProvider;
|
|
|
|
var themeService = serviceProvider.GetRequiredService<IThemeService>();
|
|
Appearance = new AppearanceSettingsViewModel(themeService, _settings);
|
|
|
|
var activeProviders = GetCommandProviders();
|
|
var allProviderSettings = _settings.ProviderSettings;
|
|
|
|
foreach (var item in activeProviders)
|
|
{
|
|
var providerSettings = settings.GetProviderSettings(item);
|
|
|
|
var settingsModel = new ProviderSettingsViewModel(item, providerSettings, _serviceProvider);
|
|
CommandProviders.Add(settingsModel);
|
|
}
|
|
|
|
Extensions = new SettingsExtensionsViewModel(CommandProviders, scheduler);
|
|
}
|
|
|
|
private IEnumerable<CommandProviderWrapper> GetCommandProviders()
|
|
{
|
|
var manager = _serviceProvider.GetService<TopLevelCommandManager>()!;
|
|
var allProviders = manager.CommandProviders;
|
|
return allProviders;
|
|
}
|
|
|
|
private void Save() => SettingsModel.SaveSettings(_settings);
|
|
}
|