修复剪贴板被占用时无提示

This commit is contained in:
camileko
2026-09-22 23:25:55 +08:00
parent 8f76864574
commit d1e969d742
3 changed files with 15 additions and 20 deletions
@@ -1021,23 +1021,21 @@ Public Module ModBase
''' <summary>
''' 设置剪贴板。将在另一线程运行,且不会抛出异常。
''' </summary>
Public Sub ClipboardSet(Text As String, Optional ShowSuccessHint As Boolean = True)
Public Sub ClipboardSet(Text As String, Optional ShowSuccessHint As Boolean = True, Optional SuccessHint As String = "")
RunInThread(
Sub()
Try
Retrier.Attempt(delay:=Function(Attempt) TimeSpan.FromMilliseconds(200), maxAttempts:=4, isRetryAllowed:=Function(ex) True, action:=
Sub()
RunInUi(
Sub()
Try
My.Computer.Clipboard.Clear()
If Not String.IsNullOrEmpty(Text) Then My.Computer.Clipboard.SetText(Text)
End Sub)
End Sub)
If ShowSuccessHint Then Hint("已成功复制!", HintType.Green)
If ShowSuccessHint Then Hint(If(String.IsNullOrEmpty(SuccessHint), "已成功复制!", SuccessHint), HintType.Green)
Catch ex As Exception
Logger.Error(ex, "可能由于剪贴板被其他程序占用,文本复制失败", LogBehavior.Toast)
Logger.Error(ex, behavior:=LogBehavior.None)
Hint("复制失败,可能由于剪贴板被其他程序占用!", HintType.Red)
End Try
End Sub)
End Sub)
End Sub
''' <summary>
''' 获取剪贴板文本。将在 UI 线程运行,且不会抛出异常。
@@ -358,9 +358,8 @@ Public Class PageLinkMain
'复制邀请码
Private Sub Copy() Handles BtnFinishCopy.Click
Dim CodeText As String = $"在 PCL 启动器中输入邀请码【{GetInviteCode()}】,即可加入联机房间!"
ClipboardSet(CodeText, False)
ClipboardSet(CodeText, SuccessHint:="已复制邀请码!")
Settings.Set("LinkLastAutoJoinInviteCode", CodeText)
Hint("已复制邀请码!", HintType.Green)
End Sub
Private Function GetInviteCode() As String
Return $"{NetworkName}-{NetworkSecret}-{INVITE_CODE_VERSION.ToString.PadLeft(2, "0"c)}{ _
@@ -369,8 +368,7 @@ Public Class PageLinkMain
'复制 IP
Private Sub BtnFinishIp_MouseLeftButtonUp(sender As Object, e As MouseButtonEventArgs) Handles BtnFinishIp.MouseLeftButtonUp
ClipboardSet(ClientAddress, False)
Hint("已复制服务器地址!", HintType.Green)
ClipboardSet(ClientAddress, SuccessHint:="已复制服务器地址!")
End Sub
#End Region
@@ -93,8 +93,7 @@ Public Class PageSpeedLeft
Tb.Text = Loader.Error.GetDisplay(True)
AddHandler Tb.MouseLeftButtonDown,
Sub(sender As TextBlock, e As EventArgs)
ClipboardSet(sender.Text, False)
Hint("已复制错误详情!", HintType.Green)
ClipboardSet(sender.Text, SuccessHint:="已复制错误详情!")
End Sub
Card.Children.Add(Tb)
#End Region