diff --git a/Cargo.lock b/Cargo.lock index 8d460b549..e6e990f4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,6 +39,7 @@ dependencies = [ "truck-shapeops", "ttf-parser", "ureq", + "web-sys", "windows-sys 0.61.2", "winresource", ] diff --git a/Cargo.toml b/Cargo.toml index c4c8b5098..8308f3d68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,6 +82,8 @@ ureq = { version = "3", default-features = false, features = ["rustls"] } [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1" +# Opening external URLs (Donate / feedback / release notes) via window.open. +web-sys = { version = "0.3", features = ["Window"] } # Browsers without WebGPU (e.g. Firefox by default) need wgpu's WebGL2 backend; # `webgl` enables it. `fira-sans` embeds the default UI font — the web has no # system fonts, so without it all iced text (ribbon labels, command line) is diff --git a/src/app/commands.rs b/src/app/commands.rs index f6b25b905..578dba801 100644 --- a/src/app/commands.rs +++ b/src/app/commands.rs @@ -36,7 +36,7 @@ impl OpenCADStudio { && !matches!( cmd, "NEW" | "OPEN" | "EXIT" | "QUIT" | "REPORT" | "CHANGELOG" | "ABOUT" - | "PLUGINS" | "PLUGINMANAGER" + | "PLUGINS" | "PLUGINMANAGER" | "DONATE" ) { self.command_line diff --git a/src/sys.rs b/src/sys.rs index 48149bede..58e0a2697 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -1,17 +1,20 @@ // Small platform shims for things the desktop build does natively but the web // (wasm) build must handle differently or skip. -/// Open a URL in the user's browser. On the desktop this launches the default -/// handler; on the web the app already *is* in a browser, so for now this is a -/// no-op (a real implementation would call `window.open`). +/// Open a URL in the user's browser. The desktop launches the default handler; +/// the web opens a new tab (the button click is a user gesture, so it isn't +/// caught by the pop-up blocker). Focus of the opened page is left to the +/// OS / browser. #[cfg(not(target_arch = "wasm32"))] pub fn open_url(url: &str) { let _ = open::that(url); } #[cfg(target_arch = "wasm32")] -pub fn open_url(_url: &str) { - // TODO(web): web_sys::window().open_with_url(_url) +pub fn open_url(url: &str) { + if let Some(window) = web_sys::window() { + let _ = window.open_with_url_and_target(url, "_blank"); + } } /// Turn an `rfd` file handle into a `PathBuf` the rest of the app keys on.