-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add WASM clipboard support with async/sync APIs #7
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
base: main
Are you sure you want to change the base?
feat: add WASM clipboard support with async/sync APIs #7
Conversation
Implements clipboard functionality for web targets with feature flags: - feature enables hybrid sync API with background async updates - features provide fully async API - Maintains SSR safety and supports both desktop and web platforms - Includes examples demonstrating sync and async usage
|
Would close #3 I have not tested this on desktop but it seems it should work, didn't really change anything on that end. If someone could test that before it merges that would be great |
|
Good work, this could be the way forward, I will check it out! |
| fn get(&mut self) -> Result<String, ClipboardError> { | ||
| // Return cached value and trigger background refresh | ||
| let cached_value = self.clipboard_cache.read().clone(); | ||
|
|
||
| // Spawn background refresh | ||
| let mut cache_signal = self.clipboard_cache; | ||
| let _ = spawn(async move { | ||
| if let Ok(content) = read_clipboard_async().await { | ||
| *cache_signal.write() = Some(content); | ||
| } | ||
| }); | ||
|
|
||
| cached_value.ok_or(ClipboardError::NotAvailable) | ||
| } |
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.
I feel like this could be very confusing. Maybe there should not be a wasm sync implementation at all?
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.
The WASM sync implementation is basically just a wrapper as you can see. It's definitely a bit hackish but I wanted a way that someone could enable WASM and still have their sync interfaces. Btw, it's the same for the "async" interface for desktop, just a wrapper really (albeit a bit simpler).
If you want me to remove this, I guess if WASM feature is enabled then crate becomes async and without it stays sync with no web? Basically remove the async flag
Implements clipboard functionality for web targets with feature flags: