From 903bfbfc9ab546f57a3db8f902e283878667b114 Mon Sep 17 00:00:00 2001 From: rangoDJ Date: Thu, 15 Oct 2026 21:19:38 -0400 Subject: [PATCH 01/70] feat(web): embedded mode hides external community links (#2490) --- apps/pdfcraft-web/src/main.rs | 11 +++++++ crates/ui-egui/src/chrome.rs | 20 +++++++----- crates/ui-egui/src/home.rs | 42 ++++++++++++++------------ crates/ui-egui/src/lib.rs | 4 +++ crates/ui-egui/tests/ui_group/links.rs | 31 +++++++++++++++++++ packaging/web/README.md | 11 ++++--- 6 files changed, 88 insertions(+), 31 deletions(-) diff --git a/apps/pdfcraft-web/src/main.rs b/apps/pdfcraft-web/src/main.rs index a46a4674b9..a7a625405f 100644 --- a/apps/pdfcraft-web/src/main.rs +++ b/apps/pdfcraft-web/src/main.rs @@ -27,6 +27,10 @@ fn main() { if let Some(json) = cc.storage.and_then(|s| s.get_string("pdfcraft").or_else(|| s.get_string("printcraft"))) { app.restore(&json); } + // `?embedded`: hide external community links when framed without `allow-popups` (#2490). + if query_flag("embedded") { + app.embedded = true; + } // `?file=` opens a PDF from a URL (same-origin or CORS-enabled). if let Some(url) = query_param("file") { let inbox = app.startup_inbox.clone(); @@ -106,6 +110,13 @@ fn query_param(key: &str) -> Option { web_sys::UrlSearchParams::new_with_str(&search).ok()?.get(key) } +#[cfg(target_arch = "wasm32")] +fn query_flag(key: &str) -> bool { + let Some(search) = web_sys::window().and_then(|w| w.location().search().ok()) else { return false }; + let Ok(params) = web_sys::UrlSearchParams::new_with_str(&search) else { return false }; + params.has(key) && params.get(key).as_deref() != Some("0") && params.get(key).as_deref() != Some("false") +} + #[cfg(target_arch = "wasm32")] async fn fetch_bytes(url: &str) -> Result, String> { use eframe::wasm_bindgen::JsCast; diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index e8bf3b48dd..c3c8243abd 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -66,11 +66,13 @@ pub fn tab_strip(app: &mut PdfCraftApp, ui: &mut egui::Ui) { app.active = None; app.combine_tab.focused = false; } - // Keep the two icon buttons, Discord's text/padding and three gaps outside the scrolling tabs. - let controls_width = ui.fonts_mut(|f| f.layout_no_wrap("Discord".into(), theme::medium(13.0), t.text).size().x) - + 2.0 * button - + 50.0 - + window_controls::width(&controls.right); + // Keep the two icon buttons, Discord's text/padding (unless embedded) and gaps outside the scrolling tabs. + let discord_width = if app.embedded { + 0.0 + } else { + ui.fonts_mut(|f| f.layout_no_wrap("Discord".into(), theme::medium(13.0), t.text).size().x) + 50.0 + }; + let controls_width = discord_width + 2.0 * button + window_controls::width(&controls.right); // Open stays in sight after the tabs: its icon, text and padding, and the gaps around it. let open_width = ui.fonts_mut(|f| f.layout_no_wrap(tl!("Open").into(), theme::medium(13.0), t.text).size().x) + 38.0 + 12.0; let mut tabs_width = (ui.available_width() - controls_width - open_width).max(0.0); @@ -298,8 +300,12 @@ pub fn tab_strip(app: &mut PdfCraftApp, ui: &mut egui::Ui) { if icons::button(ui, "circle-help", button, false, tl!("Keyboard shortcuts")).clicked() { app.dialog = Some(Dialog::Shortcuts); } - // One click to the community, from anywhere in the app. - if widgets::ghost_button_sized(ui, "messages-square", "Discord", tab_h).on_hover_text(pdfcraft_engine::links::DISCORD).clicked() { + // One click to the community, from anywhere in the app (hidden in embedded mode). + if !app.embedded + && widgets::ghost_button_sized(ui, "messages-square", "Discord", tab_h) + .on_hover_text(pdfcraft_engine::links::DISCORD) + .clicked() + { app.execute("help.discord"); } }); diff --git a/crates/ui-egui/src/home.rs b/crates/ui-egui/src/home.rs index 3e70f34e42..84a4c2f904 100644 --- a/crates/ui-egui/src/home.rs +++ b/crates/ui-egui/src/home.rs @@ -28,27 +28,31 @@ pub fn show(app: &mut PdfCraftApp, ui: &mut egui::Ui) { .color(t.text_muted) .font(theme::regular(14.0)), ); - ui.add_space(14.0); - egui::Frame::NONE - .fill(t.card) - .stroke(Stroke::new(1.0, t.border)) - .corner_radius(CornerRadius::same(12)) - .inner_margin(egui::Margin::same(14)) - .show(ui, |ui| { - ui.set_width(ui.available_width()); - ui.horizontal(|ui| { - widgets::artcraft_mark(ui, 28.0); - ui.vertical(|ui| { - ui.label(egui::RichText::new(tl!("Join the ArtCraft community")).font(theme::semibold(15.0))); - ui.label(egui::RichText::new(tl!("Get help, share feedback and follow development on Discord.")).color(t.text_muted)); + if !app.embedded { + ui.add_space(14.0); + egui::Frame::NONE + .fill(t.card) + .stroke(Stroke::new(1.0, t.border)) + .corner_radius(CornerRadius::same(12)) + .inner_margin(egui::Margin::same(14)) + .show(ui, |ui| { + ui.set_width(ui.available_width()); + ui.horizontal(|ui| { + widgets::artcraft_mark(ui, 28.0); + ui.vertical(|ui| { + ui.label(egui::RichText::new(tl!("Join the ArtCraft community")).font(theme::semibold(15.0))); + ui.label(egui::RichText::new(tl!("Get help, share feedback and follow development on Discord.")).color(t.text_muted)); + }); }); + ui.add_space(8.0); + if let Some(cmd) = widgets::community_links(ui) { + app.execute(cmd); + } }); - ui.add_space(8.0); - if let Some(cmd) = widgets::community_links(ui) { - app.execute(cmd); - } - }); - ui.add_space(22.0); + ui.add_space(22.0); + } else { + ui.add_space(22.0); + } egui::Frame::NONE .fill(t.card) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index d101d812e0..bb1dd2e3dc 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -617,6 +617,8 @@ pub struct PdfCraftApp { pub host_save: Option, /// Reports unsaved work to the embedding page (web, see [`HostDirtyFn`]). pub host_dirty: Option, + /// Embedded mode (web iframe with `?embedded`): hides external links (#2490). + pub embedded: bool, /// A pending "save changes?" question (closing a dirty tab or quitting). pub close_request: Option, /// A save waiting behind [`Dialog::OverwriteChanged`] (the web build has no files to check). @@ -961,6 +963,7 @@ impl PdfCraftApp { os_events: None, host_save: None, host_dirty: None, + embedded: false, close_request: None, #[cfg(not(target_arch = "wasm32"))] pending_overwrite: None, @@ -2507,6 +2510,7 @@ impl PdfCraftApp { } ("left", _) => self.left_open = value != "closed", ("home", _) => self.active = None, + ("embedded", _) => self.embedded = value == "true" || value == "on" || value == "1", ("dialog", _) => { self.dialog = match value { "properties" => Some(Dialog::Properties(PropsTab::Description)), diff --git a/crates/ui-egui/tests/ui_group/links.rs b/crates/ui-egui/tests/ui_group/links.rs index b08036b11d..bdd651d824 100644 --- a/crates/ui-egui/tests/ui_group/links.rs +++ b/crates/ui-egui/tests/ui_group/links.rs @@ -100,3 +100,34 @@ fn about_dialog_has_contributors_and_models_tabs() { h.run_steps(4); assert!(h.query_all_by_label("Anthropic").count() >= 1); } + +#[test] +fn embedded_mode_hides_community_links_and_discord_button() { + let h = harness(|app| { + app.embedded = true; + }); + assert!(h.query_by_label("Join the ArtCraft community").is_none()); + assert!(h.query_by_label("Join our Discord").is_none()); + assert!(h.query_by_label("PdfCraft web page").is_none()); + assert!(h.query_by_label("PdfCraft on GitHub").is_none()); + assert!(h.query_by_label("ArtCraft website").is_none()); + assert!(h.query_by_label("Discord").is_none()); +} + +#[test] +fn set_option_embedded_configures_flag() { + let mut app = PdfCraftApp::new(); + assert!(!app.embedded); + app.set_option("embedded", "true").unwrap(); + assert!(app.embedded); + app.set_option("embedded", "off").unwrap(); + assert!(!app.embedded); + app.set_option("embedded", "1").unwrap(); + assert!(app.embedded); + app.set_option("embedded", "0").unwrap(); + assert!(!app.embedded); + app.set_option("embedded", "on").unwrap(); + assert!(app.embedded); + app.set_option("embedded", "false").unwrap(); + assert!(!app.embedded); +} diff --git a/packaging/web/README.md b/packaging/web/README.md index 7aaa49d6a5..ba81dd378c 100644 --- a/packaging/web/README.md +++ b/packaging/web/README.md @@ -75,20 +75,21 @@ Local test: `python3 -m http.server 8765` inside the folder, then open http://lo - **Sandboxed iframes** need at least `sandbox="allow-scripts allow-same-origin allow-downloads allow-popups"`. Without `allow-same-origin` there's no storage. Without `allow-downloads`, Save and Export (browser - downloads) are blocked. + downloads) are blocked. Without `allow-popups`, external links (community, documentation) cannot + open; pass `?embedded` on the iframe `src` to hide external community links cleanly. - Don't send `X-Frame-Options: DENY` or a `frame-ancestors` CSP that excludes the embedding page. -## Renderer selection and fallback flags +## URL query flags -PdfCraft renders with wgpu. It uses **WebGPU** when the browser has it and falls back to -**WebGL2** on its own. URL query flags override this, and they work on the iframe `src` too: +URL query flags configure startup behavior and renderer selection. They work on the iframe `src` too: | Flag | Effect | |---|---| | *(none)* | WebGPU if available, otherwise WebGL2 | | `?webgl` | Force the WebGL2 backend (useful when a WebGPU driver misbehaves) | | `?cpu` | Force the CPU canvas path (slowest, most compatible) | +| `?embedded` | Hide external community links (welcome screen card and header bar Discord button) | -For example: `