use winui3 icons

This commit is contained in:
vanzue
2025-12-11 17:03:40 +08:00
parent 609a687908
commit 538358b47b
12 changed files with 68 additions and 60 deletions

View File

@@ -52,6 +52,8 @@ internal static class AwakeCommandsFactory
Toast: "Awake timer set for 2 hours"),
];
private static readonly IconInfo AwakeIcon = PowerToysResourcesHelper.IconFromSettingsIcon("Awake.png");
internal static void PopulateModuleCommands(List<ICommandContextItem> moreCommands)
{
ArgumentNullException.ThrowIfNull(moreCommands);
@@ -76,7 +78,7 @@ internal static class AwakeCommandsFactory
{
Title = "Current status",
Subtitle = statusSubtitle,
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png"),
Icon = AwakeIcon,
};
results.Add(statusItem);
@@ -94,7 +96,7 @@ internal static class AwakeCommandsFactory
{
Title = preset.Title,
Subtitle = preset.Subtitle,
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png"),
Icon = AwakeIcon,
};
results.Add(item);
}
@@ -119,7 +121,7 @@ internal static class AwakeCommandsFactory
{
Title = title,
Subtitle = subtitle,
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png"),
Icon = AwakeIcon,
};
results.Add(item);
}
@@ -130,7 +132,7 @@ internal static class AwakeCommandsFactory
{
Title = "Bind Awake to another process",
Subtitle = "Stop automatically when the target process exits",
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png"),
Icon = AwakeIcon,
};
results.Add(new ListItem(processPageItem)
@@ -148,7 +150,7 @@ internal static class AwakeCommandsFactory
{
Title = "Set Awake to Off",
Subtitle = "Switch Awake to passive mode",
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png"),
Icon = AwakeIcon,
};
results.Add(stopItem);
}
@@ -160,7 +162,7 @@ internal static class AwakeCommandsFactory
{
Title = "Open Awake settings",
Subtitle = "Configure Awake inside PowerToys",
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png"),
Icon = AwakeIcon,
};
results.Add(settingsItem);
}
@@ -207,7 +209,7 @@ internal static class AwakeCommandsFactory
{
Title = title,
Subtitle = "Keep the PC awake while this process is running",
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png"),
Icon = AwakeIcon,
};
results.Add(item);
}

View File

@@ -9,48 +9,52 @@ namespace PowerToysExtension.Helpers;
internal static class PowerToysResourcesHelper
{
public static IconInfo ProviderIcon() => IconHelpers.FromRelativePath("Assets\\PowerToys.png");
private const string SettingsIconRoot = "WinUI3Apps\\Assets\\Settings\\Icons\\";
internal static IconInfo IconFromSettingsIcon(string fileName) => IconHelpers.FromRelativePath($"{SettingsIconRoot}{fileName}");
public static IconInfo ProviderIcon() => IconFromSettingsIcon("PowerToys.png");
public static IconInfo ModuleIcon(this SettingsWindow module)
{
var iconPath = module switch
var iconFile = module switch
{
SettingsWindow.ColorPicker => "Assets\\ColorPicker.png",
SettingsWindow.FancyZones => "Assets\\FancyZones.png",
SettingsWindow.Hosts => "Assets\\Hosts.png",
SettingsWindow.PowerOCR => "Assets\\TextExtractor.png",
SettingsWindow.RegistryPreview => "Assets\\RegistryPreview.png",
SettingsWindow.MeasureTool => "Assets\\ScreenRuler.png",
SettingsWindow.ShortcutGuide => "Assets\\ShortcutGuide.png",
SettingsWindow.CropAndLock => "Assets\\CropAndLock.png",
SettingsWindow.EnvironmentVariables => "Assets\\EnvironmentVariables.png",
SettingsWindow.Awake => "Assets\\Awake.png",
SettingsWindow.PowerRename => "Assets\\PowerRename.png",
SettingsWindow.Run => "Assets\\PowerToysRun.png",
SettingsWindow.ImageResizer => "Assets\\ImageResizer.png",
SettingsWindow.KBM => "Assets\\KeyboardManager.png",
SettingsWindow.MouseUtils => "Assets\\MouseUtils.png",
SettingsWindow.Workspaces => "Assets\\Workspaces.png",
SettingsWindow.AdvancedPaste => "Assets\\AdvancedPaste.png",
SettingsWindow.CmdPal => "Assets\\CmdPal.png",
SettingsWindow.ZoomIt => "Assets\\ZoomIt.png",
SettingsWindow.FileExplorer => "Assets\\FileExplorerPreview.png",
SettingsWindow.FileLocksmith => "Assets\\FileLocksmith.png",
SettingsWindow.NewPlus => "Assets\\NewPlus.png",
SettingsWindow.Peek => "Assets\\Peek.png",
SettingsWindow.LightSwitch => "Assets\\LightSwitch.png",
SettingsWindow.AlwaysOnTop => "Assets\\AlwaysOnTop.png",
SettingsWindow.CmdNotFound => "Assets\\CommandNotFound.png",
SettingsWindow.MouseWithoutBorders => "Assets\\MouseWithoutBorders.png",
SettingsWindow.PowerAccent => "Assets\\QuickAccent.png",
SettingsWindow.PowerLauncher => "Assets\\PowerToysRun.png",
SettingsWindow.PowerPreview => "Assets\\FileExplorerPreview.png",
SettingsWindow.Overview => "Assets\\PowerToys.png",
SettingsWindow.Dashboard => "Assets\\PowerToys.png",
_ => "Assets\\PowerToys.png",
SettingsWindow.ColorPicker => "ColorPicker.png",
SettingsWindow.FancyZones => "FancyZones.png",
SettingsWindow.Hosts => "Hosts.png",
SettingsWindow.PowerOCR => "TextExtractor.png",
SettingsWindow.RegistryPreview => "RegistryPreview.png",
SettingsWindow.MeasureTool => "ScreenRuler.png",
SettingsWindow.ShortcutGuide => "ShortcutGuide.png",
SettingsWindow.CropAndLock => "CropAndLock.png",
SettingsWindow.EnvironmentVariables => "EnvironmentVariables.png",
SettingsWindow.Awake => "Awake.png",
SettingsWindow.PowerRename => "PowerRename.png",
SettingsWindow.Run => "PowerToysRun.png",
SettingsWindow.ImageResizer => "ImageResizer.png",
SettingsWindow.KBM => "KeyboardManager.png",
SettingsWindow.MouseUtils => "MouseUtils.png",
SettingsWindow.Workspaces => "Workspaces.png",
SettingsWindow.AdvancedPaste => "AdvancedPaste.png",
SettingsWindow.CmdPal => "CmdPal.png",
SettingsWindow.ZoomIt => "ZoomIt.png",
SettingsWindow.FileExplorer => "FileExplorerPreview.png",
SettingsWindow.FileLocksmith => "FileLocksmith.png",
SettingsWindow.NewPlus => "NewPlus.png",
SettingsWindow.Peek => "Peek.png",
SettingsWindow.LightSwitch => "LightSwitch.png",
SettingsWindow.AlwaysOnTop => "AlwaysOnTop.png",
SettingsWindow.CmdNotFound => "CommandNotFound.png",
SettingsWindow.MouseWithoutBorders => "MouseWithoutBorders.png",
SettingsWindow.PowerAccent => "QuickAccent.png",
SettingsWindow.PowerLauncher => "PowerToysRun.png",
SettingsWindow.PowerPreview => "FileExplorerPreview.png",
SettingsWindow.Overview => "PowerToys.png",
SettingsWindow.Dashboard => "PowerToys.png",
_ => "PowerToys.png",
};
return IconHelpers.FromRelativePath(iconPath);
return IconFromSettingsIcon(iconFile);
}
public static string ModuleDisplayName(this SettingsWindow module)

View File

@@ -17,7 +17,7 @@ internal sealed class AwakeModuleCommandProvider : ModuleCommandProvider
public override IEnumerable<ListItem> BuildCommands()
{
var items = new List<ListItem>();
var icon = IconHelpers.FromRelativePath("Assets\\Awake.png");
var icon = PowerToysResourcesHelper.IconFromSettingsIcon("Awake.png");
// Settings entry with quick actions in MoreCommands.
var settingsTitle = SettingsDeepLink.SettingsWindow.Awake.ModuleDisplayName();

View File

@@ -21,6 +21,7 @@ internal sealed class WorkspacesModuleCommandProvider : ModuleCommandProvider
public override IEnumerable<ListItem> BuildCommands()
{
var items = new List<ListItem>();
var icon = PowerToysResourcesHelper.IconFromSettingsIcon("Workspaces.png");
// Settings entry plus common actions.
var title = SettingsDeepLink.SettingsWindow.Workspaces.ModuleDisplayName();
@@ -40,7 +41,7 @@ internal sealed class WorkspacesModuleCommandProvider : ModuleCommandProvider
{
Title = "Workspaces: Open editor",
Subtitle = "Create or edit workspaces",
Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png"),
Icon = icon,
});
// Per-workspace entries via the shared service.
@@ -55,7 +56,7 @@ internal sealed class WorkspacesModuleCommandProvider : ModuleCommandProvider
{
Title = workspace.Name,
Subtitle = BuildSubtitle(workspace),
Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png"),
Icon = icon,
Details = BuildDetails(workspace),
});
}
@@ -104,7 +105,7 @@ internal sealed class WorkspacesModuleCommandProvider : ModuleCommandProvider
return new Details
{
HeroImage = IconHelpers.FromRelativePath("Assets\\Workspaces.png"),
HeroImage = PowerToysResourcesHelper.IconFromSettingsIcon("Workspaces.png"),
Title = workspace.Name,
Metadata = BuildAppMetadata(workspace),
};

View File

@@ -14,7 +14,7 @@ internal sealed partial class AwakeProcessListPage : DynamicListPage
public AwakeProcessListPage()
{
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png");
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("Awake.png");
Title = "Bind Awake to process";
Name = "AwakeProcessBinding";
Id = "com.microsoft.powertoys.awake.processBinding";
@@ -23,7 +23,7 @@ internal sealed partial class AwakeProcessListPage : DynamicListPage
{
Title = "No matching processes",
Subtitle = "Try another search.",
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png"),
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("Awake.png"),
};
EmptyContent = _emptyContent;

View File

@@ -14,7 +14,7 @@ internal sealed partial class AwakeSessionsPage : DynamicListPage
public AwakeSessionsPage()
{
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png");
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("Awake.png");
Title = "Awake actions";
Name = "AwakeActions";
Id = "com.microsoft.powertoys.awake.actions";
@@ -23,7 +23,7 @@ internal sealed partial class AwakeSessionsPage : DynamicListPage
{
Title = "No Awake actions",
Subtitle = "Try a different search phrase.",
Icon = IconHelpers.FromRelativePath("Assets\\Awake.png"),
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("Awake.png"),
};
EmptyContent = _emptyContent;

View File

@@ -19,7 +19,7 @@ internal sealed partial class ColorPickerSavedColorsPage : DynamicListPage
public ColorPickerSavedColorsPage()
{
Icon = IconHelpers.FromRelativePath("Assets\\ColorPicker.png");
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("ColorPicker.png");
Title = "Saved colors";
Name = "ColorPickerSavedColors";
Id = "com.microsoft.powertoys.colorpicker.savedColors";
@@ -28,7 +28,7 @@ internal sealed partial class ColorPickerSavedColorsPage : DynamicListPage
{
Title = "No saved colors",
Subtitle = "Pick a color first, then try again.",
Icon = IconHelpers.FromRelativePath("Assets\\ColorPicker.png"),
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("ColorPicker.png"),
};
EmptyContent = _emptyContent;

View File

@@ -13,7 +13,7 @@ internal sealed partial class PowerToysExtensionPage : ListPage
{
public PowerToysExtensionPage()
{
Icon = IconHelpers.FromRelativePath("Assets\\PowerToys.png");
Icon = Helpers.PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png");
Title = "PowerToys";
Name = "PowerToys commands";
}

View File

@@ -14,12 +14,12 @@ internal sealed partial class PowerToysListPage : DynamicListPage
public PowerToysListPage()
{
Icon = IconHelpers.FromRelativePath("Assets\\PowerToys.png");
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png");
Name = Title = "PowerToys";
Id = "com.microsoft.cmdpal.powertoys";
_empty = new CommandItem()
{
Icon = IconHelpers.FromRelativePath("Assets\\PowerToys.png"),
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png"),
Title = "No matching module found",
Subtitle = SearchText,
};

View File

@@ -5,6 +5,7 @@
using System.Linq;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using PowerToysExtension.Helpers;
using PowerToysExtension.Modules;
namespace PowerToysExtension.Pages;
@@ -15,12 +16,12 @@ internal sealed partial class WorkspacesListPage : DynamicListPage
public WorkspacesListPage()
{
Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png");
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("Workspaces.png");
Name = Title = "Workspaces";
Id = "com.microsoft.cmdpal.powertoys.workspaces";
_emptyMessage = new CommandItem()
{
Icon = IconHelpers.FromRelativePath("Assets\\Workspaces.png"),
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("Workspaces.png"),
Title = "No workspaces found",
Subtitle = SearchText,
};

View File

@@ -15,7 +15,7 @@ public sealed partial class PowerToysCommandsProvider : CommandProvider
public PowerToysCommandsProvider()
{
DisplayName = "PowerToys";
Icon = IconHelpers.FromRelativePath("Assets\\PowerToys.png");
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png");
}
public override ICommandItem[] TopLevelCommands() =>

View File

@@ -16,7 +16,7 @@ public partial class PowerToysExtensionCommandsProvider : CommandProvider
public PowerToysExtensionCommandsProvider()
{
DisplayName = "PowerToys";
Icon = IconHelpers.FromRelativePath("Assets\\PowerToys.png");
Icon = PowerToysResourcesHelper.IconFromSettingsIcon("PowerToys.png");
_commands = [
new CommandItem(new Pages.PowerToysListPage())
{