diff --git a/src/app/mod.rs b/src/app/mod.rs index 38a750b..008f80f 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -117,6 +117,8 @@ pub enum AppMessage { ToggleDeafenPressed, UiEventReceived(UiEvent), CopyToClipboard, + /// Copy an arbitrary string to the clipboard (e.g. the full node ID). + CopyText(String), TogglePtt(bool), StartSettingHotkey, PeerVolumeChanged(EndpointId, f32), @@ -691,6 +693,9 @@ fn update(state: &mut AppState, message: AppMessage) -> Task { return iced::clipboard::write(state.ticket.clone()); } } + AppMessage::CopyText(s) => { + return iced::clipboard::write(s); + } AppMessage::TogglePtt(enabled) => { state.ptt_enabled = enabled; let _ = state.controller.send(CoreCommand::SetPttMode(enabled)); @@ -1549,13 +1554,35 @@ fn view(state: &AppState) -> Element<'_, AppMessage> { }) .into() }; + // The ID line shows a short form (iced text isn't selectable) plus a Copy + // button that puts the FULL node id on the clipboard, so it's shareable. + let id_row: Element = match state.self_node_id.clone() { + Some(full) => row![ + text(format!("ID: {id_display}")).size(13).color(color_text), + button( + row![ + icon(IconKind::Copy, 13.0, color_text), + text("Copy").size(12), + ] + .spacing(5) + .align_y(iced::alignment::Vertical::Center) + ) + .on_press(AppMessage::CopyText(full)) + .style(b_style(color_surface, color_blue, color_text, 6.0)) + .padding(6), + ] + .spacing(10) + .align_y(iced::alignment::Vertical::Center) + .into(), + None => text(format!("ID: {id_display}")).size(13).color(color_text).into(), + }; let identity_section = column![ text("Your permanent ID — friends recognise you by this. It stays the \ same across launches; regenerate only to start fresh as a new \ identity (friends who saved the old one will no longer reach you).") .size(12) .color(color_subtext), - text(format!("ID: {id_display}")).size(13).color(color_text), + id_row, button(text("Regenerate identity").size(13)) .on_press(AppMessage::OpenRegenerateIdentityConfirm) .style(b_style(color_surface, color_maroon, color_text, 6.0))