mirror of
https://github.com/knah/VRCMelonAssistant.git
synced 2024-06-29 03:20: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);
|
ShowMessageBoxDelegate caller = new ShowMessageBoxDelegate(ShowMessageBox);
|
||||||
caller.BeginInvoke(Message, null, null, null);
|
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)
|
private void CopyText(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
System.Windows.Clipboard.SetText(((TextBlock)sender).Text);
|
var textBlock = sender as TextBlock;
|
||||||
Utils.SendNotify("Copied text to clipboard");
|
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)
|
private void SearchButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
|
|
@ -206,7 +206,7 @@ namespace ModAssistant.Pages
|
||||||
await Task.Run(async () => await UploadLog());
|
await Task.Run(async () => await UploadLog());
|
||||||
|
|
||||||
System.Diagnostics.Process.Start(LogURL);
|
System.Diagnostics.Process.Start(LogURL);
|
||||||
Clipboard.SetText(LogURL);
|
Utils.SetClipboard(LogURL);
|
||||||
MainWindow.Instance.MainText = (string)Application.Current.FindResource("Options:LogUrlCopied");
|
MainWindow.Instance.MainText = (string)Application.Current.FindResource("Options:LogUrlCopied");
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
|
Loading…
Reference in a new issue