Skip to content

Commit 7da3fb1

Browse files
committed
Implement stub Clipboard in iced_web
We need to figure out browser permissions and use of unstable `web-sys` APIs
1 parent a365998 commit 7da3fb1

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

src/application.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,12 @@ where
305305
self.0.title()
306306
}
307307

308-
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
309-
self.0.update(message)
308+
fn update(
309+
&mut self,
310+
message: Self::Message,
311+
clipboard: &mut Clipboard,
312+
) -> Command<Self::Message> {
313+
self.0.update(message, clipboard)
310314
}
311315

312316
fn subscription(&self) -> Subscription<Self::Message> {

web/src/clipboard.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// A buffer for short-term storage and transfer within and between
2+
/// applications.
3+
#[derive(Debug, Clone, Copy)]
4+
pub struct Clipboard;
5+
6+
impl Clipboard {
7+
/// Creates a new [`Clipboard`].
8+
pub fn new() -> Self {
9+
Self
10+
}
11+
12+
/// Reads the current content of the [`Clipboard`] as text.
13+
pub fn read(&self) -> Option<String> {
14+
unimplemented! {}
15+
}
16+
17+
/// Writes the given text contents to the [`Clipboard`].
18+
pub fn write(&mut self, _contents: String) {
19+
unimplemented! {}
20+
}
21+
}

web/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use dodrio::bumpalo;
5959
use std::{cell::RefCell, rc::Rc};
6060

6161
mod bus;
62+
mod clipboard;
6263
mod element;
6364
mod hasher;
6465

@@ -67,6 +68,7 @@ pub mod subscription;
6768
pub mod widget;
6869

6970
pub use bus::Bus;
71+
pub use clipboard::Clipboard;
7072
pub use css::Css;
7173
pub use dodrio;
7274
pub use element::Element;
@@ -126,7 +128,11 @@ pub trait Application {
126128
/// this method.
127129
///
128130
/// Any [`Command`] returned will be executed immediately in the background.
129-
fn update(&mut self, message: Self::Message) -> Command<Self::Message>;
131+
fn update(
132+
&mut self,
133+
message: Self::Message,
134+
clipboard: &mut Clipboard,
135+
) -> Command<Self::Message>;
130136

131137
/// Returns the widgets to display in the [`Application`].
132138
///
@@ -156,6 +162,8 @@ pub trait Application {
156162
let document = window.document().unwrap();
157163
let body = document.body().unwrap();
158164

165+
let mut clipboard = Clipboard::new();
166+
159167
let (sender, receiver) =
160168
iced_futures::futures::channel::mpsc::unbounded();
161169

@@ -182,7 +190,8 @@ pub trait Application {
182190

183191
let event_loop = receiver.for_each(move |message| {
184192
let (command, subscription) = runtime.enter(|| {
185-
let command = application.borrow_mut().update(message);
193+
let command =
194+
application.borrow_mut().update(message, &mut clipboard);
186195
let subscription = application.borrow().subscription();
187196

188197
(command, subscription)

0 commit comments

Comments
 (0)