Skip to content

Commit

Permalink
web-sys 0.3.70 support
Browse files Browse the repository at this point in the history
  • Loading branch information
surinder83singh authored Sep 13, 2024
1 parent abab068 commit 13c350e
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions crates/eframe/src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,14 @@ fn set_cursor_icon(cursor: egui::CursorIcon) -> Option<()> {
#[cfg(web_sys_unstable_apis)]
fn set_clipboard_text(s: &str) {
if let Some(window) = web_sys::window() {
if let Some(clipboard) = window.navigator().clipboard() {
let promise = clipboard.write_text(s);
let future = wasm_bindgen_futures::JsFuture::from(promise);
let future = async move {
if let Err(err) = future.await {
log::error!("Copy/cut action failed: {}", string_from_js_value(&err));
}
};
wasm_bindgen_futures::spawn_local(future);
} else {
let is_secure_context = window.is_secure_context();
if is_secure_context {
log::warn!("window.navigator.clipboard is null; can't copy text");
} else {
log::warn!("window.navigator.clipboard is null; can't copy text, probably because we're not in a secure context. See https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts");
let promise = window.navigator().clipboard().write_text(s);
let future = wasm_bindgen_futures::JsFuture::from(promise);
let future = async move {
if let Err(err) = future.await {
log::error!("Copy/cut action failed: {}", string_from_js_value(&err));
}
}
};
wasm_bindgen_futures::spawn_local(future);
}
}

Expand Down

0 comments on commit 13c350e

Please sign in to comment.