Skip to content

Commit

Permalink
Do not read query in embedded web viewer (#6515)
Browse files Browse the repository at this point in the history
  • Loading branch information
jprochazk authored Jul 2, 2024
1 parent 91b81c7 commit 4ee7634
Show file tree
Hide file tree
Showing 14 changed files with 569 additions and 308 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
// Uncomment the following option and restart rust-analyzer to get it to check code behind `cfg(target_arch=wasm32)`.
// Don't forget to put it in a comment again before committing.
// "rust-analyzer.cargo.target": "wasm32-unknown-unknown"
}
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5200,6 +5200,7 @@ dependencies = [
"image",
"itertools 0.13.0",
"js-sys",
"parking_lot",
"poll-promise",
"re_analytics",
"re_blueprint_tree",
Expand Down
2 changes: 2 additions & 0 deletions crates/re_viewer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ egui.workspace = true
ehttp.workspace = true
image = { workspace = true, default-features = false, features = ["png"] }
itertools = { workspace = true }
parking_lot.workspace = true
poll-promise = { workspace = true, features = ["web"] }
rfd.workspace = true
ron.workspace = true
Expand All @@ -121,6 +122,7 @@ wasm-bindgen.workspace = true
web-sys = { workspace = true, features = [
"History",
"Location",
"PopStateEvent",
"Storage",
"Url",
"UrlSearchParams",
Expand Down
37 changes: 34 additions & 3 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ pub struct StartupOptions {

/// Default overrides for state of top/side/bottom panels.
pub panel_state_overrides: PanelStateOverrides,

/// Whether or not to enable usage of the `History` API on web.
///
/// It is disabled by default.
///
/// This should only be enabled when it is acceptable for `rerun`
/// to push its own entries into browser history.
///
/// That only makes sense if it has "taken over" a page, and is
/// the only thing on that page. If you are embedding multiple
/// viewers onto the same page, then it's better to turn this off.
///
/// We use browser history in a limited way to track the currently
/// open example recording, see [`crate::history`].
#[cfg(target_arch = "wasm32")]
pub enable_history: bool,
}

impl Default for StartupOptions {
Expand Down Expand Up @@ -107,6 +123,9 @@ impl Default for StartupOptions {
fullscreen_options: Default::default(),

panel_state_overrides: Default::default(),

#[cfg(target_arch = "wasm32")]
enable_history: false,
}
}
}
Expand All @@ -127,6 +146,9 @@ pub struct App {
pub(crate) egui_ctx: egui::Context,
screenshotter: crate::screenshotter::Screenshotter,

#[cfg(target_arch = "wasm32")]
pub(crate) popstate_listener: Option<crate::history::PopstateListener>,

#[cfg(not(target_arch = "wasm32"))]
profiler: re_tracing::Profiler,

Expand Down Expand Up @@ -272,6 +294,9 @@ impl App {
egui_ctx,
screenshotter,

#[cfg(target_arch = "wasm32")]
popstate_listener: None,

#[cfg(not(target_arch = "wasm32"))]
profiler: Default::default(),

Expand Down Expand Up @@ -945,6 +970,11 @@ impl App {
if let Some(store_view) = store_context {
let entity_db = store_view.recording;

#[cfg(target_arch = "wasm32")]
let is_history_enabled = self.startup_options.enable_history;
#[cfg(not(target_arch = "wasm32"))]
let is_history_enabled = false;

self.state.show(
app_blueprint,
ui,
Expand All @@ -960,6 +990,7 @@ impl App {
hide: self.startup_options.hide_welcome_screen,
opacity: self.welcome_screen_opacity(egui_ctx),
},
is_history_enabled,
);
}
render_ctx.before_submit();
Expand Down Expand Up @@ -1462,18 +1493,18 @@ impl eframe::App for App {
}

#[cfg(target_arch = "wasm32")]
{
if self.startup_options.enable_history {
// Handle pressing the back/forward mouse buttons explicitly, since eframe catches those.
let back_pressed =
egui_ctx.input(|i| i.pointer.button_pressed(egui::PointerButton::Extra1));
let fwd_pressed =
egui_ctx.input(|i| i.pointer.button_pressed(egui::PointerButton::Extra2));

if back_pressed {
crate::web_tools::go_back();
crate::history::go_back();
}
if fwd_pressed {
crate::web_tools::go_forward();
crate::history::go_forward();
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/re_viewer/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl AppState {
rx: &ReceiveSet<LogMsg>,
command_sender: &CommandSender,
welcome_screen_state: &WelcomeScreenState,
is_history_enabled: bool,
) {
re_tracing::profile_function!();

Expand Down Expand Up @@ -417,7 +418,7 @@ impl AppState {
.frame(viewport_frame)
.show_inside(ui, |ui| {
if show_welcome {
welcome_screen.ui(ui, command_sender, welcome_screen_state);
welcome_screen.ui(ui, command_sender, welcome_screen_state, is_history_enabled);
} else {
viewport.viewport_ui(ui, &ctx, view_states);
}
Expand Down
Loading

0 comments on commit 4ee7634

Please sign in to comment.