// 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 Common.UI;
namespace PowerToys.ModuleContracts;
///
/// Base contract for PowerToys modules exposed to the Command Palette.
///
public interface IModuleService
{
///
/// Gets module identifier (e.g., Workspaces, Awake).
///
string Key { get; }
Task LaunchAsync(CancellationToken cancellationToken = default);
Task OpenSettingsAsync(CancellationToken cancellationToken = default);
}
///
/// Helper base to reduce duplication for simple modules.
///
public abstract class ModuleServiceBase : IModuleService
{
public abstract string Key { get; }
protected abstract SettingsDeepLink.SettingsWindow SettingsWindow { get; }
public abstract Task LaunchAsync(CancellationToken cancellationToken = default);
public virtual Task OpenSettingsAsync(CancellationToken cancellationToken = default)
{
try
{
SettingsDeepLink.OpenSettings(SettingsWindow);
return Task.FromResult(OperationResult.Ok());
}
catch (Exception ex)
{
return Task.FromResult(OperationResult.Fail($"Failed to open settings for {Key}: {ex.Message}"));
}
}
}