Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not read query in embedded web viewer #6515

Merged
merged 25 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ec560c9
wip
jprochazk Jun 7, 2024
e574ca5
update AppOptions type
jprochazk Jun 7, 2024
023c2ea
Merge branch 'main' into jan/remove-query-map
jprochazk Jun 11, 2024
750c84a
Merge branch 'main' into jan/remove-query-map
jprochazk Jun 18, 2024
d9e0a9b
wip
jprochazk Jun 18, 2024
cf83f3e
Merge branch 'main' into jan/remove-query-map
jprochazk Jun 24, 2024
b7de892
Merge branch 'main' into jan/remove-query-map
jprochazk Jun 25, 2024
1a8bafc
Merge branch 'main' into jan/remove-query-map
jprochazk Jun 26, 2024
7b67c74
refactor history api
jprochazk Jun 26, 2024
9e2c932
remove settings.json change
jprochazk Jul 1, 2024
62f8348
Merge branch 'main' into jan/remove-query-map
jprochazk Jul 1, 2024
69498b0
Merge branch 'main' into jan/remove-query-map
jprochazk Jul 2, 2024
0b9221e
Merge branch 'main' into jan/remove-query-map
jprochazk Jul 2, 2024
1adc95c
ignore generated files in lint
jprochazk Jul 2, 2024
0923c20
fix lints
jprochazk Jul 2, 2024
81f797d
improve popstate event behavior
jprochazk Jul 2, 2024
c557f02
Merge branch 'main' into jan/remove-query-map
jprochazk Jul 2, 2024
1eeea44
move history into its own file
jprochazk Jul 2, 2024
5d9d19f
add some comments
jprochazk Jul 2, 2024
e7b9050
rm dead code
jprochazk Jul 2, 2024
e3a6bc0
link to issue
jprochazk Jul 2, 2024
f2c89f3
use default + remove unwrap
jprochazk Jul 2, 2024
e4a1aec
comment about target
jprochazk Jul 2, 2024
c8e643a
Merge branch 'main' into jan/remove-query-map
jprochazk Jul 2, 2024
3749457
fix lints
jprochazk Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"rust-analyzer.cargo.target": "wasm32-unknown-unknown"
jprochazk marked this conversation as resolved.
Show resolved Hide resolved
}
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
20 changes: 19 additions & 1 deletion crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ pub struct StartupOptions {

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

#[cfg(target_arch = "wasm32")]
pub enable_history: bool,
jprochazk marked this conversation as resolved.
Show resolved Hide resolved
}

impl Default for StartupOptions {
Expand Down Expand Up @@ -107,6 +110,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 +133,9 @@ pub struct App {
pub(crate) egui_ctx: egui::Context,
screenshotter: crate::screenshotter::Screenshotter,

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

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

Expand Down Expand Up @@ -272,6 +281,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 +957,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 +977,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,7 +1480,7 @@ 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));
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
56 changes: 8 additions & 48 deletions crates/re_viewer/src/ui/welcome_screen/example_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ impl ExampleSection {
ui: &mut egui::Ui,
command_sender: &CommandSender,
header_ui: &impl Fn(&mut Ui),
is_history_enabled: bool,
) {
let examples = self
.examples
Expand Down Expand Up @@ -352,19 +353,11 @@ impl ExampleSection {
// panel to quit auto-zoom mode.
ui.input_mut(|i| i.pointer = Default::default());

let open_in_new_tab = ui.input(|i| i.modifiers.any());
open_example_url(
ui.ctx(),
command_sender,
&example.desc.rrd_url,
open_in_new_tab,
);
} else if response.middle_clicked() {
open_example_url(
ui.ctx(),
command_sender,
&example.desc.rrd_url,
true,
is_history_enabled,
);
}

Expand Down Expand Up @@ -433,28 +426,12 @@ impl ExampleSection {
}
}

#[cfg(target_arch = "wasm32")]
fn open_in_background_tab(egui_ctx: &egui::Context, rrd_url: &str) {
egui_ctx.open_url(egui::output::OpenUrl {
url: format!("/?url={}", crate::web_tools::percent_encode(rrd_url)),
new_tab: true,
});
}

fn open_example_url(
_egui_ctx: &egui::Context,
command_sender: &CommandSender,
rrd_url: &str,
_open_in_new_tab: bool,
_is_history_enabled: bool,
) {
#[cfg(target_arch = "wasm32")]
{
if _open_in_new_tab {
open_in_background_tab(_egui_ctx, rrd_url);
return;
}
}

let data_source = re_data_source::DataSource::RrdHttpUrl {
url: rrd_url.to_owned(),
follow: false,
Expand All @@ -471,30 +448,13 @@ fn open_example_url(
command_sender.send_system(SystemCommand::LoadDataSource(data_source));

#[cfg(target_arch = "wasm32")]
{
// Ensure that the user returns to the welcome page after navigating to an example.
use crate::web_tools;

// So we know where to return to
let welcome_screen_app_id = re_viewer_context::StoreHub::welcome_screen_app_id();
let welcome_screen_url = format!(
"?app_id={}",
web_tools::percent_encode(&welcome_screen_app_id.to_string())
);
if _is_history_enabled {
use crate::web_tools::{history, HistoryEntry, HistoryExt, JsResultExt};

if web_tools::current_url_suffix()
.unwrap_or_default()
.is_empty()
{
// Replace, otherwise the user would need to hit back twice to return to
// whatever linked them to `https://www.rerun.io/viewer` in the first place.
web_tools::replace_history(&welcome_screen_url);
} else {
web_tools::push_history(&welcome_screen_url);
if let Some(history) = history().ok_or_log_js_error() {
let entry = HistoryEntry::new().rrd_url(rrd_url.to_owned());
history.push_entry(entry).ok_or_log_js_error();
}

// Where we're going:
web_tools::push_history(&format!("?url={}", web_tools::percent_encode(rrd_url)));
}
}

Expand Down
9 changes: 7 additions & 2 deletions crates/re_viewer/src/ui/welcome_screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl WelcomeScreen {
ui: &mut egui::Ui,
command_sender: &re_viewer_context::CommandSender,
welcome_screen_state: &WelcomeScreenState,
is_history_enabled: bool,
) {
if welcome_screen_state.opacity <= 0.0 {
return;
Expand Down Expand Up @@ -51,8 +52,12 @@ impl WelcomeScreen {
if welcome_screen_state.hide {
no_data_ui::no_data_ui(ui);
} else {
self.example_page
.ui(ui, command_sender, &welcome_section_ui);
self.example_page.ui(
ui,
command_sender,
&welcome_section_ui,
is_history_enabled,
);
}
});
});
Expand Down
Loading
Loading