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_build_info/src/build_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ impl BuildInfo {
self.git_hash.to_owned()
}
}

pub fn short_git_hash(&self) -> &str {
if self.git_hash.is_empty() {
""
} else {
&self.git_hash[..7]
}
}

pub fn is_final(&self) -> bool {
self.version.meta.is_none()
}
}

/// For use with e.g. `--version`
Expand Down
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
36 changes: 36 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,38 @@ 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 href = location.origin;
if location.host == "app.rerun.io" {
// links to `app.rerun.io` can be made into permanent links:
let path = if self.build_info.is_final() {
// final release, use version tag
format!("version/{}", self.build_info.version)
} else {
// not a final release, use commit hash
format!("commit/{}", self.build_info.short_git_hash())
};
href = format!("{href}/{path}");
}
let direct_link = match store_context
.and_then(|ctx| ctx.recording)
.and_then(|rec| rec.data_source.as_ref())
{
Some(SmartChannelSource::RrdHttpStream { url }) => format!("{href}/?url={url}"),
_ => href,
};
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