From f63f525d5c0e0c5239fa64f753f0c5f1b91915c7 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 18 Aug 2024 12:56:13 +0200 Subject: [PATCH] update web-sys & wasm --- .github/workflows/rust.yml | 2 +- Cargo.lock | 29 +++++++++++++++-------------- Cargo.toml | 2 +- crates/eframe/src/web/events.rs | 4 ++-- crates/eframe/src/web/mod.rs | 23 +++++++---------------- crates/egui_demo_app/Cargo.toml | 2 +- scripts/setup_web.sh | 2 +- 7 files changed, 28 insertions(+), 36 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8aaa18faa36..5722f2ccedd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -108,7 +108,7 @@ jobs: - name: wasm-bindgen uses: jetli/wasm-bindgen-action@v0.1.0 with: - version: "0.2.92" + version: "0.2.93" - run: ./scripts/wasm_bindgen_check.sh --skip-setup diff --git a/Cargo.lock b/Cargo.lock index e8ad2fdc54e..c4b06ef8ffe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2235,9 +2235,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -4208,19 +4208,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -4245,9 +4246,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4255,9 +4256,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -4268,9 +4269,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "wayland-backend" @@ -4383,9 +4384,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 9b32b138dd4..21e8d847e23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -90,7 +90,7 @@ thiserror = "1.0.37" web-time = "1.1.0" # Timekeeping for native and web wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" -web-sys = "0.3.58" +web-sys = "0.3.70" wgpu = { version = "22.1.0", default-features = false, features = [ # Make the renderer `Sync` even on wasm32, because it makes the code simpler: "fragile-send-sync-non-atomic-wasm", diff --git a/crates/eframe/src/web/events.rs b/crates/eframe/src/web/events.rs index b3854d17887..ad37ef7c0a5 100644 --- a/crates/eframe/src/web/events.rs +++ b/crates/eframe/src/web/events.rs @@ -767,8 +767,8 @@ pub(crate) fn install_resize_observer(runner_ref: &WebRunner) -> Result<(), JsVa }) as Box); let observer = web_sys::ResizeObserver::new(closure.as_ref().unchecked_ref())?; - let mut options = web_sys::ResizeObserverOptions::new(); - options.box_(web_sys::ResizeObserverBoxOptions::ContentBox); + let options = web_sys::ResizeObserverOptions::new(); + options.set_box(web_sys::ResizeObserverBoxOptions::ContentBox); if let Some(runner_lock) = runner_ref.try_lock() { observer.observe_with_options(runner_lock.canvas(), &options); drop(runner_lock); diff --git a/crates/eframe/src/web/mod.rs b/crates/eframe/src/web/mod.rs index 1a6fa6b447c..7403b54cc14 100644 --- a/crates/eframe/src/web/mod.rs +++ b/crates/eframe/src/web/mod.rs @@ -171,23 +171,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); } } diff --git a/crates/egui_demo_app/Cargo.toml b/crates/egui_demo_app/Cargo.toml index 9000ac93b53..827b14fb42d 100644 --- a/crates/egui_demo_app/Cargo.toml +++ b/crates/egui_demo_app/Cargo.toml @@ -77,6 +77,6 @@ rfd = { version = "0.13", optional = true } # web: [target.'cfg(target_arch = "wasm32")'.dependencies] -wasm-bindgen = "=0.2.92" +wasm-bindgen = "=0.2.93" wasm-bindgen-futures.workspace = true web-sys.workspace = true diff --git a/scripts/setup_web.sh b/scripts/setup_web.sh index 51e53d4be4a..b295ed11fff 100755 --- a/scripts/setup_web.sh +++ b/scripts/setup_web.sh @@ -7,4 +7,4 @@ cd "$script_path/.." rustup target add wasm32-unknown-unknown # For generating JS bindings: -cargo install --quiet wasm-bindgen-cli --version 0.2.92 +cargo install --quiet wasm-bindgen-cli --version 0.2.93