Merge pull request #9383 from camileko/close-9380

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