mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-29 08:29:10 +01:00
Compare commits
6 Commits
update-tel
...
yuleng/cmd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5075610831 | ||
|
|
ffe69f7a99 | ||
|
|
a75d9fb9a0 | ||
|
|
26846772b6 | ||
|
|
efb25be698 | ||
|
|
209abd834e |
@@ -4,6 +4,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace Microsoft.CmdPal.Core.Common.Services;
|
||||
@@ -27,6 +28,12 @@ public interface IExtensionService
|
||||
|
||||
void DisableExtension(string extensionUniqueId);
|
||||
|
||||
/// <summary>
|
||||
/// Notifies all extensions that support the HostSettings capability about a settings change.
|
||||
/// </summary>
|
||||
/// <param name="settings">The updated host settings.</param>
|
||||
void NotifyHostSettingsChanged(IHostSettings settings);
|
||||
|
||||
///// <summary>
|
||||
///// Gets a boolean indicating whether the extension was disabled due to the corresponding Windows optional feature
|
||||
///// being absent from the machine or in an unknown state.
|
||||
|
||||
@@ -110,4 +110,10 @@ public interface IExtensionWrapper
|
||||
/// <returns>Nullable instance of the provider</returns>
|
||||
Task<IEnumerable<T>> GetListOfProvidersAsync<T>()
|
||||
where T : class;
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the extension that host settings have changed.
|
||||
/// </summary>
|
||||
/// <param name="settings">The updated host settings.</param>
|
||||
void NotifyHostSettingsChanged(IHostSettings settings);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.CmdPal.Core.Common;
|
||||
using Microsoft.CmdPal.Core.Common.Services;
|
||||
using Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.Foundation;
|
||||
@@ -13,6 +14,12 @@ namespace Microsoft.CmdPal.Core.ViewModels;
|
||||
|
||||
public abstract partial class AppExtensionHost : IExtensionHost
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a function that returns the current IHostSettings.
|
||||
/// This is set by the application to provide settings to extensions.
|
||||
/// </summary>
|
||||
public static Func<IHostSettings?>? GetHostSettingsFunc { get; set; }
|
||||
|
||||
private static readonly GlobalLogPageContext _globalLogPageContext = new();
|
||||
|
||||
private static ulong _hostingHwnd;
|
||||
|
||||
@@ -214,10 +214,52 @@ public sealed class CommandProviderWrapper
|
||||
Logger.LogDebug($"Provider supports {apiExtensions.Length} extensions");
|
||||
foreach (var a in apiExtensions)
|
||||
{
|
||||
if (a is IExtendedAttributesProvider command2)
|
||||
if (a is IExtendedAttributesProvider)
|
||||
{
|
||||
Logger.LogDebug($"{ProviderId}: Found an IExtendedAttributesProvider");
|
||||
}
|
||||
|
||||
if (a is IHostSettingsChanged)
|
||||
{
|
||||
Logger.LogDebug($"{ProviderId}: Found an IHostSettingsChanged");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the initial host settings to the provider.
|
||||
/// For extensions, this goes through ExtensionWrapper (cross-process).
|
||||
/// For built-in commands, this calls the handler directly (in-proc).
|
||||
/// </summary>
|
||||
public void SendInitialHostSettings()
|
||||
{
|
||||
var settings = AppExtensionHost.GetHostSettingsFunc?.Invoke();
|
||||
if (settings == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (Extension != null)
|
||||
{
|
||||
// OOP extension: send through ExtensionWrapper (cross-process)
|
||||
Extension.NotifyHostSettingsChanged(settings);
|
||||
Logger.LogDebug($"{ProviderId}: Sent initial host settings via ExtensionWrapper");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Built-in command: call directly (in-proc)
|
||||
if (_commandProvider.Unsafe is IHostSettingsChanged handler)
|
||||
{
|
||||
handler.OnHostSettingsChanged(settings);
|
||||
Logger.LogDebug($"{ProviderId}: Sent initial host settings directly");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogDebug($"Failed to send initial settings to {ProviderId}: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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 Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
namespace Microsoft.CmdPal.UI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// Provides conversion between SettingsModel and IHostSettings for extension communication.
|
||||
/// </summary>
|
||||
public static class HostSettingsConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a SettingsModel to an IHostSettings object that can be passed to extensions.
|
||||
/// </summary>
|
||||
/// <param name="settings">The settings model to convert.</param>
|
||||
/// <returns>An IHostSettings object with the current settings values.</returns>
|
||||
public static IHostSettings ToHostSettings(this SettingsModel settings)
|
||||
{
|
||||
return new HostSettings
|
||||
{
|
||||
Hotkey = settings.Hotkey?.ToString() ?? string.Empty,
|
||||
ShowAppDetails = settings.ShowAppDetails,
|
||||
HotkeyGoesHome = settings.HotkeyGoesHome,
|
||||
BackspaceGoesBack = settings.BackspaceGoesBack,
|
||||
SingleClickActivates = settings.SingleClickActivates,
|
||||
HighlightSearchOnActivate = settings.HighlightSearchOnActivate,
|
||||
ShowSystemTrayIcon = settings.ShowSystemTrayIcon,
|
||||
IgnoreShortcutWhenFullscreen = settings.IgnoreShortcutWhenFullscreen,
|
||||
DisableAnimations = settings.DisableAnimations,
|
||||
SummonOn = ConvertSummonTarget(settings.SummonOn),
|
||||
};
|
||||
}
|
||||
|
||||
private static SummonTarget ConvertSummonTarget(MonitorBehavior behavior)
|
||||
{
|
||||
return behavior switch
|
||||
{
|
||||
MonitorBehavior.ToMouse => SummonTarget.ToMouse,
|
||||
MonitorBehavior.ToPrimary => SummonTarget.ToPrimary,
|
||||
MonitorBehavior.ToFocusedWindow => SummonTarget.ToFocusedWindow,
|
||||
MonitorBehavior.InPlace => SummonTarget.InPlace,
|
||||
MonitorBehavior.ToLast => SummonTarget.ToLast,
|
||||
_ => SummonTarget.ToMouse,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -400,6 +400,29 @@ public partial class ExtensionService : IExtensionService, IDisposable
|
||||
_enabledExtensions.Remove(extension.First());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notifies all extensions about a settings change.
|
||||
/// </summary>
|
||||
/// <param name="settings">The updated host settings.</param>
|
||||
public void NotifyHostSettingsChanged(IHostSettings settings)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
var extensions = await GetInstalledExtensionsAsync();
|
||||
foreach (var extension in extensions)
|
||||
{
|
||||
try
|
||||
{
|
||||
extension.NotifyHostSettingsChanged(settings);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"Failed to notify extension {extension.ExtensionUniqueId} of settings change", ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
///// <inheritdoc cref="IExtensionService.DisableExtensionIfWindowsFeatureNotAvailable(IExtensionWrapper)"/>
|
||||
//public async Task<bool> DisableExtensionIfWindowsFeatureNotAvailable(IExtensionWrapper extension)
|
||||
|
||||
@@ -201,4 +201,37 @@ public class ExtensionWrapper : IExtensionWrapper
|
||||
public void AddProviderType(ProviderType providerType) => _providerTypes.Add(providerType);
|
||||
|
||||
public bool HasProviderType(ProviderType providerType) => _providerTypes.Contains(providerType);
|
||||
|
||||
/// <summary>
|
||||
/// Notifies the extension that host settings have changed.
|
||||
/// </summary>
|
||||
/// <param name="settings">The updated host settings.</param>
|
||||
public void NotifyHostSettingsChanged(IHostSettings settings)
|
||||
{
|
||||
try
|
||||
{
|
||||
var provider = GetExtensionObject()?.GetProvider(ProviderType.Commands);
|
||||
if (provider is not ICommandProvider2 provider2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the IHostSettingsChanged handler from GetApiExtensionStubs().
|
||||
// This pattern works reliably in OOP scenarios because the stub objects
|
||||
// are properly marshalled across the process boundary.
|
||||
var apiExtensions = provider2.GetApiExtensionStubs();
|
||||
foreach (var stub in apiExtensions)
|
||||
{
|
||||
if (stub is IHostSettingsChanged handler)
|
||||
{
|
||||
handler.OnHostSettingsChanged(settings);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogDebug($"Failed to notify {ExtensionDisplayName} of settings change: {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,9 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
|
||||
await commandProvider.LoadTopLevelCommands(_serviceProvider, weakSelf);
|
||||
|
||||
// Send initial host settings after the provider is fully initialized
|
||||
commandProvider.SendInitialHostSettings();
|
||||
|
||||
var commands = await Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
|
||||
@@ -160,10 +160,23 @@ public partial class App : Application
|
||||
services.AddSingleton(sm);
|
||||
var state = AppStateModel.LoadState();
|
||||
services.AddSingleton(state);
|
||||
services.AddSingleton<IExtensionService, ExtensionService>();
|
||||
var extensionService = new ExtensionService();
|
||||
services.AddSingleton<IExtensionService>(extensionService);
|
||||
services.AddSingleton<TrayIconService>();
|
||||
services.AddSingleton<IRunHistoryService, RunHistoryService>();
|
||||
|
||||
// Set up host settings for extensions
|
||||
AppExtensionHost.GetHostSettingsFunc = () => sm.ToHostSettings();
|
||||
|
||||
// Subscribe to settings changes and notify extensions
|
||||
sm.SettingsChanged += (sender, _) =>
|
||||
{
|
||||
if (sender is SettingsModel settings)
|
||||
{
|
||||
extensionService.NotifyHostSettingsChanged(settings.ToHostSettings());
|
||||
}
|
||||
};
|
||||
|
||||
services.AddSingleton<IRootPageService, PowerToysRootPageService>();
|
||||
services.AddSingleton<IAppHostService, PowerToysAppHostService>();
|
||||
services.AddSingleton<ITelemetryService, TelemetryForwarder>();
|
||||
|
||||
@@ -68,6 +68,7 @@ functionality.
|
||||
- [Fallback commands](#fallback-commands)
|
||||
- [`GetCommand`](#getcommand)
|
||||
- [Settings](#settings)
|
||||
- [Host Settings Awareness](#host-settings-awareness)
|
||||
- [Helper SDK Classes](#helper-sdk-classes)
|
||||
- [Default implementations](#default-implementations)
|
||||
- [Using the Clipboard](#using-the-clipboard)
|
||||
@@ -1639,6 +1640,59 @@ We're then additionally going to provide a collection of
|
||||
should allow developers to quickly work to add settings, without mucking around
|
||||
in building the form JSON themselves.
|
||||
|
||||
##### Host Settings Awareness
|
||||
|
||||
Extensions can access the Command Palette's global configuration through the
|
||||
`HostSettingsManager` class provided by the Toolkit. This allows extensions to
|
||||
read user preferences like the global hotkey, animation settings, and more.
|
||||
|
||||
**Reading Current Settings**
|
||||
|
||||
Use `HostSettingsManager.Current` to get the current host settings:
|
||||
|
||||
```cs
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
// Get current settings - this is the primary way to access host configuration
|
||||
var settings = HostSettingsManager.Current;
|
||||
|
||||
// Access individual settings
|
||||
var hotkey = settings.Hotkey; // e.g., "Win+Alt+Space"
|
||||
var disableAnimations = settings.DisableAnimations;
|
||||
var singleClick = settings.SingleClickActivates;
|
||||
var summonTarget = settings.SummonOn; // ToMouse, ToPrimary, etc.
|
||||
```
|
||||
|
||||
Available properties on `HostSettingsManager.Current`:
|
||||
|
||||
| Property | Type | Description |
|
||||
|----------|------|-------------|
|
||||
| `Hotkey` | `string` | Global summon hotkey |
|
||||
| `ShowAppDetails` | `bool` | Show app details in UI |
|
||||
| `HotkeyGoesHome` | `bool` | Hotkey returns to home page |
|
||||
| `BackspaceGoesBack` | `bool` | Backspace navigates back |
|
||||
| `SingleClickActivates` | `bool` | Single-click activation |
|
||||
| `HighlightSearchOnActivate` | `bool` | Highlight search on activate |
|
||||
| `ShowSystemTrayIcon` | `bool` | Show system tray icon |
|
||||
| `IgnoreShortcutWhenFullscreen` | `bool` | Ignore hotkey in fullscreen |
|
||||
| `DisableAnimations` | `bool` | Animations disabled |
|
||||
| `SummonOn` | `SummonTarget` | Monitor positioning behavior |
|
||||
|
||||
|
||||
**Responding to Changes (Optional)**
|
||||
|
||||
If your extension needs to update when settings change, subscribe to
|
||||
`HostSettingsManager.SettingsChanged`:
|
||||
|
||||
```cs
|
||||
HostSettingsManager.SettingsChanged += () =>
|
||||
{
|
||||
// Re-read settings and update your UI
|
||||
var settings = HostSettingsManager.Current;
|
||||
RaiseItemsChanged();
|
||||
};
|
||||
```
|
||||
|
||||
## Helper SDK Classes
|
||||
|
||||
As a part of the `Microsoft.CommandPalette.Extensions` namespace, we'll provide a set of
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// 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 Microsoft.CommandPalette.Extensions;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
namespace SamplePagesExtension;
|
||||
|
||||
/// <summary>
|
||||
/// A sample page that displays the current Host Settings values.
|
||||
/// This demonstrates how extensions can access and display the Command Palette's global settings.
|
||||
/// </summary>
|
||||
internal sealed partial class HostSettingsPage : ListPage
|
||||
{
|
||||
public HostSettingsPage()
|
||||
{
|
||||
Icon = new IconInfo("\uE713"); // Settings icon
|
||||
Name = "Host Settings";
|
||||
Title = "Current Host Settings";
|
||||
|
||||
// Subscribe to settings changes to refresh the page when settings are updated
|
||||
HostSettingsManager.SettingsChanged += OnSettingsChanged;
|
||||
ExtensionHost.LogMessage($"[HostSettingsPage] Constructor called, subscribed to SettingsChanged");
|
||||
}
|
||||
|
||||
private void OnSettingsChanged()
|
||||
{
|
||||
ExtensionHost.LogMessage($"[HostSettingsPage] OnSettingsChanged called, invoking RaiseItemsChanged");
|
||||
|
||||
// Notify the UI to refresh the items list
|
||||
RaiseItemsChanged(0);
|
||||
ExtensionHost.LogMessage($"[HostSettingsPage] RaiseItemsChanged completed");
|
||||
}
|
||||
|
||||
public override IListItem[] GetItems()
|
||||
{
|
||||
ExtensionHost.LogMessage($"[HostSettingsPage] GetItems called");
|
||||
var settings = HostSettingsManager.Current;
|
||||
|
||||
if (settings == null)
|
||||
{
|
||||
return [
|
||||
new ListItem(new NoOpCommand())
|
||||
{
|
||||
Title = "Host Settings not available",
|
||||
Subtitle = "Settings have not been received from the host yet",
|
||||
Icon = new IconInfo("\uE7BA"), // Warning icon
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
CreateSettingItem("Hotkey", settings.Hotkey, "\uE765"), // Keyboard icon
|
||||
CreateSettingItem("Show App Details", settings.ShowAppDetails, "\uE946"), // View icon
|
||||
CreateSettingItem("Hotkey Goes Home", settings.HotkeyGoesHome, "\uE80F"), // Home icon
|
||||
CreateSettingItem("Backspace Goes Back", settings.BackspaceGoesBack, "\uE72B"), // Back icon
|
||||
CreateSettingItem("Single Click Activates", settings.SingleClickActivates, "\uE8B0"), // Mouse icon
|
||||
CreateSettingItem("Highlight Search On Activate", settings.HighlightSearchOnActivate, "\uE8D6"), // Highlight icon
|
||||
CreateSettingItem("Show System Tray Icon", settings.ShowSystemTrayIcon, "\uE8A5"), // System icon
|
||||
CreateSettingItem("Ignore Shortcut When Fullscreen", settings.IgnoreShortcutWhenFullscreen, "\uE740"), // Fullscreen icon
|
||||
CreateSettingItem("Disable Animations", settings.DisableAnimations, "\uE916"), // Play icon
|
||||
CreateSettingItem("Summon On", settings.SummonOn.ToString(), "\uE7C4"), // Position icon
|
||||
];
|
||||
}
|
||||
|
||||
private static ListItem CreateSettingItem(string name, object value, string iconGlyph)
|
||||
{
|
||||
var displayValue = value switch
|
||||
{
|
||||
bool b => b ? "Enabled" : "Disabled",
|
||||
string s when string.IsNullOrEmpty(s) => "(not set)",
|
||||
_ => value?.ToString() ?? "null",
|
||||
};
|
||||
|
||||
return new ListItem(new NoOpCommand())
|
||||
{
|
||||
Title = name,
|
||||
Subtitle = displayValue,
|
||||
Icon = new IconInfo(iconGlyph),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,14 @@ public partial class SamplesListPage : ListPage
|
||||
Subtitle = "A demo of the settings helpers",
|
||||
},
|
||||
|
||||
// Host Settings
|
||||
new ListItem(new HostSettingsPage())
|
||||
{
|
||||
Title = "Host Settings",
|
||||
Subtitle = "View current Command Palette host settings",
|
||||
Icon = new IconInfo("\uE713"), // Settings icon
|
||||
},
|
||||
|
||||
// Evil edge cases
|
||||
// Anything weird that might break the palette - put that in here.
|
||||
new ListItem(new EvilSamplesPage())
|
||||
|
||||
@@ -6,7 +6,7 @@ using Windows.Foundation;
|
||||
|
||||
namespace Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
public abstract partial class CommandProvider : ICommandProvider, ICommandProvider2
|
||||
public abstract partial class CommandProvider : ICommandProvider, ICommandProvider2, IHostSettingsChanged
|
||||
{
|
||||
public virtual string Id { get; protected set; } = string.Empty;
|
||||
|
||||
@@ -30,6 +30,16 @@ public abstract partial class CommandProvider : ICommandProvider, ICommandProvid
|
||||
|
||||
public virtual void InitializeWithHost(IExtensionHost host) => ExtensionHost.Initialize(host);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the host settings have changed. Override this method to respond to settings changes.
|
||||
/// The base implementation updates the HostSettingsManager cache.
|
||||
/// </summary>
|
||||
/// <param name="settings">The updated host settings.</param>
|
||||
public virtual void OnHostSettingsChanged(IHostSettings settings)
|
||||
{
|
||||
HostSettingsManager.Update(settings);
|
||||
}
|
||||
|
||||
#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
|
||||
public virtual void Dispose()
|
||||
{
|
||||
@@ -57,7 +67,7 @@ public abstract partial class CommandProvider : ICommandProvider, ICommandProvid
|
||||
/// <returns>an array of objects that implement all the leaf interfaces we support</returns>
|
||||
public object[] GetApiExtensionStubs()
|
||||
{
|
||||
return [new SupportCommandsWithProperties()];
|
||||
return [new SupportCommandsWithProperties(), new HostSettingsChangedHandler(this)];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,4 +79,18 @@ public abstract partial class CommandProvider : ICommandProvider, ICommandProvid
|
||||
{
|
||||
public IDictionary<string, object>? GetProperties() => null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A stub class which implements IHostSettingsChanged. This is marshalled across
|
||||
/// the ABI so that the host can call OnHostSettingsChanged on this object,
|
||||
/// which then delegates to the CommandProvider's OnHostSettingsChanged method.
|
||||
/// </summary>
|
||||
private sealed partial class HostSettingsChangedHandler : IHostSettingsChanged
|
||||
{
|
||||
private readonly CommandProvider _provider;
|
||||
|
||||
public HostSettingsChangedHandler(CommandProvider provider) => _provider = provider;
|
||||
|
||||
public void OnHostSettingsChanged(IHostSettings settings) => _provider.OnHostSettingsChanged(settings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
/// <summary>
|
||||
/// Concrete implementation of IHostSettings for the Command Palette host settings.
|
||||
/// This class is used by the host to create settings objects that can be passed to extensions.
|
||||
/// </summary>
|
||||
public partial class HostSettings : IHostSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the global hotkey for summoning the Command Palette.
|
||||
/// </summary>
|
||||
public string Hotkey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to show app details in the UI.
|
||||
/// </summary>
|
||||
public bool ShowAppDetails { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether pressing the hotkey goes to the home page.
|
||||
/// </summary>
|
||||
public bool HotkeyGoesHome { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether backspace navigates back.
|
||||
/// </summary>
|
||||
public bool BackspaceGoesBack { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether single click activates items.
|
||||
/// </summary>
|
||||
public bool SingleClickActivates { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to highlight the search box on activation.
|
||||
/// </summary>
|
||||
public bool HighlightSearchOnActivate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to show the system tray icon.
|
||||
/// </summary>
|
||||
public bool ShowSystemTrayIcon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to ignore the shortcut when in fullscreen mode.
|
||||
/// </summary>
|
||||
public bool IgnoreShortcutWhenFullscreen { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether animations are disabled.
|
||||
/// </summary>
|
||||
public bool DisableAnimations { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the target monitor behavior when summoning the Command Palette.
|
||||
/// </summary>
|
||||
public SummonTarget SummonOn { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
|
||||
/// <summary>
|
||||
/// Provides static access to the current Command Palette host settings.
|
||||
/// Extensions can use this class to read the current settings values and respond to changes.
|
||||
/// </summary>
|
||||
public static class HostSettingsManager
|
||||
{
|
||||
private static IHostSettings? _current;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the host settings have changed.
|
||||
/// Extensions can subscribe to this event to refresh their UI when settings are updated.
|
||||
/// </summary>
|
||||
public static event Action? SettingsChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current host settings, or null if not yet initialized.
|
||||
/// </summary>
|
||||
public static IHostSettings? Current => _current;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether host settings are available.
|
||||
/// Returns false if the extension is running with an older host that doesn't support settings.
|
||||
/// </summary>
|
||||
public static bool IsAvailable => _current != null;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the cached host settings. Called internally when settings change.
|
||||
/// </summary>
|
||||
/// <param name="settings">The updated host settings.</param>
|
||||
internal static void Update(IHostSettings settings)
|
||||
{
|
||||
_current = settings;
|
||||
SettingsChanged?.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -391,6 +391,53 @@ namespace Microsoft.CommandPalette.Extensions
|
||||
{
|
||||
Object[] GetApiExtensionStubs();
|
||||
};
|
||||
|
||||
|
||||
// =========================================================================
|
||||
// Host Settings and Capability System
|
||||
// =========================================================================
|
||||
|
||||
/// <summary>
|
||||
/// Represents the position behavior when summoning the Command Palette.
|
||||
/// </summary>
|
||||
[contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 1)]
|
||||
enum SummonTarget
|
||||
{
|
||||
ToMouse = 0,
|
||||
ToPrimary = 1,
|
||||
ToFocusedWindow = 2,
|
||||
InPlace = 3,
|
||||
ToLast = 4,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Interface for host settings that can be passed to extensions across process boundaries.
|
||||
/// Extensions can access these settings to adapt their behavior accordingly.
|
||||
/// The Toolkit provides a concrete HostSettings class that implements this interface.
|
||||
/// </summary>
|
||||
[contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 1)]
|
||||
interface IHostSettings
|
||||
{
|
||||
String Hotkey { get; };
|
||||
Boolean ShowAppDetails { get; };
|
||||
Boolean HotkeyGoesHome { get; };
|
||||
Boolean BackspaceGoesBack { get; };
|
||||
Boolean SingleClickActivates { get; };
|
||||
Boolean HighlightSearchOnActivate { get; };
|
||||
Boolean ShowSystemTrayIcon { get; };
|
||||
Boolean IgnoreShortcutWhenFullscreen { get; };
|
||||
Boolean DisableAnimations { get; };
|
||||
SummonTarget SummonOn { get; };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for extensions to receive notifications when host settings change.
|
||||
/// Extensions implementing this interface will be notified whenever the user
|
||||
/// modifies Command Palette settings, including initial settings on startup.
|
||||
/// </summary>
|
||||
[contract(Microsoft.CommandPalette.Extensions.ExtensionsContract, 1)]
|
||||
interface IHostSettingsChanged
|
||||
{
|
||||
void OnHostSettingsChanged(IHostSettings settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user