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

Add command to copy direct link to fully qualified URL #4165

Merged
merged 8 commits into from
Nov 7, 2023
12 changes: 12 additions & 0 deletions crates/re_ui/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ pub enum UICommand {
ScreenshotWholeApp,
#[cfg(not(target_arch = "wasm32"))]
PrintDatastore,

#[cfg(target_arch = "wasm32")]
CopyDirectLink,
}

impl UICommand {
Expand Down Expand Up @@ -161,6 +164,12 @@ impl UICommand {
"Print datastore",
"Prints the entire data store to the console. WARNING: this may be A LOT of text.",
),

#[cfg(target_arch = "wasm32")]
UICommand::CopyDirectLink => (
"Copy direct link",
"Copy a link to the viewer with the URL parameter set to the current .rrd data source."
)
}
}

Expand Down Expand Up @@ -231,6 +240,9 @@ impl UICommand {
UICommand::ScreenshotWholeApp => None,
#[cfg(not(target_arch = "wasm32"))]
UICommand::PrintDatastore => None,

#[cfg(target_arch = "wasm32")]
UICommand::CopyDirectLink => None,
}
}

Expand Down
31 changes: 31 additions & 0 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,10 @@ impl App {
}
}
}
#[cfg(target_arch = "wasm32")]
UICommand::CopyDirectLink => {
self.run_copy_direct_link_command(store_context);
}
}
}

Expand Down Expand Up @@ -562,6 +566,33 @@ impl App {
}
}

#[cfg(target_arch = "wasm32")]
fn run_copy_direct_link_command(&mut self, store_context: Option<&StoreContext<'_>>) {
let Some(SmartChannelSource::RrdHttpStream { url }) = store_context
.and_then(|ctx| ctx.recording)
.and_then(|rec| rec.data_source.as_ref())
else {
self.toasts.add(toasts::Toast {
kind: toasts::ToastKind::Warning,
text: format!("Could not copy direct link, no recording is open"),
options: toasts::ToastOptions::with_ttl_in_seconds(4.0),
});
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be an error? I would expect to just get a copy to the viewer in this case (https://app.rerun.io)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, anything logged with re_log::warn! will also show up as a warning toast

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, changed it to default to location.origin by itself

};
let direct_link = match &self.startup_options.location {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is StartupOptions::location None? Looking at the code it seems to always be set on wasm, so maybe it doesn't need to be an Option? In any case, you could also call eframe::web::web_location() here if you prefer. That way we don't need the hard-coded fallback to app.rerun.io

Copy link
Member Author

@jprochazk jprochazk Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's an Option because of this Default impl:

location: None,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like that impl Default for StartupOptions could have a #[cfg(not(target_arch = "wasm32"))] around it though, so I don't think it needs to be an Option.

Some(eframe::Location { origin, .. }) => format!("{origin}/?url={url}"),
None => format!("https://app.rerun.io/?url={url}"),
};
self.re_ui
.egui_ctx
.output_mut(|o| o.copied_text = direct_link.clone());
self.toasts.add(toasts::Toast {
kind: toasts::ToastKind::Success,
text: format!("Copied {direct_link:?} to clipboard"),
options: toasts::ToastOptions::with_ttl_in_seconds(4.0),
});
}

fn memory_panel_ui(
&mut self,
ui: &mut egui::Ui,
Expand Down
Loading