Compare commits
No files matched your search
@@ -31,10 +31,46 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows
|
|||||||
sound, hold to talk and copy an invite link, as in the Slint app; the window's
|
sound, hold to talk and copy an invite link, as in the Slint app; the window's
|
||||||
title names the server on screen, and its size and whether it was maximized
|
title names the server on screen, and its size and whether it was maximized
|
||||||
are kept for the next run (setting `ui.window`; on X11 the window is
|
are kept for the next run (setting `ui.window`; on X11 the window is
|
||||||
maximized once it is shown, not before the window manager has it). The channel tree, the chat and the other pages are the
|
maximized once it is shown, not before the window manager has it, and a
|
||||||
next slices; the search and the settings buttons only log that. `VOELIN_DEMO_UI=1`
|
resize made before it answers is kept). The chat and the other pages are the
|
||||||
shows the Slint app's sample servers without sending or keeping anything
|
next slices; the search and the settings buttons only log that.
|
||||||
(docs/ui.md, "The desktop shell").
|
`VOELIN_DEMO_UI=1` shows the Slint app's sample servers without sending or
|
||||||
|
keeping anything (docs/ui.md, "The desktop shell").
|
||||||
|
- The GPUI front end's channel tree and members panel. The server on screen's
|
||||||
|
channels nest in the sidebar with their spacers, icons, banners (under a veil
|
||||||
|
that keeps the names readable on any picture), locks and counts, and the
|
||||||
|
people in them with their badges and marks; a click selects a channel, a
|
||||||
|
double-click joins it (a locked one asks for its password: Enter joins, and
|
||||||
|
Escape closes the prompt), the chevron folds it, a right-click offers the
|
||||||
|
same, and what is folded and selected is kept for each server (setting
|
||||||
|
`ui.tree`). The panel on the right lists everyone on the server in sections,
|
||||||
|
with a search; a click on a person opens their card. A person who starts or
|
||||||
|
stops talking is marked in the tree (the ring on their avatar and the bars on
|
||||||
|
their row, as in the Slint app) and the members panel, which are redrawn for
|
||||||
|
it and nothing else of the window, and the pictures the engine writes again show
|
||||||
|
at once. `VOELIN_METER=1` counts the renders of each pane;
|
||||||
|
`VOELIN_DEMO_SERVER` and `VOELIN_DEMO_TALK` pick the sample server and make a
|
||||||
|
sample person talk (docs/ui.md, "The channel tree and the members").
|
||||||
|
- The GPUI front end's voice channel page and call bar. A server's Voice channel
|
||||||
|
button (or `VOELIN_OPEN=voice`) shows the channel we are in with its topic,
|
||||||
|
its banner and who is there: large avatars ringed green while they talk and
|
||||||
|
blue while they stream, with the marks of a microphone or sound that is off,
|
||||||
|
and under them the call bar (mute, deafen, share and the voice settings, which
|
||||||
|
only log until their pages come, and Leave). The smaller stage, one row of
|
||||||
|
small avatars centred while it fits and scrolling sideways when crowded, is
|
||||||
|
remembered and a window under 800 pixels tall always has it (the same setting
|
||||||
|
as the Slint app's); toggle icon buttons refresh their tooltips as soon as
|
||||||
|
their state flips. The sidebar's server card shows the server's banner, a
|
||||||
|
person's card has their volume and a mute for us, and the voice card says the
|
||||||
|
transmit mode when it is not push-to-talk. Hold to talk and the global
|
||||||
|
push-to-talk key (`Ctrl+Shift+T` by default, as in the Slint app, working
|
||||||
|
while another window has focus) track button and hotkey holds independently and
|
||||||
|
fail closed across voice drops (including drop and reconnect within one event
|
||||||
|
batch), window focus loss, leaving push-to-talk mode, switching or removing
|
||||||
|
servers, repeated portal activations across servers, desktop shortcut removal,
|
||||||
|
hotkey task exit, and window shutdown. A person's picture is round in its
|
||||||
|
avatar. `voelin-gpui` is still not the app (docs/ui.md, "The voice page and
|
||||||
|
the call bar").
|
||||||
- Log files: each run logs to `<state>/voelin/logs/voelin.log`, the previous
|
- Log files: each run logs to `<state>/voelin/logs/voelin.log`, the previous
|
||||||
four runs are kept; `VOELIN_LOG` sets what is logged. Settings → Advanced
|
four runs are kept; `VOELIN_LOG` sets what is logged. Settings → Advanced
|
||||||
opens the folder.
|
opens the folder.
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ anyhow = "1.0.104"
|
|||||||
# GPUI, gpui-component and gpui-kit-assets behind one pinned dependency.
|
# GPUI, gpui-component and gpui-kit-assets behind one pinned dependency.
|
||||||
gpui-kit = { workspace = true }
|
gpui-kit = { workspace = true }
|
||||||
# The engine's runtime and the channel of its events (a tokio receiver needs no
|
# The engine's runtime and the channel of its events (a tokio receiver needs no
|
||||||
# reactor, so GPUI's executor can await it).
|
# reactor, so GPUI's executor can await it); `macros` for the hotkey task's
|
||||||
tokio = { version = "1.53.1", features = ["rt-multi-thread", "sync", "time"] }
|
# `select!`.
|
||||||
|
tokio = { version = "1.53.1", features = ["macros", "rt-multi-thread", "sync", "time"] }
|
||||||
tracing = "0.1.44"
|
tracing = "0.1.44"
|
||||||
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
|
||||||
# The TeamSpeak identity a connection is made with (the store hands it out).
|
# The TeamSpeak identity a connection is made with (the store hands it out).
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ use voelin_core::settings::{AUDIO, Settings};
|
|||||||
use voelin_core::{AudioSettings, Command, Engine, History, IdentityBlob};
|
use voelin_core::{AudioSettings, Command, Engine, History, IdentityBlob};
|
||||||
use voelin_store::{Bookmark, IdentityOrigin, MemorySecrets, Secrets, Store};
|
use voelin_store::{Bookmark, IdentityOrigin, MemorySecrets, Secrets, Store};
|
||||||
use voelin_ui_vm::servers::logic::CREATED_IDENTITY;
|
use voelin_ui_vm::servers::logic::CREATED_IDENTITY;
|
||||||
use voelin_ui_vm::settings::{CLIENT_PLAYBACK, ClientPlaybackMap, UI, UI_WINDOW, UiSettings};
|
use voelin_ui_vm::settings::{
|
||||||
|
CLIENT_PLAYBACK, ClientPlaybackMap, UI, UI_TREE, UI_WINDOW, UiSettings,
|
||||||
|
};
|
||||||
|
|
||||||
/// The client's database, its settings and its secrets.
|
/// The client's database, its settings and its secrets.
|
||||||
pub struct Backend {
|
pub struct Backend {
|
||||||
@@ -67,10 +69,11 @@ fn open_settings(dir: &Path) -> Settings {
|
|||||||
voelin_ui_vm::settings::open_settings(dir, &[], register_own_keys)
|
voelin_ui_vm::settings::open_settings(dir, &[], register_own_keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The key that only this front end uses: where the window was
|
/// The keys that only this front end uses: where the window was
|
||||||
/// (`ui.window`).
|
/// (`ui.window`) and what the channel trees remember (`ui.tree`).
|
||||||
fn register_own_keys(prefs: &Settings) {
|
fn register_own_keys(prefs: &Settings) {
|
||||||
prefs.register(&UI_WINDOW);
|
prefs.register(&UI_WINDOW);
|
||||||
|
prefs.register(&UI_TREE);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend {
|
impl Backend {
|
||||||
|
|||||||
@@ -7,8 +7,19 @@
|
|||||||
//! components, the icons) in place of the shell. The Slint front end's
|
//! components, the icons) in place of the shell. The Slint front end's
|
||||||
//! other pages do not exist here yet; they are named in a warning and
|
//! other pages do not exist here yet; they are named in a warning and
|
||||||
//! skipped.
|
//! skipped.
|
||||||
|
//! - `VOELIN_OPEN=voice` (`voice:compact`): the voice channel page on screen
|
||||||
|
//! once voice is connected, in place of the server page; `voice:compact`
|
||||||
|
//! with the smaller stage, which is not stored.
|
||||||
//! - `VOELIN_DEMO_UI=1`: the Slint front end's sample servers, shown through
|
//! - `VOELIN_DEMO_UI=1`: the Slint front end's sample servers, shown through
|
||||||
//! the app's own events; nothing is sent to the engine or kept in the store.
|
//! the app's own events, with their pictures as files of a folder in the
|
||||||
|
//! temporary directory (removed when the window closes); nothing is sent to
|
||||||
|
//! the engine or kept in the store.
|
||||||
|
//! - `VOELIN_DEMO_SERVER=2`: with `VOELIN_DEMO_UI`, the sample server on
|
||||||
|
//! screen, counting from 0 (the first, which is connected and populated, is
|
||||||
|
//! the default; the second is observed, the third not connected).
|
||||||
|
//! - `VOELIN_DEMO_TALK=10`: with `VOELIN_DEMO_UI`, one of the sample people
|
||||||
|
//! starts and stops talking this many times a second, through the app's own
|
||||||
|
//! events (what the meter measures while someone talks).
|
||||||
//! - `VOELIN_DEV_THEME=dark|light|system`: the theme mode, in place of the
|
//! - `VOELIN_DEV_THEME=dark|light|system`: the theme mode, in place of the
|
||||||
//! one the settings give (`ui.theme`).
|
//! one the settings give (`ui.theme`).
|
||||||
//! - `VOELIN_FONT_SCALE=1.25`: the text size factor, in place of the
|
//! - `VOELIN_FONT_SCALE=1.25`: the text size factor, in place of the
|
||||||
@@ -34,8 +45,25 @@ pub enum Page {
|
|||||||
pub struct Switches {
|
pub struct Switches {
|
||||||
/// The page to open on.
|
/// The page to open on.
|
||||||
pub open: Page,
|
pub open: Page,
|
||||||
|
/// The voice channel page is asked for (`VOELIN_OPEN=voice`): it shows
|
||||||
|
/// once voice is connected.
|
||||||
|
pub voice: bool,
|
||||||
|
/// With the voice page, the smaller stage, as the switch says (it is not
|
||||||
|
/// stored, as the Slint front end's `voice:compact`).
|
||||||
|
pub voice_compact: bool,
|
||||||
/// Show the sample servers instead of the stored ones.
|
/// Show the sample servers instead of the stored ones.
|
||||||
pub demo_ui: bool,
|
pub demo_ui: bool,
|
||||||
|
/// Write the sample servers' pictures to a folder of the temporary
|
||||||
|
/// directory and deliver them: what the binary does with the sample
|
||||||
|
/// servers, and what a test asks for by name (a test that does not leaves
|
||||||
|
/// nothing behind).
|
||||||
|
pub demo_pictures: bool,
|
||||||
|
/// The sample server to show, by its place in the list, when the switch
|
||||||
|
/// names one.
|
||||||
|
pub demo_server: Option<usize>,
|
||||||
|
/// How many times a second a sample person starts or stops talking (with
|
||||||
|
/// the sample servers), when the switch names a rate.
|
||||||
|
pub demo_talk: Option<f32>,
|
||||||
/// The theme mode, when the switch names one.
|
/// The theme mode, when the switch names one.
|
||||||
pub theme: Option<Choice>,
|
pub theme: Option<Choice>,
|
||||||
/// The text size factor, when the switch names one.
|
/// The text size factor, when the switch names one.
|
||||||
@@ -50,7 +78,12 @@ impl Default for Switches {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
open: Page::Shell,
|
open: Page::Shell,
|
||||||
|
voice: false,
|
||||||
|
voice_compact: false,
|
||||||
demo_ui: false,
|
demo_ui: false,
|
||||||
|
demo_pictures: false,
|
||||||
|
demo_server: None,
|
||||||
|
demo_talk: None,
|
||||||
theme: None,
|
theme: None,
|
||||||
font_scale: None,
|
font_scale: None,
|
||||||
window: None,
|
window: None,
|
||||||
@@ -73,8 +106,10 @@ impl Switches {
|
|||||||
for what in list.split(',').map(str::trim).filter(|w| !w.is_empty()) {
|
for what in list.split(',').map(str::trim).filter(|w| !w.is_empty()) {
|
||||||
match what {
|
match what {
|
||||||
"swatch" => switches.open = Page::Swatch,
|
"swatch" => switches.open = Page::Swatch,
|
||||||
|
"voice" => switches.voice = true,
|
||||||
|
"voice:compact" => (switches.voice, switches.voice_compact) = (true, true),
|
||||||
other => tracing::warn!(
|
other => tracing::warn!(
|
||||||
"VOELIN_OPEN={other}: this page is not in the GPUI front end yet (swatch is)"
|
"VOELIN_OPEN={other}: this page is not in the GPUI front end yet (swatch and voice are)"
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,8 +132,21 @@ impl Switches {
|
|||||||
None => tracing::warn!("VOELIN_WINDOW_SIZE={text}: WIDTHxHEIGHT, such as 1440x960"),
|
None => tracing::warn!("VOELIN_WINDOW_SIZE={text}: WIDTHxHEIGHT, such as 1440x960"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(text) = get("VOELIN_DEMO_SERVER") {
|
||||||
|
match text.trim().parse::<usize>() {
|
||||||
|
Ok(place) if place < 3 => switches.demo_server = Some(place),
|
||||||
|
_ => tracing::warn!("VOELIN_DEMO_SERVER={text}: 0, 1 or 2 (a sample server)"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(text) = get("VOELIN_DEMO_TALK") {
|
||||||
|
match text.trim().parse::<f32>() {
|
||||||
|
Ok(rate) if (0.1..=100.0).contains(&rate) => switches.demo_talk = Some(rate),
|
||||||
|
_ => tracing::warn!("VOELIN_DEMO_TALK={text}: a rate from 0.1 to 100 a second"),
|
||||||
|
}
|
||||||
|
}
|
||||||
let flag = |name: &str| get(name).is_some_and(|v| !matches!(v.trim(), "" | "0"));
|
let flag = |name: &str| get(name).is_some_and(|v| !matches!(v.trim(), "" | "0"));
|
||||||
switches.demo_ui = flag("VOELIN_DEMO_UI");
|
switches.demo_ui = flag("VOELIN_DEMO_UI");
|
||||||
|
switches.demo_pictures = switches.demo_ui;
|
||||||
switches.meter = flag("VOELIN_METER");
|
switches.meter = flag("VOELIN_METER");
|
||||||
switches
|
switches
|
||||||
}
|
}
|
||||||
@@ -131,21 +179,32 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn every_switch_is_read() {
|
fn every_switch_is_read() {
|
||||||
let s = env(&[
|
let s = env(&[
|
||||||
("VOELIN_OPEN", "swatch"),
|
("VOELIN_OPEN", "swatch,voice:compact"),
|
||||||
("VOELIN_DEMO_UI", "1"),
|
("VOELIN_DEMO_UI", "1"),
|
||||||
|
("VOELIN_DEMO_SERVER", "2"),
|
||||||
|
("VOELIN_DEMO_TALK", "10"),
|
||||||
("VOELIN_DEV_THEME", "light"),
|
("VOELIN_DEV_THEME", "light"),
|
||||||
("VOELIN_FONT_SCALE", "1.25"),
|
("VOELIN_FONT_SCALE", "1.25"),
|
||||||
("VOELIN_WINDOW_SIZE", "1440x960"),
|
("VOELIN_WINDOW_SIZE", "1440x960"),
|
||||||
("VOELIN_METER", "1"),
|
("VOELIN_METER", "1"),
|
||||||
]);
|
]);
|
||||||
assert_eq!(s.open, Page::Swatch);
|
assert_eq!(s.open, Page::Swatch);
|
||||||
assert!(s.demo_ui);
|
assert!(s.voice && s.voice_compact, "the voice page, with the smaller stage");
|
||||||
|
assert!(s.demo_ui && s.demo_pictures, "the sample servers come with their pictures");
|
||||||
|
assert_eq!(s.demo_server, Some(2));
|
||||||
|
assert_eq!(s.demo_talk, Some(10.0));
|
||||||
assert_eq!(s.theme, Some(Choice::Light));
|
assert_eq!(s.theme, Some(Choice::Light));
|
||||||
assert_eq!(s.font_scale, Some(1.25));
|
assert_eq!(s.font_scale, Some(1.25));
|
||||||
assert_eq!(s.window, Some((1440.0, 960.0)));
|
assert_eq!(s.window, Some((1440.0, 960.0)));
|
||||||
assert!(s.meter);
|
assert!(s.meter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_voice_page_alone_has_the_larger_stage() {
|
||||||
|
let s = env(&[("VOELIN_OPEN", "voice")]);
|
||||||
|
assert_eq!((s.open, s.voice, s.voice_compact), (Page::Shell, true, false));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn what_makes_no_sense_is_left_out() {
|
fn what_makes_no_sense_is_left_out() {
|
||||||
let s = env(&[
|
let s = env(&[
|
||||||
@@ -154,6 +213,8 @@ mod tests {
|
|||||||
("VOELIN_FONT_SCALE", "9"),
|
("VOELIN_FONT_SCALE", "9"),
|
||||||
("VOELIN_WINDOW_SIZE", "10x10"),
|
("VOELIN_WINDOW_SIZE", "10x10"),
|
||||||
("VOELIN_DEMO_UI", "0"),
|
("VOELIN_DEMO_UI", "0"),
|
||||||
|
("VOELIN_DEMO_SERVER", "7"),
|
||||||
|
("VOELIN_DEMO_TALK", "fast"),
|
||||||
("VOELIN_METER", "0"),
|
("VOELIN_METER", "0"),
|
||||||
]);
|
]);
|
||||||
assert_eq!(s, Switches::default());
|
assert_eq!(s, Switches::default());
|
||||||
|
|||||||
@@ -0,0 +1,361 @@
|
|||||||
|
//! Global push-to-talk: a task owns the [`voelin_platform::HotkeyManager`] (the
|
||||||
|
//! desktop's portal on Wayland, XInput2 on X11, a hook on Windows) and reports
|
||||||
|
//! the key's presses and releases, whichever window has the focus.
|
||||||
|
//!
|
||||||
|
//! It is the Slint front end's `GlobalPtt` (`crates/voelin-ui/src/hotkey.rs`),
|
||||||
|
//! repeated here as `engine.rs` repeats `HostedEngine`: the loop needs the
|
||||||
|
//! engine's runtime and the front end's own way back to its state, and the
|
||||||
|
//! Slint crate cannot be a dependency (it brings Slint in); both go into one
|
||||||
|
//! place when the Slint front end is retired.
|
||||||
|
//!
|
||||||
|
//! **The task runs on the engine's runtime** ([`GlobalPtt::start`] spawns on
|
||||||
|
//! it), not from a foreground task of GPUI: the portal's backend calls
|
||||||
|
//! `tokio::spawn` when it is made (`voelin-platform`, `hotkey/portal.rs`), which
|
||||||
|
//! panics where no tokio runtime is current, and GPUI's executor has none.
|
||||||
|
|
||||||
|
use std::future::Future;
|
||||||
|
|
||||||
|
use tokio::runtime::Handle;
|
||||||
|
use tokio::sync::mpsc;
|
||||||
|
use voelin_platform::{BackendKind, Hotkey, HotkeyEvent, HotkeyEvents, HotkeyManager};
|
||||||
|
|
||||||
|
/// The id of the push-to-talk registration (the portal remembers the user's
|
||||||
|
/// choice by it).
|
||||||
|
const PTT_ID: &str = "push-to-talk";
|
||||||
|
|
||||||
|
/// The handle to the hotkey task.
|
||||||
|
pub struct GlobalPtt {
|
||||||
|
tx: mpsc::UnboundedSender<Option<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GlobalPtt {
|
||||||
|
/// Start the task on `runtime`. `status` gets a line that says how the key
|
||||||
|
/// stands ("Active: Ctrl+Shift+T (X11)", why it could not be registered),
|
||||||
|
/// `transmit` the key's state; both are called on the runtime, so they hand
|
||||||
|
/// over to GPUI's thread ([`crate::app::Later`]).
|
||||||
|
pub fn start(
|
||||||
|
runtime: &Handle,
|
||||||
|
status: impl Fn(String) + Send + 'static,
|
||||||
|
transmit: impl Fn(bool) + Send + 'static,
|
||||||
|
) -> Self {
|
||||||
|
let (tx, rx) = mpsc::unbounded_channel();
|
||||||
|
runtime.spawn(run(rx, status, transmit));
|
||||||
|
Self { tx }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Register `key` (such as `Ctrl+Shift+T`) in place of the one registered,
|
||||||
|
/// or nothing.
|
||||||
|
pub fn set(&self, key: Option<String>) {
|
||||||
|
let _ = self.tx.send(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A stream of press and release events for one registered hotkey (`None` once
|
||||||
|
/// the desktop removes it).
|
||||||
|
trait EventStream: Send {
|
||||||
|
fn recv(&mut self) -> impl Future<Output = Option<HotkeyEvent>> + Send;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventStream for HotkeyEvents {
|
||||||
|
fn recv(&mut self) -> impl Future<Output = Option<HotkeyEvent>> + Send {
|
||||||
|
HotkeyEvents::recv(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Registers and unregisters the global push-to-talk hotkey with the platform
|
||||||
|
/// (or a test double).
|
||||||
|
trait Registrar: Send {
|
||||||
|
type Events: EventStream;
|
||||||
|
|
||||||
|
fn register(
|
||||||
|
&mut self,
|
||||||
|
key: String,
|
||||||
|
hotkey: Hotkey,
|
||||||
|
) -> impl Future<Output = Result<(Self::Events, String), String>> + Send;
|
||||||
|
|
||||||
|
fn unregister(&mut self) -> impl Future<Output = ()> + Send;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The real platform hotkey manager, opened lazily on the first registration.
|
||||||
|
struct PlatformRegistrar {
|
||||||
|
manager: Option<HotkeyManager>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Registrar for PlatformRegistrar {
|
||||||
|
type Events = HotkeyEvents;
|
||||||
|
|
||||||
|
async fn register(
|
||||||
|
&mut self,
|
||||||
|
key: String,
|
||||||
|
hotkey: Hotkey,
|
||||||
|
) -> Result<(Self::Events, String), String> {
|
||||||
|
if self.manager.is_none() {
|
||||||
|
match HotkeyManager::new().await {
|
||||||
|
Ok(m) => self.manager = Some(m),
|
||||||
|
Err(e) => return Err(format!("Global hotkeys are not available: {e}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let Some(m) = &mut self.manager else {
|
||||||
|
return Err("Global hotkeys are not available.".into());
|
||||||
|
};
|
||||||
|
match m.register(PTT_ID, "Push to talk", hotkey).await {
|
||||||
|
Ok(registered) => {
|
||||||
|
let line = match m.backend() {
|
||||||
|
BackendKind::Portal => format!(
|
||||||
|
"Registered with the desktop: {}",
|
||||||
|
m.trigger_description(PTT_ID).unwrap_or(key)
|
||||||
|
),
|
||||||
|
BackendKind::X11 => format!("Active: {hotkey} (X11)"),
|
||||||
|
BackendKind::WindowsHook => format!("Active: {hotkey}"),
|
||||||
|
};
|
||||||
|
Ok((registered, line))
|
||||||
|
}
|
||||||
|
Err(e) => Err(format!("Could not register {key}: {e}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn unregister(&mut self) {
|
||||||
|
if let Some(m) = &mut self.manager {
|
||||||
|
let _ = m.unregister(PTT_ID).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The next event of the registration, or never while there is none.
|
||||||
|
async fn next_event<E: EventStream>(events: &mut Option<E>) -> Option<HotkeyEvent> {
|
||||||
|
match events {
|
||||||
|
Some(events) => events.recv().await,
|
||||||
|
None => std::future::pending().await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The task: a key to register (or none) arrives on `rx`, the registered key's
|
||||||
|
/// events are reported through `transmit`, and `status` says what happened.
|
||||||
|
async fn run(
|
||||||
|
rx: mpsc::UnboundedReceiver<Option<String>>,
|
||||||
|
status: impl Fn(String),
|
||||||
|
transmit: impl Fn(bool),
|
||||||
|
) {
|
||||||
|
run_loop(rx, PlatformRegistrar { manager: None }, status, transmit).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The event loop of [`run`], parameterised over `registrar` so the
|
||||||
|
/// fail-closed release paths are tested without a portal or display.
|
||||||
|
async fn run_loop<R: Registrar>(
|
||||||
|
mut rx: mpsc::UnboundedReceiver<Option<String>>,
|
||||||
|
mut registrar: R,
|
||||||
|
status: impl Fn(String),
|
||||||
|
transmit: impl Fn(bool),
|
||||||
|
) {
|
||||||
|
let mut events: Option<R::Events> = None;
|
||||||
|
loop {
|
||||||
|
tokio::select! {
|
||||||
|
key = rx.recv() => {
|
||||||
|
let Some(key) = key else {
|
||||||
|
// Fail closed on task exit: drop any hold that was still down.
|
||||||
|
transmit(false);
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
events = None;
|
||||||
|
// Whatever was held no longer counts.
|
||||||
|
transmit(false);
|
||||||
|
registrar.unregister().await;
|
||||||
|
let Some(key) = key else {
|
||||||
|
status("Off.".into());
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let hotkey: Hotkey = match key.parse() {
|
||||||
|
Ok(h) => h,
|
||||||
|
Err(e) => {
|
||||||
|
status(format!("{e}"));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
match registrar.register(key, hotkey).await {
|
||||||
|
Ok((registered, line)) => {
|
||||||
|
events = Some(registered);
|
||||||
|
status(line);
|
||||||
|
}
|
||||||
|
Err(line) => status(line),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
event = next_event(&mut events) => match event {
|
||||||
|
Some(HotkeyEvent::Pressed) => transmit(true),
|
||||||
|
Some(HotkeyEvent::Released) => transmit(false),
|
||||||
|
None => {
|
||||||
|
events = None;
|
||||||
|
// Fail closed if the desktop removes the shortcut mid-hold.
|
||||||
|
transmit(false);
|
||||||
|
status("The hotkey was removed by the desktop.".into());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// A channel-backed event stream for testing [`run_loop`] without a display.
|
||||||
|
struct FakeEvents(mpsc::UnboundedReceiver<HotkeyEvent>);
|
||||||
|
|
||||||
|
impl EventStream for FakeEvents {
|
||||||
|
async fn recv(&mut self) -> Option<HotkeyEvent> {
|
||||||
|
self.0.recv().await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A registrar that hands out a prepared [`FakeEvents`] stream once.
|
||||||
|
struct FakeRegistrar {
|
||||||
|
stream: Option<FakeEvents>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Registrar for FakeRegistrar {
|
||||||
|
type Events = FakeEvents;
|
||||||
|
|
||||||
|
async fn register(
|
||||||
|
&mut self,
|
||||||
|
_key: String,
|
||||||
|
hotkey: Hotkey,
|
||||||
|
) -> Result<(Self::Events, String), String> {
|
||||||
|
let events = self.stream.take().ok_or_else(|| "no fake stream left".to_owned())?;
|
||||||
|
Ok((events, format!("Active: {hotkey} (test)")))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn unregister(&mut self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Next recorded message from the task, bounded only against a hang.
|
||||||
|
async fn recv_log(rx: &mut mpsc::UnboundedReceiver<String>) -> String {
|
||||||
|
tokio::time::timeout(Duration::from_secs(30), rx.recv())
|
||||||
|
.await
|
||||||
|
.expect("hotkey loop timed out")
|
||||||
|
.expect("log channel closed unexpectedly")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A key that is not one is said so and registers nothing, and the held
|
||||||
|
/// state is let go first; no display or desktop is needed to say it.
|
||||||
|
#[test]
|
||||||
|
fn a_key_that_cannot_be_parsed_is_reported_and_lets_go_of_the_hold() {
|
||||||
|
let runtime = tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap();
|
||||||
|
let log = Arc::new(Mutex::new(Vec::<String>::new()));
|
||||||
|
let (said, held) = (log.clone(), log.clone());
|
||||||
|
let ptt = GlobalPtt::start(
|
||||||
|
runtime.handle(),
|
||||||
|
move |line| said.lock().unwrap().push(format!("status: {line}")),
|
||||||
|
move |on| held.lock().unwrap().push(format!("transmit: {on}")),
|
||||||
|
);
|
||||||
|
ptt.set(Some("Ctrl+Hyper+Banana".into()));
|
||||||
|
ptt.set(None);
|
||||||
|
// The task answers in order: the last answer says the end of the list.
|
||||||
|
let deadline = std::time::Instant::now() + Duration::from_secs(30);
|
||||||
|
while log.lock().unwrap().len() < 4 {
|
||||||
|
assert!(std::time::Instant::now() < deadline, "{:?}", log.lock().unwrap());
|
||||||
|
std::thread::sleep(Duration::from_millis(5));
|
||||||
|
}
|
||||||
|
let log = log.lock().unwrap().clone();
|
||||||
|
assert_eq!(log[0], "transmit: false", "{log:?}");
|
||||||
|
assert!(log[1].starts_with("status: "), "the parse error: {log:?}");
|
||||||
|
assert_eq!(log[2], "transmit: false", "{log:?}");
|
||||||
|
assert_eq!(log[3], "status: Off.", "{log:?}");
|
||||||
|
drop(ptt);
|
||||||
|
runtime.shutdown_timeout(Duration::from_secs(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// When the desktop removes the registered hotkey while it is pressed, the
|
||||||
|
/// loop releases transmit before reporting the removal.
|
||||||
|
#[test]
|
||||||
|
fn desktop_removal_mid_hold_releases_transmit_before_reporting_status() {
|
||||||
|
let runtime = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
|
||||||
|
runtime.block_on(async {
|
||||||
|
let (tx_key, rx_key) = mpsc::unbounded_channel();
|
||||||
|
let (tx_evt, rx_evt) = mpsc::unbounded_channel();
|
||||||
|
let (tx_log, mut rx_log) = mpsc::unbounded_channel();
|
||||||
|
let (said, held) = (tx_log.clone(), tx_log);
|
||||||
|
let registrar = FakeRegistrar { stream: Some(FakeEvents(rx_evt)) };
|
||||||
|
let task = tokio::spawn(run_loop(
|
||||||
|
rx_key,
|
||||||
|
registrar,
|
||||||
|
move |line| {
|
||||||
|
let _ = said.send(format!("status: {line}"));
|
||||||
|
},
|
||||||
|
move |on| {
|
||||||
|
let _ = held.send(format!("transmit: {on}"));
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
tx_key.send(Some("Ctrl+Shift+T".into())).unwrap();
|
||||||
|
assert_eq!(recv_log(&mut rx_log).await, "transmit: false");
|
||||||
|
assert!(recv_log(&mut rx_log).await.starts_with("status: Active: "));
|
||||||
|
|
||||||
|
tx_evt.send(HotkeyEvent::Pressed).unwrap();
|
||||||
|
assert_eq!(recv_log(&mut rx_log).await, "transmit: true");
|
||||||
|
|
||||||
|
// Desktop removes the shortcut while held.
|
||||||
|
drop(tx_evt);
|
||||||
|
assert_eq!(
|
||||||
|
recv_log(&mut rx_log).await,
|
||||||
|
"transmit: false",
|
||||||
|
"transmit must fail closed before reporting removal"
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
recv_log(&mut rx_log).await,
|
||||||
|
"status: The hotkey was removed by the desktop."
|
||||||
|
);
|
||||||
|
|
||||||
|
drop(tx_key);
|
||||||
|
tokio::time::timeout(Duration::from_secs(30), task)
|
||||||
|
.await
|
||||||
|
.expect("task exit timed out")
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// When the command channel closes (task exit) while the hotkey is pressed,
|
||||||
|
/// the loop releases transmit before exiting.
|
||||||
|
#[test]
|
||||||
|
fn closing_command_channel_mid_hold_releases_transmit_before_exiting() {
|
||||||
|
let runtime = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
|
||||||
|
runtime.block_on(async {
|
||||||
|
let (tx_key, rx_key) = mpsc::unbounded_channel();
|
||||||
|
let (tx_evt, rx_evt) = mpsc::unbounded_channel();
|
||||||
|
let (tx_log, mut rx_log) = mpsc::unbounded_channel();
|
||||||
|
let (said, held) = (tx_log.clone(), tx_log);
|
||||||
|
let registrar = FakeRegistrar { stream: Some(FakeEvents(rx_evt)) };
|
||||||
|
let task = tokio::spawn(run_loop(
|
||||||
|
rx_key,
|
||||||
|
registrar,
|
||||||
|
move |line| {
|
||||||
|
let _ = said.send(format!("status: {line}"));
|
||||||
|
},
|
||||||
|
move |on| {
|
||||||
|
let _ = held.send(format!("transmit: {on}"));
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
tx_key.send(Some("Ctrl+Shift+T".into())).unwrap();
|
||||||
|
assert_eq!(recv_log(&mut rx_log).await, "transmit: false");
|
||||||
|
assert!(recv_log(&mut rx_log).await.starts_with("status: Active: "));
|
||||||
|
|
||||||
|
tx_evt.send(HotkeyEvent::Pressed).unwrap();
|
||||||
|
assert_eq!(recv_log(&mut rx_log).await, "transmit: true");
|
||||||
|
|
||||||
|
// Keep the event stream open while the handle drops (task exit).
|
||||||
|
drop(tx_key);
|
||||||
|
tokio::time::timeout(Duration::from_secs(30), task)
|
||||||
|
.await
|
||||||
|
.expect("task exit timed out")
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
rx_log.try_recv().ok().as_deref(),
|
||||||
|
Some("transmit: false"),
|
||||||
|
"closing rx mid-hold must release transmit before breaking"
|
||||||
|
);
|
||||||
|
drop(tx_evt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,8 +11,11 @@ pub mod backend;
|
|||||||
pub mod dev;
|
pub mod dev;
|
||||||
pub mod engine;
|
pub mod engine;
|
||||||
pub mod fonts;
|
pub mod fonts;
|
||||||
|
pub mod hotkey;
|
||||||
pub mod meter;
|
pub mod meter;
|
||||||
|
pub mod pictures;
|
||||||
pub mod shell;
|
pub mod shell;
|
||||||
|
pub mod signals;
|
||||||
pub mod swatch;
|
pub mod swatch;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
pub mod view;
|
pub mod view;
|
||||||
@@ -148,6 +151,9 @@ fn open_main_window(
|
|||||||
};
|
};
|
||||||
move |cx| AppState::new(setup, cx)
|
move |cx| AppState::new(setup, cx)
|
||||||
});
|
});
|
||||||
|
// The global push-to-talk key, on the engine's runtime (docs/ui.md): once the
|
||||||
|
// state exists, and never from a test of the state.
|
||||||
|
app.update(cx, |app, _| app.start_global_ptt());
|
||||||
let options = {
|
let options = {
|
||||||
let app = app.read(cx);
|
let app = app.read(cx);
|
||||||
window_options(switches, app.remembered_window(), app.window_title(), cx)
|
window_options(switches, app.remembered_window(), app.window_title(), cx)
|
||||||
@@ -215,6 +221,7 @@ pub fn run() -> Result<()> {
|
|||||||
let closed_sessions = closed_sessions.clone();
|
let closed_sessions = closed_sessions.clone();
|
||||||
move |cx| {
|
move |cx| {
|
||||||
gpui_kit::init(cx);
|
gpui_kit::init(cx);
|
||||||
|
shell::bind_keys(cx);
|
||||||
fonts::load(cx);
|
fonts::load(cx);
|
||||||
// The mode and the text size are the settings', or a development
|
// The mode and the text size are the settings', or a development
|
||||||
// switch's.
|
// switch's.
|
||||||
|
|||||||
@@ -41,6 +41,44 @@ impl Counter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// How many times each pane of the window was rendered (per second). A pane
|
||||||
|
/// is an entity of its own that the window draws again only when it was
|
||||||
|
/// notified (`Entity::cached`), or when something below it was; the figures
|
||||||
|
/// say which panes a change of the state cost.
|
||||||
|
#[derive(Clone, Default, Debug)]
|
||||||
|
pub struct Panes {
|
||||||
|
/// The server rail.
|
||||||
|
pub rail: Counter,
|
||||||
|
/// The top bar.
|
||||||
|
pub topbar: Counter,
|
||||||
|
/// The sidebar (the server card, the voice and user cards; the tree is
|
||||||
|
/// inside it).
|
||||||
|
pub sidebar: Counter,
|
||||||
|
/// The channel tree.
|
||||||
|
pub tree: Counter,
|
||||||
|
/// The main area.
|
||||||
|
pub main: Counter,
|
||||||
|
/// The members panel.
|
||||||
|
pub members: Counter,
|
||||||
|
/// The voice channel page.
|
||||||
|
pub voice: Counter,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Panes {
|
||||||
|
/// The counters with the names the meter reports them under.
|
||||||
|
pub fn named(&self) -> [(&'static str, Counter); 7] {
|
||||||
|
[
|
||||||
|
("rail", self.rail.clone()),
|
||||||
|
("topbar", self.topbar.clone()),
|
||||||
|
("sidebar", self.sidebar.clone()),
|
||||||
|
("tree", self.tree.clone()),
|
||||||
|
("main", self.main.clone()),
|
||||||
|
("members", self.members.clone()),
|
||||||
|
("voice", self.voice.clone()),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The app's own numbers the meter reports besides the process's.
|
/// The app's own numbers the meter reports besides the process's.
|
||||||
#[derive(Clone, Default, Debug)]
|
#[derive(Clone, Default, Debug)]
|
||||||
pub struct Counters {
|
pub struct Counters {
|
||||||
@@ -50,6 +88,8 @@ pub struct Counters {
|
|||||||
pub ticks: Counter,
|
pub ticks: Counter,
|
||||||
/// Windows drawn (frames, per second).
|
/// Windows drawn (frames, per second).
|
||||||
pub renders: Counter,
|
pub renders: Counter,
|
||||||
|
/// Renders of each pane of the window (per second).
|
||||||
|
pub panes: Panes,
|
||||||
/// Jobs other threads handed to the foreground through
|
/// Jobs other threads handed to the foreground through
|
||||||
/// [`crate::app::Later`] (per second).
|
/// [`crate::app::Later`] (per second).
|
||||||
pub later_jobs: Counter,
|
pub later_jobs: Counter,
|
||||||
@@ -194,12 +234,15 @@ pub fn start(counters: Counters) {
|
|||||||
tracing::warn!(target: "voelin_gpui::meter", "the meter reads /proc/self; there is none here");
|
tracing::warn!(target: "voelin_gpui::meter", "the meter reads /proc/self; there is none here");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let rated = [
|
let rated: Vec<(&str, Counter)> = [
|
||||||
("engine_events", counters.engine_events.clone()),
|
("engine_events", counters.engine_events.clone()),
|
||||||
("ticks", counters.ticks.clone()),
|
("ticks", counters.ticks.clone()),
|
||||||
("renders", counters.renders.clone()),
|
("renders", counters.renders.clone()),
|
||||||
("later_jobs", counters.later_jobs.clone()),
|
]
|
||||||
];
|
.into_iter()
|
||||||
|
.chain(counters.panes.named())
|
||||||
|
.chain([("later_jobs", counters.later_jobs.clone())])
|
||||||
|
.collect();
|
||||||
let mut last_counts: Vec<u64> = rated.iter().map(|(_, c)| c.get()).collect();
|
let mut last_counts: Vec<u64> = rated.iter().map(|(_, c)| c.get()).collect();
|
||||||
tracing::info!(target: "voelin_gpui::meter", "meter on: one line a second (VOELIN_METER)");
|
tracing::info!(target: "voelin_gpui::meter", "meter on: one line a second (VOELIN_METER)");
|
||||||
loop {
|
loop {
|
||||||
@@ -232,6 +275,17 @@ pub fn start(counters: Counters) {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_panes_are_counted_by_name() {
|
||||||
|
let panes = Panes::default();
|
||||||
|
panes.members.incr();
|
||||||
|
let named = panes.named();
|
||||||
|
let names: Vec<&str> = named.iter().map(|(name, _)| *name).collect();
|
||||||
|
assert_eq!(names, ["rail", "topbar", "sidebar", "tree", "main", "members", "voice"]);
|
||||||
|
let seen: Vec<u64> = named.iter().map(|(_, counter)| counter.get()).collect();
|
||||||
|
assert_eq!(seen, [0, 0, 0, 0, 0, 1, 0], "the counters are the panes' own");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn groups_drop_trailing_numbers() {
|
fn groups_drop_trailing_numbers() {
|
||||||
assert_eq!(group_of("llvmpipe-12"), "llvmpipe");
|
assert_eq!(group_of("llvmpipe-12"), "llvmpipe");
|
||||||
|
|||||||
@@ -0,0 +1,205 @@
|
|||||||
|
//! Pictures of the engine's cache on screen.
|
||||||
|
//!
|
||||||
|
//! The engine writes a picture that arrives again into the same file in its
|
||||||
|
//! cache (an avatar or a server icon that changed), and GPUI's `img(path)`
|
||||||
|
//! keeps what it decoded in the asset cache under the path alone, so the new
|
||||||
|
//! picture would never show. Here the key of a decoded picture is the file
|
||||||
|
//! and what the file was when the reference to it was made
|
||||||
|
//! ([`PictureKey`]: the path and the [`Stamp`] of `voelin_ui_vm::image`, its
|
||||||
|
//! length and time), so a reference made after the file changed is another
|
||||||
|
//! picture: it is decoded, and the lists that show it compare unequal and
|
||||||
|
//! draw the row again. What a changed file left in the cache (the decoded
|
||||||
|
//! copy under the old key, and the texture the atlas made of it) is dropped
|
||||||
|
//! when the engine says the file was written again
|
||||||
|
//! ([`forget_stale`], for `Update::reloaded`).
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::future::Future;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use gpui_kit::{
|
||||||
|
App, Asset, Global, ImageAssetLoader, ImageCacheError, ImageSource, Img, RenderImage, Resource,
|
||||||
|
img,
|
||||||
|
};
|
||||||
|
use voelin_ui_vm::image::{ImageRef, ImageSource as Picture, Stamp};
|
||||||
|
|
||||||
|
/// What identifies a decoded picture: the file in the engine's cache and what
|
||||||
|
/// it was when the picture was referred to.
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub struct PictureKey {
|
||||||
|
path: Arc<Path>,
|
||||||
|
stamp: Stamp,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PictureKey {
|
||||||
|
/// The key of a reference to a file of the cache; none for no picture, a
|
||||||
|
/// picture that cannot be shown (missing or damaged: the reference's
|
||||||
|
/// size is none) and the pictures that are not files, which the slices
|
||||||
|
/// that decode them show.
|
||||||
|
pub fn of(image: &ImageRef) -> Option<Self> {
|
||||||
|
match &**image {
|
||||||
|
Picture::File { path, stamp } if image.size().width > 0 => {
|
||||||
|
Some(Self { path: Arc::from(path.as_path()), stamp: *stamp })
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The file.
|
||||||
|
pub fn path(&self) -> &Path {
|
||||||
|
&self.path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decodes the file of a [`PictureKey`] as `img(path)` does, keeping the
|
||||||
|
/// result under the whole key.
|
||||||
|
enum PictureLoader {}
|
||||||
|
|
||||||
|
impl Asset for PictureLoader {
|
||||||
|
type Source = PictureKey;
|
||||||
|
type Output = Result<Arc<RenderImage>, ImageCacheError>;
|
||||||
|
|
||||||
|
fn load(
|
||||||
|
source: PictureKey,
|
||||||
|
cx: &mut App,
|
||||||
|
) -> impl Future<Output = Self::Output> + Send + 'static {
|
||||||
|
<ImageAssetLoader as Asset>::load(Resource::Path(source.path), cx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The keys that were drawn, by file: what [`forget_stale`] has to look at.
|
||||||
|
#[derive(Default)]
|
||||||
|
struct Drawn(HashMap<Arc<Path>, Vec<PictureKey>>);
|
||||||
|
|
||||||
|
impl Global for Drawn {}
|
||||||
|
|
||||||
|
/// Note that `key` is being drawn.
|
||||||
|
fn note(key: &PictureKey, cx: &mut App) {
|
||||||
|
let known = cx.has_global::<Drawn>()
|
||||||
|
&& cx.global::<Drawn>().0.get(key.path()).is_some_and(|keys| keys.contains(key));
|
||||||
|
if !known {
|
||||||
|
cx.default_global::<Drawn>().0.entry(key.path.clone()).or_default().push(key.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The picture at `key` as an image element: decoded once per key, and again
|
||||||
|
/// when the file is another by the stamp. Give it a size and an object fit.
|
||||||
|
pub fn picture(key: PictureKey) -> Img {
|
||||||
|
img(ImageSource::Custom(Arc::new(move |window, cx| {
|
||||||
|
note(&key, cx);
|
||||||
|
window.use_asset::<PictureLoader>(&key, cx)
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The engine wrote the file at `path` again: drop what was decoded of it
|
||||||
|
/// under a stamp it no longer has, and the textures the atlas made of that.
|
||||||
|
/// The picture under the stamp it has now (a reference made after the write)
|
||||||
|
/// is kept; one that is made from the old file is drawn again when it is next
|
||||||
|
/// asked for.
|
||||||
|
pub fn forget_stale(path: &Path, cx: &mut App) {
|
||||||
|
if !cx.has_global::<Drawn>() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let now = Stamp::of(path);
|
||||||
|
let stale: Vec<PictureKey> = {
|
||||||
|
let Some(keys) = cx.global_mut::<Drawn>().0.get_mut(path) else { return };
|
||||||
|
let (stale, kept) = std::mem::take(keys).into_iter().partition(|key| key.stamp != now);
|
||||||
|
*keys = kept;
|
||||||
|
stale
|
||||||
|
};
|
||||||
|
for key in stale {
|
||||||
|
if let Some(Ok(image)) = cx.fetch_asset::<PictureLoader>(&key) {
|
||||||
|
cx.drop_image(image, None);
|
||||||
|
}
|
||||||
|
cx.remove_asset::<PictureLoader>(&key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the decoded copy of `key` is in the asset cache (the tests ask).
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn is_cached(key: &PictureKey, cx: &App) -> bool {
|
||||||
|
cx.has_asset::<PictureLoader>(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use gpui::TestAppContext;
|
||||||
|
use voelin_ui_vm::image::ImageSource as Source;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use crate::backend::testing::TempDir;
|
||||||
|
|
||||||
|
/// A PNG of `width` by 2 pixels.
|
||||||
|
fn png(width: u32) -> Vec<u8> {
|
||||||
|
voelin_ui_vm::dev::logic::demo_picture(width, 2, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The key of a picture follows the file: a reference made after the
|
||||||
|
/// engine wrote the file again is another picture, one made before still
|
||||||
|
/// refers to the old, and what is not a file of the cache has none.
|
||||||
|
#[test]
|
||||||
|
fn the_key_of_a_picture_changes_when_the_file_does() {
|
||||||
|
let dir = TempDir::new("picture-key");
|
||||||
|
std::fs::create_dir_all(&dir.0).unwrap();
|
||||||
|
let path = dir.0.join("avatar");
|
||||||
|
std::fs::write(&path, png(3)).unwrap();
|
||||||
|
let first = Source::file(&path);
|
||||||
|
let key = PictureKey::of(&first).expect("a picture in the cache");
|
||||||
|
assert_eq!(key.path(), path);
|
||||||
|
assert_eq!(PictureKey::of(&Source::file(&path)), Some(key.clone()), "same file, same key");
|
||||||
|
|
||||||
|
std::fs::write(&path, png(7)).unwrap();
|
||||||
|
let second = PictureKey::of(&Source::file(&path)).unwrap();
|
||||||
|
assert_ne!(second, key, "the file was written again");
|
||||||
|
assert_eq!(PictureKey::of(&first), Some(key), "a reference made before keeps its own");
|
||||||
|
|
||||||
|
assert_eq!(PictureKey::of(&Source::none()), None);
|
||||||
|
assert_eq!(PictureKey::of(&Source::file(dir.0.join("missing"))), None);
|
||||||
|
std::fs::write(dir.0.join("damaged"), b"not a picture").unwrap();
|
||||||
|
assert_eq!(PictureKey::of(&Source::file(dir.0.join("damaged"))), None);
|
||||||
|
assert_eq!(PictureKey::of(&Source::rgba(1, 1, vec![0; 4])), None, "not a file");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A picture rewritten into the same file is decoded again under its new
|
||||||
|
/// key, and what was decoded of the old one is dropped when the engine says
|
||||||
|
/// the file was written again; the key of the file as it is stays.
|
||||||
|
#[gpui::test]
|
||||||
|
fn a_picture_written_again_is_decoded_again_and_the_old_copy_goes(cx: &mut TestAppContext) {
|
||||||
|
let dir = TempDir::new("picture-reload");
|
||||||
|
std::fs::create_dir_all(&dir.0).unwrap();
|
||||||
|
let path = dir.0.join("avatar");
|
||||||
|
std::fs::write(&path, png(3)).unwrap();
|
||||||
|
let old = PictureKey::of(&Source::file(&path)).unwrap();
|
||||||
|
let width = |cx: &mut TestAppContext, key: &PictureKey| {
|
||||||
|
cx.update(|cx| match cx.fetch_asset::<PictureLoader>(key) {
|
||||||
|
Some(Ok(image)) => Some(image.size(0).width.0),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
};
|
||||||
|
cx.update(|cx| note(&old, cx));
|
||||||
|
assert_eq!(width(cx, &old), None, "loading");
|
||||||
|
cx.run_until_parked();
|
||||||
|
assert_eq!(width(cx, &old), Some(3));
|
||||||
|
|
||||||
|
// The engine writes the file again, and the window draws the picture
|
||||||
|
// under the key of the file as it is now, before it is told so.
|
||||||
|
std::fs::write(&path, png(7)).unwrap();
|
||||||
|
let new = PictureKey::of(&Source::file(&path)).unwrap();
|
||||||
|
cx.update(|cx| note(&new, cx));
|
||||||
|
assert_eq!(width(cx, &new), None, "loading");
|
||||||
|
cx.run_until_parked();
|
||||||
|
assert_eq!(width(cx, &new), Some(7), "the new bytes, not the old ones");
|
||||||
|
assert_eq!(width(cx, &old), Some(3), "the old copy is still there");
|
||||||
|
|
||||||
|
cx.update(|cx| forget_stale(&path, cx));
|
||||||
|
assert!(!cx.update(|cx| cx.has_asset::<PictureLoader>(&old)), "the old copy is dropped");
|
||||||
|
assert!(cx.update(|cx| cx.has_asset::<PictureLoader>(&new)), "the current key is kept");
|
||||||
|
assert_eq!(width(cx, &new), Some(7));
|
||||||
|
|
||||||
|
// Nothing more to forget; a file nobody drew is nothing to forget.
|
||||||
|
cx.update(|cx| forget_stale(&path, cx));
|
||||||
|
cx.update(|cx| forget_stale(&dir.0.join("never-drawn"), cx));
|
||||||
|
assert!(cx.update(|cx| cx.has_asset::<PictureLoader>(&new)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,12 +6,19 @@
|
|||||||
//! ([`crate::app::AppState`]) for what the callback did in Slint: key bindings
|
//! ([`crate::app::AppState`]) for what the callback did in Slint: key bindings
|
||||||
//! and menus come to the same handlers later.
|
//! and menus come to the same handlers later.
|
||||||
//!
|
//!
|
||||||
//! The callbacks of `bind/servers.rs` that are not here belong to the slices
|
//! The voice page and the call bar add `show_voice_view`, the page's own
|
||||||
//! after this one: `search_members`, `show_voice_view`, `join_channel`,
|
//! buttons (the smaller stage, Leave) and the two affordances of the call bar
|
||||||
//! `join_with_password`, `toggle_collapse`, `open_client` and
|
//! whose pages come with later slices (Share, the voice settings), which are
|
||||||
//! `client_audio_changed` to the channel tree and the voice page, and `copied`
|
//! logged.
|
||||||
//! (the toast that follows a copy) to whichever copies: [`Invite`] sets it
|
//!
|
||||||
//! itself.
|
//! The channel tree and the members panel add `join_channel`,
|
||||||
|
//! `join_with_password`, `toggle_collapse`, `search_members`, `open_member` and
|
||||||
|
//! `open_client` (the last one only logs: the client's volume dialog is a
|
||||||
|
//! dialog of its own slice). The callbacks of `bind/servers.rs` that are
|
||||||
|
//! still not here belong to the slices after: `client_audio_changed` to the
|
||||||
|
//! dialogs (the member card has the volume and the mute of a person,
|
||||||
|
//! [`SetMemberVolume`] and [`SetMemberMuted`]), and `copied` (the toast that
|
||||||
|
//! follows a copy) to whichever copies: [`Invite`] sets it itself.
|
||||||
|
|
||||||
use gpui_kit::{Action, actions};
|
use gpui_kit::{Action, actions};
|
||||||
|
|
||||||
@@ -36,9 +43,51 @@ actions!(
|
|||||||
OpenSearch,
|
OpenSearch,
|
||||||
/// The settings buttons: the settings come with their slice, today it is logged.
|
/// The settings buttons: the settings come with their slice, today it is logged.
|
||||||
OpenSettings,
|
OpenSettings,
|
||||||
|
/// `join_with_password`: the password prompt's Join, with what it holds.
|
||||||
|
SubmitChannelPassword,
|
||||||
|
/// Close the password prompt without joining.
|
||||||
|
CancelChannelPassword,
|
||||||
|
/// The voice page's Leave (`Nav.show-voice(false)` then `disconnect_voice`).
|
||||||
|
LeaveVoice,
|
||||||
|
/// The voice page's Smaller stage / Larger stage (`ui.voice_compact`).
|
||||||
|
ToggleVoiceCompact,
|
||||||
|
/// The call bar's Share: the share menu comes with the stream slices, today it is logged.
|
||||||
|
OpenShare,
|
||||||
|
/// The call bar's voice settings: the settings come with their slice, today it is logged.
|
||||||
|
OpenVoiceSettings,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/// `show_voice_view`: the voice channel page on (the main area) or off (back to
|
||||||
|
/// the server page, where the chat will be).
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct ShowVoiceView {
|
||||||
|
/// Shown from now on.
|
||||||
|
pub on: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The member card's volume slider: the person's playback volume, in percent
|
||||||
|
/// (`member_volume` of the Slint card).
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct SetMemberVolume {
|
||||||
|
/// The client's id on the server.
|
||||||
|
pub client: u16,
|
||||||
|
/// 0 to 200.
|
||||||
|
pub percent: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The member card's Mute for me: stop playing the person (local only).
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct SetMemberMuted {
|
||||||
|
/// The client's id on the server.
|
||||||
|
pub client: u16,
|
||||||
|
/// Muted from now on.
|
||||||
|
pub muted: bool,
|
||||||
|
}
|
||||||
|
|
||||||
/// `select_server`: show a server (and observe it).
|
/// `select_server`: show a server (and observe it).
|
||||||
#[derive(Clone, Debug, PartialEq, Action)]
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
#[action(namespace = voelin, no_json)]
|
#[action(namespace = voelin, no_json)]
|
||||||
@@ -86,3 +135,72 @@ pub struct PushToTalk {
|
|||||||
/// Transmitting from now on.
|
/// Transmitting from now on.
|
||||||
pub on: bool,
|
pub on: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// `join_channel`: join a channel of the server on screen (a double-click on
|
||||||
|
/// its row, the context menu's Join).
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct JoinChannel {
|
||||||
|
/// The channel's id on the server.
|
||||||
|
pub channel: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A click on a channel's row: select it (the Slint tree opens the channel's
|
||||||
|
/// chat, which comes with the chat slice).
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct SelectChannel {
|
||||||
|
/// The channel's id on the server.
|
||||||
|
pub channel: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `toggle_collapse`: fold or unfold a channel of the tree.
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct ToggleChannel {
|
||||||
|
/// The channel's id on the server.
|
||||||
|
pub channel: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The context menu's Edit channel: the channel editor is a slice of its own,
|
||||||
|
/// today it is logged.
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct EditChannel {
|
||||||
|
/// The channel's id on the server.
|
||||||
|
pub channel: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The context menu's Move to my channel: moving another client needs a command
|
||||||
|
/// the engine does not have yet, so today it is logged.
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct MoveClient {
|
||||||
|
/// The client's id on the server.
|
||||||
|
pub client: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `open_client`: a click on a person in the tree opens their volume dialog,
|
||||||
|
/// which is a dialog of its own slice: today it is logged.
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct OpenClient {
|
||||||
|
/// The client's id on the server.
|
||||||
|
pub client: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `search_members`: the members panel's search text.
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct SearchMembers {
|
||||||
|
/// What the box holds; empty shows everyone.
|
||||||
|
pub text: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `open_member`: open the card of a person over the members panel; -1 closes it.
|
||||||
|
#[derive(Clone, Debug, PartialEq, Action)]
|
||||||
|
#[action(namespace = voelin, no_json)]
|
||||||
|
pub struct OpenMember {
|
||||||
|
/// The client's id on the server, or -1.
|
||||||
|
pub client: i32,
|
||||||
|
}
|
||||||
@@ -0,0 +1,502 @@
|
|||||||
|
//! The channel tree of the sidebar (`ChannelTree` of `screens/channels.slint`):
|
||||||
|
//! the channels of the server on screen with the people in them, nested, with
|
||||||
|
//! their spacers, pictures, passwords and counts, and the person's marks.
|
||||||
|
//!
|
||||||
|
//! A cached pane ([`gpui_kit::Entity::cached`], which needs the size the
|
||||||
|
//! sidebar gives it) over a virtual list ([`gpui_kit::list`]: only the rows in
|
||||||
|
//! view are built, the rows differ in height) that follows [`TreeModel`]: the
|
||||||
|
//! model says which rows changed ([`TreeEvent::Rows`]) and the pane tells its
|
||||||
|
//! list, so a person who joins is a row inserted and the scroll stays where it
|
||||||
|
//! was. The pane reads nothing but its own fields while it renders, so
|
||||||
|
//! nothing but its own notify draws it again. A click selects a channel, a
|
||||||
|
//! double-click joins it, the chevron folds it, a right-click offers the
|
||||||
|
//! same; a click on a person is logged (their volume dialog is a slice of
|
||||||
|
//! its own).
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use gpui_kit::component::menu::ContextMenuExt as _;
|
||||||
|
use gpui_kit::prelude::FluentBuilder as _;
|
||||||
|
use gpui_kit::{
|
||||||
|
AnyElement, Context, Entity, FontWeight, InteractiveElement as _, IntoElement, ListAlignment,
|
||||||
|
ListState, ObjectFit, ParentElement as _, Render, SharedString,
|
||||||
|
StatefulInteractiveElement as _, Styled as _, StyledImage as _, Subscription, Window, div,
|
||||||
|
list, px,
|
||||||
|
};
|
||||||
|
use voelin_ui_vm::bridge::TreeItem;
|
||||||
|
use voelin_ui_vm::tree::ChannelId;
|
||||||
|
|
||||||
|
use super::actions::{
|
||||||
|
EditChannel, JoinChannel, MoveClient, OpenClient, OpenMember, SelectChannel, ToggleChannel,
|
||||||
|
};
|
||||||
|
use super::tree_model::{Emptiness, TreeEvent, TreeModel, debug_check};
|
||||||
|
use super::widgets::{Avatar, banner_scrim, icon, live_badge, small_picture, speaking_bars};
|
||||||
|
use crate::meter::Counters;
|
||||||
|
use crate::pictures::{PictureKey, picture};
|
||||||
|
use crate::theme::{VoelinTheme, hsla};
|
||||||
|
|
||||||
|
/// How far each level of the tree is indented.
|
||||||
|
const INDENT: f32 = 14.0;
|
||||||
|
|
||||||
|
/// How opaque the hover and selection tints of a row with a banner are over
|
||||||
|
/// the banner and its veil: the hover is `channels.slint`'s (`Theme.surface-3.
|
||||||
|
/// transparentize(0.5)`), the selection, which Slint has no state for, is a
|
||||||
|
/// stronger one of the same colour.
|
||||||
|
const BANNER_HOVER: f32 = 0.5;
|
||||||
|
const BANNER_SELECTED: f32 = 0.75;
|
||||||
|
|
||||||
|
/// The channel tree.
|
||||||
|
pub struct ChannelTree {
|
||||||
|
rows: Arc<Vec<TreeItem>>,
|
||||||
|
selected: Option<ChannelId>,
|
||||||
|
emptiness: Emptiness,
|
||||||
|
list: ListState,
|
||||||
|
/// The text size factor the list measured its rows at.
|
||||||
|
measured_at: f32,
|
||||||
|
counters: Counters,
|
||||||
|
_subscription: Subscription,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ChannelTree {
|
||||||
|
/// A tree that follows `model`.
|
||||||
|
pub fn new(model: &Entity<TreeModel>, counters: Counters, cx: &mut Context<Self>) -> Self {
|
||||||
|
let (rows, selected, emptiness) = {
|
||||||
|
let model = model.read(cx);
|
||||||
|
(model.rows().clone(), model.selected(), model.emptiness())
|
||||||
|
};
|
||||||
|
let subscription = cx.subscribe(model, |this: &mut Self, model, event: &TreeEvent, cx| {
|
||||||
|
match event {
|
||||||
|
TreeEvent::Rows(changes, rows) => this.apply(changes, rows.clone()),
|
||||||
|
TreeEvent::Selection => this.selected = model.read(cx).selected(),
|
||||||
|
// The count of people is the members panel's.
|
||||||
|
TreeEvent::Lists => {
|
||||||
|
let emptiness = model.read(cx).emptiness();
|
||||||
|
if emptiness == this.emptiness {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.emptiness = emptiness;
|
||||||
|
}
|
||||||
|
TreeEvent::People(..) | TreeEvent::Voice(_) | TreeEvent::Card => return,
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
Self {
|
||||||
|
list: ListState::new(rows.len(), ListAlignment::Top, px(240.0)),
|
||||||
|
rows,
|
||||||
|
selected,
|
||||||
|
emptiness,
|
||||||
|
measured_at: 0.0,
|
||||||
|
counters,
|
||||||
|
_subscription: subscription,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rows it shows.
|
||||||
|
pub fn rows(&self) -> &[TreeItem] {
|
||||||
|
&self.rows
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The channel it shows selected.
|
||||||
|
pub fn selected(&self) -> Option<ChannelId> {
|
||||||
|
self.selected
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Why it shows no rows, were it empty.
|
||||||
|
pub fn emptiness(&self) -> Emptiness {
|
||||||
|
self.emptiness
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Take the new rows in (the rows `changes` lead to, carried by the event),
|
||||||
|
/// telling the list which rows came, went or changed their height (a
|
||||||
|
/// channel row and a person's differ).
|
||||||
|
fn apply(&mut self, changes: &voelin_ui_vm::list::Changes, new: Arc<Vec<TreeItem>>) {
|
||||||
|
use voelin_ui_vm::list::Change;
|
||||||
|
|
||||||
|
debug_check(self.rows.len(), changes, new.len());
|
||||||
|
let mut channels: Vec<bool> = self.rows.iter().map(|row| row.is_channel).collect();
|
||||||
|
for change in &changes.0 {
|
||||||
|
match *change {
|
||||||
|
Change::Update(i) => {
|
||||||
|
if channels[i] != new[i].is_channel {
|
||||||
|
self.list.splice(i..i + 1, 1);
|
||||||
|
}
|
||||||
|
channels[i] = new[i].is_channel;
|
||||||
|
}
|
||||||
|
Change::Remove(i) => {
|
||||||
|
channels.remove(i);
|
||||||
|
self.list.splice(i..i + 1, 0);
|
||||||
|
}
|
||||||
|
Change::Insert(i) => {
|
||||||
|
channels.insert(i, new[i].is_channel);
|
||||||
|
self.list.splice(i..i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.rows = new;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The row at `ix`, for the list.
|
||||||
|
fn row(&mut self, ix: usize, cx: &mut Context<Self>) -> AnyElement {
|
||||||
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
|
match self.rows.get(ix) {
|
||||||
|
Some(item) if item.is_channel => {
|
||||||
|
channel_row(&theme, item, self.selected == Some(item.id as ChannelId))
|
||||||
|
}
|
||||||
|
Some(item) => client_row(&theme, item),
|
||||||
|
None => div().into_any_element(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The words of a tree with no rows.
|
||||||
|
fn empty_words(emptiness: Emptiness) -> &'static str {
|
||||||
|
match emptiness {
|
||||||
|
Emptiness::NoServer => "No server yet.",
|
||||||
|
Emptiness::Loading => "Loading the channels…",
|
||||||
|
// The tree is not searched, so it is never `NoMatch` (the members
|
||||||
|
// panel's, `TreeModel::people_emptiness`): the model gives it
|
||||||
|
// `Emptiness::of`, which does not say it.
|
||||||
|
Emptiness::Connect | Emptiness::NoMatch => "Connect to see the channels.",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The chevron of a channel, which folds it.
|
||||||
|
fn chevron(item: &TreeItem, covered: bool, theme: &VoelinTheme) -> impl IntoElement {
|
||||||
|
let c = &theme.colors;
|
||||||
|
let id = item.id as ChannelId;
|
||||||
|
div()
|
||||||
|
.id(("tree-toggle", id))
|
||||||
|
.debug_selector(move || format!("tree-toggle-{id}"))
|
||||||
|
.w(px(18.0))
|
||||||
|
.h(px(18.0))
|
||||||
|
.flex_none()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.on_click(move |_, window, cx| {
|
||||||
|
cx.stop_propagation();
|
||||||
|
window.dispatch_action(Box::new(ToggleChannel { channel: id }), cx);
|
||||||
|
})
|
||||||
|
.child(icon(
|
||||||
|
if item.collapsed { "chevron-right" } else { "chevron-down" },
|
||||||
|
14.0,
|
||||||
|
if covered { c.text } else { c.text_muted },
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One channel: its icon (or a speaker, or a lock), its name as the server
|
||||||
|
/// set it out, how many are in it, and the chevron.
|
||||||
|
fn channel_row(theme: &VoelinTheme, item: &TreeItem, selected: bool) -> AnyElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let id = item.id as ChannelId;
|
||||||
|
let indent = item.depth as f32 * INDENT;
|
||||||
|
let banner = PictureKey::of(&item.banner);
|
||||||
|
let covered = banner.is_some();
|
||||||
|
let strong = item.own || covered;
|
||||||
|
let (hover, accent_soft, accent, selected_fill) =
|
||||||
|
(hsla(c.surface_3), hsla(c.accent_soft), hsla(c.accent), hsla(c.surface_3));
|
||||||
|
let own = item.own;
|
||||||
|
let has_icon = PictureKey::of(&item.icon).is_some();
|
||||||
|
let name_color = if strong { c.text } else { c.text_secondary };
|
||||||
|
let weight = if strong { FontWeight::SEMIBOLD } else { FontWeight::MEDIUM };
|
||||||
|
let name = div()
|
||||||
|
.flex_1()
|
||||||
|
.min_w_0()
|
||||||
|
.text_size(px(m.font_body))
|
||||||
|
.font_weight(weight)
|
||||||
|
.text_color(hsla(name_color))
|
||||||
|
.when(item.spacer == 2, |name| name.text_center())
|
||||||
|
.when(item.spacer == 3, |name| name.text_right())
|
||||||
|
// A line is cut where the row ends; it does not widen the list.
|
||||||
|
.when(item.spacer == 4, |name| name.overflow_hidden().whitespace_nowrap())
|
||||||
|
.when(item.spacer != 4, |name| name.truncate())
|
||||||
|
.child(item.name.to_string());
|
||||||
|
let counted = item.spacer == 0 && (item.members > 0 || item.max_members >= 0);
|
||||||
|
let count = if item.max_members >= 0 {
|
||||||
|
format!("{}/{}", item.members, item.max_members)
|
||||||
|
} else {
|
||||||
|
item.members.to_string()
|
||||||
|
};
|
||||||
|
let group = SharedString::from(format!("tree-row-{id}"));
|
||||||
|
let row = div()
|
||||||
|
.id(("tree-channel", id))
|
||||||
|
.debug_selector(move || format!("tree-channel-{id}"))
|
||||||
|
.group(group.clone())
|
||||||
|
.relative()
|
||||||
|
.w_full()
|
||||||
|
.h(px(34.0 * m.font_scale))
|
||||||
|
.flex_none()
|
||||||
|
.overflow_hidden()
|
||||||
|
.rounded(px(m.radius_md))
|
||||||
|
.cursor_pointer()
|
||||||
|
.when(own, |row| row.bg(accent_soft).border_1().border_color(accent))
|
||||||
|
.when(!own && selected, |row| row.bg(selected_fill))
|
||||||
|
.when(!own && !selected, |row| row.hover(move |style| style.bg(hover)))
|
||||||
|
// Artwork behind the same compact row as its title, from the indent on,
|
||||||
|
// under a veil of the surface colour that keeps the text readable over
|
||||||
|
// any picture, and under the tints of the row: our own channel's, the
|
||||||
|
// selected one and the one the pointer is over. The artwork covers the
|
||||||
|
// row's own background (which only the indent shows), so the tints
|
||||||
|
// are translucent children above the veil, as `channels.slint` does
|
||||||
|
// for the hover.
|
||||||
|
.when_some(banner, |row, key| {
|
||||||
|
let tint = || {
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.top(px(0.0))
|
||||||
|
.bottom(px(0.0))
|
||||||
|
.left(px(indent))
|
||||||
|
.right(px(0.0))
|
||||||
|
.rounded(px(m.radius_md))
|
||||||
|
};
|
||||||
|
row.child(
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.top(px(0.0))
|
||||||
|
.bottom(px(0.0))
|
||||||
|
.left(px(indent))
|
||||||
|
.right(px(0.0))
|
||||||
|
.child(picture(key).size_full().object_fit(ObjectFit::Cover)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id(("tree-scrim", id))
|
||||||
|
.debug_selector(move || format!("tree-scrim-{id}"))
|
||||||
|
.absolute()
|
||||||
|
.top(px(0.0))
|
||||||
|
.bottom(px(0.0))
|
||||||
|
.left(px(indent))
|
||||||
|
.right(px(0.0))
|
||||||
|
.bg(banner_scrim(theme)),
|
||||||
|
)
|
||||||
|
.when(own, |row| {
|
||||||
|
row.child(
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.top(px(0.0))
|
||||||
|
.bottom(px(0.0))
|
||||||
|
.left(px(indent))
|
||||||
|
.right(px(0.0))
|
||||||
|
.rounded(px(m.radius_md))
|
||||||
|
.bg(accent_soft.opacity(0.65)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when(!own && selected, |row| {
|
||||||
|
row.child(
|
||||||
|
tint()
|
||||||
|
.debug_selector(move || format!("tree-selected-{id}"))
|
||||||
|
.bg(selected_fill.opacity(BANNER_SELECTED)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when(!own && !selected, |row| {
|
||||||
|
row.child(
|
||||||
|
tint().group_hover(group, move |style| style.bg(hover.opacity(BANNER_HOVER))),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.pl(px(m.space_2 + indent))
|
||||||
|
.pr(px(m.space_3))
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
// A centred spacer is balanced against the chevron.
|
||||||
|
.when(item.spacer == 2, |row| row.child(div().w(px(18.0)).flex_none()))
|
||||||
|
.when(item.spacer == 0, |row| match small_picture(&item.icon, 16.0) {
|
||||||
|
Some(picture) => row.child(picture),
|
||||||
|
None => row.child(icon(
|
||||||
|
if item.locked { "lock" } else { "volume-2" },
|
||||||
|
18.0,
|
||||||
|
if strong { c.text } else { c.icon },
|
||||||
|
)),
|
||||||
|
})
|
||||||
|
.child(name)
|
||||||
|
.when(item.locked && (has_icon || item.spacer != 0), |row| {
|
||||||
|
row.child(icon("lock", 14.0, if covered { c.text } else { c.icon }))
|
||||||
|
})
|
||||||
|
.when(counted, |row| {
|
||||||
|
row.child(
|
||||||
|
div()
|
||||||
|
.flex_none()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(3.0))
|
||||||
|
.when(own, |count| count.child(icon("users", 14.0, c.text_secondary)))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(if strong { c.text } else { c.text_muted }))
|
||||||
|
.child(count),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.child(chevron(item, covered, theme))
|
||||||
|
.on_click(move |event, window, cx| {
|
||||||
|
if event.click_count() >= 2 {
|
||||||
|
window.dispatch_action(Box::new(JoinChannel { channel: id }), cx);
|
||||||
|
} else {
|
||||||
|
window.dispatch_action(Box::new(SelectChannel { channel: id }), cx);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.context_menu(move |menu, _, _| {
|
||||||
|
menu.menu("Join channel", Box::new(JoinChannel { channel: id }))
|
||||||
|
.menu("Fold or unfold", Box::new(ToggleChannel { channel: id }))
|
||||||
|
.separator()
|
||||||
|
.menu("Edit channel…", Box::new(EditChannel { channel: id }))
|
||||||
|
});
|
||||||
|
row.into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One person: their avatar, name and badges, and the marks of what they do.
|
||||||
|
fn client_row(theme: &VoelinTheme, item: &TreeItem) -> AnyElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let id = item.id as u64;
|
||||||
|
let indent = item.depth as f32 * INDENT;
|
||||||
|
let (hover, myself) = (hsla(c.surface_3), item.myself);
|
||||||
|
let name_color = if item.away {
|
||||||
|
c.text_muted
|
||||||
|
} else if myself {
|
||||||
|
c.accent_text
|
||||||
|
} else {
|
||||||
|
c.text_secondary
|
||||||
|
};
|
||||||
|
let mark = |name: &'static str, color| icon(name, 14.0, color);
|
||||||
|
div()
|
||||||
|
.id(("tree-client", id))
|
||||||
|
.debug_selector(move || format!("tree-client-{id}"))
|
||||||
|
.w_full()
|
||||||
|
.h(px(30.0 * m.font_scale))
|
||||||
|
.flex_none()
|
||||||
|
.rounded(px(m.radius_md))
|
||||||
|
.cursor_pointer()
|
||||||
|
.hover(move |style| style.bg(hover))
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.pl(px(m.space_2 + indent + 12.0))
|
||||||
|
.pr(px(m.space_3))
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.child(
|
||||||
|
Avatar::new(("tree-avatar", id), 22.0, &item.initials, item.tint)
|
||||||
|
.image(item.avatar.clone())
|
||||||
|
.speaking(item.talking),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.min_w_0()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_body))
|
||||||
|
.font_weight(if myself { FontWeight::SEMIBOLD } else { FontWeight::NORMAL })
|
||||||
|
.text_color(hsla(name_color))
|
||||||
|
.child(item.name.to_string()),
|
||||||
|
)
|
||||||
|
// Badges after the name, then the free room.
|
||||||
|
.child(
|
||||||
|
div().flex_1().min_w_0().flex().flex_row().items_center().gap(px(2.0)).children(
|
||||||
|
[&item.badge, &item.badge_2, &item.badge_3]
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|badge| small_picture(badge, 14.0)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
// The Slint bars move; these stand still (nothing here draws the window
|
||||||
|
// anew with the clock).
|
||||||
|
.when(item.talking, |row| {
|
||||||
|
row.child(
|
||||||
|
div()
|
||||||
|
.debug_selector(move || format!("tree-speaking-{id}"))
|
||||||
|
.flex_none()
|
||||||
|
.child(speaking_bars(theme, 14.0)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when(item.streaming, |row| row.child(live_badge(theme)))
|
||||||
|
.when(item.local_muted, |row| row.child(mark("volume-x", c.warning)))
|
||||||
|
.when(!item.local_muted && item.local_volume != 100, |row| {
|
||||||
|
row.child(
|
||||||
|
div()
|
||||||
|
.text_size(px(m.font_xs))
|
||||||
|
.text_color(hsla(c.text_muted))
|
||||||
|
.child(format!("{}%", item.local_volume)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when(item.muted, |row| row.child(mark("mic-off", c.danger)))
|
||||||
|
.when(item.sound_off, |row| row.child(mark("headphone-off", c.danger)))
|
||||||
|
.when(item.away, |row| {
|
||||||
|
row.child(div().text_size(px(m.font_xs)).text_color(hsla(c.text_muted)).child("away"))
|
||||||
|
})
|
||||||
|
.children(
|
||||||
|
[&item.icon, &item.icon_2, &item.icon_3]
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|i| small_picture(i, 16.0)),
|
||||||
|
)
|
||||||
|
.on_click(move |_, window, cx| {
|
||||||
|
if !myself {
|
||||||
|
window.dispatch_action(Box::new(OpenClient { client: id as u16 }), cx);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.context_menu(move |menu, _, _| {
|
||||||
|
menu.menu("Show the card", Box::new(OpenMember { client: id as i32 }))
|
||||||
|
.menu("Volume…", Box::new(OpenClient { client: id as u16 }))
|
||||||
|
.separator()
|
||||||
|
.menu("Move to my channel", Box::new(MoveClient { client: id as u16 }))
|
||||||
|
})
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ChannelTree {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.counters.panes.tree.incr();
|
||||||
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
// A new text size makes the rows another height.
|
||||||
|
if (self.measured_at - m.font_scale).abs() > f32::EPSILON {
|
||||||
|
if self.measured_at != 0.0 {
|
||||||
|
self.list.remeasure();
|
||||||
|
}
|
||||||
|
self.measured_at = m.font_scale;
|
||||||
|
}
|
||||||
|
div()
|
||||||
|
.id("sidebar-channels")
|
||||||
|
.debug_selector(|| "sidebar-channels".into())
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.px(px(m.space_2))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.min_h(px(24.0))
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.font_weight(FontWeight::SEMIBOLD)
|
||||||
|
.text_color(hsla(c.text_secondary))
|
||||||
|
.child(icon("volume-2", m.icon_sm, c.text_secondary))
|
||||||
|
.child("Channels"),
|
||||||
|
)
|
||||||
|
.map(|pane| {
|
||||||
|
if self.rows.is_empty() {
|
||||||
|
pane.child(
|
||||||
|
div()
|
||||||
|
.id("tree-empty")
|
||||||
|
.debug_selector(|| "tree-empty".into())
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(c.text_muted))
|
||||||
|
.child(empty_words(self.emptiness)),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
pane.child(
|
||||||
|
list(
|
||||||
|
self.list.clone(),
|
||||||
|
cx.processor(|this, ix, _window, cx| this.row(ix, cx)),
|
||||||
|
)
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.min_h_0(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
//! The main area. Until the chat, the voice page and the rest come, it is the
|
//! The main area. Until the voice page, the chat and the rest come, it is the
|
||||||
//! empty page: the "no server selected" state with the way to add one, and for
|
//! empty page: the "no server selected" state with the way to add one, and for
|
||||||
//! a server on screen its name, address and state with the buttons that
|
//! a server on screen its name, address and state with the buttons that
|
||||||
//! connect, disconnect and edit it. An entity of its own: it observes the root
|
//! connect, disconnect and edit it. An entity of its own, drawn as a cached
|
||||||
//! state and tells the window only when what it shows changed.
|
//! pane: it listens to the servers' signal and tells the window only when
|
||||||
|
//! what it shows changed.
|
||||||
|
|
||||||
use gpui_kit::component::button::{Button, ButtonVariants as _};
|
use gpui_kit::component::button::{Button, ButtonVariants as _};
|
||||||
use gpui_kit::prelude::FluentBuilder as _;
|
use gpui_kit::prelude::FluentBuilder as _;
|
||||||
@@ -13,9 +14,11 @@ use gpui_kit::{
|
|||||||
use voelin_ui_vm::bridge::ServerItem;
|
use voelin_ui_vm::bridge::ServerItem;
|
||||||
use voelin_ui_vm::servers::logic;
|
use voelin_ui_vm::servers::logic;
|
||||||
|
|
||||||
use super::actions::{AddServer, ConnectVoice, DisconnectVoice, EditServer};
|
use super::actions::{AddServer, ConnectVoice, DisconnectVoice, EditServer, ShowVoiceView};
|
||||||
use super::widgets::{Avatar, Presence, icon, panel, tagged};
|
use super::widgets::{Avatar, Presence, icon, panel, tagged};
|
||||||
use crate::app::AppState;
|
use crate::app::AppState;
|
||||||
|
use crate::meter::Counters;
|
||||||
|
use crate::signals::Area;
|
||||||
use crate::theme::{VoelinTheme, hsla};
|
use crate::theme::{VoelinTheme, hsla};
|
||||||
|
|
||||||
/// What the main area shows.
|
/// What the main area shows.
|
||||||
@@ -51,21 +54,25 @@ fn state_words(status: &str) -> &'static str {
|
|||||||
/// The main area.
|
/// The main area.
|
||||||
pub struct MainPanel {
|
pub struct MainPanel {
|
||||||
state: MainState,
|
state: MainState,
|
||||||
_subscription: Subscription,
|
counters: Counters,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MainPanel {
|
impl MainPanel {
|
||||||
/// A main area that follows `app`.
|
/// A main area that follows the server on screen in `app`.
|
||||||
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
||||||
let state = MainState::of(app.read(cx));
|
let (state, counters, signals) = {
|
||||||
let subscription = cx.observe(app, |this: &mut Self, app, cx| {
|
let shown = app.read(cx);
|
||||||
|
(MainState::of(shown), shown.counters().clone(), shown.signals().clone())
|
||||||
|
};
|
||||||
|
let subscriptions = signals.watch(app, &[Area::Servers], cx, |this: &mut Self, app, cx| {
|
||||||
let state = MainState::of(app.read(cx));
|
let state = MainState::of(app.read(cx));
|
||||||
if state != this.state {
|
if state != this.state {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Self { state, _subscription: subscription }
|
Self { state, counters, _subscriptions: subscriptions }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What it shows now.
|
/// What it shows now.
|
||||||
@@ -76,6 +83,7 @@ impl MainPanel {
|
|||||||
|
|
||||||
impl Render for MainPanel {
|
impl Render for MainPanel {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.counters.panes.main.incr();
|
||||||
let theme = VoelinTheme::global(cx).clone();
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
let (c, m) = (&theme.colors, &theme.metrics);
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
let body = match &self.state {
|
let body = match &self.state {
|
||||||
@@ -165,7 +173,7 @@ impl Render for MainPanel {
|
|||||||
.text_center()
|
.text_center()
|
||||||
.text_size(px(m.font_body))
|
.text_size(px(m.font_body))
|
||||||
.text_color(hsla(c.text_muted))
|
.text_color(hsla(c.text_muted))
|
||||||
.child("Its channels and its chat come with the next slices."),
|
.child("Its chat comes with a later slice."),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
@@ -194,6 +202,20 @@ impl Render for MainPanel {
|
|||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
.when(connected, |row| {
|
||||||
|
row.child(tagged(
|
||||||
|
"main-voice",
|
||||||
|
Button::new("main-voice")
|
||||||
|
.primary()
|
||||||
|
.label("Voice channel")
|
||||||
|
.on_click(|_, window, cx| {
|
||||||
|
window.dispatch_action(
|
||||||
|
Box::new(ShowVoiceView { on: true }),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
})
|
||||||
.child(tagged(
|
.child(tagged(
|
||||||
"main-edit",
|
"main-edit",
|
||||||
Button::new("main-edit").label("Edit").on_click(
|
Button::new("main-edit").label("Edit").on_click(
|
||||||
@@ -205,13 +227,8 @@ impl Render for MainPanel {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
panel(&theme)
|
// The root of a cached pane takes the size its place gives it: laid out
|
||||||
.id("main")
|
// on its own, `flex_1` would be as wide as its contents.
|
||||||
.flex_1()
|
panel(&theme).id("main").size_full().items_center().justify_center().child(body)
|
||||||
.min_w_0()
|
|
||||||
.h_full()
|
|
||||||
.items_center()
|
|
||||||
.justify_center()
|
|
||||||
.child(body)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,768 @@
|
|||||||
|
//! The members panel (`MembersPanel` and `MemberCardPopup` of
|
||||||
|
//! `screens/members.slint`): everyone on the server in sections (those
|
||||||
|
//! streaming first, then each server group), a search, and the card of one
|
||||||
|
//! person over the panel.
|
||||||
|
//!
|
||||||
|
//! [`MembersPane`] is a cached pane over a virtual list that follows
|
||||||
|
//! [`TreeModel`] as the tree does ([`TreeEvent::People`]: the row operations
|
||||||
|
//! the list applies). A talker redraws it, with the tree: a person's row has
|
||||||
|
//! the speaking ring, "Speaking" and the bars, and no other pane of the window
|
||||||
|
//! is told. [`MemberCardView`] is the card, a card over the window with a scrim
|
||||||
|
//! that a click outside closes; it has the volume and the mute of the person for
|
||||||
|
//! us (`SetMemberVolume`, `SetMemberMuted`), and its other buttons (a message, a
|
||||||
|
//! poke, friends, blocking) come with the slices that have those dialogs.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use gpui_kit::component::input::{Input, InputEvent, InputState};
|
||||||
|
use gpui_kit::component::slider::{Slider, SliderEvent, SliderState};
|
||||||
|
use gpui_kit::prelude::FluentBuilder as _;
|
||||||
|
use gpui_kit::{
|
||||||
|
AnyElement, AppContext as _, Context, Entity, FontWeight, InteractiveElement as _, IntoElement,
|
||||||
|
ListAlignment, ListState, ParentElement as _, Render, SharedString,
|
||||||
|
StatefulInteractiveElement as _, Styled as _, Subscription, Window, div, list, px,
|
||||||
|
};
|
||||||
|
use voelin_ui_vm::bridge::{MemberCard, MemberItem};
|
||||||
|
use voelin_ui_vm::list::Changes;
|
||||||
|
|
||||||
|
use super::actions::{OpenMember, SearchMembers, SetMemberMuted, SetMemberVolume};
|
||||||
|
use super::tree_model::{Emptiness, TreeEvent, TreeModel, debug_check};
|
||||||
|
use super::widgets::{
|
||||||
|
Avatar, IconButton, Presence, chip, icon, live_badge, small_picture, speaking_bars,
|
||||||
|
};
|
||||||
|
use crate::meter::Counters;
|
||||||
|
use crate::theme::tokens::Rgba;
|
||||||
|
use crate::theme::{VoelinTheme, hsla};
|
||||||
|
|
||||||
|
/// The colour of the shield of a moderator's role.
|
||||||
|
const ROLE: Rgba = Rgba(0xc06c_ffff);
|
||||||
|
|
||||||
|
/// The members panel.
|
||||||
|
pub struct MembersPane {
|
||||||
|
rows: Arc<Vec<MemberItem>>,
|
||||||
|
total: i32,
|
||||||
|
emptiness: Emptiness,
|
||||||
|
/// The person whose card is open.
|
||||||
|
open: Option<i32>,
|
||||||
|
list: ListState,
|
||||||
|
search: Entity<InputState>,
|
||||||
|
searching: bool,
|
||||||
|
/// The text size factor the list measured its rows at.
|
||||||
|
measured_at: f32,
|
||||||
|
counters: Counters,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MembersPane {
|
||||||
|
/// A panel that follows `model`.
|
||||||
|
pub fn new(
|
||||||
|
model: &Entity<TreeModel>,
|
||||||
|
counters: Counters,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> Self {
|
||||||
|
let (rows, total, emptiness, open) = {
|
||||||
|
let model = model.read(cx);
|
||||||
|
(
|
||||||
|
model.people().clone(),
|
||||||
|
model.total(),
|
||||||
|
model.people_emptiness(),
|
||||||
|
model.card().map(|c| c.id),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
let search = cx.new(|cx| {
|
||||||
|
InputState::new(window, cx).placeholder(SharedString::from("Search members…"))
|
||||||
|
});
|
||||||
|
let subscriptions = vec![
|
||||||
|
cx.subscribe(model, |this: &mut Self, model, event: &TreeEvent, cx| {
|
||||||
|
match event {
|
||||||
|
TreeEvent::People(changes, rows) => this.apply(changes, rows.clone()),
|
||||||
|
TreeEvent::Lists => {
|
||||||
|
let model = model.read(cx);
|
||||||
|
let now = (model.total(), model.people_emptiness());
|
||||||
|
if now == (this.total, this.emptiness) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
(this.total, this.emptiness) = now;
|
||||||
|
}
|
||||||
|
TreeEvent::Card => this.open = model.read(cx).card().map(|card| card.id),
|
||||||
|
TreeEvent::Rows(..) | TreeEvent::Voice(_) | TreeEvent::Selection => return,
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
}),
|
||||||
|
cx.subscribe_in(&search, window, |_, input, event: &InputEvent, window, cx| {
|
||||||
|
if matches!(event, InputEvent::Change) {
|
||||||
|
let text = input.read(cx).value().to_string();
|
||||||
|
window.dispatch_action(Box::new(SearchMembers { text }), cx);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
Self {
|
||||||
|
list: ListState::new(rows.len(), ListAlignment::Top, px(240.0)),
|
||||||
|
rows,
|
||||||
|
total,
|
||||||
|
emptiness,
|
||||||
|
open,
|
||||||
|
search,
|
||||||
|
searching: false,
|
||||||
|
measured_at: 0.0,
|
||||||
|
counters,
|
||||||
|
_subscriptions: subscriptions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rows it shows.
|
||||||
|
pub fn rows(&self) -> &[MemberItem] {
|
||||||
|
&self.rows
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The person whose card is open, as the panel marks them.
|
||||||
|
pub fn open(&self) -> Option<i32> {
|
||||||
|
self.open
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Why it shows no one, were it empty.
|
||||||
|
pub fn emptiness(&self) -> Emptiness {
|
||||||
|
self.emptiness
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the search box is shown.
|
||||||
|
pub fn searching(&self) -> bool {
|
||||||
|
self.searching
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Take the new rows in (the rows `changes` lead to, carried by the event),
|
||||||
|
/// telling the list which rows came, went or changed their height (the
|
||||||
|
/// first row of a section has the heading above it).
|
||||||
|
fn apply(&mut self, changes: &Changes, new: Arc<Vec<MemberItem>>) {
|
||||||
|
use voelin_ui_vm::list::Change;
|
||||||
|
|
||||||
|
debug_check(self.rows.len(), changes, new.len());
|
||||||
|
let mut headed: Vec<bool> = self.rows.iter().map(|row| row.first_in_group).collect();
|
||||||
|
for change in &changes.0 {
|
||||||
|
match *change {
|
||||||
|
Change::Update(i) => {
|
||||||
|
if headed[i] != new[i].first_in_group {
|
||||||
|
self.list.splice(i..i + 1, 1);
|
||||||
|
}
|
||||||
|
headed[i] = new[i].first_in_group;
|
||||||
|
}
|
||||||
|
Change::Remove(i) => {
|
||||||
|
headed.remove(i);
|
||||||
|
self.list.splice(i..i + 1, 0);
|
||||||
|
}
|
||||||
|
Change::Insert(i) => {
|
||||||
|
headed.insert(i, new[i].first_in_group);
|
||||||
|
self.list.splice(i..i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.rows = new;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The search box was opened or closed: closing it shows everyone again.
|
||||||
|
fn toggle_search(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
|
self.searching = !self.searching;
|
||||||
|
if self.searching {
|
||||||
|
self.search.update(cx, |input, cx| input.focus(window, cx));
|
||||||
|
} else {
|
||||||
|
self.search.update(cx, |input, cx| input.set_value("", window, cx));
|
||||||
|
window.dispatch_action(Box::new(SearchMembers { text: String::new() }), cx);
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The entry at `ix` for the list: the heading of its section if it opens
|
||||||
|
/// one, then the person.
|
||||||
|
fn entry(&mut self, ix: usize, cx: &mut Context<Self>) -> AnyElement {
|
||||||
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
|
let Some(item) = self.rows.get(ix) else { return div().into_any_element() };
|
||||||
|
let m = &theme.metrics;
|
||||||
|
div()
|
||||||
|
.w_full()
|
||||||
|
.px(px(m.space_3))
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.when(item.first_in_group, |entry| entry.child(group_header(&theme, item)))
|
||||||
|
.child(member_row(&theme, item, self.open == Some(item.id)))
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The words of a panel with nobody in it.
|
||||||
|
fn empty_words(emptiness: Emptiness) -> &'static str {
|
||||||
|
match emptiness {
|
||||||
|
Emptiness::Loading => "Loading who is here…",
|
||||||
|
Emptiness::NoMatch => "Nobody matches.",
|
||||||
|
Emptiness::NoServer | Emptiness::Connect => "Connect to see who is here.",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The heading above the first person of a section: "Moderator — 3".
|
||||||
|
fn group_header(theme: &VoelinTheme, item: &MemberItem) -> impl IntoElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let words = if item.group_count > 0 {
|
||||||
|
format!("{} — {}", item.group, item.group_count)
|
||||||
|
} else {
|
||||||
|
item.group.to_string()
|
||||||
|
};
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.pt(px(m.space_5))
|
||||||
|
.pb(px(m.space_2))
|
||||||
|
.pl(px(m.space_2))
|
||||||
|
.children(small_picture(&item.group_icon, 16.0))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.min_w_0()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_md))
|
||||||
|
.font_weight(FontWeight::MEDIUM)
|
||||||
|
.text_color(hsla(c.text_secondary))
|
||||||
|
.child(words),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One person: avatar, name with their badges and role, what they are doing.
|
||||||
|
fn member_row(theme: &VoelinTheme, item: &MemberItem, open: bool) -> AnyElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let id = item.id;
|
||||||
|
let hover = hsla(c.surface_3);
|
||||||
|
let presence = if item.away {
|
||||||
|
Presence::Idle
|
||||||
|
} else if item.sound_off {
|
||||||
|
Presence::Dnd
|
||||||
|
} else {
|
||||||
|
Presence::Online
|
||||||
|
};
|
||||||
|
let name_color = if item.myself {
|
||||||
|
c.accent_text
|
||||||
|
} else if !item.role.is_empty() {
|
||||||
|
c.name_text
|
||||||
|
} else {
|
||||||
|
c.text
|
||||||
|
};
|
||||||
|
let crowns = div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(3.0))
|
||||||
|
.when(item.admin, |row| row.child(icon("crown", 14.0, c.gold)))
|
||||||
|
.when(item.priority, |row| row.child(icon("star", 14.0, c.accent_text)))
|
||||||
|
.when(item.commander, |row| row.child(icon("flag", 14.0, c.info)))
|
||||||
|
.when(item.recording, |row| row.child(icon("circle-dot", 14.0, c.danger)));
|
||||||
|
let badges = div().flex().flex_row().items_center().gap(px(2.0)).children(
|
||||||
|
[&item.badge, &item.badge_2, &item.badge_3]
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|b| small_picture(b, 14.0)),
|
||||||
|
);
|
||||||
|
div()
|
||||||
|
.id(("member", id as u64))
|
||||||
|
.debug_selector(move || format!("member-{id}"))
|
||||||
|
.w_full()
|
||||||
|
.h(px(52.0 * m.font_scale))
|
||||||
|
.flex_none()
|
||||||
|
.rounded(px(m.radius_md))
|
||||||
|
.cursor_pointer()
|
||||||
|
.when(open, |row| row.bg(hsla(c.accent_soft)))
|
||||||
|
.when(!open, |row| row.hover(move |style| style.bg(hover)))
|
||||||
|
.when(item.away, |row| row.opacity(0.6))
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.px(px(m.space_2))
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.child(
|
||||||
|
Avatar::new(("member-avatar", id as u64), 40.0, &item.initials, item.tint)
|
||||||
|
.image(item.avatar.clone())
|
||||||
|
.presence(presence)
|
||||||
|
.speaking(item.talking),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.min_w_0()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(1.0))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.min_w_0()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_md))
|
||||||
|
.font_weight(FontWeight::MEDIUM)
|
||||||
|
.text_color(hsla(name_color))
|
||||||
|
.child(item.name.to_string()),
|
||||||
|
)
|
||||||
|
.child(crowns)
|
||||||
|
.child(badges),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.min_w_0()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(if item.talking {
|
||||||
|
c.success
|
||||||
|
} else {
|
||||||
|
c.text_muted
|
||||||
|
}))
|
||||||
|
.child(item.status.to_string()),
|
||||||
|
)
|
||||||
|
.when(item.talking, |row| row.child(speaking_bars(theme, 12.0)))
|
||||||
|
.when(item.streaming, |row| {
|
||||||
|
row.child(icon("monitor", 14.0, c.text_secondary))
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.when(!item.role.is_empty(), |row| {
|
||||||
|
row.child(icon("shield-check", 18.0, ROLE)).child(chip(
|
||||||
|
theme,
|
||||||
|
item.role.to_string(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.when(item.streaming, |row| row.child(live_badge(theme)))
|
||||||
|
.when(item.muted, |row| row.child(icon("mic-off", 16.0, c.danger)))
|
||||||
|
.when(item.sound_off, |row| row.child(icon("headphone-off", 16.0, c.danger)))
|
||||||
|
// A hand, as TeamSpeak asks for talk power; the card has the number.
|
||||||
|
.when(item.cannot_talk, |row| {
|
||||||
|
row.child(
|
||||||
|
div()
|
||||||
|
.id(("member-hand", id as u64))
|
||||||
|
.tooltip(|window, cx| {
|
||||||
|
gpui_kit::component::tooltip::Tooltip::new("Needs talk power to speak")
|
||||||
|
.build(window, cx)
|
||||||
|
})
|
||||||
|
.child(icon("hand", 16.0, c.text_muted)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.on_click(move |_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(OpenMember { client: id }), cx)
|
||||||
|
})
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for MembersPane {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.counters.panes.members.incr();
|
||||||
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
if (self.measured_at - m.font_scale).abs() > f32::EPSILON {
|
||||||
|
if self.measured_at != 0.0 {
|
||||||
|
self.list.remeasure();
|
||||||
|
}
|
||||||
|
self.measured_at = m.font_scale;
|
||||||
|
}
|
||||||
|
let searching = self.searching;
|
||||||
|
let this = cx.entity();
|
||||||
|
let search_button = IconButton::new("members-search", "search", "Search members")
|
||||||
|
.size(32.0)
|
||||||
|
.checked(searching)
|
||||||
|
.on_click(move |_, window, cx| {
|
||||||
|
this.update(cx, |pane, cx| pane.toggle_search(window, cx));
|
||||||
|
});
|
||||||
|
div()
|
||||||
|
.id("members")
|
||||||
|
.debug_selector(|| "members".into())
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.pt(px(m.space_4))
|
||||||
|
.pb(px(m.space_2))
|
||||||
|
.rounded(px(m.radius_xl))
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(c.border))
|
||||||
|
.bg(hsla(c.surface.with_alpha(235)))
|
||||||
|
.overflow_hidden()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.pl(px(m.space_5))
|
||||||
|
.pr(px(m.space_3))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("members-title")
|
||||||
|
.flex_1()
|
||||||
|
.min_w_0()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_lg))
|
||||||
|
.font_weight(FontWeight::MEDIUM)
|
||||||
|
.text_color(hsla(c.text))
|
||||||
|
.child(format!("Members — {}", self.total)),
|
||||||
|
)
|
||||||
|
.child(search_button),
|
||||||
|
)
|
||||||
|
.when(searching, |pane| {
|
||||||
|
pane.child(
|
||||||
|
div()
|
||||||
|
.id("members-search-box")
|
||||||
|
.debug_selector(|| "members-search-box".into())
|
||||||
|
.px(px(m.space_4))
|
||||||
|
.child(Input::new(&self.search)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.map(|pane| {
|
||||||
|
if self.rows.is_empty() {
|
||||||
|
pane.child(
|
||||||
|
div()
|
||||||
|
.id("members-empty")
|
||||||
|
.debug_selector(|| "members-empty".into())
|
||||||
|
.px(px(m.space_5))
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(c.text_muted))
|
||||||
|
.child(empty_words(self.emptiness)),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
pane.child(
|
||||||
|
list(
|
||||||
|
self.list.clone(),
|
||||||
|
cx.processor(|this, ix, _window, cx| this.entry(ix, cx)),
|
||||||
|
)
|
||||||
|
.flex_1()
|
||||||
|
.w_full()
|
||||||
|
.min_h_0(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The card over a member row, over the window: a scrim that a click outside
|
||||||
|
/// the card closes, and the card with what is known of the person, and the
|
||||||
|
/// volume and the mute of their voice for us (the Slint card's Volume rows).
|
||||||
|
pub struct MemberCardView {
|
||||||
|
card: Option<MemberCard>,
|
||||||
|
/// How wide the members panel is: the card stands beside it.
|
||||||
|
panel_width: f32,
|
||||||
|
/// The volume slider, in percent (0 to 200, as the Slint card's).
|
||||||
|
slider: Entity<SliderState>,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The loudest the card's slider plays a person, in percent.
|
||||||
|
const LOUDEST: f32 = 200.0;
|
||||||
|
|
||||||
|
impl MemberCardView {
|
||||||
|
/// A card that follows `model`, beside a panel `panel_width` pixels wide.
|
||||||
|
pub fn new(
|
||||||
|
model: &Entity<TreeModel>,
|
||||||
|
panel_width: f32,
|
||||||
|
window: &mut Window,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> Self {
|
||||||
|
let card = model.read(cx).card().cloned();
|
||||||
|
let slider = cx.new(|_| {
|
||||||
|
SliderState::new()
|
||||||
|
.min(0.0)
|
||||||
|
.max(LOUDEST)
|
||||||
|
.step(5.0)
|
||||||
|
.default_value(card.as_ref().map_or(100.0, |card| card.volume))
|
||||||
|
});
|
||||||
|
let subscriptions = vec![
|
||||||
|
cx.subscribe_in(
|
||||||
|
model,
|
||||||
|
window,
|
||||||
|
|this: &mut Self, model, event: &TreeEvent, window, cx| {
|
||||||
|
if matches!(event, TreeEvent::Card) {
|
||||||
|
this.card = model.read(cx).card().cloned();
|
||||||
|
// The slider shows the person's volume as it is now (a change
|
||||||
|
// the slider itself made comes back the same).
|
||||||
|
if let Some(card) = &this.card {
|
||||||
|
let volume = card.volume.clamp(0.0, LOUDEST);
|
||||||
|
this.slider
|
||||||
|
.update(cx, |slider, cx| slider.set_value(volume, window, cx));
|
||||||
|
}
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
cx.subscribe_in(
|
||||||
|
&slider,
|
||||||
|
window,
|
||||||
|
|this: &mut Self, _, event: &SliderEvent, window, cx| {
|
||||||
|
if let (SliderEvent::Change(value), Some(card)) = (event, &this.card) {
|
||||||
|
let client = u16::try_from(card.id).unwrap_or_default();
|
||||||
|
let percent = value.end();
|
||||||
|
window.dispatch_action(Box::new(SetMemberVolume { client, percent }), cx);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
];
|
||||||
|
Self { card, panel_width, slider, _subscriptions: subscriptions }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The card that is open.
|
||||||
|
pub fn card(&self) -> Option<&MemberCard> {
|
||||||
|
self.card.as_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The heading of a part of the card: "Groups", "Badges".
|
||||||
|
fn caption(theme: &VoelinTheme, text: &'static str) -> impl IntoElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
div()
|
||||||
|
.text_size(px(m.font_xs))
|
||||||
|
.font_weight(FontWeight::SEMIBOLD)
|
||||||
|
.text_color(hsla(c.text_muted))
|
||||||
|
.child(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The card's Volume rows: what the person is played at, a mute for us and
|
||||||
|
/// the slider. Both need a person the server gave a unique id (the choice is
|
||||||
|
/// kept by it), as the Slint card's do.
|
||||||
|
fn volume(
|
||||||
|
theme: &VoelinTheme,
|
||||||
|
person: &MemberCard,
|
||||||
|
slider: &Entity<SliderState>,
|
||||||
|
) -> impl IntoElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let client = u16::try_from(person.id).unwrap_or_default();
|
||||||
|
let (muted, known) = (person.muted, person.known);
|
||||||
|
div()
|
||||||
|
.id("member-volume")
|
||||||
|
.debug_selector(|| "member-volume".into())
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.pt(px(m.space_3))
|
||||||
|
.border_t_1()
|
||||||
|
.border_color(hsla(c.border_popup))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(c.text_secondary))
|
||||||
|
.child("Volume"),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("member-volume-percent")
|
||||||
|
.debug_selector(|| "member-volume-percent".into())
|
||||||
|
.text_size(px(m.font_xs))
|
||||||
|
.text_color(hsla(c.text_muted))
|
||||||
|
.child(format!("{}%", person.volume.round() as i32)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.child(
|
||||||
|
IconButton::new(
|
||||||
|
"member-mute",
|
||||||
|
if muted { "volume-x" } else { "volume-2" },
|
||||||
|
if muted { "Unmute for me" } else { "Mute for me" },
|
||||||
|
)
|
||||||
|
.size(30.0)
|
||||||
|
.danger()
|
||||||
|
.checked(muted)
|
||||||
|
.enabled(known)
|
||||||
|
.on_click(move |_, window, cx| {
|
||||||
|
window
|
||||||
|
.dispatch_action(Box::new(SetMemberMuted { client, muted: !muted }), cx)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("member-slider")
|
||||||
|
.debug_selector(|| "member-slider".into())
|
||||||
|
.flex_1()
|
||||||
|
.child(Slider::new(slider).disabled(!known || muted)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for MemberCardView {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let Some(person) = self.card.clone() else { return div().into_any_element() };
|
||||||
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let facts = div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.flex_wrap()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.when(person.talk_power > 0, |row| {
|
||||||
|
row.child(chip(
|
||||||
|
&theme,
|
||||||
|
format!("talk power {}", person.talk_power),
|
||||||
|
Some("mic"),
|
||||||
|
None,
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.when(!person.country.is_empty(), |row| {
|
||||||
|
row.child(chip(&theme, person.country.to_string(), Some("globe"), None))
|
||||||
|
});
|
||||||
|
let body = div()
|
||||||
|
.id("member-card")
|
||||||
|
.debug_selector(|| "member-card".into())
|
||||||
|
.w(px(300.0))
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.p(px(m.space_4))
|
||||||
|
.rounded(px(m.radius_lg))
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(c.border_popup))
|
||||||
|
.bg(hsla(c.surface_3))
|
||||||
|
// Clicks inside stay inside.
|
||||||
|
.on_click(|_, _, cx| cx.stop_propagation())
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.child(
|
||||||
|
Avatar::new("member-card-avatar", 52.0, &person.initials, person.tint)
|
||||||
|
.image(person.avatar.clone()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.min_w_0()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(2.0))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_lg))
|
||||||
|
.font_weight(FontWeight::SEMIBOLD)
|
||||||
|
.text_color(hsla(c.text))
|
||||||
|
.child(person.name.to_string()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(c.text_muted))
|
||||||
|
.child(person.status.to_string()),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(IconButton::new("member-card-close", "x", "Close").size(26.0).on_click(
|
||||||
|
|_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(OpenMember { client: -1 }), cx)
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
.when(!person.description.is_empty(), |card| {
|
||||||
|
card.child(
|
||||||
|
div()
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(c.text_secondary))
|
||||||
|
.child(person.description.to_string()),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when(!person.groups.is_empty(), |card| {
|
||||||
|
card.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.child(caption(&theme, "Groups"))
|
||||||
|
.children(person.groups.iter().map(|group| {
|
||||||
|
div()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(c.text_secondary))
|
||||||
|
.child(group.to_string())
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when(!person.badges.is_empty(), |card| {
|
||||||
|
card.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.child(caption(&theme, "Badges"))
|
||||||
|
.child(div().flex().flex_row().flex_wrap().gap(px(m.space_2)).children(
|
||||||
|
person.badges.iter().enumerate().map(|(i, badge)| {
|
||||||
|
let description = badge.description.clone();
|
||||||
|
div()
|
||||||
|
.id(("member-badge", i as u64))
|
||||||
|
.tooltip(move |window, cx| {
|
||||||
|
gpui_kit::component::tooltip::Tooltip::new(
|
||||||
|
description.to_string(),
|
||||||
|
)
|
||||||
|
.build(window, cx)
|
||||||
|
})
|
||||||
|
.child(chip(
|
||||||
|
&theme,
|
||||||
|
badge.name.to_string(),
|
||||||
|
None,
|
||||||
|
small_picture(&badge.icon, 14.0),
|
||||||
|
))
|
||||||
|
}),
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.child(facts)
|
||||||
|
.child(volume(&theme, &person, &self.slider));
|
||||||
|
// The card stands beside the panel, near the top.
|
||||||
|
div()
|
||||||
|
.id("member-card-scrim")
|
||||||
|
.debug_selector(|| "member-card-scrim".into())
|
||||||
|
.absolute()
|
||||||
|
.top(px(0.0))
|
||||||
|
.left(px(0.0))
|
||||||
|
.size_full()
|
||||||
|
.bg(hsla(c.scrim_light))
|
||||||
|
.on_click(|_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(OpenMember { client: -1 }), cx)
|
||||||
|
})
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.justify_end()
|
||||||
|
.items_start()
|
||||||
|
.pt(px(120.0))
|
||||||
|
.pr(px(self.panel_width + 24.0))
|
||||||
|
.child(body)
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
/// What an empty panel says for each reason it can be empty.
|
||||||
|
#[test]
|
||||||
|
fn an_empty_panel_says_why() {
|
||||||
|
assert_eq!(empty_words(Emptiness::NoServer), "Connect to see who is here.");
|
||||||
|
assert_eq!(empty_words(Emptiness::Connect), "Connect to see who is here.");
|
||||||
|
assert_eq!(empty_words(Emptiness::Loading), "Loading who is here…");
|
||||||
|
assert_eq!(empty_words(Emptiness::NoMatch), "Nobody matches.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,23 +1,42 @@
|
|||||||
//! The desktop shell of the GPUI front end (`ui/shells/desktop.slint` and
|
//! The desktop shell of the GPUI front end (`ui/shells/desktop.slint` and
|
||||||
//! the server callbacks of `bind/servers.rs`): the server rail, the top bar,
|
//! the server callbacks of `bind/servers.rs`): the server rail, the top bar,
|
||||||
//! the sidebar, the main area, the server form and the toast, each an entity
|
//! the sidebar, the main area, the voice channel page that takes its place
|
||||||
//! that observes the root state ([`crate::app::AppState`]) and tells the window
|
//! while voice is on screen, the server form and the toast, each an entity
|
||||||
//! only when what it shows changed (the window then draws every part), and the
|
//! that listens to the per-area signals of the root state
|
||||||
//! actions the user's moves are ([`actions`]). [`crate::view::MainView`] puts
|
//! ([`crate::signals`]) and tells the window only when what it shows changed,
|
||||||
//! them in the window.
|
//! and the actions the user's moves are ([`actions`]). The rail, the top bar,
|
||||||
|
//! the main area and the voice page are embedded cached (they have a size of
|
||||||
|
//! their own), so gpui-pre 0.3.10 renders them again only when they were told
|
||||||
|
//! something changed; [`crate::view::MainView`] puts them in the window.
|
||||||
|
|
||||||
pub mod actions;
|
pub mod actions;
|
||||||
|
mod channels;
|
||||||
mod form;
|
mod form;
|
||||||
mod main_panel;
|
mod main_panel;
|
||||||
|
mod members;
|
||||||
|
mod password;
|
||||||
mod rail;
|
mod rail;
|
||||||
mod sidebar;
|
mod sidebar;
|
||||||
mod toast;
|
mod toast;
|
||||||
mod topbar;
|
mod topbar;
|
||||||
|
mod tree_model;
|
||||||
|
mod voice;
|
||||||
pub mod widgets;
|
pub mod widgets;
|
||||||
|
|
||||||
|
pub use channels::ChannelTree;
|
||||||
pub use form::ServerForm;
|
pub use form::ServerForm;
|
||||||
pub use main_panel::{MainPanel, MainState};
|
pub use main_panel::{MainPanel, MainState};
|
||||||
|
pub use members::{MemberCardView, MembersPane};
|
||||||
|
pub use password::ChannelPassword;
|
||||||
|
|
||||||
|
/// Bind the shell's keys (Escape in the password prompt): once, after the
|
||||||
|
/// widget library's own are (`gpui_kit::init`).
|
||||||
|
pub fn bind_keys(cx: &mut gpui_kit::App) {
|
||||||
|
password::bind_keys(cx);
|
||||||
|
}
|
||||||
pub use rail::{RailView, ServerRail};
|
pub use rail::{RailView, ServerRail};
|
||||||
pub use sidebar::{Sidebar, SidebarView};
|
pub use sidebar::{Sidebar, SidebarView};
|
||||||
pub use toast::{TOAST_TIME, Toast};
|
pub use toast::{TOAST_TIME, Toast};
|
||||||
pub use topbar::TopBar;
|
pub use topbar::TopBar;
|
||||||
|
pub use tree_model::{Emptiness, TreeEvent, TreeModel};
|
||||||
|
pub use voice::{SHORT_WINDOW, VoiceHead, VoicePage};
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
//! The password prompt of a locked channel (`ChannelPasswordDialog` of
|
||||||
|
//! `screens/dialogs.slint`): what the transitions ask for with
|
||||||
|
//! `Update::password` when a channel with a password is joined and the one
|
||||||
|
//! given this connection (if any) is not at hand, or was refused. It is a
|
||||||
|
//! card over the window with a scrim; until the dialogs slice makes every
|
||||||
|
//! dialog one, it is this view's own. As in the Slint dialog, Join (and Enter)
|
||||||
|
//! do nothing while the field is empty, and Escape closes the prompt.
|
||||||
|
//!
|
||||||
|
//! Escape is a key binding of the prompt's key context ([`bind_keys`]) that
|
||||||
|
//! dispatches [`CancelChannelPassword`], and the prompt is a focus target of
|
||||||
|
//! its own (its scrim, which the card is on): a click on the card, off the
|
||||||
|
//! field, takes the focus from the field, and a click outside any focus target
|
||||||
|
//! would hand it to the window's root, which the prompt is not under, so
|
||||||
|
//! without a target the context would not be on the dispatch path and Escape
|
||||||
|
//! would do nothing. With the field focused its own Escape (which has nothing
|
||||||
|
//! to undo in a password) passes the key on, and the binding closes the prompt.
|
||||||
|
|
||||||
|
use gpui_kit::component::Disableable as _;
|
||||||
|
use gpui_kit::component::button::{Button, ButtonVariants as _};
|
||||||
|
use gpui_kit::component::input::{Input, InputEvent, InputState};
|
||||||
|
use gpui_kit::prelude::FluentBuilder as _;
|
||||||
|
use gpui_kit::{
|
||||||
|
App, AppContext as _, Context, Entity, FocusHandle, FontWeight, InteractiveElement as _,
|
||||||
|
IntoElement, KeyBinding, ParentElement as _, Render, SharedString,
|
||||||
|
StatefulInteractiveElement as _, Styled as _, Window, div, px,
|
||||||
|
};
|
||||||
|
use voelin_ui_vm::host::PasswordPrompt;
|
||||||
|
|
||||||
|
use super::actions::{CancelChannelPassword, SubmitChannelPassword};
|
||||||
|
use super::widgets::tagged;
|
||||||
|
use crate::theme::{VoelinTheme, hsla};
|
||||||
|
|
||||||
|
/// The key context of the prompt.
|
||||||
|
const CONTEXT: &str = "ChannelPassword";
|
||||||
|
|
||||||
|
/// The keys of the prompt: Escape closes it. Bound once, at start, with the
|
||||||
|
/// widget library's own.
|
||||||
|
pub fn bind_keys(cx: &mut App) {
|
||||||
|
cx.bind_keys([KeyBinding::new("escape", CancelChannelPassword, Some(CONTEXT))]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The prompt for the password of one channel.
|
||||||
|
pub struct ChannelPassword {
|
||||||
|
channel: String,
|
||||||
|
wrong: bool,
|
||||||
|
input: Entity<InputState>,
|
||||||
|
/// What the prompt's scrim holds the focus with, so that Escape reaches the
|
||||||
|
/// prompt wherever in it the last click was.
|
||||||
|
focus: FocusHandle,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ChannelPassword {
|
||||||
|
/// A prompt for what `ask` names, with the field focused: Enter joins.
|
||||||
|
pub fn new(ask: &PasswordPrompt, window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||||
|
let input = cx.new(|cx| {
|
||||||
|
InputState::new(window, cx).placeholder(SharedString::from("Password")).masked(true)
|
||||||
|
});
|
||||||
|
cx.subscribe_in(&input, window, |_, _, event: &InputEvent, window, cx| match event {
|
||||||
|
InputEvent::PressEnter { .. } => {
|
||||||
|
window.dispatch_action(Box::new(SubmitChannelPassword), cx);
|
||||||
|
}
|
||||||
|
// Join is there while there is something to join with.
|
||||||
|
InputEvent::Change => cx.notify(),
|
||||||
|
_ => {}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
input.update(cx, |input, cx| input.focus(window, cx));
|
||||||
|
Self { channel: ask.name.clone(), wrong: ask.wrong, input, focus: cx.focus_handle() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The channel it asks for.
|
||||||
|
pub fn channel(&self) -> &str {
|
||||||
|
&self.channel
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether it says that the last password was refused.
|
||||||
|
pub fn wrong(&self) -> bool {
|
||||||
|
self.wrong
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What the field holds. The prompt joins only with something in it.
|
||||||
|
pub fn text(&self, cx: &App) -> String {
|
||||||
|
self.input.read(cx).value().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type `text` in the field (the tests type here).
|
||||||
|
pub fn set_text(&self, text: &str, window: &mut Window, cx: &mut App) {
|
||||||
|
self.input.update(cx, |input, cx| input.set_value(text.to_owned(), window, cx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for ChannelPassword {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let empty = self.text(cx).is_empty();
|
||||||
|
div()
|
||||||
|
.id("password-prompt")
|
||||||
|
.debug_selector(|| "password-prompt".into())
|
||||||
|
.key_context(CONTEXT)
|
||||||
|
.track_focus(&self.focus)
|
||||||
|
.absolute()
|
||||||
|
.top(px(0.0))
|
||||||
|
.left(px(0.0))
|
||||||
|
.size_full()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.bg(hsla(c.scrim))
|
||||||
|
// A click outside the card closes the prompt.
|
||||||
|
.on_click(|_, window, cx| window.dispatch_action(Box::new(CancelChannelPassword), cx))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("password-card")
|
||||||
|
.debug_selector(|| "password-card".into())
|
||||||
|
.w(px(380.0))
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(m.space_4))
|
||||||
|
.p(px(m.space_5))
|
||||||
|
.rounded(px(m.radius_lg))
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(c.border_popup))
|
||||||
|
.bg(hsla(c.surface_3))
|
||||||
|
.on_click(|_, _, cx| cx.stop_propagation())
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_size(px(m.font_lg))
|
||||||
|
.font_weight(FontWeight::SEMIBOLD)
|
||||||
|
.text_color(hsla(c.text))
|
||||||
|
.child(format!("{} has a password", self.channel)),
|
||||||
|
)
|
||||||
|
.when(self.wrong, |card| {
|
||||||
|
card.child(
|
||||||
|
div()
|
||||||
|
.id("password-wrong")
|
||||||
|
.debug_selector(|| "password-wrong".into())
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(c.danger))
|
||||||
|
.child("That password was not accepted. Try again."),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.child(Input::new(&self.input))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.justify_end()
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.child(tagged(
|
||||||
|
"password-cancel",
|
||||||
|
Button::new("password-cancel").ghost().label("Cancel").on_click(
|
||||||
|
|_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(CancelChannelPassword), cx)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.child(tagged(
|
||||||
|
"password-join",
|
||||||
|
Button::new("password-join")
|
||||||
|
.primary()
|
||||||
|
.label("Join")
|
||||||
|
.disabled(empty)
|
||||||
|
.on_click(|_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(SubmitChannelPassword), cx)
|
||||||
|
}),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
//! The server rail: the saved servers as avatars with their state, the
|
//! The server rail: the saved servers as avatars with their state, the
|
||||||
//! selection, the add-server button and the settings button (`ServerRail` of
|
//! selection, the add-server button and the settings button (`ServerRail` of
|
||||||
//! `ui/shells/desktop.slint`). An entity of its own: it observes the root
|
//! `ui/shells/desktop.slint`). An entity of its own, drawn as a cached pane:
|
||||||
//! state and tells the window only when the servers it lists changed.
|
//! it listens to the servers' signal ([`crate::signals`]) and tells the window
|
||||||
|
//! only when the servers it lists changed.
|
||||||
|
|
||||||
use gpui_kit::prelude::FluentBuilder as _;
|
use gpui_kit::prelude::FluentBuilder as _;
|
||||||
use gpui_kit::{
|
use gpui_kit::{
|
||||||
@@ -14,6 +15,8 @@ use voelin_ui_vm::servers::logic;
|
|||||||
use super::actions::{AddServer, EditServer, OpenSettings, SelectServer};
|
use super::actions::{AddServer, EditServer, OpenSettings, SelectServer};
|
||||||
use super::widgets::{Avatar, IconButton, Presence};
|
use super::widgets::{Avatar, IconButton, Presence};
|
||||||
use crate::app::AppState;
|
use crate::app::AppState;
|
||||||
|
use crate::meter::Counters;
|
||||||
|
use crate::signals::Area;
|
||||||
use crate::theme::{VoelinTheme, hsla};
|
use crate::theme::{VoelinTheme, hsla};
|
||||||
|
|
||||||
/// What the rail shows: the servers in order, and which is on screen.
|
/// What the rail shows: the servers in order, and which is on screen.
|
||||||
@@ -38,21 +41,25 @@ impl RailView {
|
|||||||
/// The rail.
|
/// The rail.
|
||||||
pub struct ServerRail {
|
pub struct ServerRail {
|
||||||
view: RailView,
|
view: RailView,
|
||||||
_subscription: Subscription,
|
counters: Counters,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerRail {
|
impl ServerRail {
|
||||||
/// A rail that follows `app`.
|
/// A rail that follows the servers of `app`.
|
||||||
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
||||||
let view = RailView::of(app.read(cx));
|
let (view, counters, signals) = {
|
||||||
let subscription = cx.observe(app, |this: &mut Self, app, cx| {
|
let state = app.read(cx);
|
||||||
|
(RailView::of(state), state.counters().clone(), state.signals().clone())
|
||||||
|
};
|
||||||
|
let subscriptions = signals.watch(app, &[Area::Servers], cx, |this: &mut Self, app, cx| {
|
||||||
let view = RailView::of(app.read(cx));
|
let view = RailView::of(app.read(cx));
|
||||||
if view != this.view {
|
if view != this.view {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Self { view, _subscription: subscription }
|
Self { view, counters, _subscriptions: subscriptions }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What it shows now.
|
/// What it shows now.
|
||||||
@@ -160,6 +167,7 @@ fn server(theme: &VoelinTheme, item: &ServerItem, selected: bool) -> impl IntoEl
|
|||||||
|
|
||||||
impl Render for ServerRail {
|
impl Render for ServerRail {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.counters.panes.rail.incr();
|
||||||
let theme = VoelinTheme::global(cx).clone();
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
let (c, m) = (&theme.colors, &theme.metrics);
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
let current = self.view.current;
|
let current = self.view.current;
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
//! The sidebar (`Sidebar` of `ui/shells/desktop.slint`, with the cards of
|
//! The sidebar (`Sidebar` of `ui/shells/desktop.slint`, with the cards of
|
||||||
//! `shells/common.slint`): the server on screen, the place of its channel tree
|
//! `shells/common.slint`): the server on screen (its card has the server's
|
||||||
//! (the next slice), the voice card while voice is connecting or connected, and
|
//! banner behind it, under the same veil as the tree's rows), its channel tree
|
||||||
//! the user's own card with the voice buttons. An entity of its own: it
|
//! ([`super::ChannelTree`], a cached pane of its own), the voice card while
|
||||||
//! observes the root state and tells the window only when what it shows changed.
|
//! voice is connecting or connected, and the user's own card with the voice
|
||||||
|
//! buttons. An entity of its own: it listens to the servers' and the toolbar's
|
||||||
|
//! signals and tells the window only when what it shows changed.
|
||||||
|
|
||||||
use gpui_kit::prelude::FluentBuilder as _;
|
use gpui_kit::prelude::FluentBuilder as _;
|
||||||
use gpui_kit::{
|
use gpui_kit::{
|
||||||
Context, Entity, FontWeight, InteractiveElement as _, IntoElement, MouseButton, MouseUpEvent,
|
Context, Entity, FontWeight, InteractiveElement as _, IntoElement, MouseButton, MouseUpEvent,
|
||||||
ParentElement as _, Render, StatefulInteractiveElement as _, Styled as _, Subscription, Window,
|
ObjectFit, ParentElement as _, Render, StatefulInteractiveElement as _, StyleRefinement,
|
||||||
div, px,
|
Styled as _, StyledImage as _, Subscription, Window, div, px,
|
||||||
};
|
};
|
||||||
use voelin_core::TransmitMode;
|
use voelin_core::TransmitMode;
|
||||||
use voelin_ui_vm::Rgb;
|
use voelin_ui_vm::Rgb;
|
||||||
@@ -19,8 +21,12 @@ use voelin_ui_vm::servers::logic;
|
|||||||
use super::actions::{
|
use super::actions::{
|
||||||
DisconnectVoice, Invite, OpenSettings, PushToTalk, SetInputMuted, SetOutputMuted,
|
DisconnectVoice, Invite, OpenSettings, PushToTalk, SetInputMuted, SetOutputMuted,
|
||||||
};
|
};
|
||||||
use super::widgets::{Avatar, IconButton, Presence, card, icon, panel};
|
use super::channels::ChannelTree;
|
||||||
|
use super::widgets::{Avatar, IconButton, Presence, banner_scrim, card, icon, panel};
|
||||||
use crate::app::AppState;
|
use crate::app::AppState;
|
||||||
|
use crate::meter::Counters;
|
||||||
|
use crate::pictures::{PictureKey, picture};
|
||||||
|
use crate::signals::Area;
|
||||||
use crate::theme::{VoelinTheme, hsla};
|
use crate::theme::{VoelinTheme, hsla};
|
||||||
|
|
||||||
/// What the sidebar shows.
|
/// What the sidebar shows.
|
||||||
@@ -30,6 +36,8 @@ pub struct SidebarView {
|
|||||||
pub server: Option<ServerItem>,
|
pub server: Option<ServerItem>,
|
||||||
/// "9 online · 7 channels" once its presence is known, else empty.
|
/// "9 online · 7 channels" once its presence is known, else empty.
|
||||||
pub stats: String,
|
pub stats: String,
|
||||||
|
/// The server's banner, behind its card; empty without one.
|
||||||
|
pub server_banner: ImageRef,
|
||||||
/// Our nickname there; empty without a server.
|
/// Our nickname there; empty without a server.
|
||||||
pub nickname: String,
|
pub nickname: String,
|
||||||
/// The channel we are in; empty while connecting.
|
/// The channel we are in; empty while connecting.
|
||||||
@@ -50,6 +58,9 @@ pub struct SidebarView {
|
|||||||
pub transmitting: bool,
|
pub transmitting: bool,
|
||||||
/// The transmit mode is push-to-talk, so the card has a hold-to-talk button.
|
/// The transmit mode is push-to-talk, so the card has a hold-to-talk button.
|
||||||
pub hold_to_talk: bool,
|
pub hold_to_talk: bool,
|
||||||
|
/// How our voice is sent, as the audio settings say: the card has the
|
||||||
|
/// button for push-to-talk and says the mode otherwise.
|
||||||
|
pub transmit: TransmitMode,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SidebarView {
|
impl SidebarView {
|
||||||
@@ -64,6 +75,7 @@ impl SidebarView {
|
|||||||
Self {
|
Self {
|
||||||
server,
|
server,
|
||||||
stats: card.server_stats,
|
stats: card.server_stats,
|
||||||
|
server_banner: card.server_banner,
|
||||||
nickname: card.nickname,
|
nickname: card.nickname,
|
||||||
own_channel: card.own_channel,
|
own_channel: card.own_channel,
|
||||||
own_avatar: card.own_avatar,
|
own_avatar: card.own_avatar,
|
||||||
@@ -74,6 +86,7 @@ impl SidebarView {
|
|||||||
output_muted: card.output_muted,
|
output_muted: card.output_muted,
|
||||||
transmitting: card.transmitting,
|
transmitting: card.transmitting,
|
||||||
hold_to_talk: app.vm.audio.transmit == TransmitMode::PushToTalk,
|
hold_to_talk: app.vm.audio.transmit == TransmitMode::PushToTalk,
|
||||||
|
transmit: app.vm.audio.transmit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,23 +94,48 @@ impl SidebarView {
|
|||||||
/// The sidebar.
|
/// The sidebar.
|
||||||
pub struct Sidebar {
|
pub struct Sidebar {
|
||||||
view: SidebarView,
|
view: SidebarView,
|
||||||
|
/// The channel tree, a pane of its own between the server card and the
|
||||||
|
/// voice card.
|
||||||
|
tree: Entity<ChannelTree>,
|
||||||
/// The hold-to-talk button is held down.
|
/// The hold-to-talk button is held down.
|
||||||
holding: bool,
|
holding: bool,
|
||||||
_subscription: Subscription,
|
counters: Counters,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sidebar {
|
impl Sidebar {
|
||||||
/// A sidebar that follows `app`.
|
/// A sidebar that follows the server on screen and the voice state in
|
||||||
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
/// `app`, with `tree` between its cards.
|
||||||
let view = SidebarView::of(app.read(cx));
|
pub fn new(app: &Entity<AppState>, tree: Entity<ChannelTree>, cx: &mut Context<Self>) -> Self {
|
||||||
let subscription = cx.observe(app, |this: &mut Self, app, cx| {
|
let (view, counters, signals) = {
|
||||||
let view = SidebarView::of(app.read(cx));
|
let state = app.read(cx);
|
||||||
if view != this.view {
|
(SidebarView::of(state), state.counters().clone(), state.signals().clone())
|
||||||
this.view = view;
|
};
|
||||||
cx.notify();
|
let subscriptions =
|
||||||
}
|
signals.watch(app, &[Area::Servers, Area::Toolbar], cx, |this: &mut Self, app, cx| {
|
||||||
});
|
let state = app.read(cx);
|
||||||
Self { view, holding: false, _subscription: subscription }
|
let view = SidebarView::of(state);
|
||||||
|
// The button goes away when voice leaves `Connected`, transmit
|
||||||
|
// leaves push-to-talk, or another server is shown; and a drop
|
||||||
|
// and reconnect inside one batch ends the hold in `AppState`
|
||||||
|
// while `view.voice_connected` stays true. Keep `holding` in
|
||||||
|
// sync with the root state's own button hold (this observer
|
||||||
|
// only sets its own fields).
|
||||||
|
let same_server =
|
||||||
|
view.server.as_ref().map(|s| s.id) == this.view.server.as_ref().map(|s| s.id);
|
||||||
|
let held_here = view
|
||||||
|
.server
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|s| state.button_held() == Some(i64::from(s.id)));
|
||||||
|
if !view.voice_connected || !view.hold_to_talk || !same_server || !held_here {
|
||||||
|
this.holding = false;
|
||||||
|
}
|
||||||
|
if view != this.view {
|
||||||
|
this.view = view;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Self { view, tree, holding: false, counters, _subscriptions: subscriptions }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What it shows now.
|
/// What it shows now.
|
||||||
@@ -105,6 +143,19 @@ impl Sidebar {
|
|||||||
&self.view
|
&self.view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the hold-to-talk button is currently held down.
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn is_holding(&self) -> bool {
|
||||||
|
self.holding
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Let go of the hold-to-talk button if it is held (the window lost the
|
||||||
|
/// focus: the release will not come to it): whether it was held. The caller
|
||||||
|
/// tells the session.
|
||||||
|
pub fn release(&mut self) -> bool {
|
||||||
|
std::mem::take(&mut self.holding)
|
||||||
|
}
|
||||||
|
|
||||||
/// The hold-to-talk button was released, if it was held.
|
/// The hold-to-talk button was released, if it was held.
|
||||||
fn let_go(&mut self, _: &MouseUpEvent, window: &mut Window, cx: &mut Context<Self>) {
|
fn let_go(&mut self, _: &MouseUpEvent, window: &mut Window, cx: &mut Context<Self>) {
|
||||||
if std::mem::take(&mut self.holding) {
|
if std::mem::take(&mut self.holding) {
|
||||||
@@ -113,18 +164,41 @@ impl Sidebar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The server's name, its icon and how many are there.
|
/// The server's name, its icon and how many are there, over its banner when it
|
||||||
|
/// has one (`ServerHeader` of `channels.slint`: the picture covers the card,
|
||||||
|
/// the surface veil of `banner-picture.slint` lies over it, and the stats read
|
||||||
|
/// in the text colour instead of the secondary one).
|
||||||
fn server_card(theme: &VoelinTheme, view: &SidebarView, item: &ServerItem) -> impl IntoElement {
|
fn server_card(theme: &VoelinTheme, view: &SidebarView, item: &ServerItem) -> impl IntoElement {
|
||||||
let (c, m) = (&theme.colors, &theme.metrics);
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
let stats = if view.stats.is_empty() { item.address.to_string() } else { view.stats.clone() };
|
let stats = if view.stats.is_empty() { item.address.to_string() } else { view.stats.clone() };
|
||||||
|
let banner = PictureKey::of(&view.server_banner);
|
||||||
|
let ink = if banner.is_some() { c.text } else { c.text_muted };
|
||||||
card(theme, 0xff)
|
card(theme, 0xff)
|
||||||
.id("sidebar-server")
|
.id("sidebar-server")
|
||||||
.debug_selector(|| "sidebar-server".into())
|
.debug_selector(|| "sidebar-server".into())
|
||||||
|
.relative()
|
||||||
|
.overflow_hidden()
|
||||||
.p(px(m.space_3))
|
.p(px(m.space_3))
|
||||||
.flex()
|
.flex()
|
||||||
.flex_row()
|
.flex_row()
|
||||||
.items_center()
|
.items_center()
|
||||||
.gap(px(m.space_3))
|
.gap(px(m.space_3))
|
||||||
|
.when_some(banner, |card, key| {
|
||||||
|
card.child(
|
||||||
|
div()
|
||||||
|
.id("sidebar-server-banner")
|
||||||
|
.debug_selector(|| "sidebar-server-banner".into())
|
||||||
|
.absolute()
|
||||||
|
.top(px(0.0))
|
||||||
|
.left(px(0.0))
|
||||||
|
.size_full()
|
||||||
|
// The picture covers the card and is cropped to it, not past
|
||||||
|
// its border.
|
||||||
|
.overflow_hidden()
|
||||||
|
.child(picture(key).size_full().object_fit(ObjectFit::Cover)),
|
||||||
|
)
|
||||||
|
.child(div().absolute().top(px(0.0)).left(px(0.0)).size_full().bg(banner_scrim(theme)))
|
||||||
|
})
|
||||||
.child(
|
.child(
|
||||||
Avatar::new("sidebar-server-avatar", 40.0, &item.initials, item.tint)
|
Avatar::new("sidebar-server-avatar", 40.0, &item.initials, item.tint)
|
||||||
.image(item.icon.clone())
|
.image(item.icon.clone())
|
||||||
@@ -145,46 +219,22 @@ fn server_card(theme: &VoelinTheme, view: &SidebarView, item: &ServerItem) -> im
|
|||||||
.child(item.name.to_string()),
|
.child(item.name.to_string()),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div().truncate().text_size(px(m.font_sm)).text_color(hsla(ink)).child(stats),
|
||||||
.truncate()
|
|
||||||
.text_size(px(m.font_sm))
|
|
||||||
.text_color(hsla(c.text_muted))
|
|
||||||
.child(stats),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Where the channel tree goes: the next slice.
|
/// How our voice is sent, in words, for the modes that have no button.
|
||||||
fn channels(theme: &VoelinTheme, has_server: bool) -> impl IntoElement {
|
fn transmit_words(mode: TransmitMode) -> &'static str {
|
||||||
let (c, m) = (&theme.colors, &theme.metrics);
|
match mode {
|
||||||
div()
|
TransmitMode::PushToTalk => "Push to talk",
|
||||||
.id("sidebar-channels")
|
TransmitMode::VoiceActivation => "Voice activity",
|
||||||
.flex_1()
|
TransmitMode::Continuous => "Open microphone",
|
||||||
.min_h_0()
|
}
|
||||||
.flex()
|
|
||||||
.flex_col()
|
|
||||||
.gap(px(m.space_2))
|
|
||||||
.px(px(m.space_2))
|
|
||||||
.child(
|
|
||||||
div()
|
|
||||||
.flex()
|
|
||||||
.flex_row()
|
|
||||||
.items_center()
|
|
||||||
.gap(px(m.space_2))
|
|
||||||
.text_size(px(m.font_xs))
|
|
||||||
.font_weight(FontWeight::SEMIBOLD)
|
|
||||||
.text_color(hsla(c.text_secondary))
|
|
||||||
.child(icon("volume-2", m.icon_sm, c.text_secondary))
|
|
||||||
.child("Channels"),
|
|
||||||
)
|
|
||||||
.child(div().text_size(px(m.font_sm)).text_color(hsla(c.text_muted)).child(if has_server {
|
|
||||||
"The channel tree comes with the next slice."
|
|
||||||
} else {
|
|
||||||
"Add a server to see its channels."
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// "Voice Connected" and our channel, disconnect and hold to talk.
|
/// "Voice Connected" and our channel, disconnect, and Hold to talk in the
|
||||||
|
/// push-to-talk mode (the other modes say themselves).
|
||||||
fn voice_card(
|
fn voice_card(
|
||||||
theme: &VoelinTheme,
|
theme: &VoelinTheme,
|
||||||
view: &SidebarView,
|
view: &SidebarView,
|
||||||
@@ -252,6 +302,26 @@ fn voice_card(
|
|||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
.when(view.voice_connected && !view.hold_to_talk, |card| {
|
||||||
|
card.child(
|
||||||
|
div()
|
||||||
|
.id("transmit-mode")
|
||||||
|
.debug_selector(|| "transmit-mode".into())
|
||||||
|
.h(px(m.control_height_sm))
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.child(icon("mic", m.icon_sm, c.text_muted))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(c.text_muted))
|
||||||
|
.child(transmit_words(view.transmit)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})
|
||||||
.when(view.voice_connected && view.hold_to_talk, |card| {
|
.when(view.voice_connected && view.hold_to_talk, |card| {
|
||||||
card.child(
|
card.child(
|
||||||
div()
|
div()
|
||||||
@@ -400,6 +470,7 @@ fn name_initials(name: &str) -> String {
|
|||||||
|
|
||||||
impl Render for Sidebar {
|
impl Render for Sidebar {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.counters.panes.sidebar.incr();
|
||||||
let theme = VoelinTheme::global(cx).clone();
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
let m = &theme.metrics;
|
let m = &theme.metrics;
|
||||||
let view = &self.view;
|
let view = &self.view;
|
||||||
@@ -413,7 +484,8 @@ impl Render for Sidebar {
|
|||||||
.when_some(view.server.as_ref(), |sidebar, item| {
|
.when_some(view.server.as_ref(), |sidebar, item| {
|
||||||
sidebar.child(server_card(&theme, view, item))
|
sidebar.child(server_card(&theme, view, item))
|
||||||
})
|
})
|
||||||
.child(channels(&theme, view.server.is_some()))
|
// The tree has the room the cards leave, whatever their height.
|
||||||
|
.child(self.tree.clone().cached(StyleRefinement::default().flex_1().min_h_0().w_full()))
|
||||||
.when(view.voice_connected || view.voice_connecting, |sidebar| {
|
.when(view.voice_connected || view.voice_connecting, |sidebar| {
|
||||||
sidebar.child(voice_card(&theme, view, cx))
|
sidebar.child(voice_card(&theme, view, cx))
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ use gpui_kit::{
|
|||||||
use super::actions::{OpenSearch, OpenSettings};
|
use super::actions::{OpenSearch, OpenSettings};
|
||||||
use super::widgets::{IconButton, icon};
|
use super::widgets::{IconButton, icon};
|
||||||
use crate::app::AppState;
|
use crate::app::AppState;
|
||||||
|
use crate::meter::Counters;
|
||||||
|
use crate::signals::Area;
|
||||||
use crate::theme::{VoelinTheme, hsla};
|
use crate::theme::{VoelinTheme, hsla};
|
||||||
|
|
||||||
/// The page title: the server on screen, else the app's name.
|
/// The page title: the server on screen, else the app's name.
|
||||||
@@ -24,21 +26,25 @@ pub fn title(app: &AppState) -> String {
|
|||||||
/// The top bar.
|
/// The top bar.
|
||||||
pub struct TopBar {
|
pub struct TopBar {
|
||||||
title: String,
|
title: String,
|
||||||
_subscription: Subscription,
|
counters: Counters,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TopBar {
|
impl TopBar {
|
||||||
/// A top bar that follows `app`.
|
/// A top bar that follows the server on screen in `app`.
|
||||||
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
||||||
let shown = title(app.read(cx));
|
let (shown, counters, signals) = {
|
||||||
let subscription = cx.observe(app, |this: &mut Self, app, cx| {
|
let state = app.read(cx);
|
||||||
|
(title(state), state.counters().clone(), state.signals().clone())
|
||||||
|
};
|
||||||
|
let subscriptions = signals.watch(app, &[Area::Servers], cx, |this: &mut Self, app, cx| {
|
||||||
let shown = title(app.read(cx));
|
let shown = title(app.read(cx));
|
||||||
if shown != this.title {
|
if shown != this.title {
|
||||||
this.title = shown;
|
this.title = shown;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Self { title: shown, _subscription: subscription }
|
Self { title: shown, counters, _subscriptions: subscriptions }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The title it shows now.
|
/// The title it shows now.
|
||||||
@@ -49,6 +55,7 @@ impl TopBar {
|
|||||||
|
|
||||||
impl Render for TopBar {
|
impl Render for TopBar {
|
||||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.counters.panes.topbar.incr();
|
||||||
let theme = VoelinTheme::global(cx).clone();
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
let (c, m) = (&theme.colors, &theme.metrics);
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
div()
|
div()
|
||||||
|
|||||||
@@ -0,0 +1,319 @@
|
|||||||
|
//! The narrow entity behind the channel tree and the members panel: what
|
||||||
|
//! `voelin_ui_vm::servers::logic::tree_view` makes of the state, kept between
|
||||||
|
//! one change and the next so that the two panes can be told what changed.
|
||||||
|
//!
|
||||||
|
//! It listens to the tree, toolbar and member-card signals
|
||||||
|
//! ([`crate::signals`]), builds the rows once for both panes, compares them
|
||||||
|
//! with the rows it had ([`voelin_ui_vm::list::diff`], the row operations the
|
||||||
|
//! Slint front end applies to its `VecModel`) and emits what differs
|
||||||
|
//! ([`TreeEvent`], with the rows the operations lead to): a pane applies the
|
||||||
|
//! operations to its list state, so a person who joins is a row that is
|
||||||
|
//! inserted, not a list that starts again at the top. A change that moves none
|
||||||
|
//! of what a pane shows emits nothing.
|
||||||
|
//!
|
||||||
|
//! The people of our voice channel (`TreeView::members`, the voice page's
|
||||||
|
//! rows) come out of the same build as the other two lists: the model keeps
|
||||||
|
//! them and emits them when they differ ([`TreeEvent::Voice`]), so the voice
|
||||||
|
//! page needs no build of its own.
|
||||||
|
//!
|
||||||
|
//! **The tree marks who is talking**, as the Slint tree does (the ring on the
|
||||||
|
//! avatar and the speaking bars on the row): someone who starts or stops
|
||||||
|
//! talking changes one row of the tree and one of the members panel, so each
|
||||||
|
//! of the two panes is drawn again once for it, and no other pane is
|
||||||
|
//! (docs/ui.md, "What a change costs").
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use gpui_kit::{App, Context, Entity, EventEmitter, Subscription};
|
||||||
|
use voelin_core::{ObserveState, VoiceState};
|
||||||
|
use voelin_ui_vm::bridge::{MemberCard, MemberItem, TreeItem};
|
||||||
|
use voelin_ui_vm::list::{Changes, diff};
|
||||||
|
use voelin_ui_vm::servers::logic;
|
||||||
|
use voelin_ui_vm::tree::{ChannelId, member_card};
|
||||||
|
|
||||||
|
use crate::app::{AppState, VmState};
|
||||||
|
use crate::signals::Area;
|
||||||
|
|
||||||
|
/// Why a list has no rows, which the pane says in words.
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum Emptiness {
|
||||||
|
/// No server is on screen.
|
||||||
|
NoServer,
|
||||||
|
/// The server is observed or being connected to, and its presence is on
|
||||||
|
/// the way.
|
||||||
|
Loading,
|
||||||
|
/// Nothing is known of the server until it is connected.
|
||||||
|
Connect,
|
||||||
|
/// The server has people and the members' search matches none of them (the
|
||||||
|
/// members panel's only: the tree is not searched).
|
||||||
|
NoMatch,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Emptiness {
|
||||||
|
/// Why the lists of the server on screen are empty: never
|
||||||
|
/// [`Emptiness::NoMatch`], which is [`Emptiness::of_people`]'s.
|
||||||
|
pub fn of(vm: &VmState) -> Self {
|
||||||
|
match vm.current {
|
||||||
|
None => Self::NoServer,
|
||||||
|
Some(id) => match vm.sessions.get(&id) {
|
||||||
|
Some(view)
|
||||||
|
if view.state.observe != ObserveState::Off
|
||||||
|
|| view.state.voice == VoiceState::Connecting =>
|
||||||
|
{
|
||||||
|
Self::Loading
|
||||||
|
}
|
||||||
|
_ => Self::Connect,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Why the members panel is empty: as [`Emptiness::of`], except that a
|
||||||
|
/// search that leaves nobody of the `total` on the server (`shown` rows
|
||||||
|
/// are left) is [`Emptiness::NoMatch`], where "Connect to see who is here"
|
||||||
|
/// would be false.
|
||||||
|
pub fn of_people(vm: &VmState, shown: usize, total: i32) -> Self {
|
||||||
|
if shown == 0 && total > 0 && !vm.member_filter.trim().is_empty() {
|
||||||
|
Self::NoMatch
|
||||||
|
} else {
|
||||||
|
Self::of(vm)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What changed in the model, as the panes need it.
|
||||||
|
///
|
||||||
|
/// The list events carry the rows their operations lead to. A model that
|
||||||
|
/// refreshed twice before the first event is delivered (an observer that
|
||||||
|
/// changes the state inside a flush makes it) holds the second rows by the
|
||||||
|
/// time a pane hears of the first operations, and operations applied to rows
|
||||||
|
/// they were not made for index past their end. A pane applies them to the
|
||||||
|
/// rows it has and keeps the rows the event carries, so the events, in the
|
||||||
|
/// order they are delivered, lead from the rows the pane started with to the
|
||||||
|
/// model's last.
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub enum TreeEvent {
|
||||||
|
/// The tree's rows: the operations from the rows the pane has to the rows
|
||||||
|
/// carried (the model's [`TreeModel::rows`] when it made them).
|
||||||
|
Rows(Changes, Arc<Vec<TreeItem>>),
|
||||||
|
/// The members panel's rows: the operations from the rows the pane has to
|
||||||
|
/// the rows carried (the model's [`TreeModel::people`] when it made them).
|
||||||
|
People(Changes, Arc<Vec<MemberItem>>),
|
||||||
|
/// The people of our voice channel, the voice page's rows, as they are
|
||||||
|
/// now (the whole list: the page lays its people out in a wrapping row, not
|
||||||
|
/// a virtual list, and takes them as they come).
|
||||||
|
Voice(Arc<Vec<MemberItem>>),
|
||||||
|
/// The card over a member row opened, changed or closed
|
||||||
|
/// ([`TreeModel::card`]).
|
||||||
|
Card,
|
||||||
|
/// The selected channel ([`TreeModel::selected`]).
|
||||||
|
Selection,
|
||||||
|
/// Why the lists are empty, or how many people there are
|
||||||
|
/// ([`TreeModel::emptiness`], [`TreeModel::people_emptiness`],
|
||||||
|
/// [`TreeModel::total`]).
|
||||||
|
Lists,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The areas the model listens to.
|
||||||
|
const AREAS: [Area; 3] = [Area::Tree, Area::Toolbar, Area::MemberCard];
|
||||||
|
|
||||||
|
/// How many times each of [`AREAS`] was raised.
|
||||||
|
fn generations(app: &Entity<AppState>, cx: &App) -> [u64; 3] {
|
||||||
|
let signals = app.read(cx).signals();
|
||||||
|
AREAS.map(|area| signals.of(area).read(cx).generation())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rows of the tree and of the members panel, the member card and the
|
||||||
|
/// selection of the server on screen.
|
||||||
|
pub struct TreeModel {
|
||||||
|
app: Entity<AppState>,
|
||||||
|
/// The generations of its signals it last built the rows at: a batch that
|
||||||
|
/// raises several of them (a picture that arrives raises three) has them
|
||||||
|
/// all raised before the first is heard, so the first refresh builds the
|
||||||
|
/// rows and the others find nothing new.
|
||||||
|
seen: [u64; 3],
|
||||||
|
refreshes: u64,
|
||||||
|
rows: Arc<Vec<TreeItem>>,
|
||||||
|
people: Arc<Vec<MemberItem>>,
|
||||||
|
voice: Arc<Vec<MemberItem>>,
|
||||||
|
total: i32,
|
||||||
|
card: Option<MemberCard>,
|
||||||
|
selected: Option<ChannelId>,
|
||||||
|
emptiness: Emptiness,
|
||||||
|
people_emptiness: Emptiness,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EventEmitter<TreeEvent> for TreeModel {}
|
||||||
|
|
||||||
|
/// Check that `changes` lead from a list of `old` rows to one of `new` rows
|
||||||
|
/// (debug builds): a pane that applies operations to rows they were not made
|
||||||
|
/// for finds the counts out of step, where a release build would index past
|
||||||
|
/// the end or leave its list state out of step with its rows.
|
||||||
|
pub(super) fn debug_check(old: usize, changes: &Changes, new: usize) {
|
||||||
|
debug_assert_eq!(
|
||||||
|
old + changes.inserted(),
|
||||||
|
new + changes.removed(),
|
||||||
|
"{changes:?} do not lead from {old} rows to {new}: applied to rows they were not made \
|
||||||
|
for? (docs/ui.md, \"For the next slices\": no state change from a signal's observer \
|
||||||
|
inside a flush)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Everything the model keeps, as the state gives it now.
|
||||||
|
struct Snapshot {
|
||||||
|
rows: Vec<TreeItem>,
|
||||||
|
people: Vec<MemberItem>,
|
||||||
|
voice: Vec<MemberItem>,
|
||||||
|
total: i32,
|
||||||
|
card: Option<MemberCard>,
|
||||||
|
selected: Option<ChannelId>,
|
||||||
|
emptiness: Emptiness,
|
||||||
|
people_emptiness: Emptiness,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Snapshot {
|
||||||
|
fn of(app: &AppState) -> Self {
|
||||||
|
let vm = &app.vm;
|
||||||
|
let view = vm.current.and_then(|id| vm.sessions.get(&id));
|
||||||
|
let (rows, people, voice, total) = match logic::tree_view(vm, false) {
|
||||||
|
Some(tree) => (tree.rows, tree.server_members, tree.members, tree.member_total),
|
||||||
|
None => (Vec::new(), Vec::new(), Vec::new(), 0),
|
||||||
|
};
|
||||||
|
Self {
|
||||||
|
people_emptiness: Emptiness::of_people(vm, people.len(), total),
|
||||||
|
rows,
|
||||||
|
people,
|
||||||
|
voice,
|
||||||
|
total,
|
||||||
|
card: view
|
||||||
|
.and_then(|view| view.member_card.map(|id| (view, id)))
|
||||||
|
.and_then(|(view, id)| member_card(view, id, &vm.contacts, &vm.playback)),
|
||||||
|
selected: app.selected_channel(),
|
||||||
|
emptiness: Emptiness::of(vm),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TreeModel {
|
||||||
|
/// A model of what `app` shows now, following its tree signals.
|
||||||
|
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
||||||
|
let (snapshot, signals) = {
|
||||||
|
let state = app.read(cx);
|
||||||
|
(Snapshot::of(state), state.signals().clone())
|
||||||
|
};
|
||||||
|
let subscriptions =
|
||||||
|
signals.watch(app, &AREAS, cx, |this: &mut Self, _, cx| this.refresh(cx));
|
||||||
|
Self {
|
||||||
|
app: app.clone(),
|
||||||
|
seen: generations(app, cx),
|
||||||
|
refreshes: 0,
|
||||||
|
rows: Arc::new(snapshot.rows),
|
||||||
|
people: Arc::new(snapshot.people),
|
||||||
|
voice: Arc::new(snapshot.voice),
|
||||||
|
total: snapshot.total,
|
||||||
|
card: snapshot.card,
|
||||||
|
selected: snapshot.selected,
|
||||||
|
emptiness: snapshot.emptiness,
|
||||||
|
people_emptiness: snapshot.people_emptiness,
|
||||||
|
_subscriptions: subscriptions,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rows of the channel tree: channels with the clients in them.
|
||||||
|
pub fn rows(&self) -> &Arc<Vec<TreeItem>> {
|
||||||
|
&self.rows
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rows of the members panel: everyone on the server, in sections.
|
||||||
|
pub fn people(&self) -> &Arc<Vec<MemberItem>> {
|
||||||
|
&self.people
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The people of our voice channel, in the voice page's order (empty while
|
||||||
|
/// voice is not connected).
|
||||||
|
pub fn voice(&self) -> &Arc<Vec<MemberItem>> {
|
||||||
|
&self.voice
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How many are on the server (the query clients not counted).
|
||||||
|
pub fn total(&self) -> i32 {
|
||||||
|
self.total
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The card over a member row, when one is open.
|
||||||
|
pub fn card(&self) -> Option<&MemberCard> {
|
||||||
|
self.card.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The channel selected in the tree.
|
||||||
|
pub fn selected(&self) -> Option<ChannelId> {
|
||||||
|
self.selected
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Why the tree is empty, were it.
|
||||||
|
pub fn emptiness(&self) -> Emptiness {
|
||||||
|
self.emptiness
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Why the members panel is empty, were it: the same as
|
||||||
|
/// [`TreeModel::emptiness`], or that the search matches nobody.
|
||||||
|
pub fn people_emptiness(&self) -> Emptiness {
|
||||||
|
self.people_emptiness
|
||||||
|
}
|
||||||
|
|
||||||
|
/// How many times the rows were built again since the model was made: one
|
||||||
|
/// for each batch of changes, not one for each signal it raised.
|
||||||
|
pub fn refreshes(&self) -> u64 {
|
||||||
|
self.refreshes
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Build the rows again, and tell the panes what differs. Nothing, when
|
||||||
|
/// none of the signals was raised since the last time.
|
||||||
|
fn refresh(&mut self, cx: &mut Context<Self>) {
|
||||||
|
let now = generations(&self.app, cx);
|
||||||
|
if now == self.seen {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.seen = now;
|
||||||
|
self.refreshes += 1;
|
||||||
|
let new = Snapshot::of(self.app.read(cx));
|
||||||
|
let rows = diff(&self.rows, &new.rows);
|
||||||
|
let people = diff(&self.people, &new.people);
|
||||||
|
if !rows.is_empty() {
|
||||||
|
self.rows = Arc::new(new.rows);
|
||||||
|
}
|
||||||
|
if !people.is_empty() {
|
||||||
|
self.people = Arc::new(new.people);
|
||||||
|
}
|
||||||
|
let voice = *self.voice != new.voice;
|
||||||
|
if voice {
|
||||||
|
self.voice = Arc::new(new.voice);
|
||||||
|
}
|
||||||
|
let lists = (self.emptiness, self.people_emptiness, self.total)
|
||||||
|
!= (new.emptiness, new.people_emptiness, new.total);
|
||||||
|
(self.emptiness, self.people_emptiness, self.total) =
|
||||||
|
(new.emptiness, new.people_emptiness, new.total);
|
||||||
|
let card = self.card != new.card;
|
||||||
|
self.card = new.card;
|
||||||
|
let selection = self.selected != new.selected;
|
||||||
|
self.selected = new.selected;
|
||||||
|
if !rows.is_empty() {
|
||||||
|
cx.emit(TreeEvent::Rows(rows, self.rows.clone()));
|
||||||
|
}
|
||||||
|
if !people.is_empty() {
|
||||||
|
cx.emit(TreeEvent::People(people, self.people.clone()));
|
||||||
|
}
|
||||||
|
if voice {
|
||||||
|
cx.emit(TreeEvent::Voice(self.voice.clone()));
|
||||||
|
}
|
||||||
|
if lists {
|
||||||
|
cx.emit(TreeEvent::Lists);
|
||||||
|
}
|
||||||
|
if card {
|
||||||
|
cx.emit(TreeEvent::Card);
|
||||||
|
}
|
||||||
|
if selection {
|
||||||
|
cx.emit(TreeEvent::Selection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,657 @@
|
|||||||
|
//! The voice channel page (`VoiceView` of `screens/voice.slint`, with its
|
||||||
|
//! `Participant` of `voice-parts.slint` and the `CallBar`): the channel we are
|
||||||
|
//! in, who is there and who talks, and the call's controls under them.
|
||||||
|
//!
|
||||||
|
//! [`VoicePage`] is a cached pane of its own, a sibling of the server page
|
||||||
|
//! ([`super::MainPanel`]) that [`crate::view::MainView`] puts in the main
|
||||||
|
//! area in its place while the page is asked for and voice is connected
|
||||||
|
//! ([`crate::app::AppState::voice_page_shown`]). It takes its people from the
|
||||||
|
//! tree model ([`TreeEvent::Voice`]: the rows `TreeView::members` gave the one
|
||||||
|
//! build the tree and the members panel come from, so the page builds nothing
|
||||||
|
//! of its own) and the header and the call bar from the servers' and the
|
||||||
|
//! toolbar's signals, compares what it would show with what it showed, and
|
||||||
|
//! tells the window only when they differ. A person who starts or stops
|
||||||
|
//! talking, or mutes, is one row of the page and one render of this pane.
|
||||||
|
//!
|
||||||
|
//! The larger stage lays the people out as large avatars in a wrapping row;
|
||||||
|
//! the smaller stage (`ui.voice_compact`, and always in a window under 800
|
||||||
|
//! pixels tall) is one row of small avatars that scrolls sideways. The streams
|
||||||
|
//! of the Slint page come with the stream slices and its chat with the chat's.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use gpui_kit::prelude::FluentBuilder as _;
|
||||||
|
use gpui_kit::{
|
||||||
|
AnyElement, Context, Entity, FontWeight, InteractiveElement as _, IntoElement, ObjectFit,
|
||||||
|
ParentElement as _, Render, StatefulInteractiveElement as _, Styled as _, StyledImage as _,
|
||||||
|
Subscription, Window, div, px,
|
||||||
|
};
|
||||||
|
use voelin_ui_vm::bridge::MemberItem;
|
||||||
|
use voelin_ui_vm::image::ImageRef;
|
||||||
|
use voelin_ui_vm::servers::logic;
|
||||||
|
|
||||||
|
use super::actions::{
|
||||||
|
Invite, LeaveVoice, OpenMember, OpenShare, OpenVoiceSettings, SetInputMuted, SetOutputMuted,
|
||||||
|
ShowVoiceView, ToggleVoiceCompact,
|
||||||
|
};
|
||||||
|
use super::tree_model::{TreeEvent, TreeModel};
|
||||||
|
use super::widgets::{Avatar, IconButton, banner_scrim, icon, live_badge, panel, speaking_bars_in};
|
||||||
|
use crate::app::AppState;
|
||||||
|
use crate::meter::Counters;
|
||||||
|
use crate::pictures::{PictureKey, picture};
|
||||||
|
use crate::signals::Area;
|
||||||
|
use crate::theme::tokens::Rgba;
|
||||||
|
use crate::theme::{VoelinTheme, hsla};
|
||||||
|
|
||||||
|
/// A window under this tall (pixels) has the smaller stage whatever the
|
||||||
|
/// setting says (`Nav.short` of the Slint front end).
|
||||||
|
pub const SHORT_WINDOW: f32 = 800.0;
|
||||||
|
|
||||||
|
/// What the page's header and call bar show, from the state.
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct VoiceHead {
|
||||||
|
/// The channel we are in, as the tree shows it.
|
||||||
|
pub channel: String,
|
||||||
|
/// Its topic.
|
||||||
|
pub topic: String,
|
||||||
|
/// Its banner, empty without one.
|
||||||
|
pub banner: ImageRef,
|
||||||
|
/// Its client limit, -1 without one.
|
||||||
|
pub limit: i32,
|
||||||
|
/// Voice is connected.
|
||||||
|
pub connected: bool,
|
||||||
|
/// Our microphone is muted.
|
||||||
|
pub input_muted: bool,
|
||||||
|
/// Our sound is muted.
|
||||||
|
pub output_muted: bool,
|
||||||
|
/// The server can stream (TeamSpeak 6 with voice): the call bar has Share.
|
||||||
|
pub can_share: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VoiceHead {
|
||||||
|
/// The header and the call bar for the state.
|
||||||
|
pub fn of(app: &AppState) -> Self {
|
||||||
|
let card = logic::toolbar(&app.vm, |_| ImageRef::default());
|
||||||
|
let can_share = app
|
||||||
|
.vm
|
||||||
|
.current
|
||||||
|
.and_then(|id| app.vm.sessions.get(&id))
|
||||||
|
.is_some_and(|view| view.streams_available());
|
||||||
|
Self {
|
||||||
|
channel: card.own_channel,
|
||||||
|
topic: card.own_channel_topic,
|
||||||
|
banner: card.own_channel_banner,
|
||||||
|
limit: card.own_channel_limit,
|
||||||
|
connected: card.voice_connected,
|
||||||
|
input_muted: card.input_muted,
|
||||||
|
output_muted: card.output_muted,
|
||||||
|
can_share,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The voice channel page.
|
||||||
|
pub struct VoicePage {
|
||||||
|
head: VoiceHead,
|
||||||
|
people: Arc<Vec<MemberItem>>,
|
||||||
|
/// The smaller stage by choice.
|
||||||
|
compact: bool,
|
||||||
|
/// The window is too short for the larger stage.
|
||||||
|
short: bool,
|
||||||
|
counters: Counters,
|
||||||
|
_subscriptions: Vec<Subscription>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VoicePage {
|
||||||
|
/// A page that follows `app` for the header and the call bar and `model` for
|
||||||
|
/// the people, on the stage the setting says (`compact`) in a window that is
|
||||||
|
/// `short` or not.
|
||||||
|
pub fn new(
|
||||||
|
app: &Entity<AppState>,
|
||||||
|
model: &Entity<TreeModel>,
|
||||||
|
compact: bool,
|
||||||
|
short: bool,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> Self {
|
||||||
|
let (head, counters, signals) = {
|
||||||
|
let state = app.read(cx);
|
||||||
|
(VoiceHead::of(state), state.counters().clone(), state.signals().clone())
|
||||||
|
};
|
||||||
|
let mut subscriptions =
|
||||||
|
signals.watch(app, &[Area::Servers, Area::Toolbar], cx, |this: &mut Self, app, cx| {
|
||||||
|
let head = VoiceHead::of(app.read(cx));
|
||||||
|
if head != this.head {
|
||||||
|
this.head = head;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
subscriptions.push(cx.subscribe(model, |this: &mut Self, _, event: &TreeEvent, cx| {
|
||||||
|
if let TreeEvent::Voice(people) = event {
|
||||||
|
this.people = people.clone();
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
let people = model.read(cx).voice().clone();
|
||||||
|
Self { head, people, compact, short, counters, _subscriptions: subscriptions }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What the header and the call bar show.
|
||||||
|
pub fn head(&self) -> &VoiceHead {
|
||||||
|
&self.head
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The people it shows.
|
||||||
|
pub fn people(&self) -> &[MemberItem] {
|
||||||
|
&self.people
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the page is on the smaller stage now: chosen, or the window is too
|
||||||
|
/// short for the larger.
|
||||||
|
pub fn compact_shown(&self) -> bool {
|
||||||
|
self.compact || self.short
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the window is too short for the larger stage (the stage button is
|
||||||
|
/// off then).
|
||||||
|
pub fn short(&self) -> bool {
|
||||||
|
self.short
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The setting `ui.voice_compact` is `compact`: tells the window if the stage
|
||||||
|
/// changes.
|
||||||
|
pub fn set_compact(&mut self, compact: bool, cx: &mut Context<Self>) {
|
||||||
|
if self.compact != compact {
|
||||||
|
self.compact = compact;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The window is `short` (under [`SHORT_WINDOW`] tall) or not.
|
||||||
|
pub fn set_short(&mut self, short: bool, cx: &mut Context<Self>) {
|
||||||
|
if self.short != short {
|
||||||
|
self.short = short;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The ring around a person's avatar: green while they talk, blue while they
|
||||||
|
/// stream (3 pixels, 2 on the smaller stage), else the quiet border of the
|
||||||
|
/// larger stage (2 pixels; the smaller has none).
|
||||||
|
fn ring(theme: &VoelinTheme, person: &MemberItem, compact: bool) -> (u8, Rgba) {
|
||||||
|
let c = &theme.colors;
|
||||||
|
let loud = if compact { 2 } else { 3 };
|
||||||
|
if person.talking {
|
||||||
|
(loud, c.success)
|
||||||
|
} else if person.streaming {
|
||||||
|
(loud, c.accent)
|
||||||
|
} else {
|
||||||
|
(if compact { 0 } else { 2 }, c.border_strong)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What the corner of a person's avatar says: the bars while they talk, else
|
||||||
|
/// that their sound or their microphone is off.
|
||||||
|
fn corner(theme: &VoelinTheme, person: &MemberItem, compact: bool) -> Option<AnyElement> {
|
||||||
|
let (c, bars) = (&theme.colors, if compact { 12.0 } else { 14.0 });
|
||||||
|
let size = if compact { 22.0 } else { 26.0 };
|
||||||
|
if !(person.talking || person.muted || person.sound_off) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let (face, inside) = if person.talking {
|
||||||
|
if compact {
|
||||||
|
(c.accent, speaking_bars_in(theme, bars, c.on_accent).into_any_element())
|
||||||
|
} else {
|
||||||
|
(c.surface, speaking_bars_in(theme, bars, c.success).into_any_element())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let name = if person.sound_off { "headphone-off" } else { "mic-off" };
|
||||||
|
(c.surface, icon(name, if compact { 12.0 } else { 15.0 }, c.danger).into_any_element())
|
||||||
|
};
|
||||||
|
let (id, talking) = (person.id, person.talking);
|
||||||
|
let inset = if compact { 0.0 } else { 2.0 };
|
||||||
|
Some(
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.right(px(inset))
|
||||||
|
.bottom(px(inset))
|
||||||
|
.debug_selector(move || {
|
||||||
|
format!("voice-{}-{id}", if talking { "speaking" } else { "off" })
|
||||||
|
})
|
||||||
|
.size(px(size))
|
||||||
|
.rounded(px(size / 2.0))
|
||||||
|
.border_2()
|
||||||
|
.border_color(hsla(c.surface))
|
||||||
|
.bg(hsla(face))
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.child(inside)
|
||||||
|
.into_any_element(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One person: an avatar with its ring, the mark in its corner, the name with
|
||||||
|
/// the crown of an admin, and what they do. A click opens their card.
|
||||||
|
fn participant(theme: &VoelinTheme, person: &MemberItem, compact: bool) -> AnyElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let size = if compact { 54.0 } else { 80.0 };
|
||||||
|
let width = if compact { 68.0 } else { 120.0 };
|
||||||
|
let outer = size + 8.0;
|
||||||
|
let id = person.id;
|
||||||
|
let (ring_width, ring_color) = ring(theme, person, compact);
|
||||||
|
let client = u16::try_from(id).unwrap_or_default();
|
||||||
|
let name_width = width - if person.admin { 16.0 } else { 0.0 };
|
||||||
|
let words = if person.talking {
|
||||||
|
"Speaking"
|
||||||
|
} else if person.streaming {
|
||||||
|
"Streaming"
|
||||||
|
} else if person.away {
|
||||||
|
"Away"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
};
|
||||||
|
let mut face = div()
|
||||||
|
.relative()
|
||||||
|
.size(px(outer))
|
||||||
|
.flex_none()
|
||||||
|
.rounded(px(outer / 2.0))
|
||||||
|
.border_color(hsla(ring_color))
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center();
|
||||||
|
face = match ring_width {
|
||||||
|
3 => face.border_3(),
|
||||||
|
2 => face.border_2(),
|
||||||
|
_ => face,
|
||||||
|
};
|
||||||
|
let mut face = face.child(
|
||||||
|
Avatar::new(("voice-avatar", id as u64), size, &person.initials, person.tint)
|
||||||
|
.image(person.avatar.clone()),
|
||||||
|
);
|
||||||
|
if let Some(mark) = corner(theme, person, compact) {
|
||||||
|
face = face.child(mark);
|
||||||
|
}
|
||||||
|
div()
|
||||||
|
.id(("voice-member", id as u64))
|
||||||
|
.debug_selector(move || format!("voice-member-{id}"))
|
||||||
|
.w(px(width))
|
||||||
|
.flex_none()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(if compact { m.space_1 } else { m.space_2 }))
|
||||||
|
.cursor_pointer()
|
||||||
|
.on_click(move |_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(OpenMember { client: i32::from(client) }), cx)
|
||||||
|
})
|
||||||
|
.child(face)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.gap(px(if compact { m.space_1 } else { m.space_2 }))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.max_w(px(name_width))
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(if compact { m.font_sm } else { m.font_md }))
|
||||||
|
.font_weight(if compact { FontWeight::NORMAL } else { FontWeight::MEDIUM })
|
||||||
|
.text_color(hsla(if person.myself { c.accent_text } else { c.text }))
|
||||||
|
.child(person.name.to_string()),
|
||||||
|
)
|
||||||
|
.when(person.admin, |row| {
|
||||||
|
row.child(icon("crown", if compact { 13.0 } else { 15.0 }, c.gold))
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.when(!compact, |column| {
|
||||||
|
column.child(
|
||||||
|
div()
|
||||||
|
.h(px(m.font_sm + 4.0))
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.when(person.talking, |row| row.child(speaking_bars_in(theme, 12.0, c.success)))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_sm))
|
||||||
|
.text_color(hsla(if person.talking {
|
||||||
|
c.success
|
||||||
|
} else {
|
||||||
|
c.text_secondary
|
||||||
|
}))
|
||||||
|
.child(words),
|
||||||
|
)
|
||||||
|
.when(person.streaming && !person.talking, |row| {
|
||||||
|
row.child(icon("monitor", 14.0, c.text_secondary))
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.when(compact && person.streaming, |column| column.child(live_badge(theme)))
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The channel's name, its topic and how many are in voice, over its banner.
|
||||||
|
fn header(
|
||||||
|
theme: &VoelinTheme,
|
||||||
|
head: &VoiceHead,
|
||||||
|
people: usize,
|
||||||
|
page: &VoicePage,
|
||||||
|
) -> impl IntoElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let banner = PictureKey::of(&head.banner);
|
||||||
|
let ink = if banner.is_some() { c.text } else { c.text_secondary };
|
||||||
|
let compact = page.compact_shown();
|
||||||
|
let count = if head.limit >= 0 {
|
||||||
|
format!("{people} in voice / {} total", head.limit)
|
||||||
|
} else {
|
||||||
|
format!("{people} in voice")
|
||||||
|
};
|
||||||
|
let stage = if page.short() {
|
||||||
|
"The window is too short for the larger stage"
|
||||||
|
} else if compact {
|
||||||
|
"Larger stage"
|
||||||
|
} else {
|
||||||
|
"Smaller stage"
|
||||||
|
};
|
||||||
|
div()
|
||||||
|
.id("voice-header")
|
||||||
|
.debug_selector(|| "voice-header".into())
|
||||||
|
.relative()
|
||||||
|
.w_full()
|
||||||
|
.flex_none()
|
||||||
|
.overflow_hidden()
|
||||||
|
.when_some(banner, |header, key| {
|
||||||
|
header
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.absolute()
|
||||||
|
.top(px(0.0))
|
||||||
|
.left(px(0.0))
|
||||||
|
.size_full()
|
||||||
|
.child(picture(key).size_full().object_fit(ObjectFit::Cover)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("voice-banner")
|
||||||
|
.debug_selector(|| "voice-banner".into())
|
||||||
|
.absolute()
|
||||||
|
.top(px(0.0))
|
||||||
|
.left(px(0.0))
|
||||||
|
.size_full()
|
||||||
|
.bg(banner_scrim(theme)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.relative()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.gap(px(m.space_5))
|
||||||
|
.pl(px(m.space_7))
|
||||||
|
.pr(px(m.space_5))
|
||||||
|
.pt(px(m.space_5))
|
||||||
|
.pb(px(m.space_3))
|
||||||
|
.child(div().pt(px(m.space_1)).child(icon("volume-2", 40.0, c.text_secondary)))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.min_w_0()
|
||||||
|
.flex()
|
||||||
|
.flex_col()
|
||||||
|
.gap(px(m.space_1))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("voice-channel")
|
||||||
|
.debug_selector(|| "voice-channel".into())
|
||||||
|
.flex_1()
|
||||||
|
.min_w_0()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_3xl))
|
||||||
|
.font_weight(FontWeight::SEMIBOLD)
|
||||||
|
.text_color(hsla(c.text))
|
||||||
|
.child(head.channel.clone()),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
IconButton::new(
|
||||||
|
"voice-invite",
|
||||||
|
"user-plus",
|
||||||
|
"Copy invite link",
|
||||||
|
)
|
||||||
|
.on_click(|_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(Invite), cx)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
IconButton::new(
|
||||||
|
"voice-stage",
|
||||||
|
if compact { "chevron-down" } else { "chevron-up" },
|
||||||
|
stage,
|
||||||
|
)
|
||||||
|
.enabled(!page.short())
|
||||||
|
.on_click(|_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(ToggleVoiceCompact), cx)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
IconButton::new(
|
||||||
|
"voice-chat-only",
|
||||||
|
"message-square",
|
||||||
|
"Chat only",
|
||||||
|
)
|
||||||
|
.on_click(|_, window, cx| {
|
||||||
|
window.dispatch_action(
|
||||||
|
Box::new(ShowVoiceView { on: false }),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.when(!head.topic.is_empty(), |column| {
|
||||||
|
column.child(
|
||||||
|
div()
|
||||||
|
.truncate()
|
||||||
|
.text_size(px(m.font_md))
|
||||||
|
.text_color(hsla(ink))
|
||||||
|
.child(head.topic.clone()),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.child(icon("users", 16.0, c.text_secondary))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("voice-count")
|
||||||
|
.debug_selector(|| "voice-count".into())
|
||||||
|
.text_size(px(m.font_body))
|
||||||
|
.text_color(hsla(ink))
|
||||||
|
.child(count),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Mute, deafen, share, the voice settings and Leave, under the people.
|
||||||
|
fn call_bar(theme: &VoelinTheme, head: &VoiceHead) -> impl IntoElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let (input_muted, output_muted) = (head.input_muted, head.output_muted);
|
||||||
|
let leave = c.danger;
|
||||||
|
div()
|
||||||
|
.id("voice-callbar")
|
||||||
|
.debug_selector(|| "voice-callbar".into())
|
||||||
|
.w_full()
|
||||||
|
.flex_none()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.justify_center()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.px(px(m.space_6))
|
||||||
|
.pb(px(m.space_3))
|
||||||
|
.child(
|
||||||
|
IconButton::new(
|
||||||
|
"call-mic",
|
||||||
|
if input_muted { "mic-off" } else { "mic" },
|
||||||
|
if input_muted { "Microphone off" } else { "Microphone on" },
|
||||||
|
)
|
||||||
|
.size(44.0)
|
||||||
|
.round()
|
||||||
|
.filled()
|
||||||
|
.danger()
|
||||||
|
.checked(input_muted)
|
||||||
|
.enabled(head.connected)
|
||||||
|
.on_click(move |_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(SetInputMuted { muted: !input_muted }), cx)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
IconButton::new(
|
||||||
|
"call-sound",
|
||||||
|
if output_muted { "headphone-off" } else { "headphones" },
|
||||||
|
if output_muted { "Sound off" } else { "Sound on" },
|
||||||
|
)
|
||||||
|
.size(44.0)
|
||||||
|
.round()
|
||||||
|
.filled()
|
||||||
|
.danger()
|
||||||
|
.checked(output_muted)
|
||||||
|
.enabled(head.connected)
|
||||||
|
.on_click(move |_, window, cx| {
|
||||||
|
window.dispatch_action(Box::new(SetOutputMuted { muted: !output_muted }), cx)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.when(head.can_share, |bar| {
|
||||||
|
bar.child(
|
||||||
|
IconButton::new("call-share", "monitor-up", "Share or go live")
|
||||||
|
.size(44.0)
|
||||||
|
.round()
|
||||||
|
.filled()
|
||||||
|
.on_click(|_, window, cx| window.dispatch_action(Box::new(OpenShare), cx)),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.child(
|
||||||
|
IconButton::new("call-settings", "settings", "Voice Settings")
|
||||||
|
.size(44.0)
|
||||||
|
.round()
|
||||||
|
.filled()
|
||||||
|
.on_click(|_, window, cx| window.dispatch_action(Box::new(OpenVoiceSettings), cx)),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.id("call-leave")
|
||||||
|
.debug_selector(|| "call-leave".into())
|
||||||
|
.h(px(m.control_height))
|
||||||
|
.px(px(m.space_5))
|
||||||
|
.flex_none()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.rounded(px(m.radius_md))
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(leave.with_alpha(0x73)))
|
||||||
|
.bg(hsla(c.danger_soft))
|
||||||
|
.cursor_pointer()
|
||||||
|
.hover(move |style| style.bg(hsla(c.danger_soft.mix(leave, 0.25))))
|
||||||
|
.on_click(|_, window, cx| window.dispatch_action(Box::new(LeaveVoice), cx))
|
||||||
|
.child(icon("phone-off", m.icon_md, leave))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.text_size(px(m.font_body))
|
||||||
|
.font_weight(FontWeight::MEDIUM)
|
||||||
|
.text_color(hsla(leave))
|
||||||
|
.child("Leave"),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for VoicePage {
|
||||||
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
|
self.counters.panes.voice.incr();
|
||||||
|
let theme = VoelinTheme::global(cx).clone();
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
let compact = self.compact_shown();
|
||||||
|
let stage = if compact {
|
||||||
|
// One row, scrolling sideways when there are many; centred while it fits.
|
||||||
|
div()
|
||||||
|
.id("voice-people")
|
||||||
|
.debug_selector(|| "voice-people".into())
|
||||||
|
.w_full()
|
||||||
|
.h(px(112.0))
|
||||||
|
.flex_none()
|
||||||
|
.overflow_x_scroll()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.h_full()
|
||||||
|
.flex_none()
|
||||||
|
.mx_auto()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.gap(px(m.space_3))
|
||||||
|
.px(px(m.space_6))
|
||||||
|
.pt(px(m.space_2))
|
||||||
|
.children(
|
||||||
|
self.people.iter().map(|person| participant(&theme, person, true)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// Centred, wrapping into more rows when there are many.
|
||||||
|
div()
|
||||||
|
.id("voice-people")
|
||||||
|
.debug_selector(|| "voice-people".into())
|
||||||
|
.w_full()
|
||||||
|
// Rows taller than the page scroll; the header and the call bar keep
|
||||||
|
// their places.
|
||||||
|
.flex_shrink(1.0)
|
||||||
|
.min_h_0()
|
||||||
|
.overflow_y_scroll()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.flex_wrap()
|
||||||
|
.justify_center()
|
||||||
|
.gap_x(px(m.space_6))
|
||||||
|
.gap_y(px(m.space_4))
|
||||||
|
.px(px(m.space_6))
|
||||||
|
.pt(px(m.space_3))
|
||||||
|
.pb(px(m.space_4))
|
||||||
|
.children(self.people.iter().map(|person| participant(&theme, person, false)))
|
||||||
|
};
|
||||||
|
// A cached pane's root takes the size its place gives it.
|
||||||
|
panel(&theme)
|
||||||
|
.id("voice-page")
|
||||||
|
.debug_selector(|| "voice-page".into())
|
||||||
|
.size_full()
|
||||||
|
.child(header(&theme, &self.head, self.people.len(), self))
|
||||||
|
.child(stage)
|
||||||
|
.child(call_bar(&theme, &self.head))
|
||||||
|
.child(
|
||||||
|
div()
|
||||||
|
.flex_1()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.justify_center()
|
||||||
|
.text_size(px(m.font_body))
|
||||||
|
.text_color(hsla(c.text_muted))
|
||||||
|
.child("The channel's chat comes with a later slice."),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,14 +4,19 @@
|
|||||||
//! counterparts of `ui/components/avatar.slint`, `button.slint` and
|
//! counterparts of `ui/components/avatar.slint`, `button.slint` and
|
||||||
//! `shells/common.slint`'s `Panel`.
|
//! `shells/common.slint`'s `Panel`.
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui_kit::{
|
use gpui_kit::{
|
||||||
App, ClickEvent, FontWeight, InteractiveElement as _, IntoElement, ParentElement as _,
|
AnyElement, App, Background, ClickEvent, FontWeight, InteractiveElement as _, IntoElement,
|
||||||
RenderOnce, SharedString, StatefulInteractiveElement as _, Styled as _, Window, div, img, px,
|
ParentElement as _, RenderOnce, SharedString, StatefulInteractiveElement as _, Styled as _,
|
||||||
svg,
|
Window, div, linear_color_stop, linear_gradient, px, svg,
|
||||||
};
|
};
|
||||||
use gpui_kit::{ElementId, ObjectFit, StyledImage as _};
|
use gpui_kit::{ElementId, ObjectFit, StyledImage as _};
|
||||||
use voelin_ui_vm::Rgb;
|
use voelin_ui_vm::Rgb;
|
||||||
use voelin_ui_vm::image::{ImageRef, ImageSource};
|
use voelin_ui_vm::avatar::first_letter;
|
||||||
|
use voelin_ui_vm::image::ImageRef;
|
||||||
|
|
||||||
|
use crate::pictures::{PictureKey, picture};
|
||||||
|
|
||||||
use crate::theme::tokens::Rgba;
|
use crate::theme::tokens::Rgba;
|
||||||
use crate::theme::{VoelinTheme, hsla};
|
use crate::theme::{VoelinTheme, hsla};
|
||||||
@@ -34,6 +39,8 @@ pub enum Presence {
|
|||||||
Info,
|
Info,
|
||||||
/// Not connected.
|
/// Not connected.
|
||||||
Offline,
|
Offline,
|
||||||
|
/// Their sound is off (a person who does not hear).
|
||||||
|
Dnd,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Presence {
|
impl Presence {
|
||||||
@@ -58,6 +65,7 @@ impl Presence {
|
|||||||
Self::Idle => Some(c.idle),
|
Self::Idle => Some(c.idle),
|
||||||
Self::Info => Some(c.info),
|
Self::Info => Some(c.info),
|
||||||
Self::Offline => Some(c.offline),
|
Self::Offline => Some(c.offline),
|
||||||
|
Self::Dnd => Some(c.dnd),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,11 +75,46 @@ pub fn tint(color: Rgb) -> Rgba {
|
|||||||
Rgba(color.0 << 8 | 0xff)
|
Rgba(color.0 << 8 | 0xff)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// How opaque the veil over a banner is at its left edge and at its right
|
||||||
|
/// (`components/banner-picture.slint`: `transparentize(0.26)` and `(0.34)`).
|
||||||
|
const BANNER_VEIL: (f32, f32) = (0.74, 0.66);
|
||||||
|
|
||||||
|
/// The veil over a banner picture: the surface colour, left to right from 74 %
|
||||||
|
/// to 66 % opaque. A row's text (`text`) keeps more than 4.5 to 1 against it
|
||||||
|
/// whatever the picture, even white behind the dark theme's light text or
|
||||||
|
/// black behind the light theme's dark text. It lies over the picture and
|
||||||
|
/// under the row's own tint.
|
||||||
|
pub fn banner_scrim(theme: &VoelinTheme) -> Background {
|
||||||
|
let surface = hsla(theme.colors.surface);
|
||||||
|
linear_gradient(
|
||||||
|
90.0,
|
||||||
|
linear_color_stop(surface.opacity(BANNER_VEIL.0), 0.0),
|
||||||
|
linear_color_stop(surface.opacity(BANNER_VEIL.1), 1.0),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Under this size (pixels) an avatar shows one letter, larger (`avatar.slint`).
|
||||||
|
const SMALL_AVATAR: f32 = 28.0;
|
||||||
|
|
||||||
|
/// What an avatar of `size` pixels writes on its colour, and how large:
|
||||||
|
/// the initials at 0.38 of the size, but only the first letter at half of it
|
||||||
|
/// under 28 pixels, where two letters at 0.38 are a few pixels high and cramped
|
||||||
|
/// (`avatar.slint`'s `small`, with `Images.first-letter`).
|
||||||
|
fn initials_for(initials: &str, size: f32) -> (SharedString, f32) {
|
||||||
|
if size < SMALL_AVATAR {
|
||||||
|
(first_letter(initials).into(), size * 0.5)
|
||||||
|
} else {
|
||||||
|
(initials.to_owned().into(), size * 0.38)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An avatar: the picture when there is one (a file of the engine's cache),
|
/// An avatar: the picture when there is one (a file of the engine's cache),
|
||||||
/// else the initials on `tint`, square with rounded corners for a server
|
/// else the initials on `tint` (one letter under 28 pixels), square with
|
||||||
/// and round for a person, with a presence dot and a green ring while the
|
/// rounded corners for a server and round for a person, with a presence dot and
|
||||||
/// person's voice goes out. Pictures other than files of the cache are drawn
|
/// a green ring while the person's voice goes out. The picture is keyed by the
|
||||||
/// as initials until the slices that decode them (the chat's, the members').
|
/// file and its stamp ([`crate::pictures`]), so a picture the engine writes
|
||||||
|
/// again shows. Pictures other than files of the cache are drawn as initials
|
||||||
|
/// until the slices that decode them (the chat's).
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Avatar {
|
pub struct Avatar {
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
@@ -129,10 +172,7 @@ impl RenderOnce for Avatar {
|
|||||||
let theme = VoelinTheme::global(cx);
|
let theme = VoelinTheme::global(cx);
|
||||||
let (c, m) = (&theme.colors, &theme.metrics);
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
let radius = if self.square { m.radius_lg } else { self.size / 2.0 };
|
let radius = if self.square { m.radius_lg } else { self.size / 2.0 };
|
||||||
let picture = match &*self.image {
|
let key = PictureKey::of(&self.image);
|
||||||
ImageSource::File { path, .. } if self.image.size().width > 0 => Some(path.clone()),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
let face = div()
|
let face = div()
|
||||||
.size(px(self.size))
|
.size(px(self.size))
|
||||||
.flex_none()
|
.flex_none()
|
||||||
@@ -141,16 +181,22 @@ impl RenderOnce for Avatar {
|
|||||||
.flex()
|
.flex()
|
||||||
.items_center()
|
.items_center()
|
||||||
.justify_center()
|
.justify_center()
|
||||||
.bg(hsla(if picture.is_some() { c.surface_3 } else { tint(self.tint) }));
|
.bg(hsla(if key.is_some() { c.surface_3 } else { tint(self.tint) }));
|
||||||
let face = match picture {
|
let face = match key {
|
||||||
Some(path) => face.child(img(path).size_full().object_fit(ObjectFit::Cover)),
|
// The picture rounds its own corners: a parent's `overflow_hidden`
|
||||||
None => face.child(
|
// clips to a rectangle.
|
||||||
div()
|
Some(key) => face
|
||||||
.text_size(px(self.size * 0.38))
|
.child(picture(key).size_full().rounded(px(radius)).object_fit(ObjectFit::Cover)),
|
||||||
.font_weight(FontWeight::SEMIBOLD)
|
None => {
|
||||||
.text_color(hsla(Rgba(0xffff_ffff)))
|
let (letters, size) = initials_for(&self.initials, self.size);
|
||||||
.child(self.initials),
|
face.child(
|
||||||
),
|
div()
|
||||||
|
.text_size(px(size))
|
||||||
|
.font_weight(FontWeight::SEMIBOLD)
|
||||||
|
.text_color(hsla(Rgba(0xffff_ffff)))
|
||||||
|
.child(letters),
|
||||||
|
)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let mut avatar = div().id(self.id).relative().size(px(self.size)).flex_none();
|
let mut avatar = div().id(self.id).relative().size(px(self.size)).flex_none();
|
||||||
if self.speaking {
|
if self.speaking {
|
||||||
@@ -188,7 +234,7 @@ type Handler = Box<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>;
|
|||||||
|
|
||||||
/// A button that is an icon: 36 pixels (or `size`) square, round or with
|
/// A button that is an icon: 36 pixels (or `size`) square, round or with
|
||||||
/// rounded corners, with a tooltip. Without a handler or disabled it draws
|
/// rounded corners, with a tooltip. Without a handler or disabled it draws
|
||||||
/// dimmed and does nothing.
|
/// dimmed and does nothing, and keeps its tooltip.
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct IconButton {
|
pub struct IconButton {
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
@@ -296,8 +342,14 @@ impl RenderOnce for IconButton {
|
|||||||
let icon_size = if self.size >= 40.0 { m.icon_md } else { m.icon_sm.max(self.size * 0.5) };
|
let icon_size = if self.size >= 40.0 { m.icon_md } else { m.icon_sm.max(self.size * 0.5) };
|
||||||
let label = self.label.clone();
|
let label = self.label.clone();
|
||||||
let selector = self.id.to_string();
|
let selector = self.id.to_string();
|
||||||
|
#[cfg(test)]
|
||||||
|
let tooltip_selector = selector.clone();
|
||||||
|
// Key the element by both its id and its label so GPUI drops stale
|
||||||
|
// hover/tooltip state when a toggle button's label changes, while
|
||||||
|
// keeping the debug selector stable for tests.
|
||||||
|
let id = ElementId::NamedChild(Arc::new(self.id), self.label);
|
||||||
let mut button = div()
|
let mut button = div()
|
||||||
.id(self.id)
|
.id(id)
|
||||||
.debug_selector(move || selector)
|
.debug_selector(move || selector)
|
||||||
.size(px(self.size))
|
.size(px(self.size))
|
||||||
.flex_none()
|
.flex_none()
|
||||||
@@ -310,14 +362,17 @@ impl RenderOnce for IconButton {
|
|||||||
if self.filled {
|
if self.filled {
|
||||||
button = button.border_1().border_color(hsla(ink));
|
button = button.border_1().border_color(hsla(ink));
|
||||||
}
|
}
|
||||||
|
// The tooltip is there while the button is off too: it says why (the voice
|
||||||
|
// page's stage button in a window too short for the larger stage).
|
||||||
|
button = button.tooltip(move |window, cx| {
|
||||||
|
#[cfg(test)]
|
||||||
|
tests::record_tooltip(&tooltip_selector, &label);
|
||||||
|
gpui_kit::component::tooltip::Tooltip::new(label.clone()).build(window, cx)
|
||||||
|
});
|
||||||
if !self.enabled {
|
if !self.enabled {
|
||||||
return button.opacity(0.4).into_any_element();
|
return button.opacity(0.4).into_any_element();
|
||||||
}
|
}
|
||||||
button = button.cursor_pointer().hover(move |style| style.bg(hsla(hover))).tooltip(
|
button = button.cursor_pointer().hover(move |style| style.bg(hsla(hover)));
|
||||||
move |window, cx| {
|
|
||||||
gpui_kit::component::tooltip::Tooltip::new(label.clone()).build(window, cx)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
match self.on_click {
|
match self.on_click {
|
||||||
Some(handler) => button.on_click(move |event, window, cx| handler(event, window, cx)),
|
Some(handler) => button.on_click(move |event, window, cx| handler(event, window, cx)),
|
||||||
None => button,
|
None => button,
|
||||||
@@ -356,3 +411,153 @@ pub fn card(theme: &VoelinTheme, alpha: u8) -> gpui_kit::Div {
|
|||||||
pub fn tagged(selector: &'static str, element: impl IntoElement) -> impl IntoElement {
|
pub fn tagged(selector: &'static str, element: impl IntoElement) -> impl IntoElement {
|
||||||
div().flex_none().debug_selector(|| selector.into()).child(element)
|
div().flex_none().debug_selector(|| selector.into()).child(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A picture of the cache in its own colours, `size` pixels square (a group's
|
||||||
|
/// or a client's icon, a badge); none when it is no picture that shows.
|
||||||
|
pub fn small_picture(image: &ImageRef, size: f32) -> Option<AnyElement> {
|
||||||
|
let key = PictureKey::of(image)?;
|
||||||
|
Some(
|
||||||
|
picture(key)
|
||||||
|
.w(px(size))
|
||||||
|
.h(px(size))
|
||||||
|
.flex_none()
|
||||||
|
.object_fit(ObjectFit::Contain)
|
||||||
|
.into_any_element(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The red LIVE tag.
|
||||||
|
pub fn live_badge(theme: &VoelinTheme) -> impl IntoElement {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
div()
|
||||||
|
.h(px(18.0))
|
||||||
|
.px(px(5.0))
|
||||||
|
.flex_none()
|
||||||
|
.flex()
|
||||||
|
.items_center()
|
||||||
|
.rounded(px(m.radius_xs))
|
||||||
|
.bg(hsla(c.live))
|
||||||
|
.text_size(px(m.font_xs))
|
||||||
|
.font_weight(FontWeight::BOLD)
|
||||||
|
.text_color(hsla(Rgba(0xffff_ffff)))
|
||||||
|
.child("LIVE")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Three bars: someone speaks. (The Slint bars move; these stand still, as
|
||||||
|
/// nothing here may draw the window anew with the clock.)
|
||||||
|
pub fn speaking_bars(theme: &VoelinTheme, size: f32) -> impl IntoElement {
|
||||||
|
speaking_bars_in(theme, size, theme.colors.success)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The speaking bars in `color`, for a ground the green does not stand out on
|
||||||
|
/// (the accent of the voice page's corner badge).
|
||||||
|
pub fn speaking_bars_in(_theme: &VoelinTheme, size: f32, color: Rgba) -> impl IntoElement {
|
||||||
|
let bar = move |height: f32| {
|
||||||
|
div().w(px(size * 3.0 / 14.0)).h(px(size * height)).rounded(px(size / 9.0)).bg(hsla(color))
|
||||||
|
};
|
||||||
|
div()
|
||||||
|
.w(px(size))
|
||||||
|
.h(px(size))
|
||||||
|
.flex_none()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.justify_between()
|
||||||
|
.child(bar(1.0))
|
||||||
|
.child(bar(0.6))
|
||||||
|
.child(bar(0.8))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A small rounded label: a role, a fact (talk power, a country), a badge.
|
||||||
|
/// `picture` is a badge's own picture, `icon` a Lucide icon in the label's
|
||||||
|
/// colour.
|
||||||
|
pub fn chip(
|
||||||
|
theme: &VoelinTheme,
|
||||||
|
text: impl Into<SharedString>,
|
||||||
|
icon_name: Option<&'static str>,
|
||||||
|
picture: Option<AnyElement>,
|
||||||
|
) -> gpui_kit::Div {
|
||||||
|
let (c, m) = (&theme.colors, &theme.metrics);
|
||||||
|
div()
|
||||||
|
.h(px(22.0))
|
||||||
|
.px(px(m.space_3))
|
||||||
|
.flex_none()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.items_center()
|
||||||
|
.gap(px(m.space_2))
|
||||||
|
.rounded(px(m.radius_pill))
|
||||||
|
.border_1()
|
||||||
|
.border_color(hsla(c.border_strong))
|
||||||
|
.bg(hsla(c.surface_3))
|
||||||
|
.text_size(px(m.font_xs))
|
||||||
|
.font_weight(FontWeight::MEDIUM)
|
||||||
|
.text_color(hsla(c.text_secondary))
|
||||||
|
.children(icon_name.map(|name| icon(name, 12.0, c.text_secondary).into_any_element()))
|
||||||
|
.children(picture)
|
||||||
|
.child(text.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Tooltips built by [`IconButton`] since the last call, as `(selector, label)`.
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn take_tooltips() -> Vec<(String, String)> {
|
||||||
|
tests::TOOLTIPS.with(|log| std::mem::take(&mut *log.borrow_mut()))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
use crate::theme::Choice;
|
||||||
|
|
||||||
|
thread_local! {
|
||||||
|
pub(super) static TOOLTIPS: RefCell<Vec<(String, String)>> = const { RefCell::new(Vec::new()) };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn record_tooltip(selector: &str, label: &str) {
|
||||||
|
TOOLTIPS.with(|log| log.borrow_mut().push((selector.to_owned(), label.to_owned())));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn two_letters_are_written_large_enough_and_one_letter_under_28_pixels() {
|
||||||
|
// The tree's 22 pixel avatars: one letter, half the size.
|
||||||
|
assert_eq!(initials_for("DE", 22.0), (SharedString::from("D"), 11.0));
|
||||||
|
assert_eq!(initials_for("GP", 27.9).0, SharedString::from("G"));
|
||||||
|
// 28 pixels and up: the initials at 0.38 of the size.
|
||||||
|
let (letters, size) = initials_for("NS", 28.0);
|
||||||
|
assert_eq!((letters, size), (SharedString::from("NS"), 28.0 * 0.38));
|
||||||
|
assert_eq!(initials_for("NS", 46.0).0, SharedString::from("NS"));
|
||||||
|
// What the engine gave when there is none, and a letter with a mark.
|
||||||
|
assert_eq!(initials_for("", 22.0).0, SharedString::from(""));
|
||||||
|
assert_eq!(initials_for("A\u{308}B", 22.0).0, SharedString::from("A\u{308}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_banner_veil_keeps_the_text_readable_over_any_picture() {
|
||||||
|
for choice in [Choice::Dark, Choice::Light] {
|
||||||
|
let theme = VoelinTheme::new(choice, choice == Choice::Dark, 1.0);
|
||||||
|
let c = &theme.colors;
|
||||||
|
// The weakest end of the veil, over the two pictures that are the
|
||||||
|
// worst for light and dark text.
|
||||||
|
for picture in [Rgba(0x0000_00ff), Rgba(0xffff_ffff)] {
|
||||||
|
let seen = c.surface.mix(picture, 1.0 - BANNER_VEIL.1);
|
||||||
|
assert!(
|
||||||
|
c.text.contrast(seen) > 4.5,
|
||||||
|
"{choice:?}: text on {picture:?} under the veil is {}",
|
||||||
|
c.text.contrast(seen)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Left to right, from the stronger end to the weaker, in the surface's colour.
|
||||||
|
let surface = hsla(c.surface);
|
||||||
|
assert_eq!(
|
||||||
|
banner_scrim(&theme),
|
||||||
|
linear_gradient(
|
||||||
|
90.0,
|
||||||
|
linear_color_stop(surface.opacity(0.74), 0.0),
|
||||||
|
linear_color_stop(surface.opacity(0.66), 1.0),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
//! Per-area signals: `Update.refresh` of the transitions
|
||||||
|
//! ([`voelin_ui_vm::host::Refresh`]) turned into what the window's parts
|
||||||
|
//! listen to.
|
||||||
|
//!
|
||||||
|
//! The Slint front end draws again what a transition's `refresh` flags name.
|
||||||
|
//! Here a part of the window is an entity, and gpui-pre 0.3.10 draws a part
|
||||||
|
//! again when its entity is notified, so each area has an entity of its own,
|
||||||
|
//! a [`Signal`] with a generation, that the root state raises for the flags
|
||||||
|
//! of an update ([`Signals::raise`]) and that the parts observe
|
||||||
|
//! ([`Signals::watch`]): a change of the channel tree notifies the tree's
|
||||||
|
//! listeners, and the rail, the top bar and the main area are not asked
|
||||||
|
//! whether anything changed for them. A part still compares what it would show
|
||||||
|
//! with what it showed before it tells the window, for the many events that
|
||||||
|
//! set a flag and change nothing it shows.
|
||||||
|
//!
|
||||||
|
//! Only the flags of areas this front end has parts for are signals; the
|
||||||
|
//! others (`chat`, `streams`, ...) are dropped until their slices come, as
|
||||||
|
//! `perform` dropped all of them before.
|
||||||
|
|
||||||
|
use gpui_kit::{App, AppContext as _, Context, Entity, Subscription};
|
||||||
|
use voelin_ui_vm::host::Refresh;
|
||||||
|
|
||||||
|
use crate::app::AppState;
|
||||||
|
|
||||||
|
/// An area of the window that a change of the state can concern.
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum Area {
|
||||||
|
/// The servers: the rail, the top bar's title, the main area, the server
|
||||||
|
/// card (`Refresh::servers`).
|
||||||
|
Servers,
|
||||||
|
/// The voice and user cards of the sidebar (`Refresh::toolbar`).
|
||||||
|
Toolbar,
|
||||||
|
/// The channel tree and the members panel (`Refresh::tree`).
|
||||||
|
Tree,
|
||||||
|
/// The card over a member row (`Refresh::member_card`).
|
||||||
|
MemberCard,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Area {
|
||||||
|
/// Every area.
|
||||||
|
pub const ALL: [Area; 4] = [Area::Servers, Area::Toolbar, Area::Tree, Area::MemberCard];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The entity of an area: it has nothing but a count of how many times it was
|
||||||
|
/// raised, so that what observes it is told.
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Signal {
|
||||||
|
generation: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Signal {
|
||||||
|
/// How many times it was raised.
|
||||||
|
pub fn generation(&self) -> u64 {
|
||||||
|
self.generation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The signals of the areas, owned by the root state.
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Signals {
|
||||||
|
servers: Entity<Signal>,
|
||||||
|
toolbar: Entity<Signal>,
|
||||||
|
tree: Entity<Signal>,
|
||||||
|
member_card: Entity<Signal>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Signals {
|
||||||
|
/// One signal per area, made in the entity `cx` belongs to.
|
||||||
|
pub fn new<T: 'static>(cx: &mut Context<T>) -> Self {
|
||||||
|
Self {
|
||||||
|
servers: cx.new(|_| Signal::default()),
|
||||||
|
toolbar: cx.new(|_| Signal::default()),
|
||||||
|
tree: cx.new(|_| Signal::default()),
|
||||||
|
member_card: cx.new(|_| Signal::default()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The signal of an area.
|
||||||
|
pub fn of(&self, area: Area) -> &Entity<Signal> {
|
||||||
|
match area {
|
||||||
|
Area::Servers => &self.servers,
|
||||||
|
Area::Toolbar => &self.toolbar,
|
||||||
|
Area::Tree => &self.tree,
|
||||||
|
Area::MemberCard => &self.member_card,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The areas an update's flags name.
|
||||||
|
pub fn areas(refresh: &Refresh) -> Vec<Area> {
|
||||||
|
[
|
||||||
|
(refresh.servers, Area::Servers),
|
||||||
|
(refresh.toolbar, Area::Toolbar),
|
||||||
|
(refresh.tree, Area::Tree),
|
||||||
|
(refresh.member_card, Area::MemberCard),
|
||||||
|
]
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|(flagged, area)| flagged.then_some(area))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Raise one area: whatever observes it is told.
|
||||||
|
pub fn raise_area(&self, area: Area, cx: &mut App) {
|
||||||
|
self.of(area).update(cx, |signal, cx| {
|
||||||
|
signal.generation += 1;
|
||||||
|
cx.notify();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Raise the areas `refresh` names, each once however many flags a batch
|
||||||
|
/// of events merged into it.
|
||||||
|
pub fn raise(&self, refresh: &Refresh, cx: &mut App) {
|
||||||
|
for area in Self::areas(refresh) {
|
||||||
|
self.raise_area(area, cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run `on` whenever one of `areas` is raised, with the root state; the
|
||||||
|
/// subscriptions end with the part that holds them. `on` reads the state
|
||||||
|
/// outside of the part's render: a part that read the root entity while it
|
||||||
|
/// renders would be drawn again with every change of the root, which is
|
||||||
|
/// what the signals are for not doing.
|
||||||
|
pub fn watch<T: 'static>(
|
||||||
|
&self,
|
||||||
|
app: &Entity<AppState>,
|
||||||
|
areas: &[Area],
|
||||||
|
cx: &mut Context<T>,
|
||||||
|
on: impl Fn(&mut T, &Entity<AppState>, &mut Context<T>) + Clone + 'static,
|
||||||
|
) -> Vec<Subscription> {
|
||||||
|
areas
|
||||||
|
.iter()
|
||||||
|
.map(|&area| {
|
||||||
|
let (app, on) = (app.clone(), on.clone());
|
||||||
|
cx.observe(self.of(area), move |this, _, cx| on(this, &app, cx))
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_flags_of_an_update_name_the_areas_this_front_end_has() {
|
||||||
|
assert!(Signals::areas(&Refresh::default()).is_empty());
|
||||||
|
let refresh = Refresh { tree: true, servers: true, chat: true, ..Default::default() };
|
||||||
|
assert_eq!(Signals::areas(&refresh), [Area::Servers, Area::Tree], "chat has no part yet");
|
||||||
|
assert_eq!(Signals::areas(&Refresh::ALL), Area::ALL);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -119,6 +119,56 @@ impl Refresh {
|
|||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
*self == Self::default()
|
*self == Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Every part either of the two names: what a front end that handles a
|
||||||
|
/// batch of events draws once, however many events set a part.
|
||||||
|
pub fn merge(&mut self, other: Self) {
|
||||||
|
let Self {
|
||||||
|
servers,
|
||||||
|
toolbar,
|
||||||
|
tree,
|
||||||
|
chat,
|
||||||
|
streams,
|
||||||
|
viewer,
|
||||||
|
member_card,
|
||||||
|
home,
|
||||||
|
events,
|
||||||
|
gateways,
|
||||||
|
people,
|
||||||
|
conversations,
|
||||||
|
dm,
|
||||||
|
} = other;
|
||||||
|
self.servers |= servers;
|
||||||
|
self.toolbar |= toolbar;
|
||||||
|
self.tree |= tree;
|
||||||
|
self.chat |= chat;
|
||||||
|
self.streams |= streams;
|
||||||
|
self.viewer |= viewer;
|
||||||
|
self.member_card |= member_card;
|
||||||
|
self.home |= home;
|
||||||
|
self.events |= events;
|
||||||
|
self.gateways |= gateways;
|
||||||
|
self.people |= people;
|
||||||
|
self.conversations |= conversations;
|
||||||
|
self.dm |= dm;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod refresh_tests {
|
||||||
|
use super::Refresh;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn merging_names_the_parts_of_both() {
|
||||||
|
let mut a = Refresh { tree: true, chat: true, ..Default::default() };
|
||||||
|
a.merge(Refresh { toolbar: true, tree: true, ..Default::default() });
|
||||||
|
assert_eq!(a, Refresh { toolbar: true, tree: true, chat: true, ..Default::default() });
|
||||||
|
let mut none = Refresh::default();
|
||||||
|
none.merge(Refresh::default());
|
||||||
|
assert!(none.is_empty());
|
||||||
|
none.merge(Refresh::ALL);
|
||||||
|
assert_eq!(none, Refresh::ALL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What a transition wants kept.
|
/// What a transition wants kept.
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ impl fmt::Debug for ImageSource {
|
|||||||
|
|
||||||
/// What identifies a file's content without reading it: its length and the
|
/// What identifies a file's content without reading it: its length and the
|
||||||
/// time it was last written. Both zero for a file that is missing.
|
/// time it was last written. Both zero for a file that is missing.
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
pub struct Stamp {
|
pub struct Stamp {
|
||||||
len: u64,
|
len: u64,
|
||||||
modified: Option<SystemTime>,
|
modified: Option<SystemTime>,
|
||||||
|
|||||||
@@ -339,6 +339,16 @@ pub fn search_members<L>(state: &mut AppState<L>, cx: &mut Cx<'_>, text: String)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Open the card of a client of the server shown over the members panel
|
||||||
|
/// (`None` closes it).
|
||||||
|
pub fn open_member<L>(state: &mut AppState<L>, cx: &mut Cx<'_>, client: Option<u16>) {
|
||||||
|
let Some(view) = state.current.and_then(|id| state.sessions.get_mut(&id)) else { return };
|
||||||
|
if view.member_card != client {
|
||||||
|
view.member_card = client;
|
||||||
|
cx.update.refresh.member_card = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The voice channel view was opened or closed: its chat is our channel's,
|
/// The voice channel view was opened or closed: its chat is our channel's,
|
||||||
/// and its people lead the members panel.
|
/// and its people lead the members panel.
|
||||||
pub fn show_voice_view<L: Lines>(state: &mut AppState<L>, cx: &mut Cx<'_>, on: bool) {
|
pub fn show_voice_view<L: Lines>(state: &mut AppState<L>, cx: &mut Cx<'_>, on: bool) {
|
||||||
@@ -863,6 +873,32 @@ mod tests {
|
|||||||
assert!(st.sessions[&1].collapsed.is_empty());
|
assert!(st.sessions[&1].collapsed.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The card of a client opens over the members panel of the server shown
|
||||||
|
/// and closes again; the card is drawn again only when it changed.
|
||||||
|
#[test]
|
||||||
|
fn the_member_card_opens_and_closes() {
|
||||||
|
let (mut st, host) = (state(), Fake::default());
|
||||||
|
st.current = Some(1);
|
||||||
|
st.sessions.insert(1, SessionView::default());
|
||||||
|
let mut cx = Cx::new(&host);
|
||||||
|
open_member(&mut st, &mut cx, Some(11));
|
||||||
|
assert_eq!(st.sessions[&1].member_card, Some(11));
|
||||||
|
assert!(cx.update.refresh.member_card);
|
||||||
|
|
||||||
|
let mut cx = Cx::new(&host);
|
||||||
|
open_member(&mut st, &mut cx, Some(11));
|
||||||
|
assert!(!cx.update.refresh.member_card, "the same card: nothing to draw");
|
||||||
|
open_member(&mut st, &mut cx, None);
|
||||||
|
assert_eq!(st.sessions[&1].member_card, None);
|
||||||
|
assert!(cx.update.refresh.member_card);
|
||||||
|
|
||||||
|
// No server on screen: no card.
|
||||||
|
st.current = None;
|
||||||
|
let mut cx = Cx::new(&host);
|
||||||
|
open_member(&mut st, &mut cx, Some(11));
|
||||||
|
assert!(cx.update.refresh.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
/// A chat takes its server's colour only while it is a server chat of a
|
/// A chat takes its server's colour only while it is a server chat of a
|
||||||
/// server in the list: a chat whose server is gone, and a chat that is a
|
/// server in the list: a chat whose server is gone, and a chat that is a
|
||||||
/// channel's or a person's, take the colour of their own title. Black
|
/// channel's or a person's, take the colour of their own title. Black
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ use std::time::Instant;
|
|||||||
use tracing::{debug, info, warn};
|
use tracing::{debug, info, warn};
|
||||||
use voelin_core::stream::PeerConfig;
|
use voelin_core::stream::PeerConfig;
|
||||||
use voelin_core::{Command, IdentityBlob, ObserveState};
|
use voelin_core::{Command, IdentityBlob, ObserveState};
|
||||||
|
use voelin_model::ChannelId;
|
||||||
use voelin_store::{Bookmark, QueryTransport, Secrets, Store};
|
use voelin_store::{Bookmark, QueryTransport, Secrets, Store};
|
||||||
|
|
||||||
use super::logic::{self, CREATED_IDENTITY, GatewayFound, ObservePlan};
|
use super::logic::{self, CREATED_IDENTITY, GatewayFound, ObservePlan};
|
||||||
@@ -147,6 +148,67 @@ pub fn connect_voice_to<L>(
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Join a channel of a session (a double-click in the tree, joining a friend):
|
||||||
|
/// move there with voice ([`logic::join_channel`]), ask for the password of a
|
||||||
|
/// locked channel first, and without voice on that server connect into it.
|
||||||
|
pub fn join_channel<L: Lines>(
|
||||||
|
state: &mut AppState<L>,
|
||||||
|
cx: &mut Cx<'_>,
|
||||||
|
backing: &Backing<'_>,
|
||||||
|
session: i64,
|
||||||
|
channel: ChannelId,
|
||||||
|
stream_peer: Option<PeerConfig>,
|
||||||
|
) {
|
||||||
|
if let Some(password) = logic::join_channel(state, cx, session, channel) {
|
||||||
|
connect_into(state, cx, backing, session, channel, password, stream_peer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The password dialog's Join ([`logic::join_with_password`]): the same, with
|
||||||
|
/// the password given.
|
||||||
|
pub fn join_with_password<L: Lines>(
|
||||||
|
state: &mut AppState<L>,
|
||||||
|
cx: &mut Cx<'_>,
|
||||||
|
backing: &Backing<'_>,
|
||||||
|
password: String,
|
||||||
|
stream_peer: Option<PeerConfig>,
|
||||||
|
) {
|
||||||
|
if let Some((session, channel, password)) = logic::join_with_password(state, cx, password) {
|
||||||
|
connect_into(state, cx, backing, session, channel, password, stream_peer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Connect voice into a channel of a server that has none: the server is
|
||||||
|
/// shown first, and the channel is named by its id (by its name the server
|
||||||
|
/// finds only a top-level channel, and a subchannel's name connects into the
|
||||||
|
/// default channel). Joined again after the connect if the server puts us
|
||||||
|
/// elsewhere ([`logic::join_after_connect`]).
|
||||||
|
fn connect_into<L: Lines>(
|
||||||
|
state: &mut AppState<L>,
|
||||||
|
cx: &mut Cx<'_>,
|
||||||
|
backing: &Backing<'_>,
|
||||||
|
session: i64,
|
||||||
|
channel: ChannelId,
|
||||||
|
password: Option<String>,
|
||||||
|
stream_peer: Option<PeerConfig>,
|
||||||
|
) {
|
||||||
|
if state.current != Some(session) {
|
||||||
|
select_server(state, cx, backing, session);
|
||||||
|
}
|
||||||
|
let asked = connect_voice_to(
|
||||||
|
state,
|
||||||
|
cx,
|
||||||
|
backing,
|
||||||
|
Some(format!("/{channel}")),
|
||||||
|
password,
|
||||||
|
None,
|
||||||
|
stream_peer,
|
||||||
|
);
|
||||||
|
if asked {
|
||||||
|
logic::join_after_connect(state, session, channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Ask for the gateway of a server to be looked up ([`voelin_core::discover`]),
|
/// Ask for the gateway of a server to be looked up ([`voelin_core::discover`]),
|
||||||
/// once a run ([`logic::discover_wanted`]): every one the server publishes is
|
/// once a run ([`logic::discover_wanted`]): every one the server publishes is
|
||||||
/// kept, best first, and tried in turn; they take the place of a stored one
|
/// kept, best first, and tried in turn; they take the place of a stored one
|
||||||
@@ -356,9 +418,13 @@ pub fn delete_bookmark<L: Lines>(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use voelin_store::{MemorySecrets, QueryConfig};
|
use voelin_store::{MemorySecrets, QueryConfig};
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use voelin_core::VoiceState;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::host::Update;
|
use crate::host::Update;
|
||||||
use crate::host::testing::{Fake, State};
|
use crate::host::testing::{Fake, State, presence, session};
|
||||||
|
|
||||||
/// A store, secrets and a front end of the tests' own.
|
/// A store, secrets and a front end of the tests' own.
|
||||||
struct Rig {
|
struct Rig {
|
||||||
@@ -482,6 +548,115 @@ mod tests {
|
|||||||
assert!(!asked, "no server on screen");
|
assert!(!asked, "no server on screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A state whose first server has a session with `voice` and the channels
|
||||||
|
/// of `host::testing::presence`: Lobby (1), Games (2, where we are).
|
||||||
|
fn joined(rig: &Rig, voice: VoiceState, locked: Option<ChannelId>) -> (State, i64) {
|
||||||
|
let mut state = rig.state(&[("Nightfall", "ts.example")]);
|
||||||
|
let id = state.current.unwrap();
|
||||||
|
let mut presence = (*presence()).clone();
|
||||||
|
if let Some(channel) = locked {
|
||||||
|
presence.channels.get_mut(&channel).unwrap().has_password = true;
|
||||||
|
}
|
||||||
|
let view = state.sessions.entry(id).or_default();
|
||||||
|
view.presence = Arc::new(presence);
|
||||||
|
view.state = session(voice, Some(2));
|
||||||
|
(state, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A double-click in the tree with voice up asks the engine to move there,
|
||||||
|
/// and connects nothing.
|
||||||
|
#[test]
|
||||||
|
fn joining_a_channel_with_voice_moves_there() {
|
||||||
|
let rig = Rig::new();
|
||||||
|
let (mut state, id) = joined(&rig, VoiceState::Connected, None);
|
||||||
|
let (_, update) =
|
||||||
|
rig.run(&mut state, |state, cx, backing| join_channel(state, cx, backing, id, 1, None));
|
||||||
|
let [Command::MoveToChannel { session, channel, password }] = &update.commands[..] else {
|
||||||
|
panic!("{:?}", update.commands)
|
||||||
|
};
|
||||||
|
assert_eq!((*session, *channel, password.as_deref()), (id as u64, 1, None));
|
||||||
|
assert!(update.password.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// With no voice on the server the join connects into the channel, named
|
||||||
|
/// by its id, and remembers to join it again if the server puts us
|
||||||
|
/// elsewhere; a server that is not the one shown is shown first.
|
||||||
|
#[test]
|
||||||
|
fn joining_a_channel_without_voice_connects_into_it() {
|
||||||
|
let rig = Rig::new();
|
||||||
|
let (mut state, id) = joined(&rig, VoiceState::Disconnected, None);
|
||||||
|
let (_, update) =
|
||||||
|
rig.run(&mut state, |state, cx, backing| join_channel(state, cx, backing, id, 1, None));
|
||||||
|
let [Command::ConnectVoice { session, options }] = &update.commands[..] else {
|
||||||
|
panic!("{:?}", update.commands)
|
||||||
|
};
|
||||||
|
assert_eq!((*session, options.channel.as_deref()), (id as u64, Some("/1")));
|
||||||
|
assert_eq!(state.sessions[&id].join_after_connect, Some(1));
|
||||||
|
assert_eq!(update.status.as_deref(), Some("Connecting to ts.example…"));
|
||||||
|
|
||||||
|
// Another server is shown, then connected into the channel.
|
||||||
|
let other = rig.store.add_bookmark(&Bookmark {
|
||||||
|
name: "Lounge".into(),
|
||||||
|
address: "lounge.example".into(),
|
||||||
|
nickname: "Nova".into(),
|
||||||
|
..Default::default()
|
||||||
|
});
|
||||||
|
state.bookmarks = rig.store.bookmarks().unwrap();
|
||||||
|
let other = other.unwrap();
|
||||||
|
let view = state.sessions.entry(other).or_default();
|
||||||
|
view.presence = Arc::new((*presence()).clone());
|
||||||
|
let (_, update) = rig
|
||||||
|
.run(&mut state, |state, cx, backing| join_channel(state, cx, backing, other, 2, None));
|
||||||
|
assert_eq!(state.current, Some(other));
|
||||||
|
assert!(
|
||||||
|
update.commands.iter().any(|c| matches!(c, Command::ConnectVoice { session, options }
|
||||||
|
if *session == other as u64 && options.channel.as_deref() == Some("/2"))),
|
||||||
|
"{:?}",
|
||||||
|
update.commands
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A locked channel asks for its password first (nothing is sent), the
|
||||||
|
/// dialog's Join sends it with the move, and the same channel does not ask
|
||||||
|
/// again this connection.
|
||||||
|
#[test]
|
||||||
|
fn a_locked_channel_asks_for_its_password_and_joins_with_it() {
|
||||||
|
let rig = Rig::new();
|
||||||
|
let (mut state, id) = joined(&rig, VoiceState::Connected, Some(1));
|
||||||
|
let (_, update) =
|
||||||
|
rig.run(&mut state, |state, cx, backing| join_channel(state, cx, backing, id, 1, None));
|
||||||
|
assert!(update.commands.is_empty(), "{:?}", update.commands);
|
||||||
|
let prompt = update.password.expect("the dialog opens");
|
||||||
|
assert_eq!((prompt.name.as_str(), prompt.wrong), ("Lobby", false));
|
||||||
|
assert_eq!(state.join_target, Some((id, 1)));
|
||||||
|
|
||||||
|
let (_, update) = rig.run(&mut state, |state, cx, backing| {
|
||||||
|
join_with_password(state, cx, backing, "secret".into(), None)
|
||||||
|
});
|
||||||
|
let [Command::MoveToChannel { channel, password, .. }] = &update.commands[..] else {
|
||||||
|
panic!("{:?}", update.commands)
|
||||||
|
};
|
||||||
|
assert_eq!((*channel, password.as_deref()), (1, Some("secret")));
|
||||||
|
assert_eq!(state.join_target, None);
|
||||||
|
|
||||||
|
// Remembered for this connection: no dialog the second time.
|
||||||
|
let (_, update) =
|
||||||
|
rig.run(&mut state, |state, cx, backing| join_channel(state, cx, backing, id, 1, None));
|
||||||
|
assert!(update.password.is_none());
|
||||||
|
assert!(
|
||||||
|
matches!(&update.commands[..], [Command::MoveToChannel { password, .. }]
|
||||||
|
if password.as_deref() == Some("secret")),
|
||||||
|
"{:?}",
|
||||||
|
update.commands
|
||||||
|
);
|
||||||
|
// An empty password joins nothing.
|
||||||
|
state.join_target = Some((id, 1));
|
||||||
|
let (_, update) = rig.run(&mut state, |state, cx, backing| {
|
||||||
|
join_with_password(state, cx, backing, String::new(), None)
|
||||||
|
});
|
||||||
|
assert!(update.commands.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
/// A new server is in the store with its password in the secrets, is the
|
/// A new server is in the store with its password in the secrets, is the
|
||||||
/// one on screen, and has its gateway looked up (it has none to observe
|
/// one on screen, and has its gateway looked up (it has none to observe
|
||||||
/// through yet).
|
/// through yet).
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use tracing::warn;
|
|||||||
use voelin_audio::process::NoiseLevel;
|
use voelin_audio::process::NoiseLevel;
|
||||||
use voelin_core::settings::{Key, Kind, Settings};
|
use voelin_core::settings::{Key, Kind, Settings};
|
||||||
use voelin_core::{AudioSettings, TransmitMode};
|
use voelin_core::{AudioSettings, TransmitMode};
|
||||||
|
use voelin_model::ChannelId;
|
||||||
|
|
||||||
use crate::bridge::AudioForm;
|
use crate::bridge::AudioForm;
|
||||||
|
|
||||||
@@ -173,6 +174,55 @@ pub static UI_WINDOW: Key<Option<WindowState>> = Key::new(
|
|||||||
)
|
)
|
||||||
.validated(valid_window);
|
.validated(valid_window);
|
||||||
|
|
||||||
|
/// What the channel tree remembers of one server: the channels folded shut and
|
||||||
|
/// the channel last selected (a click on its row).
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub struct TreeState {
|
||||||
|
/// The channels folded shut, in ascending order.
|
||||||
|
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||||
|
pub collapsed: Vec<ChannelId>,
|
||||||
|
/// The channel last selected, if one was.
|
||||||
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||||
|
pub selected: Option<ChannelId>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TreeState {
|
||||||
|
/// Nothing is remembered.
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.collapsed.is_empty() && self.selected.is_none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What the channel tree remembers, by the id of the server's bookmark
|
||||||
|
/// (as text: a JSON object's keys are).
|
||||||
|
pub type TreeStates = BTreeMap<String, TreeState>;
|
||||||
|
|
||||||
|
/// The most channels one server may have folded in [`UI_TREE`]: a server has
|
||||||
|
/// far fewer channels, so more is a damaged setting.
|
||||||
|
const TREE_STATE_LIMIT: usize = 10_000;
|
||||||
|
|
||||||
|
fn valid_tree(states: &TreeStates) -> Result<(), String> {
|
||||||
|
if states.keys().any(|id| id.parse::<i64>().is_err()) {
|
||||||
|
return Err("keyed by the id of a server".into());
|
||||||
|
}
|
||||||
|
if states.values().any(|state| state.collapsed.len() > TREE_STATE_LIMIT) {
|
||||||
|
return Err(format!("at most {TREE_STATE_LIMIT} folded channels of a server"));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `ui.tree`: which channels each server's tree has folded shut, and which
|
||||||
|
/// channel was selected, by the id of the server's bookmark. The GPUI front
|
||||||
|
/// end writes it; the Slint one does not read it (its tree forgets both
|
||||||
|
/// when the app ends).
|
||||||
|
pub static UI_TREE: Key<TreeStates> = Key::new(
|
||||||
|
"ui.tree",
|
||||||
|
Kind::Json,
|
||||||
|
"The channels each server's tree has folded and the channel selected, by server.",
|
||||||
|
TreeStates::new,
|
||||||
|
)
|
||||||
|
.validated(valid_tree);
|
||||||
|
|
||||||
/// The UI's keys besides [`UI`] and [`CLIENT_PLAYBACK`], for registering.
|
/// The UI's keys besides [`UI`] and [`CLIENT_PLAYBACK`], for registering.
|
||||||
pub fn appearance_keys() -> [&'static dyn voelin_core::settings::Setting; 6] {
|
pub fn appearance_keys() -> [&'static dyn voelin_core::settings::Setting; 6] {
|
||||||
[
|
[
|
||||||
@@ -750,6 +800,35 @@ mod tests {
|
|||||||
std::fs::remove_dir_all(&dir).unwrap();
|
std::fs::remove_dir_all(&dir).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The tree's memory is a JSON object by server, round-trips through the
|
||||||
|
/// service, and a damaged value is refused.
|
||||||
|
#[test]
|
||||||
|
fn tree_key() {
|
||||||
|
let settings = voelin_core::settings::Settings::in_memory();
|
||||||
|
settings.register(&UI_TREE);
|
||||||
|
assert!(settings.get(&UI_TREE).is_empty(), "nothing remembered at first");
|
||||||
|
let states = TreeStates::from([
|
||||||
|
("3".to_owned(), TreeState { collapsed: vec![4, 9], selected: Some(2) }),
|
||||||
|
("5".to_owned(), TreeState { collapsed: Vec::new(), selected: Some(1) }),
|
||||||
|
]);
|
||||||
|
settings.set(&UI_TREE, states.clone()).unwrap();
|
||||||
|
assert_eq!(settings.get(&UI_TREE), states);
|
||||||
|
assert_eq!(
|
||||||
|
settings.get_json("ui.tree"),
|
||||||
|
Some(
|
||||||
|
serde_json::json!({"3": {"collapsed": [4, 9], "selected": 2}, "5": {"selected": 1}})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
// What an older build wrote without a field still loads.
|
||||||
|
settings.set_json("ui.tree", serde_json::json!({"7": {}})).unwrap();
|
||||||
|
assert!(settings.get(&UI_TREE)["7"].is_empty());
|
||||||
|
for damaged in
|
||||||
|
[serde_json::json!({"nope": {}}), serde_json::json!({"1": {"selected": "x"}})]
|
||||||
|
{
|
||||||
|
assert!(settings.set_json("ui.tree", damaged).is_err());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn voice_compact_key() {
|
fn voice_compact_key() {
|
||||||
let settings = voelin_core::settings::Settings::in_memory();
|
let settings = voelin_core::settings::Settings::in_memory();
|
||||||
|
|||||||
@@ -4,16 +4,18 @@
|
|||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub use voelin_model::channel_title;
|
|
||||||
use voelin_model::{
|
use voelin_model::{
|
||||||
BannerMode, ChannelId, ChannelInfo, ClientInfo, GroupInfo, Presence, Spacer, TreeRow, badges,
|
BannerMode, ChannelInfo, ClientInfo, GroupInfo, Presence, Spacer, TreeRow, badges, tree_rows,
|
||||||
tree_rows,
|
|
||||||
};
|
};
|
||||||
|
pub use voelin_model::{ChannelId, channel_title};
|
||||||
|
|
||||||
|
use voelin_core::{Contact, Relation};
|
||||||
|
|
||||||
use crate::avatar;
|
use crate::avatar;
|
||||||
use crate::bridge::{BadgeItem, MemberItem, TreeItem};
|
use crate::bridge::{BadgeItem, MemberCard, MemberItem, TreeItem};
|
||||||
use crate::image::ImageRef;
|
use crate::image::ImageRef;
|
||||||
use crate::settings::ClientPlaybackMap;
|
use crate::settings::ClientPlaybackMap;
|
||||||
|
use crate::state::SessionView;
|
||||||
|
|
||||||
/// A banner mode as the UI takes it (`TreeItem.banner-mode`).
|
/// A banner mode as the UI takes it (`TreeItem.banner-mode`).
|
||||||
pub fn banner_mode(mode: BannerMode) -> i32 {
|
pub fn banner_mode(mode: BannerMode) -> i32 {
|
||||||
@@ -54,6 +56,47 @@ pub fn badge_items(guids: &[String], pictures: &HashMap<String, PathBuf>) -> Vec
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The card over a member row: everything about the client `id` of a session
|
||||||
|
/// and what is known of it locally (the contact, the playback settings).
|
||||||
|
/// None when the presence has no such client (it left).
|
||||||
|
pub fn member_card<L>(
|
||||||
|
view: &SessionView<L>,
|
||||||
|
id: u16,
|
||||||
|
contacts: &HashMap<String, Contact>,
|
||||||
|
playback: &ClientPlaybackMap,
|
||||||
|
) -> Option<MemberCard> {
|
||||||
|
let client = view.presence.clients.get(&id)?;
|
||||||
|
let uid = client.uid.as_ref();
|
||||||
|
let contact = uid.and_then(|u| contacts.get(u));
|
||||||
|
let local = uid.and_then(|u| playback.get(u)).copied().unwrap_or_default();
|
||||||
|
let groups = client
|
||||||
|
.server_groups
|
||||||
|
.iter()
|
||||||
|
.filter_map(|g| view.server_groups.iter().find(|i| i.id == *g))
|
||||||
|
.map(|g| g.name.as_str().into())
|
||||||
|
.collect();
|
||||||
|
Some(MemberCard {
|
||||||
|
open: true,
|
||||||
|
id: i32::from(id),
|
||||||
|
name: client.nickname.as_str().into(),
|
||||||
|
initials: avatar::initials(&client.nickname).into(),
|
||||||
|
tint: avatar::tint(&client.nickname),
|
||||||
|
avatar: avatar::image(view.avatar(id)),
|
||||||
|
status: status_of(client, view.talking.contains(&id)).into(),
|
||||||
|
description: client.description.as_deref().unwrap_or_default().into(),
|
||||||
|
groups,
|
||||||
|
badges: badge_items(&client.badges, &view.pictures),
|
||||||
|
country: client.country.as_deref().unwrap_or_default().into(),
|
||||||
|
talk_power: client.talk_power,
|
||||||
|
friend: contact.is_some_and(|c| c.relation == Relation::Friend),
|
||||||
|
blocked: contact.is_some_and(|c| c.relation == Relation::Blocked),
|
||||||
|
volume: local.volume * 100.0,
|
||||||
|
muted: local.muted,
|
||||||
|
known: uid.is_some(),
|
||||||
|
streaming: client.streaming == Some(true),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// What the tree shows besides the presence.
|
/// What the tree shows besides the presence.
|
||||||
pub struct TreeInput<'a> {
|
pub struct TreeInput<'a> {
|
||||||
/// The channels and clients of the server.
|
/// The channels and clients of the server.
|
||||||
@@ -901,6 +944,61 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The card has what the row has, the groups by name, the badges, the
|
||||||
|
/// contact's relation and the local playback; a client that left has none.
|
||||||
|
#[test]
|
||||||
|
fn the_member_card_is_what_is_known_of_one_client() {
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::settings::ClientPlayback;
|
||||||
|
|
||||||
|
let mut p = presence();
|
||||||
|
let bob = p.clients.get_mut(&11).unwrap();
|
||||||
|
bob.uid = Some("bob=".into());
|
||||||
|
bob.server_groups = vec![6, 99];
|
||||||
|
bob.description = Some("Raid lead".into());
|
||||||
|
bob.country = Some("DE".into());
|
||||||
|
bob.talk_power = 75;
|
||||||
|
bob.badges = vec!["4b27be5a-b92a-4b30-8b2d-14b59653f427".into()];
|
||||||
|
bob.streaming = Some(true);
|
||||||
|
let mut view = SessionView::<()> {
|
||||||
|
presence: Arc::new(p),
|
||||||
|
server_groups: vec![GroupInfo {
|
||||||
|
id: 6,
|
||||||
|
name: "Moderator".into(),
|
||||||
|
..Default::default()
|
||||||
|
}],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
view.talking.insert(11);
|
||||||
|
let mut friend = Contact::new("bob=");
|
||||||
|
friend.relation = Relation::Friend;
|
||||||
|
let contacts = HashMap::from([("bob=".to_owned(), friend)]);
|
||||||
|
let playback = ClientPlaybackMap::from([(
|
||||||
|
"bob=".to_owned(),
|
||||||
|
ClientPlayback { volume: 1.5, muted: true },
|
||||||
|
)]);
|
||||||
|
|
||||||
|
let card = member_card(&view, 11, &contacts, &playback).expect("bob is there");
|
||||||
|
assert!(card.open);
|
||||||
|
assert_eq!((card.id, &*card.name, &*card.initials), (11, "bob", "BO"));
|
||||||
|
assert_eq!(card.tint, avatar::tint("bob"));
|
||||||
|
assert_eq!(&*card.status, "Speaking");
|
||||||
|
assert_eq!((&*card.description, &*card.country, card.talk_power), ("Raid lead", "DE", 75));
|
||||||
|
let groups: Vec<&str> = card.groups.iter().map(|g| &**g).collect();
|
||||||
|
assert_eq!(groups, ["Moderator"], "a group the server did not list is left out");
|
||||||
|
assert_eq!(card.badges.len(), 1);
|
||||||
|
assert_eq!(&*card.badges[0].name, "20th Anniversary");
|
||||||
|
assert!(card.friend && !card.blocked && card.known && card.streaming && card.muted);
|
||||||
|
assert_eq!(card.volume, 150.0);
|
||||||
|
|
||||||
|
// Someone nobody knows: not known, nothing local, listening.
|
||||||
|
let alice = member_card(&view, 10, &contacts, &playback).unwrap();
|
||||||
|
assert!(!alice.known && !alice.friend && !alice.muted && alice.volume == 100.0);
|
||||||
|
assert_eq!(&*alice.status, "Listening");
|
||||||
|
assert!(member_card(&view, 99, &contacts, &playback).is_none(), "a client that left");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn channel_paths() {
|
fn channel_paths() {
|
||||||
let mut p = presence();
|
let mut p = presence();
|
||||||
|
|||||||
@@ -426,23 +426,22 @@ impl App {
|
|||||||
self.state.own_uids = uids;
|
self.state.own_uids = uids;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The identity servers see us as on `bookmark` (the one place that
|
/// The identity a bookmark names, if it names one.
|
||||||
/// picks it): the bookmark's own if it names one that exists, else the
|
fn named_identity(&self, bookmark: Option<i64>) -> Option<i64> {
|
||||||
/// store's default.
|
bookmark.and_then(|b| self.bookmark(b)).and_then(|b| b.identity)
|
||||||
fn identity_id_for(&self, bookmark: Option<i64>) -> Option<i64> {
|
|
||||||
let entries = self.store.identities().unwrap_or_default();
|
|
||||||
bookmark
|
|
||||||
.and_then(|b| self.bookmark(b))
|
|
||||||
.and_then(|b| b.identity)
|
|
||||||
.filter(|id| entries.iter().any(|e| e.id == *id))
|
|
||||||
.or_else(|| self.default_identity_id())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The identity a connection to `bookmark` uses ([`Self::identity_id_for`]).
|
/// The identity servers see us as on `bookmark`: the bookmark's own if it
|
||||||
|
/// names one that exists, else the store's default (the one place that
|
||||||
|
/// picks it is [`voelin_store::Store::identity_id_for`]).
|
||||||
|
fn identity_id_for(&self, bookmark: Option<i64>) -> Option<i64> {
|
||||||
|
self.store.identity_id_for(self.named_identity(bookmark))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The identity a connection to `bookmark` uses
|
||||||
|
/// ([`voelin_store::Store::identity_for`]).
|
||||||
pub(crate) fn identity_for(&self, bookmark: Option<i64>) -> tsclientlib::Identity {
|
pub(crate) fn identity_for(&self, bookmark: Option<i64>) -> tsclientlib::Identity {
|
||||||
self.identity_id_for(bookmark)
|
self.store.identity_for(self.named_identity(bookmark), &self.identity)
|
||||||
.and_then(|id| self.store.identity(id).ok())
|
|
||||||
.unwrap_or_else(|| self.identity.clone())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The store's default identity (`Store::default_identity`).
|
/// The store's default identity (`Store::default_identity`).
|
||||||
|
|||||||
@@ -39,21 +39,44 @@ desktop shell, is slice 1 of the step's list and landed on `phase5/gpui-shell`
|
|||||||
UI's keys, the secrets, the default identity), the server rail, the sidebar,
|
UI's keys, the secrets, the default identity), the server rail, the sidebar,
|
||||||
the top bar and the main area as entities that tell the window when what they
|
the top bar and the main area as entities that tell the window when what they
|
||||||
show changed (the window then draws every part: gpui-pre 0.3.10 renders every
|
show changed (the window then draws every part: gpui-pre 0.3.10 renders every
|
||||||
uncached child view on every frame), the eleven callbacks of `bind/servers.rs` as actions through
|
uncached child view on every frame), the eleven callbacks of `bind/servers.rs`
|
||||||
`voelin-ui-vm`'s logic and the engine's commands, the window's size and
|
as actions through `voelin-ui-vm`'s logic and the engine's commands, the
|
||||||
position kept in `ui.window`, the engine-event task in steps and a tick that
|
window's size and position kept in `ui.window`, the engine-event task in steps
|
||||||
draws nothing. What it shows, what it costs idle and what it leaves to the
|
and a tick that draws nothing. What it shows, what it costs idle and what it
|
||||||
slices after it are in docs/ui.md, "The desktop shell"; the next slice is the
|
leaves to the slices after it are in docs/ui.md, "The desktop shell"; the next
|
||||||
channel tree and the members. The shell was reviewed and gated the same day (an
|
slice is the channel tree and the members. The shell was reviewed and gated the
|
||||||
Opus gate: no blocker and no major, six minors), and the minors are closed on
|
same day (an Opus gate: no blocker and no major, six minors), and the minors are
|
||||||
`phase5/gpui-shell-minors`: the records that said the parts draw only when what
|
closed on `phase5/gpui-shell-minors`: the records that said the parts draw only
|
||||||
they show changed are corrected (a part tells the window, and the window draws
|
when what they show changed are corrected (a part tells the window, and the
|
||||||
every part, as gpui-pre 0.3.10 renders every uncached child view on every
|
window draws every part, as gpui-pre 0.3.10 renders every uncached child view on
|
||||||
frame), a window left maximized is maximized again on X11, the pictures are
|
every frame), a window left maximized is maximized again on X11, the pictures
|
||||||
1440 by 960, the connect test sends no DNS query, the sequences both front ends
|
are 1440 by 960, the connect test sends no DNS query, the sequences both front
|
||||||
ran are shared in `voelin-ui-vm`, and the `ui.window` row is in the settings
|
ends ran are shared in `voelin-ui-vm`, and the `ui.window` row is in the
|
||||||
table; the gate's four risks of the shell are in docs/ui.md, "For the next
|
settings table; the gate's four risks of the shell are in docs/ui.md, "For the
|
||||||
slices".
|
next slices". Slice 2, the channel tree and the members panel, landed on
|
||||||
|
`phase5/gpui-tree` (2026-10-28): `Update.refresh` as per-area signals and the
|
||||||
|
shell's panes cached (the design the shell's review left for it), the pictures
|
||||||
|
the engine writes again shown and the old copies dropped, the tree over a
|
||||||
|
virtual list that applies the row operations of `voelin-ui-vm`'s `list::diff`,
|
||||||
|
the members panel, the member card and the password prompt, with the folds and
|
||||||
|
the selection kept per server; what a change costs, figure by figure, is in
|
||||||
|
docs/ui.md, "The channel tree and the members". The slice was reviewed the same
|
||||||
|
day (one major and five minors) and the commits after it close them: a channel's
|
||||||
|
banner is drawn under the surface veil of the Slint tree's `BannerPicture`, an
|
||||||
|
avatar under 28 pixels shows one letter, the password prompt ignores an empty
|
||||||
|
field and closes on Escape, and the `ui.tree` row of the settings table, the
|
||||||
|
list of the Bridge's properties and callbacks that the two panes use and some
|
||||||
|
long lines are corrected in docs/ui.md. Slice 3, the voice page and the call bar,
|
||||||
|
landed on `phase5/gpui-voice` (2026-10-28): the page as a cached pane of its own
|
||||||
|
that takes the main area (its people from the tree model's one build, so a talker
|
||||||
|
is still one build for three lists), the call bar and the smaller stage kept in
|
||||||
|
`ui.voice_compact`, the sidebar's server card with its banner, the voice card's
|
||||||
|
transmit modes and the volume of a person following the settings, the release
|
||||||
|
guard of Hold to talk (voice that drops, a window that loses the focus) and the
|
||||||
|
global push-to-talk key started on the engine's runtime; it was seen against both
|
||||||
|
development servers with a second client that talks. What it costs and what it
|
||||||
|
leaves is in docs/ui.md, "The voice page and the call bar". The next slice is the
|
||||||
|
chat, the composer and emoji.
|
||||||
|
|
||||||
| Spike | The plan's no-go | Seen (software rendering, see Setup) | Verdict |
|
| Spike | The plan's no-go | Seen (software rendering, see Setup) | Verdict |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
|
|||||||
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 153 KiB |
|
After Width: | Height: | Size: 96 KiB |
|
After Width: | Height: | Size: 183 KiB |
|
After Width: | Height: | Size: 192 KiB |
|
After Width: | Height: | Size: 195 KiB |
|
After Width: | Height: | Size: 205 KiB |
|
After Width: | Height: | Size: 95 KiB |