-
-
Notifications
You must be signed in to change notification settings - Fork 366
Fix copy to clipboard STA thread issue & Support retry for copy & Async build-in shortcut model & Fix build shortcuts text replace issue & Fix startup window hide issue #3314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment has been minimized.
This comment has been minimized.
Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX. |
📝 WalkthroughWalkthroughThis set of changes introduces robust handling for clipboard operations on STA (Single-Threaded Apartment) threads, including the addition of Changes
Sequence Diagram(s)sequenceDiagram
participant Plugin/External as Plugin/External Caller
participant PublicAPI as PublicAPIInstance
participant Win32Helper as Win32Helper
participant STAThread as STA Thread
participant Clipboard as Clipboard
participant UI as UI/Notification
Plugin/External->>PublicAPI: CopyToClipboard(string)
activate PublicAPI
PublicAPI->>Win32Helper: StartSTATaskAsync(Clipboard.SetText/SetFileDropList)
activate Win32Helper
Win32Helper->>STAThread: Create STA Thread, call OleInitialize
activate STAThread
STAThread->>Clipboard: SetText/SetFileDropList
Clipboard-->>STAThread: (May throw if clipboard is locked)
STAThread-->>Win32Helper: Complete, call OleUninitialize
deactivate STAThread
Win32Helper-->>PublicAPI: Task result (success/failure)
deactivate Win32Helper
PublicAPI->>UI: Show notification (success/failure)
deactivate PublicAPI
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms (2)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
I am very against this. This is the core, most used, functionality, and it should be available to everyone. Plugins shouldn't need to reinvent the wheel every time. Especially considering Node and Python don't provide a way to do this. I remember seeing one plugin that packed another binary with itself just so it could copy text, which is absolutely ridiculous. |
Well, could you please give me the sample to test? |
After installing this plugin, type |
Many thanks! Sorry, I don't see this as a bug unique to the V2 plugin. In that case, the bug could be fixed. |
This reverts commit 9f8e829.
Sorry I cannot open your demo plugin. I have used 1.19.5 release version of FL (master branch) and downloaded embedded node.js environment from FL but I got this issue: I want to check it by myself, but I really know little about JavaScript. Could you please fix it? |
Could you please install a newer version of NodeJS (v22), specify it in settings (General — Node.js Path) and try again? Flow currently uses very old version that has reached end-of-life already. |
This comment has been minimized.
This comment has been minimized.
Thanks, I think I have fixed it. Now could you please help me check if copy to clipboard (directory) with JsonRPCV2 plugins can work? |
Nvm, I have checked it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (5)
Flow.Launcher.Infrastructure/Win32Helper.cs (2)
122-125
: Consider propagating exceptions rather than suppressing them.The current implementation catches all exceptions but doesn't propagate them to the caller, making it difficult to diagnose issues when they occur.
- catch (System.Exception) - { - taskCompletionSource.SetResult(); - } + catch (System.Exception ex) + { + taskCompletionSource.SetException(ex); + }
154-157
: Consider propagating exceptions rather than returning default values.Similar to the non-generic method, this implementation catches all exceptions but doesn't propagate them to the caller. Instead, it returns a default value which could mask errors.
- catch (System.Exception) - { - taskCompletionSource.SetResult(default); - } + catch (System.Exception ex) + { + taskCompletionSource.SetException(ex); + }Flow.Launcher/PublicAPIInstance.cs (3)
131-156
: Consolidate repetitive clipboard copy logic.The logic for direct file/folder copying (lines 131–156) and text copying (lines 160–181) mostly duplicates the retry mechanism and message handling. Consider extracting common retry logic into a shared helper or unify this code block to improve maintainability and clarity.
Also applies to: 160-181
164-164
: Fix minor typo in comment.Change "shouold" to "should" for clarity.
- // We shouold use SetText instead of SetDataObject to avoid the clipboard being locked by other applications + // We should use SetText instead of SetDataObject to avoid the clipboard being locked by other applications
185-204
: Reconsider returning the exception object fromRetryActionOnSTAThreadAsync
.Returning an
Exception
object directly is functional, but throwing an exception or returning a status (e.g.,bool
) might simplify the calling code. The current design requires the caller to check fornull
vs. non-null
to determine success/failure, which can be error-prone or less conventional.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
Flow.Launcher.Infrastructure/NativeMethods.txt
(1 hunks)Flow.Launcher.Infrastructure/UserSettings/Settings.cs
(1 hunks)Flow.Launcher.Infrastructure/Win32Helper.cs
(2 hunks)Flow.Launcher/Languages/en.xaml
(1 hunks)Flow.Launcher/PublicAPIInstance.cs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: gitStream.cm
- GitHub Check: gitStream.cm
- GitHub Check: gitStream.cm
🔇 Additional comments (4)
Flow.Launcher.Infrastructure/NativeMethods.txt (1)
21-22
: Good addition of required OLE function declarations.These OLE function declarations are necessary for properly initializing and uninitializing the clipboard operations on STA threads, ensuring proper COM interop which is critical for clipboard functionality.
Flow.Launcher/Languages/en.xaml (1)
339-339
: Good addition of error message for clipboard operations.This new string resource will help provide better user feedback when clipboard operations fail, improving the overall user experience.
Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1)
251-251
:✅ Verification successful
Ensure clipboard operations run on STA thread.
Good change to use the new
StartSTATaskAsync
method for clipboard text retrieval. This ensures proper threading model for COM operations.Note that using
.Result
could potentially lead to deadlocks in certain scenarios, but since this is only creating a model with a function reference to be executed later, it should be fine in this context.
🏁 Script executed:
#!/bin/bash # Check if this pattern is used elsewhere in the codebase where it might cause problems rg "StartSTATaskAsync.*\.Result" --type csLength of output: 248
Verified STA Thread Usage for Clipboard Operations
After reviewing the code and verifying the pattern usage in the codebase, it’s clear that the call to
Win32Helper.StartSTATaskAsync(Clipboard.GetText).Result
is only present inFlow.Launcher.Infrastructure/UserSettings/Settings.cs
. Since this function is used to defer clipboard text retrieval until later execution and is correctly encapsulated within a model creation, the use of.Result
here is acceptable and does not pose a deadlock risk in this context.
- Verified that the snippet is uniquely located in the intended file.
- Confirmed that clipboard operations are safely executed on an STA thread.
Flow.Launcher.Infrastructure/Win32Helper.cs (1)
104-174
: Good implementation of STA thread execution helpers.The implementation of these helper methods provides a clean way to execute actions on an STA thread, which is necessary for clipboard and other COM operations. Properly initializing and uninitializing OLE ensures resources are managed correctly.
🥷 Code experts: onesounds Jack251970, onesounds have most 👩💻 activity in the files. See details
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame:
Activity based on git-commit:
Knowledge based on git-blame: To learn more about /:\ gitStream - Visit our Docs |
Can you reproduce the clear logs function freeze in this PR? |
No, I cannot reproduce that. I check the changes I made and I found the only change I made is setting recursive to false and I have reverted this in |
hm I have it happen on both laptops and both laptop's dev build had no issues that's why I thought it's related to this PR, but I can't reproduce it now. Let's not worry about it then if you haven't made a change in this area and I can't reliably reproduce. |
Before starting this, I would like to ask you two things:
|
This comment has been minimized.
This comment has been minimized.
…970/Flow.Launcher into delete_clipboard_jsonrpc
This comment has been minimized.
This comment has been minimized.
@jjw24 I reverted changes about the update logic and please check |
Other plugins like Explorer can be queried.
Debug turned on, no logs for Programs plugin and logs for others like Explorer plugin. |
@check-spelling-bot Report🔴 Please reviewSee the 📂 files view, the 📜action log, or 📝 job summary for details.
See ❌ Event descriptions for more information. Forbidden patterns 🙅 (1)In order to address this, you could change the content to not match the forbidden patterns (comments before forbidden patterns may help explain why they're forbidden), add patterns for acceptable instances, or adjust the forbidden patterns themselves. These forbidden patterns matched content: s.b. workaround(s)
If the flagged items are 🤯 false positivesIf items relate to a ...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested prior to latest commit:
- result update has no issues
- querying response is fast
- no missing Programs plugin results after intense use
- copying file, paths, bookmark urls
Good! |
Where is the PR for the changes you pulled out? |
I will handle it now. I have not created PR yet. |
Please check #3502. |
Fix copy to clipboard STA thread issue
Fix
CopyToClipboard
function in JsonRPCAPI for JsonRPCV2 plugins: we should use STA thread to execute clipboard options.Close #3071.
Add retry for clipboard copy
Sometimes clipboard is locked, we need to wait and retry.
Async buildin shortcut model
Since new clipboard function need async, we should add support for asynchronous build-in shortcut model.
Fix query update issues
Fix build shortcuts text replace issue
Fix build shortcuts text replace issue from jjw24 and remove global query delay
Fix possible ui thread issue
Check dispatcher access before invoking dispatch to fix possible ui thread issue
Fix startup window hide issue
Fix issue that
HotkeyMapper
initialization will steal focus from main window which can cause main window forces to hide during startup.Test