diff --git a/CHANGELOG.md b/CHANGELOG.md index 705a80c..8c9e8ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows - 122 more signed client versions (`Versions.csv`). - Icon buttons show their name on hover (desktop), also while they are disabled. +- The voice channel view on desktop can copy an invite link to the channel, + as the phone's Invite button does. ### Changed diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index 9eb45f6..18b95db 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -430,6 +430,9 @@ pub(crate) struct App { pub sessions: HashMap, pub models: Models, pub status: String, + /// What the toast of the next copy says instead of "Copied" (an invite + /// names its channel and link). + pub copy_note: Option, /// The members panel's search. pub member_filter: String, /// The topics drawer's search. @@ -679,6 +682,7 @@ pub fn run(options: RunOptions) -> Result<()> { sessions: HashMap::new(), models, status: String::new(), + copy_note: None, member_filter: String::new(), topic_filter: String::new(), voice_view: false, @@ -844,6 +848,12 @@ impl App { } } + /// Nav.copy put text on the clipboard: one toast says so. + pub fn copied(&mut self) { + let text = self.copy_note.take().unwrap_or_else(|| "Copied".to_owned()); + self.set_status(text); + } + pub fn store_settings(&self) { if let Err(e) = self.prefs.set(&UI, self.settings.clone()) { warn!(%e, "could not store settings"); diff --git a/crates/voelin-ui/src/bind/servers.rs b/crates/voelin-ui/src/bind/servers.rs index 18a0960..7d61501 100644 --- a/crates/voelin-ui/src/bind/servers.rs +++ b/crates/voelin-ui/src/bind/servers.rs @@ -4,7 +4,7 @@ use slint::ComponentHandle; use voelin_core::Command; use voelin_model::ChannelId; -use crate::app::{Bridge, MainWindow, with_app}; +use crate::app::{App, Bridge, MainWindow, with_app}; pub(super) fn wire(ui: &MainWindow) { let bridge = ui.global::(); @@ -56,4 +56,8 @@ pub(super) fn wire(ui: &MainWindow) { with_app(|app| app.client_playback_changed(&form)); }); bridge.on_invite(|| with_app(|app| app.invite_link()).unwrap_or_default().into()); + // Nav.copy, from any screen. + bridge.on_copied(|| { + with_app(App::copied); + }); } diff --git a/crates/voelin-ui/src/servers.rs b/crates/voelin-ui/src/servers.rs index 821bd78..b4737f8 100644 --- a/crates/voelin-ui/src/servers.rs +++ b/crates/voelin-ui/src/servers.rs @@ -503,7 +503,8 @@ impl App { } /// A link to the voice channel we are in, for the Invite button (which - /// copies it); empty, with a note, without one. + /// copies it, and the copy's toast names the channel); empty, with a + /// note, without one. pub(crate) fn invite_link(&mut self) -> String { let bookmark = self.current.and_then(|id| self.bookmark(id)).map(|b| b.address.clone()); let path = self.view().and_then(|v| { @@ -525,7 +526,8 @@ impl App { }; let path: Vec<&str> = path.iter().map(String::as_str).collect(); let link = vm::servers::invite_link(&address, &path); - self.set_status(format!("Copied an invite to {}: {link}", path.last().unwrap_or(&""))); + self.copy_note = + Some(format!("Copied an invite to {}: {link}", path.last().unwrap_or(&""))); link } diff --git a/crates/voelin-ui/ui/app.slint b/crates/voelin-ui/ui/app.slint index 4303cc1..1e76276 100644 --- a/crates/voelin-ui/ui/app.slint +++ b/crates/voelin-ui/ui/app.slint @@ -341,6 +341,23 @@ export component MainWindow inherits Window { } } + // Nav.copy: Slint copies only what is selected in a text field, so the + // text goes through this hidden one. Rust confirms it in the toast, + // shown again even when its text is the last one's. + property clip-requests: Nav.clip-requests; + changed clip-requests => { + clipboard.text = Nav.clip-text; + clipboard.select-all(); + clipboard.copy(); + Bridge.copied(); + toast.shown = true; + } + clipboard := TextInput { + visible: false; + width: 0; + height: 0; + } + // Over the pop-ups, so their scrim does not dim it (a poke from the // member card says so here); under the dialogs. toast := Toast { diff --git a/crates/voelin-ui/ui/bridge.slint b/crates/voelin-ui/ui/bridge.slint index a6b144b..a23ce53 100644 --- a/crates/voelin-ui/ui/bridge.slint +++ b/crates/voelin-ui/ui/bridge.slint @@ -1030,8 +1030,10 @@ export global Bridge { callback dismiss-crash-notice(); callback open-about(); // A link to our voice channel (`ts3server://`) to hand to others; the - // caller copies it. + // caller copies it (Nav.copy). callback invite() -> string; + // Nav.copy put text on the clipboard: Rust says so in the toast. + callback copied(); // Home, friends, direct messages, notifications, search, events and // the settings pages. diff --git a/crates/voelin-ui/ui/icons.slint b/crates/voelin-ui/ui/icons.slint index 720ee77..ce6dc6e 100644 --- a/crates/voelin-ui/ui/icons.slint +++ b/crates/voelin-ui/ui/icons.slint @@ -116,6 +116,8 @@ export global Icons { out property video-off: @image-url("assets/icons/video-off.svg"); out property video: @image-url("assets/icons/video.svg"); out property volume-2: @image-url("assets/icons/volume-2.svg"); + // The icon for channels (voice and chat in one): the speaker. + out property channel: @image-url("assets/icons/volume-2.svg"); out property volume-x: @image-url("assets/icons/volume-x.svg"); out property x: @image-url("assets/icons/x.svg"); // Home, friends, messages, events and the settings pages (from diff --git a/crates/voelin-ui/ui/nav.slint b/crates/voelin-ui/ui/nav.slint index 46b4242..3407aed 100644 --- a/crates/voelin-ui/ui/nav.slint +++ b/crates/voelin-ui/ui/nav.slint @@ -102,6 +102,11 @@ export global Nav { in-out property dm-tab; in-out property join-open; + // Text for the clipboard, and a counter that changes with every copy: + // MainWindow copies it through a hidden text field (`copy` below). + in-out property clip-text; + in-out property clip-requests; + // The phone layout (narrow windows). // The server's members as a page of their own (the desktop shows them // beside the chat). @@ -306,4 +311,13 @@ export global Nav { show(Page.server); Bridge.select-server(id); } + + // Put text on the clipboard; a toast says so. Nothing to copy (an + // invite without a channel, which Rust explains) does nothing. + public function copy(text: string) { + if text != "" { + clip-text = text; + clip-requests += 1; + } + } } diff --git a/crates/voelin-ui/ui/screens/mobile-voice.slint b/crates/voelin-ui/ui/screens/mobile-voice.slint index 9e37500..8e9fae2 100644 --- a/crates/voelin-ui/ui/screens/mobile-voice.slint +++ b/crates/voelin-ui/ui/screens/mobile-voice.slint @@ -631,11 +631,6 @@ export component MobileVoice inherits VerticalLayout { Nav.mobile-tab = MobileTab.chat; } } - clip := TextInput { - visible: false; - width: 0; - height: 0; - } ChannelBar { } sv := ScrollView { // The stream, the people and the chat header scroll away together @@ -678,13 +673,7 @@ export component MobileVoice inherits VerticalLayout { filled: true; size: 62px; icon-size: 24px; - // Through a text field: Slint copies only - // what is selected in one. - clicked => { - clip.text = Bridge.invite(); - clip.select-all(); - clip.copy(); - } + clicked => { Nav.copy(Bridge.invite()); } } } Text { diff --git a/crates/voelin-ui/ui/screens/voice.slint b/crates/voelin-ui/ui/screens/voice.slint index a44ee55..724056a 100644 --- a/crates/voelin-ui/ui/screens/voice.slint +++ b/crates/voelin-ui/ui/screens/voice.slint @@ -244,6 +244,12 @@ export component VoiceView inherits VerticalLayout { horizontal-stretch: 1; overflow: elide; } + IconButton { + icon: Icons.user-plus; + label: @tr("Copy invite link"); + y: (parent.height - self.height) / 2; + clicked => { Nav.copy(Bridge.invite()); } + } IconButton { icon: Icons.message-square; label: @tr("Chat only"); diff --git a/docs/ui.md b/docs/ui.md index d54a30d..79f7739 100644 --- a/docs/ui.md +++ b/docs/ui.md @@ -149,7 +149,7 @@ comes from the engine's events; what a gateway adds is hidden without it. | Member card | `member` | Description, groups, talk power, country; private message, poke, friend, block; volume and mute for us | `ContactsChanged`; `Command::SetContact`, `SetClientVolume`, `SetClientMuted`, `Poke` | | Pinned messages | `pins` | In the members panel's place: cards with author, time, text, files and reactions; the pin unpins, a click jumps to the message | `Gateway` `Pins`, `Pinned`, `Unpinned`; `GatewayRequest::Pins`, `Unpin` | | Topics | `topics`, `topic:` | In the members panel's place: search, cards with the message count, creator and last activity, Create Topic; an open topic replaces the chat's messages and takes replies | `Gateway` `Topics`, `Topic`, `TopicHistory`; `GatewayRequest::Topics`, `TopicHistory`, `CreateTopic`, `Post` | -| Voice channel | `voice` | Title, topic, "5 in voice / 50 total", Voice Settings, Leave; the people as large avatars (talking ring and bars, muted, crown, streaming); the streams as cards (LIVE, viewers, kind, bitrate, sound, Watch Stream); the channel's chat | `Presence`, `Talking`, `StreamsChanged`, viewer counts from `StreamsChanged`, else the `Gateway` stream directory | +| Voice channel | `voice` | Title, topic, "5 in voice / 50 total", Copy invite link (a `ts3server://` link to the channel; the phone's Invite button does the same), Chat only, Voice Settings, Leave; the people as large avatars (talking ring and bars, muted, crown, streaming); the streams as cards (LIVE, viewers, kind, bitrate, sound, Watch Stream); the channel's chat | `Presence`, `Talking`, `StreamsChanged`, viewer counts from `StreamsChanged`, else the `Gateway` stream directory | | Watching a stream | `watch`, `popout` | The channel's header with "5 in voice" and Leave; the player with the streamer, title, viewers, LIVE, the picture's height (the simulcast picker when a Voelin streamer offers layers), volume, elapsed time, what arrives (codec, size, frame rate, bitrate), back to the chat, pop out, full screen; a note that the stream belongs to the channel; the channel's chat and a Stream Info tab. Popped out (and in full screen) it fills the window | `WatchState`, `WatchLayers`, decoded frames and their stats (`src/video.rs`), `StreamsChanged` (viewer counts; the `Gateway` stream directory where the server gives none) | The pins and topics share the place of the members panel: opening one @@ -322,7 +322,8 @@ for importing the official clients' identities on start 1. Write the screen in `ui/screens/.slint` from the components (`import { ... } from "../components/index.slint";`), reading data from `Bridge` and navigating through `Nav` (e.g. `Nav.open-settings(...)`, - `Nav.show(Page.home)`). + `Nav.show(Page.home)`). Text goes to the clipboard with `Nav.copy(text)` + (through a hidden text field in `MainWindow`; a toast confirms it). 2. New data: add a struct and a property (models: `[Struct]`) and callbacks to `ui/bridge.slint`. 3. Place it: add a `Page` value in `ui/nav.slint` if it is a page, and in