Synphonyte / leptos-use

Collection of essential Leptos utilities inspired by React-Use / VueUse / SolidJS-USE
https://leptos-use.rs/
Apache License 2.0
309 stars 67 forks source link

use_clipboard text is not shown #119

Closed tversteeg closed 1 month ago

tversteeg commented 3 months ago

When I run the demo I see the following screen even when I copy something:

image

I never get a prompt, also not when I press the copy button, but that works fine. When I run it locally, I see the same pattern, but when I copy any text on the page I see the following error in the console (I don't see anything in the console for the demo):

image

I'm using Floorp 11.13.3 which is based on Firefox 115.12.0.

I've created a simple helper struct that I pass around with use_context to show you how I access the API:

Helper script `src/clipboard.rs`: ```rust //! Global clipboard state. use leptos::{Signal, SignalGetUntracked}; use leptos_use::{PermissionState, UseClipboardOptions, UseClipboardReturn}; /// Clipboard state meant to be passed in context. #[derive(Clone)] pub struct Clipboard { /// Whether we have permission. pub permission: Signal, /// Whether the Clipboard API is supported. is_supported: Signal, /// The current state of the clipboard. text: Signal>, } impl Clipboard { /// Setup the clipboard. pub fn new() -> Self { // Request the permission state let permission = leptos_use::use_permission("clipboard"); // Request the clipboard API first let UseClipboardReturn { is_supported, text, .. } = leptos_use::use_clipboard_with_options(UseClipboardOptions::default().read(true)); Self { permission, is_supported, text, } } /// Get the contents of the clipboard. pub fn text(&self) -> Option { // Return nothing when the user didn't grant permission if !self.check_permissions() { return None; } self.text.get_untracked() } /// Check the permissions of the clipboard. /// /// If they haven't been requested yet, request them. fn check_permissions(&self) -> bool { // Handle the different permission states match self.permission.get_untracked() { // Not requested yet, request it PermissionState::Unknown => { return false; } // Permission denied PermissionState::Denied => { log::warn!("Clipboard permission is denied, can't access it"); return false; } // Permission is OK, perform the other checks PermissionState::Granted | PermissionState::Prompt => (), } // Return nothing when we can't use the clipboard if self.is_supported.get_untracked() { true } else { log::warn!("Clipboard actions are not supported"); false } } } ```
maccesch commented 3 months ago

I downloaded Floorp and opened https://leptos-use.rs/browser/use_clipboard.html and everything works just as well as in Firefox, my usual browser.

Please note that the demo doesn't have read enabled so it only updates when you click the "Copy" button.

tversteeg commented 3 months ago

Ah right, so maybe the bug is not related to the demo but specifically to read being enabled?