From 7da3fb1b2225732c87aebb13a067fbdb30b0cf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Thu, 11 Mar 2021 03:49:45 +0100 Subject: [PATCH] Implement stub `Clipboard` in `iced_web` We need to figure out browser permissions and use of unstable `web-sys` APIs --- src/application.rs | 8 ++++++-- web/src/clipboard.rs | 21 +++++++++++++++++++++ web/src/lib.rs | 13 +++++++++++-- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 web/src/clipboard.rs diff --git a/src/application.rs b/src/application.rs index 162fde84..4c6d5b7f 100644 --- a/src/application.rs +++ b/src/application.rs @@ -305,8 +305,12 @@ where self.0.title() } - fn update(&mut self, message: Self::Message) -> Command { - self.0.update(message) + fn update( + &mut self, + message: Self::Message, + clipboard: &mut Clipboard, + ) -> Command { + self.0.update(message, clipboard) } fn subscription(&self) -> Subscription { diff --git a/web/src/clipboard.rs b/web/src/clipboard.rs new file mode 100644 index 00000000..167a1e53 --- /dev/null +++ b/web/src/clipboard.rs @@ -0,0 +1,21 @@ +/// A buffer for short-term storage and transfer within and between +/// applications. +#[derive(Debug, Clone, Copy)] +pub struct Clipboard; + +impl Clipboard { + /// Creates a new [`Clipboard`]. + pub fn new() -> Self { + Self + } + + /// Reads the current content of the [`Clipboard`] as text. + pub fn read(&self) -> Option { + unimplemented! {} + } + + /// Writes the given text contents to the [`Clipboard`]. + pub fn write(&mut self, _contents: String) { + unimplemented! {} + } +} diff --git a/web/src/lib.rs b/web/src/lib.rs index 58f6591d..4c65dfa3 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -59,6 +59,7 @@ use dodrio::bumpalo; use std::{cell::RefCell, rc::Rc}; mod bus; +mod clipboard; mod element; mod hasher; @@ -67,6 +68,7 @@ pub mod subscription; pub mod widget; pub use bus::Bus; +pub use clipboard::Clipboard; pub use css::Css; pub use dodrio; pub use element::Element; @@ -126,7 +128,11 @@ pub trait Application { /// this method. /// /// Any [`Command`] returned will be executed immediately in the background. - fn update(&mut self, message: Self::Message) -> Command; + fn update( + &mut self, + message: Self::Message, + clipboard: &mut Clipboard, + ) -> Command; /// Returns the widgets to display in the [`Application`]. /// @@ -156,6 +162,8 @@ pub trait Application { let document = window.document().unwrap(); let body = document.body().unwrap(); + let mut clipboard = Clipboard::new(); + let (sender, receiver) = iced_futures::futures::channel::mpsc::unbounded(); @@ -182,7 +190,8 @@ pub trait Application { let event_loop = receiver.for_each(move |message| { let (command, subscription) = runtime.enter(|| { - let command = application.borrow_mut().update(message); + let command = + application.borrow_mut().update(message, &mut clipboard); let subscription = application.borrow().subscription(); (command, subscription)