fix: prevent crash when clipboard is locked by another application#3562
Open
Jefsky wants to merge 1 commit into
Open
fix: prevent crash when clipboard is locked by another application#3562Jefsky wants to merge 1 commit into
Jefsky wants to merge 1 commit into
Conversation
Wrap all clipboard access (SetText, GetText, SetDataObject) with retry logic to prevent COMException crash when clipboard is busy. - ServerSharingViewModel: SetClipboardTextSafe for QR code copy - OnlineConfigViewModel: SetClipboardTextSafe for link copy - MenuViewController: GetClipboardTextSafe for URL import - ShadowsocksController: SetClipboardDataObjectSafe for PAC URL copy Fixes shadowsocks#3561
Author
|
Friendly bump — the PR has been sitting for a bit. The fix wraps clipboard access in try/catch across 4 sites (ShadowsocksController, MenuViewController, OnlineConfigViewModel, ServerSharingViewModel) to prevent the crash when the clipboard is locked by another app (~116 lines, 4 files). CI is green. Happy to address any feedback or split the changes per file if reviewers prefer. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When another application holds the clipboard lock, calling
Clipboard.SetText,Clipboard.GetText, orClipboard.SetDataObjectthrows aCOMException(error code 0x800401D0 - Clipboard can not be opened) and crashes the application.Fix
Added safe wrapper methods around all clipboard operations with retry logic:
Clipboard.SetTextin ServerSharingViewModel and OnlineConfigViewModelClipboard.GetTextin MenuViewController for URL importClipboard.SetDataObjectin ShadowsocksController for PAC URL copyEach wrapper retries up to 5 times with 50ms delay, gracefully failing silently instead of crashing.
Files Changed
shadowsocks-csharp/ViewModels/ServerSharingViewModel.cs— QR code link copyshadowsocks-csharp/ViewModels/OnlineConfigViewModel.cs— online config link copyshadowsocks-csharp/View/MenuViewController.cs— URL import from clipboardshadowsocks-csharp/Controller/ShadowsocksController.cs— PAC URL copyTest Plan