Skip to content

Conversation

@Himmelschmidt
Copy link

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

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
@Himmelschmidt
Copy link
Author

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

@marc2332 marc2332 self-requested a review August 6, 2025 21:32
@marc2332 marc2332 linked an issue Aug 6, 2025 that may be closed by this pull request
@marc2332
Copy link
Member

marc2332 commented Aug 6, 2025

Good work, this could be the way forward, I will check it out!

Comment on lines +75 to +88
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)
}
Copy link
Member

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?

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web wasm support?

2 participants