[PTRun]Improve copying error handling on plugins (#35459)

This commit is contained in:
PesBandi
2024-10-21 14:42:11 +02:00
committed by GitHub
parent 5d2bb16e92
commit db3c8e621e
6 changed files with 27 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ using System.Windows.Input;
using ManagedCommon; using ManagedCommon;
using Wox.Plugin; using Wox.Plugin;
using Wox.Plugin.Logger;
namespace Community.PowerToys.Run.Plugin.UnitConverter namespace Community.PowerToys.Run.Plugin.UnitConverter
{ {
@@ -75,9 +76,10 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
Clipboard.SetText(result.ConvertedValue.ToString(UnitConversionResult.CopyFormat, CultureInfo.CurrentCulture)); Clipboard.SetText(result.ConvertedValue.ToString(UnitConversionResult.CopyFormat, CultureInfo.CurrentCulture));
ret = true; ret = true;
} }
catch (ExternalException) catch (ExternalException ex)
{ {
MessageBox.Show(Properties.Resources.copy_failed); Log.Exception("Copy failed", ex, GetType());
MessageBox.Show(ex.Message, Properties.Resources.copy_failed);
} }
}); });
thread.SetApartmentState(ApartmentState.STA); thread.SetApartmentState(ApartmentState.STA);
@@ -107,9 +109,10 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
Clipboard.SetText(result.ConvertedValue.ToString(UnitConversionResult.CopyFormat, CultureInfo.CurrentCulture)); Clipboard.SetText(result.ConvertedValue.ToString(UnitConversionResult.CopyFormat, CultureInfo.CurrentCulture));
ret = true; ret = true;
} }
catch (ExternalException) catch (ExternalException ex)
{ {
MessageBox.Show(Properties.Resources.copy_failed); Log.Exception("Copy failed", ex, GetType());
MessageBox.Show(ex.Message, Properties.Resources.copy_failed);
} }
}); });
thread.SetApartmentState(ApartmentState.STA); thread.SetApartmentState(ApartmentState.STA);

View File

@@ -184,9 +184,10 @@ namespace Community.PowerToys.Run.Plugin.ValueGenerator
Clipboard.SetText(request.ResultToString()); Clipboard.SetText(request.ResultToString());
ret = true; ret = true;
} }
catch (ExternalException) catch (ExternalException ex)
{ {
MessageBox.Show(Properties.Resources.copy_failed); Log.Exception("Copy failed", ex, GetType());
MessageBox.Show(ex.Message, Properties.Resources.copy_failed);
} }
}); });
thread.SetApartmentState(ApartmentState.STA); thread.SetApartmentState(ApartmentState.STA);

View File

@@ -8,6 +8,7 @@ using System.Threading;
using System.Windows; using System.Windows;
using Wox.Plugin; using Wox.Plugin;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.Calculator namespace Microsoft.PowerToys.Run.Plugin.Calculator
{ {
@@ -51,9 +52,10 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
Clipboard.SetText(roundedResult?.ToString(culture)); Clipboard.SetText(roundedResult?.ToString(culture));
ret = true; ret = true;
} }
catch (ExternalException) catch (ExternalException ex)
{ {
MessageBox.Show(Properties.Resources.wox_plugin_calculator_copy_failed); Log.Exception("Copy failed", ex, typeof(ResultHelper));
MessageBox.Show(ex.Message, Properties.Resources.wox_plugin_calculator_copy_failed);
} }
}); });

View File

@@ -50,13 +50,13 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Components
{ {
try try
{ {
Clipboard.Clear();
Clipboard.SetText(text); Clipboard.SetText(text);
return true; return true;
} }
catch (Exception exception) catch (Exception exception)
{ {
Log.Exception("Can't copy to clipboard", exception, typeof(ResultHelper)); Log.Exception("Can't copy to clipboard", exception, typeof(ResultHelper));
MessageBox.Show(exception.Message, Resources.Microsoft_plugin_timedate_copy_failed);
return false; return false;
} }
} }

View File

@@ -60,6 +60,15 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to Copy failed.
/// </summary>
internal static string Microsoft_plugin_timedate_copy_failed {
get {
return ResourceManager.GetString("Microsoft_plugin_timedate_copy_failed", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Copy value (Ctrl+C). /// Looks up a localized string similar to Copy value (Ctrl+C).
/// </summary> /// </summary>

View File

@@ -121,6 +121,9 @@
<value>Copy value (Ctrl+C)</value> <value>Copy value (Ctrl+C)</value>
<comment>'Ctrl+C' is a shortcut</comment> <comment>'Ctrl+C' is a shortcut</comment>
</data> </data>
<data name="Microsoft_plugin_timedate_copy_failed" xml:space="preserve">
<value>Copy failed</value>
</data>
<data name="Microsoft_plugin_timedate_Date" xml:space="preserve"> <data name="Microsoft_plugin_timedate_Date" xml:space="preserve">
<value>Date</value> <value>Date</value>
</data> </data>