mirror of
https://github.com/knah/VRCMelonAssistant.git
synced 2024-05-18 03:12:18 +12:00
Suppress exceptions when setting clipboard data
This commit is contained in:
parent
6c2894e5d4
commit
8d8bf90088
|
@ -439,5 +439,30 @@ namespace ModAssistant
|
|||
ShowMessageBoxDelegate caller = new ShowMessageBoxDelegate(ShowMessageBox);
|
||||
caller.BeginInvoke(Message, null, null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to write the specified string to the <see cref="System.Windows.Clipboard"/>.
|
||||
/// </summary>
|
||||
/// <param name="text">The string to be written</param>
|
||||
public static void SetClipboard(string text)
|
||||
{
|
||||
bool success = false;
|
||||
try
|
||||
{
|
||||
Clipboard.SetText(text);
|
||||
success = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Swallow exceptions relating to writing data to clipboard.
|
||||
}
|
||||
|
||||
// This could be placed in the try/catch block but we don't
|
||||
// want to suppress exceptions for non-clipboard operations
|
||||
if (success)
|
||||
{
|
||||
Utils.SendNotify($"Copied text to clipboard");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -716,8 +716,14 @@ namespace ModAssistant.Pages
|
|||
|
||||
private void CopyText(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||
{
|
||||
System.Windows.Clipboard.SetText(((TextBlock)sender).Text);
|
||||
Utils.SendNotify("Copied text to clipboard");
|
||||
var textBlock = sender as TextBlock;
|
||||
if (textBlock == null) { return; }
|
||||
var text = textBlock.Text;
|
||||
|
||||
// Ensure there's text to be copied
|
||||
if (string.IsNullOrWhiteSpace(text)) { return; }
|
||||
|
||||
Utils.SetClipboard(text);
|
||||
}
|
||||
|
||||
private void SearchButton_Click(object sender, RoutedEventArgs e)
|
||||
|
|
|
@ -206,7 +206,7 @@ namespace ModAssistant.Pages
|
|||
await Task.Run(async () => await UploadLog());
|
||||
|
||||
System.Diagnostics.Process.Start(LogURL);
|
||||
Clipboard.SetText(LogURL);
|
||||
Utils.SetClipboard(LogURL);
|
||||
MainWindow.Instance.MainText = (string)Application.Current.FindResource("Options:LogUrlCopied");
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
|
Loading…
Reference in a new issue