Files
PowerToys/src/settings-ui/Settings.UI.Library/EnabledModules.cs
Mike Griese f68f408be3 Add the Command Palette module (#37908)
Windows Command Palette ("CmdPal") is the next iteration of PowerToys Run. With extensibility at its core, the Command Palette is your one-stop launcher to start _anything_.

By default, CmdPal is bound to <kbd>Win+Alt+Space</kbd>.

![cmdpal-pr-002](https://github.com/user-attachments/assets/5077ec04-1009-478a-92d6-0a30989d44ac)
![cmdpal-pr-003](https://github.com/user-attachments/assets/63b4762a-9c19-48eb-9242-18ea48240ba0)

----

This brings the current preview version of CmdPal into the upstream PowerToys repo. There are still lots of bugs to work out, but it's reached the state we're ready to start sharing it with the world. From here, we can further collaborate with the community on the features that are important, and ensuring that we've got a most robust API to enable developers to build whatever extensions they want. 

Most of the built-in PT Run modules have already been ported to CmdPal's extension API. Those include:
* Installed apps
* Shell commands
* File search (powered by the indexer)
* Windows Registry search
* Web search
* Windows Terminal Profiles
* Windows Services
* Windows settings


There are a couple new extensions built-in
* You can now search for packages on `winget` and install them right from the palette. This also powers searching for extensions for the palette
* The calculator has an entirely new implementation. This is currently less feature complete than the original PT Run one - we're looking forward to updating it to be more complete for future ingestion in Windows
* "Bookmarks" allow you to save shortcuts to files, folders, and webpages as top-level commands in the palette. 

We've got a bunch of other samples too, in this repo and elsewhere

### PowerToys specific notes

CmdPal will eventually graduate out of PowerToys to live as its own application, which is why it's implemented just a little differently than most other modules. Enabling CmdPal will install its `msix` package. 

The CI was minorly changed to support CmdPal version numbers independent of PowerToys itself. It doesn't make sense for us to start CmdPal at v0.90, and in the future, we want to be able to rev CmdPal independently of PT itself. 


Closes #3200, closes #3600, closes #7770, closes #34273, closes #36471, closes #20976, closes #14495
  
  
-----

TODOs et al


**Blocking:**
- [ ] Images and descriptions in Settings and OOBE need to be properly defined, as mentioned before
  - [ ] Niels is on it
- [x] Doesn't start properly from PowerToys unless the fix PR is merged.
  - https://github.com/zadjii-msft/PowerToys/pull/556 merged
- [x] I seem to lose focus a lot when I press on some limits, like between the search bar and the results.
  - This is https://github.com/zadjii-msft/PowerToys/issues/427
- [x] Turned off an extension like Calculator and it was still working.
  - Need to get rid of that toggle, it doesn't do anything currently
- [x] `ListViewModel.<FetchItems>` crash
  - Pretty confident that was fixed in https://github.com/zadjii-msft/PowerToys/pull/553

**Not blocking / improvements:**
- Show the shortcut through settings, as mentioned before, or create a button that would open CmdPalette settings.
- When PowerToys starts, CmdPalette is always shown if enabled. That's weird when just starting PowerToys/ logging in to the computer with PowerToys auto-start activated. I think this should at least be a setting.
- Needing to double press a result for it to do the default action seems quirky. If one is already selected, I think just pressing should be enough for it to do the action.
  - This is currently a setting, though we're thinking of changing the setting even more: https://github.com/zadjii-msft/PowerToys/issues/392
- There's no URI extension. Was surprised when typing a URL that it only proposed a web search.
- [x] There's no System commands extension. Was expecting to be able to quickly restart the computer by typing restart but it wasn't there.
  - This is in PR https://github.com/zadjii-msft/PowerToys/pull/452  
  
---------

Co-authored-by: joadoumie <98557455+joadoumie@users.noreply.github.com>
Co-authored-by: Jordi Adoumie <jordiadoumie@microsoft.com>
Co-authored-by: Mike Griese <zadjii@gmail.com>
Co-authored-by: Niels Laute <niels.laute@live.nl>
Co-authored-by: Michael Hawker <24302614+michael-hawker@users.noreply.github.com>
Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com>
Co-authored-by: Seraphima <zykovas91@gmail.com>
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Kristen Schau <47155823+krschau@users.noreply.github.com>
Co-authored-by: Eric Johnson <ericjohnson327@gmail.com>
Co-authored-by: Ethan Fang <ethanfang@microsoft.com>
Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
Co-authored-by: Clint Rutkas <clint@rutkas.com>
2025-03-19 01:39:57 -07:00

542 lines
13 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;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.Telemetry;
using Microsoft.PowerToys.Telemetry;
namespace Microsoft.PowerToys.Settings.UI.Library
{
public class EnabledModules
{
private Action notifyEnabledChangedAction;
// Default values for enabled modules should match their expected "enabled by default" values.
// Otherwise, a run of DSC on clean settings will not match the expected default result.
public EnabledModules()
{
}
private bool fancyZones = true;
[JsonPropertyName("FancyZones")]
public bool FancyZones
{
get => fancyZones;
set
{
if (fancyZones != value)
{
LogTelemetryEvent(value);
fancyZones = value;
NotifyChange();
}
}
}
private bool imageResizer = true;
[JsonPropertyName("Image Resizer")]
public bool ImageResizer
{
get => imageResizer;
set
{
if (imageResizer != value)
{
LogTelemetryEvent(value);
imageResizer = value;
}
}
}
private bool fileExplorerPreview = true;
[JsonPropertyName("File Explorer Preview")]
public bool PowerPreview
{
get => fileExplorerPreview;
set
{
if (fileExplorerPreview != value)
{
LogTelemetryEvent(value);
fileExplorerPreview = value;
}
}
}
private bool shortcutGuide = true;
[JsonPropertyName("Shortcut Guide")]
public bool ShortcutGuide
{
get => shortcutGuide;
set
{
if (shortcutGuide != value)
{
LogTelemetryEvent(value);
shortcutGuide = value;
NotifyChange();
}
}
}
private bool powerRename = true;
public bool PowerRename
{
get => powerRename;
set
{
if (powerRename != value)
{
LogTelemetryEvent(value);
powerRename = value;
}
}
}
private bool keyboardManager; // defaulting to off
[JsonPropertyName("Keyboard Manager")]
public bool KeyboardManager
{
get => keyboardManager;
set
{
if (keyboardManager != value)
{
LogTelemetryEvent(value);
keyboardManager = value;
}
}
}
private bool powerLauncher = true;
[JsonPropertyName("PowerToys Run")]
public bool PowerLauncher
{
get => powerLauncher;
set
{
if (powerLauncher != value)
{
LogTelemetryEvent(value);
powerLauncher = value;
NotifyChange();
}
}
}
private bool colorPicker = true;
[JsonPropertyName("ColorPicker")]
public bool ColorPicker
{
get => colorPicker;
set
{
if (colorPicker != value)
{
LogTelemetryEvent(value);
colorPicker = value;
NotifyChange();
}
}
}
private bool cropAndLock = true;
[JsonPropertyName("CropAndLock")]
public bool CropAndLock
{
get => cropAndLock;
set
{
if (cropAndLock != value)
{
LogTelemetryEvent(value);
cropAndLock = value;
NotifyChange();
}
}
}
private bool awake = true;
[JsonPropertyName("Awake")]
public bool Awake
{
get => awake;
set
{
if (awake != value)
{
LogTelemetryEvent(value);
awake = value;
}
}
}
private bool mouseWithoutBorders; // defaulting to off
[JsonPropertyName("MouseWithoutBorders")]
public bool MouseWithoutBorders
{
get => mouseWithoutBorders;
set
{
if (mouseWithoutBorders != value)
{
LogTelemetryEvent(value);
mouseWithoutBorders = value;
}
}
}
private bool findMyMouse = true;
[JsonPropertyName("FindMyMouse")]
public bool FindMyMouse
{
get => findMyMouse;
set
{
if (findMyMouse != value)
{
LogTelemetryEvent(value);
findMyMouse = value;
}
}
}
private bool mouseHighlighter = true;
[JsonPropertyName("MouseHighlighter")]
public bool MouseHighlighter
{
get => mouseHighlighter;
set
{
if (mouseHighlighter != value)
{
LogTelemetryEvent(value);
mouseHighlighter = value;
}
}
}
private bool mouseJump; // defaulting to off
[JsonPropertyName("MouseJump")]
public bool MouseJump
{
get => mouseJump;
set
{
if (mouseJump != value)
{
LogTelemetryEvent(value);
mouseJump = value;
}
}
}
private bool alwaysOnTop = true;
[JsonPropertyName("AlwaysOnTop")]
public bool AlwaysOnTop
{
get => alwaysOnTop;
set
{
if (alwaysOnTop != value)
{
LogTelemetryEvent(value);
alwaysOnTop = value;
}
}
}
private bool mousePointerCrosshairs; // defaulting to off
[JsonPropertyName("MousePointerCrosshairs")]
public bool MousePointerCrosshairs
{
get => mousePointerCrosshairs;
set
{
if (mousePointerCrosshairs != value)
{
LogTelemetryEvent(value);
mousePointerCrosshairs = value;
}
}
}
private bool powerAccent; // defaulting to off
[JsonPropertyName("QuickAccent")]
public bool PowerAccent
{
get => powerAccent;
set
{
if (powerAccent != value)
{
LogTelemetryEvent(value);
powerAccent = value;
}
}
}
private bool powerOCR; // defaulting to off
[JsonPropertyName("TextExtractor")]
public bool PowerOcr
{
get => powerOCR;
set
{
if (powerOCR != value)
{
LogTelemetryEvent(value);
powerOCR = value;
NotifyChange();
}
}
}
private bool advancedPaste = true;
[JsonPropertyName("AdvancedPaste")]
public bool AdvancedPaste
{
get => advancedPaste;
set
{
if (advancedPaste != value)
{
LogTelemetryEvent(value);
advancedPaste = value;
NotifyChange();
}
}
}
private bool measureTool = true;
[JsonPropertyName("Measure Tool")]
public bool MeasureTool
{
get => measureTool;
set
{
if (measureTool != value)
{
LogTelemetryEvent(value);
measureTool = value;
NotifyChange();
}
}
}
private bool hosts = true;
[JsonPropertyName("Hosts")]
public bool Hosts
{
get => hosts;
set
{
if (hosts != value)
{
LogTelemetryEvent(value);
hosts = value;
NotifyChange();
}
}
}
private bool fileLocksmith = true;
[JsonPropertyName("File Locksmith")]
public bool FileLocksmith
{
get => fileLocksmith;
set
{
if (fileLocksmith != value)
{
LogTelemetryEvent(value);
fileLocksmith = value;
}
}
}
private bool peek = true;
[JsonPropertyName("Peek")]
public bool Peek
{
get => peek;
set
{
if (peek != value)
{
LogTelemetryEvent(value);
peek = value;
}
}
}
private bool registryPreview = true;
[JsonPropertyName("RegistryPreview")]
public bool RegistryPreview
{
get => registryPreview;
set
{
if (registryPreview != value)
{
LogTelemetryEvent(value);
registryPreview = value;
}
}
}
private bool cmdNotFound = true;
[JsonPropertyName("CmdNotFound")]
public bool CmdNotFound
{
get => cmdNotFound;
set
{
if (cmdNotFound != value)
{
LogTelemetryEvent(value);
cmdNotFound = value;
NotifyChange();
}
}
}
private bool environmentVariables = true;
[JsonPropertyName("EnvironmentVariables")]
public bool EnvironmentVariables
{
get => environmentVariables;
set
{
if (environmentVariables != value)
{
LogTelemetryEvent(value);
environmentVariables = value;
}
}
}
private bool newPlus;
[JsonPropertyName("NewPlus")] // This key must match newplus::constants::non_localizable
public bool NewPlus
{
get => newPlus;
set
{
if (newPlus != value)
{
LogTelemetryEvent(value);
newPlus = value;
}
}
}
private bool workspaces = true;
[JsonPropertyName("Workspaces")]
public bool Workspaces
{
get => workspaces;
set
{
if (workspaces != value)
{
LogTelemetryEvent(value);
workspaces = value;
NotifyChange();
}
}
}
private bool cmdPal = true;
[JsonPropertyName("CmdPal")]
public bool CmdPal
{
get => cmdPal;
set
{
if (cmdPal != value)
{
LogTelemetryEvent(value);
cmdPal = value;
}
}
}
private bool zoomIt;
[JsonPropertyName("ZoomIt")]
public bool ZoomIt
{
get => zoomIt;
set
{
if (zoomIt != value)
{
LogTelemetryEvent(value);
zoomIt = value;
NotifyChange();
}
}
}
private void NotifyChange()
{
notifyEnabledChangedAction?.Invoke();
}
public string ToJsonString()
{
return JsonSerializer.Serialize(this);
}
private static void LogTelemetryEvent(bool value, [CallerMemberName] string moduleName = null)
{
var dataEvent = new SettingsEnabledEvent()
{
Value = value,
Name = moduleName,
};
PowerToysTelemetry.Log.WriteEvent(dataEvent);
}
internal void AddEnabledModuleChangeNotification(Action callBack)
{
notifyEnabledChangedAction = callBack;
}
}
}