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
35 changes: 35 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,37 @@ impl App {
}
}

#[cfg(target_arch = "wasm32")]
fn run_copy_direct_link_command(&mut self, store_context: Option<&StoreContext<'_>>) {
let location = eframe::web::web_location();
let mut origin = location.origin;
if location.host == "app.rerun.io" {
// links to `app.rerun.io` can be made into permanent links:
let path = match &self.build_info.version.meta {
// not a final release, use commit hash
Some(..) => format!("commit/{}", &self.build_info.git_hash[..7]),
jprochazk marked this conversation as resolved.
Show resolved Hide resolved
jprochazk marked this conversation as resolved.
Show resolved Hide resolved
// final release, use version tag
None => format!("version/{}", self.build_info.version),
};
origin = format!("{origin}/{path}/index.html");
}
let direct_link = match store_context
.and_then(|ctx| ctx.recording)
.and_then(|rec| rec.data_source.as_ref())
{
Some(SmartChannelSource::RrdHttpStream { url }) => format!("{origin}/?url={url}"),
_ => origin,
};
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