mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 19:27:56 +01:00
PT Run Service notification improvements (#9772)
This commit is contained in:
committed by
GitHub
parent
a29b3aa500
commit
ff4a78a7f9
@@ -6,7 +6,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
@@ -75,11 +74,11 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
|
|
||||||
if (exitCode == 0)
|
if (exitCode == 0)
|
||||||
{
|
{
|
||||||
contextAPI.ShowNotification(GetLocalizedMessage(serviceResult, action));
|
contextAPI.ShowNotification(GetLocalizedMessage(action), serviceResult.DisplayName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
contextAPI.ShowNotification("An error occurred");
|
contextAPI.ShowNotification(GetLocalizedErrorMessage(action), serviceResult.DisplayName);
|
||||||
Log.Error($"The command returned {exitCode}", MethodBase.GetCurrentMethod().DeclaringType);
|
Log.Error($"The command returned {exitCode}", MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,19 +191,39 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetLocalizedMessage(ServiceResult serviceResult, Action action)
|
private static string GetLocalizedMessage(Action action)
|
||||||
{
|
{
|
||||||
if (action == Action.Start)
|
if (action == Action.Start)
|
||||||
{
|
{
|
||||||
return string.Format(CultureInfo.CurrentCulture, Resources.wox_plugin_service_started_notification, serviceResult.DisplayName);
|
return Resources.wox_plugin_service_started_notification;
|
||||||
}
|
}
|
||||||
else if (action == Action.Stop)
|
else if (action == Action.Stop)
|
||||||
{
|
{
|
||||||
return string.Format(CultureInfo.CurrentCulture, Resources.wox_plugin_service_stopped_notification, serviceResult.DisplayName);
|
return Resources.wox_plugin_service_stopped_notification;
|
||||||
}
|
}
|
||||||
else if (action == Action.Restart)
|
else if (action == Action.Restart)
|
||||||
{
|
{
|
||||||
return string.Format(CultureInfo.CurrentCulture, Resources.wox_plugin_service_restarted_notification, serviceResult.DisplayName);
|
return Resources.wox_plugin_service_restarted_notification;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetLocalizedErrorMessage(Action action)
|
||||||
|
{
|
||||||
|
if (action == Action.Start)
|
||||||
|
{
|
||||||
|
return Resources.wox_plugin_service_start_error_notification;
|
||||||
|
}
|
||||||
|
else if (action == Action.Stop)
|
||||||
|
{
|
||||||
|
return Resources.wox_plugin_service_stop_error_notification;
|
||||||
|
}
|
||||||
|
else if (action == Action.Restart)
|
||||||
|
{
|
||||||
|
return Resources.wox_plugin_service_restart_error_notification;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,7 +124,16 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to {0} has been restarted.
|
/// Looks up a localized string similar to An error occurred while restarting the service.
|
||||||
|
/// </summary>
|
||||||
|
internal static string wox_plugin_service_restart_error_notification {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("wox_plugin_service_restart_error_notification", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to The service has been restarted.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string wox_plugin_service_restarted_notification {
|
internal static string wox_plugin_service_restarted_notification {
|
||||||
get {
|
get {
|
||||||
@@ -150,6 +159,15 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to An error occurred while starting the service.
|
||||||
|
/// </summary>
|
||||||
|
internal static string wox_plugin_service_start_error_notification {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("wox_plugin_service_start_error_notification", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Automatic.
|
/// Looks up a localized string similar to Automatic.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -214,7 +232,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to {0} has been started.
|
/// Looks up a localized string similar to The service has been started.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string wox_plugin_service_started_notification {
|
internal static string wox_plugin_service_started_notification {
|
||||||
get {
|
get {
|
||||||
@@ -249,6 +267,15 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to An error occurred while stopping the service.
|
||||||
|
/// </summary>
|
||||||
|
internal static string wox_plugin_service_stop_error_notification {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("wox_plugin_service_stop_error_notification", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Stopping.
|
/// Looks up a localized string similar to Stopping.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -268,7 +295,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to {0} has been stopped.
|
/// Looks up a localized string similar to The service has been stopped.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string wox_plugin_service_stopped_notification {
|
internal static string wox_plugin_service_stopped_notification {
|
||||||
get {
|
get {
|
||||||
|
|||||||
@@ -139,7 +139,10 @@
|
|||||||
<value>Restart (Ctrl+R)</value>
|
<value>Restart (Ctrl+R)</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="wox_plugin_service_restarted_notification" xml:space="preserve">
|
<data name="wox_plugin_service_restarted_notification" xml:space="preserve">
|
||||||
<value>{0} has been restarted</value>
|
<value>The service has been restarted</value>
|
||||||
|
</data>
|
||||||
|
<data name="wox_plugin_service_restart_error_notification" xml:space="preserve">
|
||||||
|
<value>An error occurred while restarting the service</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="wox_plugin_service_running" xml:space="preserve">
|
<data name="wox_plugin_service_running" xml:space="preserve">
|
||||||
<value>Running</value>
|
<value>Running</value>
|
||||||
@@ -151,11 +154,14 @@
|
|||||||
<value>Started</value>
|
<value>Started</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="wox_plugin_service_started_notification" xml:space="preserve">
|
<data name="wox_plugin_service_started_notification" xml:space="preserve">
|
||||||
<value>{0} has been started</value>
|
<value>The service has been started</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="wox_plugin_service_startup" xml:space="preserve">
|
<data name="wox_plugin_service_startup" xml:space="preserve">
|
||||||
<value>Startup</value>
|
<value>Startup</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="wox_plugin_service_start_error_notification" xml:space="preserve">
|
||||||
|
<value>An error occurred while starting the service</value>
|
||||||
|
</data>
|
||||||
<data name="wox_plugin_service_start_mode_automatic" xml:space="preserve">
|
<data name="wox_plugin_service_start_mode_automatic" xml:space="preserve">
|
||||||
<value>Automatic</value>
|
<value>Automatic</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -184,7 +190,10 @@
|
|||||||
<value>Stopped</value>
|
<value>Stopped</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="wox_plugin_service_stopped_notification" xml:space="preserve">
|
<data name="wox_plugin_service_stopped_notification" xml:space="preserve">
|
||||||
<value>{0} has been stopped</value>
|
<value>The service has been stopped</value>
|
||||||
|
</data>
|
||||||
|
<data name="wox_plugin_service_stop_error_notification" xml:space="preserve">
|
||||||
|
<value>An error occurred while stopping the service</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="wox_plugin_service_stop_pending" xml:space="preserve">
|
<data name="wox_plugin_service_stop_pending" xml:space="preserve">
|
||||||
<value>Stopping</value>
|
<value>Stopping</value>
|
||||||
|
|||||||
@@ -84,14 +84,18 @@ namespace Wox
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowNotification(string text)
|
public void ShowNotification(string text, string secondaryText = null)
|
||||||
{
|
{
|
||||||
|
var builder = new ToastContentBuilder().AddText(text);
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(secondaryText))
|
||||||
|
{
|
||||||
|
builder.AddText(secondaryText);
|
||||||
|
}
|
||||||
|
|
||||||
Application.Current.Dispatcher.Invoke(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
ToastContent toastContent = new ToastContentBuilder()
|
var toast = new ToastNotification(builder.GetToastContent().GetXml());
|
||||||
.AddText(text)
|
|
||||||
.GetToastContent();
|
|
||||||
var toast = new ToastNotification(toastContent.GetXml());
|
|
||||||
DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast);
|
DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ namespace Wox.Plugin
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Show toast notification
|
/// Show toast notification
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">Notification text</param>
|
/// <param name="text">Notification main text</param>
|
||||||
void ShowNotification(string text);
|
/// <param name="secondaryText">Notification optional text</param>
|
||||||
|
void ShowNotification(string text, string secondaryText = null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user