Files
PowerToys/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Main.cs
Niels Laute c095cdde4e [PTRun]Fluent UX and switch to WpfUI (#28538)
* New design

* Updating icons

* Adding keywords

* Only show plugins when search query is empty

* Update App.xaml

* Update App.xaml

* Filter plugins

* Fix image name

* refresh plugins overview

* fix context menu icons in win10

* Remove unused animations

* Resolving crashing

* Fix focus visual and a11y

* Remove unused styles

* Revert "Remove unused styles"

This reverts commit 65f29ae6ed.

* Fix value generator light vs dark icon

* Fix tab characters

* Fix CI

* Update SettingsReader.cs

* Adding common OS check helper

* Update MainWindow.xaml.cs

* Fix background

* More tweaks

* XAML styler and updating legacy brushes

* Updates + xaml styling

* Fix CI

* Fix CI2

* fix font family and overview refresh

* Delete shutdown.light-1.png

* Updating icons

* Set DPI

---------

Co-authored-by: Davide Giacometti <davide.giacometti@outlook.it>
2023-11-20 10:23:26 +00:00

152 lines
5.3 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.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Input;
using ManagedCommon;
using Microsoft.PowerToys.Run.Plugin.Service.Helpers;
using Microsoft.PowerToys.Run.Plugin.Service.Properties;
using Wox.Plugin;
namespace Microsoft.PowerToys.Run.Plugin.Service
{
public class Main : IPlugin, IContextMenu, IPluginI18n
{
private PluginInitContext _context;
private string _icoPath;
public string Name => Resources.wox_plugin_service_plugin_name;
public string Description => Resources.wox_plugin_service_plugin_description;
public static string PluginID => "11A6C36E4E91439CA69F702CBD364EF7";
public void Init(PluginInitContext context)
{
_context = context;
_context.API.ThemeChanged += OnThemeChanged;
UpdateIconPath(_context.API.GetCurrentTheme());
}
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
{
if (!(selectedResult?.ContextData is ServiceResult))
{
return new List<ContextMenuResult>();
}
var contextMenuResult = new List<ContextMenuResult>();
var serviceResult = selectedResult.ContextData as ServiceResult;
if (serviceResult.IsRunning)
{
// Stop
contextMenuResult.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = Resources.wox_plugin_service_stop,
Glyph = "\xE71A",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.Enter,
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Stop, _context.API));
return true;
},
});
// Restart
contextMenuResult.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = Resources.wox_plugin_service_restart,
Glyph = "\xE72C",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.R,
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Restart, _context.API));
return true;
},
});
}
else
{
// Start
contextMenuResult.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = Resources.wox_plugin_service_start,
Glyph = "\xEDB5",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.Enter,
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Start, _context.API));
return true;
},
});
}
// Open services
contextMenuResult.Add(new ContextMenuResult
{
PluginName = Assembly.GetExecutingAssembly().GetName().Name,
Title = Resources.wox_plugin_service_open_services,
Glyph = "\xE8A7",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.O,
AcceleratorModifiers = ModifierKeys.Control,
Action = _ =>
{
Task.Run(() => ServiceHelper.OpenServices());
return true;
},
});
return contextMenuResult;
}
public List<Result> Query(Query query)
{
var search = query?.Search ?? string.Empty;
return ServiceHelper.Search(search, _icoPath, _context).ToList();
}
public string GetTranslatedPluginTitle()
{
return Resources.wox_plugin_service_plugin_name;
}
public string GetTranslatedPluginDescription()
{
return Resources.wox_plugin_service_plugin_description;
}
private void UpdateIconPath(Theme theme)
{
if (theme == Theme.Light || theme == Theme.HighContrastWhite)
{
_icoPath = "Images/service.light.png";
}
else
{
_icoPath = "Images/service.dark.png";
}
}
private void OnThemeChanged(Theme currentTheme, Theme newTheme)
{
UpdateIconPath(newTheme);
}
}
}