Skip to content

Commit db3c8e6

Browse files
authored
[PTRun]Improve copying error handling on plugins (#35459)
1 parent 5d2bb16 commit db3c8e6

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.UnitConverter/Main.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using ManagedCommon;
1616
using Wox.Plugin;
17+
using Wox.Plugin.Logger;
1718

1819
namespace Community.PowerToys.Run.Plugin.UnitConverter
1920
{
@@ -75,9 +76,10 @@ private Result GetResult(UnitConversionResult result)
7576
Clipboard.SetText(result.ConvertedValue.ToString(UnitConversionResult.CopyFormat, CultureInfo.CurrentCulture));
7677
ret = true;
7778
}
78-
catch (ExternalException)
79+
catch (ExternalException ex)
7980
{
80-
MessageBox.Show(Properties.Resources.copy_failed);
81+
Log.Exception("Copy failed", ex, GetType());
82+
MessageBox.Show(ex.Message, Properties.Resources.copy_failed);
8183
}
8284
});
8385
thread.SetApartmentState(ApartmentState.STA);
@@ -107,9 +109,10 @@ private ContextMenuResult CreateContextMenuEntry(UnitConversionResult result)
107109
Clipboard.SetText(result.ConvertedValue.ToString(UnitConversionResult.CopyFormat, CultureInfo.CurrentCulture));
108110
ret = true;
109111
}
110-
catch (ExternalException)
112+
catch (ExternalException ex)
111113
{
112-
MessageBox.Show(Properties.Resources.copy_failed);
114+
Log.Exception("Copy failed", ex, GetType());
115+
MessageBox.Show(ex.Message, Properties.Resources.copy_failed);
113116
}
114117
});
115118
thread.SetApartmentState(ApartmentState.STA);

src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.ValueGenerator/Main.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ private Result GetResult(IComputeRequest request)
184184
Clipboard.SetText(request.ResultToString());
185185
ret = true;
186186
}
187-
catch (ExternalException)
187+
catch (ExternalException ex)
188188
{
189-
MessageBox.Show(Properties.Resources.copy_failed);
189+
Log.Exception("Copy failed", ex, GetType());
190+
MessageBox.Show(ex.Message, Properties.Resources.copy_failed);
190191
}
191192
});
192193
thread.SetApartmentState(ApartmentState.STA);

src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Calculator/ResultHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Windows;
99

1010
using Wox.Plugin;
11+
using Wox.Plugin.Logger;
1112

1213
namespace Microsoft.PowerToys.Run.Plugin.Calculator
1314
{
@@ -51,9 +52,10 @@ public static bool Action(decimal? roundedResult, CultureInfo culture)
5152
Clipboard.SetText(roundedResult?.ToString(culture));
5253
ret = true;
5354
}
54-
catch (ExternalException)
55+
catch (ExternalException ex)
5556
{
56-
MessageBox.Show(Properties.Resources.wox_plugin_calculator_copy_failed);
57+
Log.Exception("Copy failed", ex, typeof(ResultHelper));
58+
MessageBox.Show(ex.Message, Properties.Resources.wox_plugin_calculator_copy_failed);
5759
}
5860
});
5961

src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Components/ResultHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ internal static bool CopyToClipBoard(in string text)
5050
{
5151
try
5252
{
53-
Clipboard.Clear();
5453
Clipboard.SetText(text);
5554
return true;
5655
}
5756
catch (Exception exception)
5857
{
5958
Log.Exception("Can't copy to clipboard", exception, typeof(ResultHelper));
59+
MessageBox.Show(exception.Message, Resources.Microsoft_plugin_timedate_copy_failed);
6060
return false;
6161
}
6262
}

src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@
121121
<value>Copy value (Ctrl+C)</value>
122122
<comment>'Ctrl+C' is a shortcut</comment>
123123
</data>
124+
<data name="Microsoft_plugin_timedate_copy_failed" xml:space="preserve">
125+
<value>Copy failed</value>
126+
</data>
124127
<data name="Microsoft_plugin_timedate_Date" xml:space="preserve">
125128
<value>Date</value>
126129
</data>

0 commit comments

Comments
 (0)