Skip to content

Commit 4aa1ff2

Browse files
authored
Add optional viewer url parameter to web app options (#11296)
1 parent b5c3d7a commit 4aa1ff2

File tree

8 files changed

+43
-20
lines changed

8 files changed

+43
-20
lines changed

crates/build/re_types_builder/src/codegen/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl<'a> ImageStack<'a> {
157157

158158
/// Set the snippet ID.
159159
///
160-
/// If set, the resulting `<picture>` element will have the `data-inline-viewr`
160+
/// If set, the resulting `<picture>` element will have the `data-inline-viewer`
161161
/// attribute set with the value of this ID.
162162
/// `data-inline-viewer` is not set for `<img>` elements.
163163
#[inline]

crates/viewer/re_viewer/src/app.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,10 @@ impl App {
630630
self.go_to_dataset_data(store_id, fragment);
631631
}
632632
SystemCommand::CopyViewerUrl(url) => {
633-
match combine_with_base_url(web_viewer_base_url().as_ref(), [url]) {
633+
match combine_with_base_url(
634+
self.startup_options.web_viewer_base_url().as_ref(),
635+
[url],
636+
) {
634637
Ok(url) => {
635638
self.copy_text(url);
636639
}
@@ -1683,7 +1686,7 @@ impl App {
16831686
}
16841687

16851688
fn run_copy_link_command(&mut self, content_url: &ViewerOpenUrl) {
1686-
let base_url = web_viewer_base_url();
1689+
let base_url = self.startup_options.web_viewer_base_url();
16871690

16881691
match content_url.sharable_url(base_url.as_ref()) {
16891692
Ok(url) => {
@@ -1857,6 +1860,7 @@ impl App {
18571860

18581861
self.state.show(
18591862
&self.app_env,
1863+
&self.startup_options,
18601864
app_blueprint,
18611865
ui,
18621866
render_ctx,
@@ -3243,16 +3247,3 @@ async fn async_save_dialog(
32433247
)?;
32443248
file_handle.write(&bytes).await.context("Failed to save")
32453249
}
3246-
3247-
pub fn web_viewer_base_url() -> Option<url::Url> {
3248-
#[cfg(target_arch = "wasm32")]
3249-
{
3250-
crate::web_tools::current_base_url().ok()
3251-
}
3252-
3253-
#[cfg(not(target_arch = "wasm32"))]
3254-
{
3255-
// TODO(RR-1878): Would be great to grab this from the dataplatform when available.
3256-
url::Url::parse("https://rerun.io/viewer").ok()
3257-
}
3258-
}

crates/viewer/re_viewer/src/app_state.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use re_viewport_blueprint::ViewportBlueprint;
2525
use re_viewport_blueprint::ui::add_view_or_container_modal_ui;
2626

2727
use crate::{
28-
app::web_viewer_base_url, app_blueprint::AppBlueprint, event::ViewerEventDispatcher,
28+
StartupOptions, app_blueprint::AppBlueprint, event::ViewerEventDispatcher,
2929
navigation::Navigation, open_url_description::ViewerOpenUrlDescription, ui::settings_screen_ui,
3030
};
3131

@@ -159,6 +159,7 @@ impl AppState {
159159
pub fn show(
160160
&mut self,
161161
app_env: &crate::AppEnvironment,
162+
startup_options: &StartupOptions,
162163
app_blueprint: &AppBlueprint<'_>,
163164
ui: &mut egui::Ui,
164165
render_ctx: &re_renderer::RenderContext,
@@ -676,7 +677,7 @@ impl AppState {
676677
self.redap_servers.modals_ui(&ctx.global_context, ui);
677678
self.open_url_modal.ui(ui);
678679
self.share_modal
679-
.ui(&ctx, ui, web_viewer_base_url().as_ref());
680+
.ui(&ctx, ui, startup_options.web_viewer_base_url().as_ref());
680681
}
681682
}
682683

crates/viewer/re_viewer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl AppEnvironment {
170170

171171
pub fn url(&self) -> Option<&String> {
172172
match self {
173-
Self::Web { url } => Some(url),
173+
Self::Web { url, .. } => Some(url),
174174
_ => None,
175175
}
176176
}

crates/viewer/re_viewer/src/startup_options.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ pub struct StartupOptions {
7878
/// open example or redap recording, see [`crate::history`].
7979
#[cfg(target_arch = "wasm32")]
8080
pub enable_history: bool,
81+
82+
/// The base viewer url that's used when sharing a link in this viewer.
83+
#[cfg(target_arch = "wasm32")]
84+
pub viewer_url: Option<String>,
8185
}
8286

8387
impl StartupOptions {
@@ -94,6 +98,24 @@ impl StartupOptions {
9498
false
9599
}
96100
}
101+
102+
/// The url to use for the web viewer when sharing links.
103+
#[allow(clippy::unused_self)] // Only used on web.
104+
pub fn web_viewer_base_url(&self) -> Option<url::Url> {
105+
#[cfg(target_arch = "wasm32")]
106+
{
107+
self.viewer_url
108+
.as_ref()
109+
.and_then(|url| url.parse().ok())
110+
.or_else(|| crate::web_tools::current_base_url().ok())
111+
}
112+
113+
#[cfg(not(target_arch = "wasm32"))]
114+
{
115+
// TODO(RR-1878): Would be great to grab this from the dataplatform when available.
116+
url::Url::parse("https://rerun.io/viewer").ok()
117+
}
118+
}
97119
}
98120

99121
impl Default for StartupOptions {
@@ -130,6 +152,9 @@ impl Default for StartupOptions {
130152

131153
#[cfg(target_arch = "wasm32")]
132154
enable_history: false,
155+
156+
#[cfg(target_arch = "wasm32")]
157+
viewer_url: None,
133158
}
134159
}
135160
}

crates/viewer/re_viewer/src/web.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ impl From<PanelState> for re_types::blueprint::components::PanelState {
661661
// Keep in sync with the `AppOptions` interface in `rerun_js/web-viewer/index.ts`.
662662
#[derive(Clone, Default, Deserialize)]
663663
pub struct AppOptions {
664+
viewer_url: Option<String>,
664665
url: Option<StringOrStringArray>,
665666
manifest_url: Option<String>,
666667
render_backend: Option<String>,
@@ -713,11 +714,13 @@ fn create_app(
713714
app_options: AppOptions,
714715
) -> Result<crate::App, re_renderer::RenderContextError> {
715716
let build_info = re_build_info::build_info!();
717+
716718
let app_env = crate::AppEnvironment::Web {
717719
url: cc.integration_info.web_info.location.url.clone(),
718720
};
719721

720722
let AppOptions {
723+
viewer_url,
721724
url,
722725
manifest_url,
723726
render_backend,
@@ -781,6 +784,7 @@ fn create_app(
781784
panel_state_overrides: panel_state_overrides.unwrap_or_default().into(),
782785

783786
enable_history,
787+
viewer_url,
784788
};
785789
crate::customize_eframe_and_setup_renderer(cc)?;
786790

crates/viewer/re_viewer/src/web_tools.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Callback {
112112
}
113113

114114
// Deserializes from JS string or array of strings.
115-
#[derive(Clone)]
115+
#[derive(Clone, Debug)]
116116
pub struct StringOrStringArray(Vec<String>);
117117

118118
impl StringOrStringArray {

rerun_js/web-viewer/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ export interface WebViewerOptions {
112112
* @private
113113
*/
114114
export interface AppOptions extends WebViewerOptions {
115+
/** The url that's used when sharing web viewer urls */
116+
viewer_url?: string;
115117
url?: string;
116118
manifest_url?: string;
117119
video_decoder?: VideoDecoder;

0 commit comments

Comments
 (0)