Merge phase5/gpui-tree: slice 2 of the GPUI front end, the channel tree and the members panel as cached panes with per-area signals (plus the shell minors' three preliminaries)
CI / Linux checks (push) Successful in 31m33s
CI / Linux checks (push) Successful in 31m33s
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
e61919ebf4
33 files changed
+4564
-304
No files matched your search
+19
-4
@@ -31,10 +31,25 @@ 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
|
||||
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
|
||||
maximized once it is shown, not before the window manager has it). The channel tree, the chat and the other pages are the
|
||||
next slices; the search and the settings buttons only log that. `VOELIN_DEMO_UI=1`
|
||||
shows the Slint app's sample servers without sending or keeping anything
|
||||
(docs/ui.md, "The desktop shell").
|
||||
maximized once it is shown, not before the window manager has it, and a
|
||||
resize made before it answers is kept). The chat and the other pages are the
|
||||
next slices; the search and the settings buttons only log that.
|
||||
`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 redraws the members panel and nothing else of the window (the
|
||||
tree does not mark who talks), 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").
|
||||
- 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
|
||||
opens the folder.
|
||||
|
||||
+457
-34
@@ -19,15 +19,22 @@
|
||||
//! channel of jobs a third foreground task runs on GPUI's thread, as
|
||||
//! `later(|app| ...)` does in the Slint front end.
|
||||
//!
|
||||
//! The root notifies on every batch of events and on every move of the user's;
|
||||
//! it is the views (`crate::shell`) that decide whether what they show changed
|
||||
//! and tell the window only then (the window draws every part). What a
|
||||
//! transition asks for besides the state (`Update`) is carried out as far as
|
||||
//! this front end has the parts: the engine's commands go out, the status line
|
||||
//! is set, what is to be kept goes to the store, a setting the theme follows
|
||||
//! is applied and the warnings are logged; the redraw flags, the notices, the pictures to decode and the
|
||||
//! streams' capture and decoder are for the slices that have those parts.
|
||||
//! The root notifies on every batch of events and on every move of the user's
|
||||
//! (the window's title and the toast follow it). What a transition's
|
||||
//! `refresh` flags name is raised as per-area signals ([`crate::signals`],
|
||||
//! once per batch of events) that the parts of the window observe, and it is
|
||||
//! the parts (`crate::shell`) that decide whether what they show changed and
|
||||
//! tell the window only then. What a transition asks for besides the state
|
||||
//! (`Update`) is carried out as far as this front end has the parts: the
|
||||
//! engine's commands go out, the status line is set, what is to be kept goes
|
||||
//! to the store, a setting the theme follows is applied, the warnings are
|
||||
//! logged and the flags of the areas that have a part are raised; the other
|
||||
//! flags, the notices, the pictures to decode and the streams' capture and
|
||||
//! decoder are for the slices that have those parts.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::task::Poll;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -39,25 +46,31 @@ use voelin_core::{Command, Engine, Event, VoiceState};
|
||||
use voelin_store::{Bookmark, ChatRead, ChatTarget as StoredTarget, Store};
|
||||
use voelin_ui_vm::bridge::{BookmarkForm, ChatLine};
|
||||
use voelin_ui_vm::events;
|
||||
use voelin_ui_vm::host::{Cx, Host, Persist, Update};
|
||||
use voelin_ui_vm::host::{Cx, Host, PasswordPrompt, Persist, Refresh, Update};
|
||||
use voelin_ui_vm::image::ImageRef;
|
||||
use voelin_ui_vm::servers::logic;
|
||||
use voelin_ui_vm::servers::sequence::{self, Backing};
|
||||
use voelin_ui_vm::settings::{
|
||||
CLIENT_PLAYBACK, ThemeChoice, UI, UI_FONT_SCALE, UI_IMAGE_PREVIEW_KB, UI_THEME, UI_WINDOW,
|
||||
WindowState,
|
||||
CLIENT_PLAYBACK, ThemeChoice, TreeStates, UI, UI_FONT_SCALE, UI_IMAGE_PREVIEW_KB, UI_THEME,
|
||||
UI_TREE, UI_WINDOW, WindowState,
|
||||
};
|
||||
use voelin_ui_vm::social::logic::Social;
|
||||
use voelin_ui_vm::tree::ChannelId;
|
||||
|
||||
use crate::backend::Backend;
|
||||
use crate::dev::Switches;
|
||||
use crate::meter::Counters;
|
||||
use crate::pictures;
|
||||
use crate::signals::{Area, Signals};
|
||||
use crate::theme::{Choice, VoelinTheme};
|
||||
|
||||
/// The toolkit-free state of the client, with the chat lines of a tab as plain
|
||||
/// rows (what a front end that draws again from the list needs).
|
||||
pub type VmState = voelin_ui_vm::state::AppState<Vec<ChatLine>>;
|
||||
|
||||
/// The sample person `VOELIN_DEMO_TALK` makes talk (Kairo, who talks at start).
|
||||
const SAMPLE_TALKER: u16 = 3;
|
||||
|
||||
/// How many engine events one update of the entity takes at most: a burst
|
||||
/// is handled in steps of this size, with a yield to GPUI's executor between
|
||||
/// them.
|
||||
@@ -180,11 +193,20 @@ struct WindowKeeper {
|
||||
/// screen's size for a maximized window, Wayland the size it returns to.)
|
||||
restore: Option<WindowState>,
|
||||
/// The window was opened to be maximized and has not been seen maximized
|
||||
/// yet: what it reports until then is the place it opened with, not one
|
||||
/// the user chose, and is not kept.
|
||||
awaiting_maximize: bool,
|
||||
/// yet: how many of its windowed reports are still the place it opened
|
||||
/// with, not one the user chose, and are not kept ([`OPENING_REPORTS`] at
|
||||
/// start, none once the window was seen maximized or the reports ran out).
|
||||
opening_reports: u8,
|
||||
}
|
||||
|
||||
/// How many windowed reports of a window opened to be maximized are taken to
|
||||
/// be the place it opened with, not the user's: the first is the window's
|
||||
/// own at its creation, the second the configure an X11 window manager may
|
||||
/// send when it maps the window. A later one is the user's own move or
|
||||
/// resize, kept even if the window manager has still not maximized the window
|
||||
/// (a tiling one never does).
|
||||
pub const OPENING_REPORTS: u8 = 2;
|
||||
|
||||
/// Give up the foreground thread once, so that GPUI's executor runs what is
|
||||
/// queued before this task goes on.
|
||||
async fn yield_now() {
|
||||
@@ -215,11 +237,23 @@ pub struct AppState {
|
||||
/// toast sees a new text by this number changing, even when the text is
|
||||
/// the same as the last.
|
||||
pub status_generation: u64,
|
||||
/// How many times a channel's password was asked for: the window opens the
|
||||
/// prompt ([`AppState::password_prompt`]) when this changes.
|
||||
pub password_generation: u64,
|
||||
engine: Option<Engine>,
|
||||
backend: Backend,
|
||||
switches: Switches,
|
||||
window: WindowKeeper,
|
||||
counters: Counters,
|
||||
signals: Signals,
|
||||
password: Option<PasswordPrompt>,
|
||||
/// What each server's tree remembers (`ui.tree`), by bookmark id.
|
||||
tree_states: TreeStates,
|
||||
/// The servers whose remembered folds are in their sessions.
|
||||
tree_restored: HashSet<i64>,
|
||||
/// Where the sample servers' pictures were written (`VOELIN_DEMO_UI`),
|
||||
/// removed with the state.
|
||||
demo_dir: Option<PathBuf>,
|
||||
later: Later,
|
||||
/// What went to the engine (tests look at it: an engine of the test's
|
||||
/// own would have to be asked what it was sent).
|
||||
@@ -283,14 +317,39 @@ impl AppState {
|
||||
})
|
||||
.detach();
|
||||
|
||||
// With the sample servers, a sample person starts and stops talking at a
|
||||
// rate (`VOELIN_DEMO_TALK`), through the events a server would send.
|
||||
if let (true, Some(rate)) = (switches.demo_ui, switches.demo_talk) {
|
||||
// Microseconds: a rate of 10 is 100 ms, not 100.000001 of an f32.
|
||||
let period = Duration::from_micros((1e6 / f64::from(rate)).round() as u64);
|
||||
cx.spawn(async move |this, cx| {
|
||||
let mut talking = true;
|
||||
loop {
|
||||
cx.background_executor().timer(period).await;
|
||||
talking = !talking;
|
||||
let event = Event::Talking {
|
||||
session: voelin_ui_vm::dev::logic::DEMO as u64,
|
||||
client: SAMPLE_TALKER,
|
||||
talking,
|
||||
};
|
||||
if this.update(cx, |state, cx| state.handle_event(event, cx)).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
|
||||
let loaded = backend.load();
|
||||
let saved = backend.prefs.get(&UI_WINDOW);
|
||||
let tree_states = backend.prefs.get(&UI_TREE);
|
||||
let mut state = Self {
|
||||
vm: VmState::new(loaded.bookmarks, loaded.settings, loaded.audio, loaded.playback),
|
||||
social: Social::default(),
|
||||
events_handled: 0,
|
||||
ticks: 0,
|
||||
status_generation: 0,
|
||||
password_generation: 0,
|
||||
engine,
|
||||
backend,
|
||||
switches,
|
||||
@@ -298,29 +357,43 @@ impl AppState {
|
||||
latest: None,
|
||||
saved,
|
||||
restore: saved.filter(WindowState::is_sane),
|
||||
awaiting_maximize: false,
|
||||
opening_reports: 0,
|
||||
},
|
||||
counters,
|
||||
signals: Signals::new(cx),
|
||||
password: None,
|
||||
tree_states,
|
||||
tree_restored: HashSet::new(),
|
||||
demo_dir: None,
|
||||
later: Later(later),
|
||||
#[cfg(test)]
|
||||
sent: Default::default(),
|
||||
};
|
||||
state.window.awaiting_maximize = state.wants_maximized();
|
||||
state.window.opening_reports = if state.wants_maximized() { OPENING_REPORTS } else { 0 };
|
||||
if state.switches.demo_ui {
|
||||
state.load_demo();
|
||||
} else if let Some(id) = state.vm.current {
|
||||
state.restore_tree(id);
|
||||
}
|
||||
state
|
||||
}
|
||||
|
||||
/// The sample servers of `VOELIN_DEMO_UI`, through the same events a server
|
||||
/// would send ([`voelin_ui_vm::dev::logic`]): the first is connected, the
|
||||
/// second observed.
|
||||
/// second observed, and the first's avatars, icons, banners and badges
|
||||
/// arrive as files of a folder of their own in the temporary directory.
|
||||
fn load_demo(&mut self) {
|
||||
use voelin_ui_vm::dev::logic as sample;
|
||||
self.vm.bookmarks = sample::bookmarks();
|
||||
self.vm.settings.last_voice = Some(sample::last_voice());
|
||||
self.vm.current = Some(sample::DEMO);
|
||||
for event in sample::server_events() {
|
||||
let pictures = if self.switches.demo_pictures {
|
||||
let address = self.vm.bookmarks.first().map(|b| b.address.clone()).unwrap_or_default();
|
||||
self.write_demo_pictures(&address)
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
for event in sample::server_events().into_iter().chain(pictures) {
|
||||
let update = self.handle(event);
|
||||
self.counters.engine_events.incr();
|
||||
self.events_handled += 1;
|
||||
@@ -328,10 +401,41 @@ impl AppState {
|
||||
// settings and bookmarks are not kept.
|
||||
self.log_warnings(update.warnings);
|
||||
}
|
||||
// The sample server to show: the first unless a switch says another.
|
||||
if let Some(id) =
|
||||
self.switches.demo_server.and_then(|place| self.vm.bookmarks.get(place)).map(|b| b.id)
|
||||
{
|
||||
self.vm.current = Some(id);
|
||||
}
|
||||
self.vm.status.clear();
|
||||
self.counters.connections.set(self.connections() as u64);
|
||||
}
|
||||
|
||||
/// The sample server's pictures as the events the engine sends once they are
|
||||
/// in its cache, written to a folder of their own in the temporary
|
||||
/// directory, which goes when the window closes ([`AppState::shutdown`]) or
|
||||
/// the state is dropped.
|
||||
fn write_demo_pictures(&mut self, address: &str) -> Vec<Event> {
|
||||
static FOLDERS: AtomicUsize = AtomicUsize::new(0);
|
||||
let folder = std::env::temp_dir().join(format!(
|
||||
"voelin-gpui-demo-{}-{}",
|
||||
std::process::id(),
|
||||
FOLDERS.fetch_add(1, Ordering::Relaxed)
|
||||
));
|
||||
if let Err(e) = std::fs::create_dir_all(&folder) {
|
||||
warn!(%e, "the sample pictures have no folder");
|
||||
return Vec::new();
|
||||
}
|
||||
self.demo_dir = Some(folder.clone());
|
||||
voelin_ui_vm::dev::logic::pictures(address, |name, png| {
|
||||
let path = folder.join(name);
|
||||
if let Err(e) = std::fs::write(&path, png) {
|
||||
warn!(%e, "a sample picture was not written");
|
||||
}
|
||||
path
|
||||
})
|
||||
}
|
||||
|
||||
/// The handle other threads use to run something on GPUI's thread.
|
||||
pub fn later(&self) -> Later {
|
||||
self.later.clone()
|
||||
@@ -352,6 +456,17 @@ impl AppState {
|
||||
&self.backend
|
||||
}
|
||||
|
||||
/// What the meter counts.
|
||||
pub fn counters(&self) -> &Counters {
|
||||
&self.counters
|
||||
}
|
||||
|
||||
/// The per-area signals the parts of the window observe
|
||||
/// ([`crate::signals`]).
|
||||
pub fn signals(&self) -> &Signals {
|
||||
&self.signals
|
||||
}
|
||||
|
||||
/// What an engine event does to the state ([`events::handle`], the one
|
||||
/// dispatch of both front ends), and what asks to be done of it.
|
||||
fn handle(&mut self, event: Event) -> Update {
|
||||
@@ -370,13 +485,16 @@ impl AppState {
|
||||
events: impl IntoIterator<Item = Event>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let mut refresh = Refresh::default();
|
||||
for event in events {
|
||||
self.events_handled += 1;
|
||||
self.counters.engine_events.incr();
|
||||
let update = self.handle(event);
|
||||
self.perform(update, cx);
|
||||
refresh.merge(self.perform(update, cx));
|
||||
}
|
||||
self.counters.connections.set(self.connections() as u64);
|
||||
// Each area once for the whole batch.
|
||||
self.signals.raise(&refresh, cx);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
@@ -417,7 +535,8 @@ impl AppState {
|
||||
let mut transition = Cx::new(&host);
|
||||
let result = f(&mut self.vm, &mut transition, &backing);
|
||||
let update = transition.update;
|
||||
self.perform(update, cx);
|
||||
let refresh = self.perform(update, cx);
|
||||
self.signals.raise(&refresh, cx);
|
||||
result
|
||||
}
|
||||
|
||||
@@ -453,10 +572,30 @@ impl AppState {
|
||||
}
|
||||
}
|
||||
|
||||
/// Do what an update asks that this front end has the parts for.
|
||||
fn perform(&mut self, update: Update, cx: &mut Context<Self>) {
|
||||
let Update { status, commands, persist, warnings, rest, password, discover, .. } = update;
|
||||
/// Do what an update asks that this front end has the parts for, and say
|
||||
/// which areas of the window it asks to draw again (`refresh`, and what
|
||||
/// the front end's own settings change): the caller raises them
|
||||
/// ([`Signals::raise`]) once for as many updates as it has handled.
|
||||
fn perform(&mut self, update: Update, cx: &mut Context<Self>) -> Refresh {
|
||||
let Update {
|
||||
refresh,
|
||||
status,
|
||||
commands,
|
||||
persist,
|
||||
warnings,
|
||||
rest,
|
||||
password,
|
||||
discover,
|
||||
reloaded,
|
||||
..
|
||||
} = update;
|
||||
self.log_warnings(warnings);
|
||||
// The pictures the engine wrote again: what was decoded of the old
|
||||
// ones goes ([`crate::pictures`]); the lists that show them compare
|
||||
// the new reference unequal and draw the rows again.
|
||||
for path in &reloaded {
|
||||
pictures::forget_stale(path, cx);
|
||||
}
|
||||
for command in commands {
|
||||
self.send(command);
|
||||
}
|
||||
@@ -470,12 +609,14 @@ impl AppState {
|
||||
self.keep(what);
|
||||
}
|
||||
if let Some(prompt) = password {
|
||||
debug!(channel = %prompt.name, "the password dialog comes with the channel tree");
|
||||
self.password = Some(prompt);
|
||||
self.password_generation += 1;
|
||||
}
|
||||
// What the front end keeps itself comes before the drawing.
|
||||
if let Some(Event::SettingChanged { key }) = rest {
|
||||
self.setting_changed(&key, cx);
|
||||
}
|
||||
refresh
|
||||
}
|
||||
|
||||
/// The status line says this from now on.
|
||||
@@ -545,20 +686,23 @@ impl AppState {
|
||||
///
|
||||
/// A window that was opened to be maximized ([`Self::wants_maximized`])
|
||||
/// reports the place it opened with first (the window manager maximizes it
|
||||
/// after it is shown, on X11 when [`crate::view::MainView`] asks): that is
|
||||
/// not kept, or a run that ended before the window was maximized would
|
||||
/// overwrite `maximized: true` with `false`. Once it has been seen
|
||||
/// maximized, what it reports is the user's. A maximized window is kept
|
||||
/// with the place it returns to, not the screen's size.
|
||||
/// after it is shown, on X11 when [`crate::view::MainView`] asks): its
|
||||
/// first [`OPENING_REPORTS`] windowed reports are not kept, or a run that
|
||||
/// ended before the window was maximized would overwrite `maximized: true`
|
||||
/// with `false`. Once it has been seen maximized, or after those reports,
|
||||
/// what it reports is the user's (a resize before the window manager
|
||||
/// answered, or with one that never maximizes, is kept). A maximized
|
||||
/// window is kept with the place it returns to, not the screen's size.
|
||||
pub fn window_moved(&mut self, state: WindowState) {
|
||||
if self.switches.window.is_some() || self.switches.demo_ui {
|
||||
return;
|
||||
}
|
||||
let keeper = &mut self.window;
|
||||
let state = if state.maximized {
|
||||
keeper.awaiting_maximize = false;
|
||||
keeper.opening_reports = 0;
|
||||
keeper.restore.map_or(state, |back| WindowState { maximized: true, ..back })
|
||||
} else if keeper.awaiting_maximize {
|
||||
} else if keeper.opening_reports > 0 {
|
||||
keeper.opening_reports -= 1;
|
||||
return;
|
||||
} else {
|
||||
keeper.restore = Some(state);
|
||||
@@ -578,10 +722,11 @@ impl AppState {
|
||||
self.switches.window.is_none() && self.remembered_window().is_some_and(|w| w.maximized)
|
||||
}
|
||||
|
||||
/// Whether the window was opened to be maximized and has not been seen so
|
||||
/// yet (the window manager has not answered, or cannot).
|
||||
/// Whether the window was opened to be maximized, has not been seen so yet
|
||||
/// (the window manager has not answered, or cannot) and has not reported
|
||||
/// more than [`OPENING_REPORTS`] places.
|
||||
pub fn awaiting_maximize(&self) -> bool {
|
||||
self.window.awaiting_maximize
|
||||
self.window.opening_reports > 0
|
||||
}
|
||||
|
||||
/// Write the window's place to the settings if it changed.
|
||||
@@ -643,6 +788,7 @@ impl AppState {
|
||||
|
||||
/// Show a server, and observe it.
|
||||
pub fn select_server(&mut self, id: i64, cx: &mut Context<Self>) {
|
||||
self.restore_tree(id);
|
||||
self.transition_with(cx, |state, cx, backing| {
|
||||
sequence::select_server(state, cx, backing, id)
|
||||
});
|
||||
@@ -716,6 +862,125 @@ impl AppState {
|
||||
Some(link)
|
||||
}
|
||||
|
||||
// The callbacks of the channel tree and the members panel.
|
||||
|
||||
/// Join a channel of the server on screen (`join_channel` of
|
||||
/// `bind/servers.rs`, through [`sequence::join_channel`]): the move there
|
||||
/// with voice, the password prompt for a locked channel, a connect into
|
||||
/// the channel without voice. `stream_peer` stays the engine's default, as
|
||||
/// in [`AppState::connect_voice`].
|
||||
pub fn join_channel(&mut self, channel: ChannelId, cx: &mut Context<Self>) {
|
||||
let Some(session) = self.vm.current else { return };
|
||||
self.transition_with(cx, |state, cx, backing| {
|
||||
sequence::join_channel(state, cx, backing, session, channel, None)
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// The password prompt's Join ([`sequence::join_with_password`]).
|
||||
pub fn join_with_password(&mut self, password: String, cx: &mut Context<Self>) {
|
||||
self.password = None;
|
||||
self.transition_with(cx, |state, cx, backing| {
|
||||
sequence::join_with_password(state, cx, backing, password, None)
|
||||
});
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// The password prompt was closed without joining.
|
||||
pub fn cancel_password(&mut self, cx: &mut Context<Self>) {
|
||||
self.password = None;
|
||||
self.vm.join_target = None;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// The password prompt that is open: the locked channel's name as the tree
|
||||
/// shows it, and whether the password given before was refused.
|
||||
pub fn password_prompt(&self) -> Option<&PasswordPrompt> {
|
||||
self.password.as_ref()
|
||||
}
|
||||
|
||||
/// Fold or unfold a channel of the tree (`toggle_collapse`), and remember
|
||||
/// it for the server ([`UI_TREE`]).
|
||||
pub fn toggle_collapse(&mut self, channel: ChannelId, cx: &mut Context<Self>) {
|
||||
self.transition(cx, |state, cx| logic::toggle_collapse(state, cx, channel));
|
||||
self.remember_folds();
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Select a channel of the tree, and remember it for the server.
|
||||
pub fn select_channel(&mut self, channel: ChannelId, cx: &mut Context<Self>) {
|
||||
let Some(id) = self.vm.current else { return };
|
||||
let state = self.tree_states.entry(id.to_string()).or_default();
|
||||
if state.selected == Some(channel) {
|
||||
return;
|
||||
}
|
||||
state.selected = Some(channel);
|
||||
self.keep_tree_states();
|
||||
self.signals.raise_area(Area::Tree, cx);
|
||||
}
|
||||
|
||||
/// The channel selected in the tree of the server on screen.
|
||||
pub fn selected_channel(&self) -> Option<ChannelId> {
|
||||
let id = self.vm.current?;
|
||||
self.tree_states.get(&id.to_string()).and_then(|state| state.selected)
|
||||
}
|
||||
|
||||
/// The members panel's search (`search_members`).
|
||||
pub fn search_members(&mut self, text: String, cx: &mut Context<Self>) {
|
||||
self.transition(cx, |state, cx| logic::search_members(state, cx, text));
|
||||
}
|
||||
|
||||
/// Open the card of a client of the server on screen over the members
|
||||
/// panel (`None` closes it).
|
||||
pub fn open_member(&mut self, client: Option<u16>, cx: &mut Context<Self>) {
|
||||
self.transition(cx, |state, cx| logic::open_member(state, cx, client));
|
||||
}
|
||||
|
||||
/// Put the folds a server's tree remembered into its session, once.
|
||||
fn restore_tree(&mut self, id: i64) {
|
||||
if self.switches.demo_ui || !self.tree_restored.insert(id) {
|
||||
return;
|
||||
}
|
||||
let Some(state) = self.tree_states.get(&id.to_string()).filter(|s| !s.collapsed.is_empty())
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let collapsed = state.collapsed.iter().copied().collect();
|
||||
self.vm.sessions.entry(id).or_default().collapsed = collapsed;
|
||||
}
|
||||
|
||||
/// Remember which channels of the server on screen are folded.
|
||||
fn remember_folds(&mut self) {
|
||||
let Some(id) = self.vm.current else { return };
|
||||
let mut collapsed: Vec<ChannelId> = self
|
||||
.vm
|
||||
.sessions
|
||||
.get(&id)
|
||||
.map(|view| view.collapsed.iter().copied().collect())
|
||||
.unwrap_or_default();
|
||||
collapsed.sort_unstable();
|
||||
let key = id.to_string();
|
||||
let state = self.tree_states.entry(key.clone()).or_default();
|
||||
let changed = state.collapsed != collapsed;
|
||||
state.collapsed = collapsed;
|
||||
if state.is_empty() {
|
||||
self.tree_states.remove(&key);
|
||||
}
|
||||
if changed {
|
||||
self.keep_tree_states();
|
||||
}
|
||||
}
|
||||
|
||||
/// Write what the trees remember to the settings (nothing in demo mode).
|
||||
fn keep_tree_states(&self) {
|
||||
if self.switches.demo_ui {
|
||||
return;
|
||||
}
|
||||
if let Err(e) = self.backend.prefs.set(&UI_TREE, self.tree_states.clone()) {
|
||||
warn!(%e, "could not store what the trees remember");
|
||||
}
|
||||
}
|
||||
|
||||
/// The server dialog's form for a server (id -1: a new one).
|
||||
pub fn bookmark_form(&self, id: i64) -> BookmarkForm {
|
||||
sequence::bookmark_form(&self.vm, &self.backend.store, &*self.backend.secrets, id)
|
||||
@@ -776,6 +1041,10 @@ impl AppState {
|
||||
self.transition_with(cx, |state, cx, backing| {
|
||||
sequence::delete_bookmark(state, cx, backing, id)
|
||||
});
|
||||
self.tree_restored.remove(&id);
|
||||
if self.tree_states.remove(&id.to_string()).is_some() {
|
||||
self.keep_tree_states();
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
@@ -817,6 +1086,10 @@ impl AppState {
|
||||
/// engine, none in demo mode).
|
||||
pub fn shutdown(&mut self, cx: &mut Context<Self>) -> usize {
|
||||
self.flush_window();
|
||||
// The sample pictures are not needed once the window is closing.
|
||||
if let Some(folder) = self.demo_dir.take() {
|
||||
let _ = std::fs::remove_dir_all(folder);
|
||||
}
|
||||
let ids: Vec<i64> = self.vm.sessions.keys().copied().collect();
|
||||
for id in &ids {
|
||||
self.transition(cx, |state, cx| voelin_ui_vm::chat::logic::save_reads(state, cx, *id));
|
||||
@@ -832,6 +1105,14 @@ impl AppState {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for AppState {
|
||||
fn drop(&mut self) {
|
||||
if let Some(folder) = self.demo_dir.take() {
|
||||
let _ = std::fs::remove_dir_all(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::cell::Cell;
|
||||
@@ -847,6 +1128,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::backend::testing::TempDir;
|
||||
use crate::engine::HostedEngine;
|
||||
use crate::signals::Area;
|
||||
|
||||
fn voice(voice: VoiceState) -> Event {
|
||||
Event::State { session: 1, state: SessionState { voice, ..Default::default() } }
|
||||
@@ -962,6 +1244,32 @@ mod tests {
|
||||
assert_eq!(counters.engine_events.get(), total as u64);
|
||||
}
|
||||
|
||||
/// A batch of events raises each area its updates name once, not once per
|
||||
/// event: the parts that listen to an area are told once per batch.
|
||||
#[gpui::test]
|
||||
fn a_burst_raises_each_area_once_per_batch(cx: &mut TestAppContext) {
|
||||
let (app, tx, _) = entity(cx);
|
||||
let signals = app.read_with(cx, |app, _| app.signals().clone());
|
||||
let generation = |cx: &mut TestAppContext, area: Area| {
|
||||
signals.of(area).read_with(cx, |signal, _| signal.generation())
|
||||
};
|
||||
for i in 0..BATCH * 2 {
|
||||
let state = SessionState {
|
||||
voice: VoiceState::Connected,
|
||||
input_muted: i % 2 == 0,
|
||||
..Default::default()
|
||||
};
|
||||
tx.send(Event::State { session: 1, state }).unwrap();
|
||||
}
|
||||
cx.run_until_parked();
|
||||
// A session's state names the servers, the toolbar and the tree; none
|
||||
// names a member card.
|
||||
for area in [Area::Servers, Area::Toolbar, Area::Tree] {
|
||||
assert_eq!(generation(cx, area), 2, "{area:?}: two batches of {BATCH}");
|
||||
}
|
||||
assert_eq!(generation(cx, Area::MemberCard), 0);
|
||||
}
|
||||
|
||||
/// The tick counts and keeps what is due, and draws nothing: a window left
|
||||
/// alone is not redrawn once a second.
|
||||
#[gpui::test]
|
||||
@@ -1406,6 +1714,87 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// The sample servers' pictures arrive as files of a folder of their own,
|
||||
/// through the events a server would send, and go with the state.
|
||||
#[gpui::test]
|
||||
fn the_sample_servers_pictures_arrive_as_files_and_go_with_the_state(cx: &mut TestAppContext) {
|
||||
let switches = Switches { demo_ui: true, demo_pictures: true, ..Switches::default() };
|
||||
let (app, _, _) = entity_over(cx, Backend::in_memory().unwrap(), switches);
|
||||
let folder = app.read_with(cx, |app, _| {
|
||||
let view = &app.vm.sessions[&sample::DEMO];
|
||||
assert_eq!(view.avatars.len(), 5, "five people have a picture");
|
||||
assert!(view.pictures.len() > 5, "banners and badges");
|
||||
assert!(view.avatars.values().all(|path| path.is_file()));
|
||||
app.demo_dir.clone().expect("the folder")
|
||||
});
|
||||
assert!(folder.is_dir());
|
||||
// Closing the window removes it, and so would dropping the state.
|
||||
app.update(cx, |app, cx| app.shutdown(cx));
|
||||
assert!(!folder.exists(), "removed when the window closes");
|
||||
|
||||
let switches = Switches { demo_ui: true, demo_pictures: true, ..Switches::default() };
|
||||
let (second, _, _) = entity_over(cx, Backend::in_memory().unwrap(), switches);
|
||||
let folder = second.read_with(cx, |app, _| app.demo_dir.clone().expect("a folder"));
|
||||
assert!(folder.is_dir());
|
||||
drop(second);
|
||||
cx.update(|_| {});
|
||||
assert!(!folder.exists(), "removed with the state");
|
||||
|
||||
// Without the switch there is no folder and no picture.
|
||||
let switches = Switches { demo_ui: true, ..Switches::default() };
|
||||
let (plain, _, _) = entity_over(cx, Backend::in_memory().unwrap(), switches);
|
||||
plain.read_with(cx, |app, _| {
|
||||
assert!(app.demo_dir.is_none());
|
||||
assert!(app.vm.sessions[&sample::DEMO].avatars.is_empty());
|
||||
});
|
||||
}
|
||||
|
||||
/// `VOELIN_DEMO_SERVER` puts another sample server on screen: the second is
|
||||
/// observed and the third is not connected, both with nothing in their
|
||||
/// trees.
|
||||
#[gpui::test]
|
||||
fn another_sample_server_can_be_on_screen(cx: &mut TestAppContext) {
|
||||
for (place, id) in [(0, sample::DEMO), (1, sample::DEMO + 1), (2, sample::DEMO + 2)] {
|
||||
let switches =
|
||||
Switches { demo_ui: true, demo_server: Some(place), ..Switches::default() };
|
||||
let (app, _, _) = entity_over(cx, Backend::in_memory().unwrap(), switches);
|
||||
assert_eq!(app.read_with(cx, |app, _| app.vm.current), Some(id));
|
||||
}
|
||||
let (app, _, _) = entity_over(
|
||||
cx,
|
||||
Backend::in_memory().unwrap(),
|
||||
Switches { demo_ui: true, ..Switches::default() },
|
||||
);
|
||||
assert_eq!(app.read_with(cx, |app, _| app.vm.current), Some(sample::DEMO), "the first");
|
||||
}
|
||||
|
||||
/// With `VOELIN_DEMO_TALK` a sample person starts and stops talking at the
|
||||
/// rate asked, through the events a server would send.
|
||||
#[gpui::test]
|
||||
fn the_sample_person_talks_at_the_rate_asked(cx: &mut TestAppContext) {
|
||||
let switches = Switches { demo_ui: true, demo_talk: Some(10.0), ..Switches::default() };
|
||||
let (app, _, counters) = entity_over(cx, Backend::in_memory().unwrap(), switches);
|
||||
let talking = |cx: &mut TestAppContext| {
|
||||
app.read_with(cx, |app, _| app.vm.sessions[&sample::DEMO].talking.contains(&3))
|
||||
};
|
||||
assert!(talking(cx), "Kairo talks as the sample starts");
|
||||
cx.run_until_parked();
|
||||
let events = counters.engine_events.get();
|
||||
for expected in [false, true, false, true] {
|
||||
cx.executor().advance_clock(Duration::from_millis(100));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(talking(cx), expected);
|
||||
}
|
||||
assert_eq!(counters.engine_events.get(), events + 4, "one event a toggle");
|
||||
// Without the sample servers the switch does nothing.
|
||||
let switches = Switches { demo_talk: Some(10.0), ..Switches::default() };
|
||||
let (quiet, _, counters) = entity_over(cx, Backend::in_memory().unwrap(), switches);
|
||||
cx.executor().advance_clock(Duration::from_secs(1));
|
||||
cx.run_until_parked();
|
||||
assert_eq!(counters.engine_events.get(), 0);
|
||||
drop(quiet);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_sample_servers_show_through_the_events_and_nothing_is_stored_or_sent(
|
||||
cx: &mut TestAppContext,
|
||||
@@ -1565,6 +1954,40 @@ mod tests {
|
||||
assert_eq!(kept(cx), WindowState { maximized: true, ..restored });
|
||||
}
|
||||
|
||||
/// The guard of a window opened to be maximized is for its first reports
|
||||
/// only: after them what the window reports is the user's even if it was
|
||||
/// never seen maximized (a window manager that does not maximize, a user
|
||||
/// who resizes before it does), so a resize is not lost for good.
|
||||
#[gpui::test]
|
||||
fn the_maximize_guard_covers_the_first_reports_only(cx: &mut TestAppContext) {
|
||||
let dir = TempDir::new("window-guard");
|
||||
let backend = Backend::open(&dir.0, Box::new(MemorySecrets::default())).unwrap();
|
||||
let left =
|
||||
WindowState { width: 1000, height: 700, x: Some(20), y: Some(30), maximized: true };
|
||||
backend.prefs.set(&UI_WINDOW, Some(left)).unwrap();
|
||||
let (app, _, _) = entity_over(cx, backend, Switches::default());
|
||||
let kept = |cx: &mut TestAppContext| {
|
||||
cx.executor().advance_clock(Duration::from_secs(1));
|
||||
cx.run_until_parked();
|
||||
app.read_with(cx, |app, _| app.backend().prefs.get(&UI_WINDOW)).unwrap()
|
||||
};
|
||||
app.read_with(cx, |app, _| assert!(app.awaiting_maximize()));
|
||||
|
||||
// The place it opened with, then the window manager's configure.
|
||||
for width in [1000, 1001] {
|
||||
app.update(cx, |app, _| {
|
||||
app.window_moved(WindowState { width, maximized: false, ..left });
|
||||
});
|
||||
assert_eq!(kept(cx), left, "report of {width} is not the user's");
|
||||
}
|
||||
app.read_with(cx, |app, _| assert!(!app.awaiting_maximize(), "the guard is spent"));
|
||||
|
||||
// The third is the user's own, and nothing maximized the window.
|
||||
let resized = WindowState { width: 800, height: 600, maximized: false, ..place() };
|
||||
app.update(cx, |app, _| app.window_moved(resized));
|
||||
assert_eq!(kept(cx), resized);
|
||||
}
|
||||
|
||||
/// A window that was not opened maximized keeps what it reports from the
|
||||
/// first report on.
|
||||
#[gpui::test]
|
||||
|
||||
@@ -21,7 +21,9 @@ use voelin_core::settings::{AUDIO, Settings};
|
||||
use voelin_core::{AudioSettings, Command, Engine, History, IdentityBlob};
|
||||
use voelin_store::{Bookmark, IdentityOrigin, MemorySecrets, Secrets, Store};
|
||||
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.
|
||||
pub struct Backend {
|
||||
@@ -67,10 +69,11 @@ fn open_settings(dir: &Path) -> Settings {
|
||||
voelin_ui_vm::settings::open_settings(dir, &[], register_own_keys)
|
||||
}
|
||||
|
||||
/// The key that only this front end uses: where the window was
|
||||
/// (`ui.window`).
|
||||
/// The keys that only this front end uses: where the window was
|
||||
/// (`ui.window`) and what the channel trees remember (`ui.tree`).
|
||||
fn register_own_keys(prefs: &Settings) {
|
||||
prefs.register(&UI_WINDOW);
|
||||
prefs.register(&UI_TREE);
|
||||
}
|
||||
|
||||
impl Backend {
|
||||
|
||||
@@ -8,7 +8,15 @@
|
||||
//! other pages do not exist here yet; they are named in a warning and
|
||||
//! skipped.
|
||||
//! - `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
|
||||
//! one the settings give (`ui.theme`).
|
||||
//! - `VOELIN_FONT_SCALE=1.25`: the text size factor, in place of the
|
||||
@@ -36,6 +44,17 @@ pub struct Switches {
|
||||
pub open: Page,
|
||||
/// Show the sample servers instead of the stored ones.
|
||||
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.
|
||||
pub theme: Option<Choice>,
|
||||
/// The text size factor, when the switch names one.
|
||||
@@ -51,6 +70,9 @@ impl Default for Switches {
|
||||
Self {
|
||||
open: Page::Shell,
|
||||
demo_ui: false,
|
||||
demo_pictures: false,
|
||||
demo_server: None,
|
||||
demo_talk: None,
|
||||
theme: None,
|
||||
font_scale: None,
|
||||
window: None,
|
||||
@@ -97,8 +119,21 @@ impl Switches {
|
||||
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"));
|
||||
switches.demo_ui = flag("VOELIN_DEMO_UI");
|
||||
switches.demo_pictures = switches.demo_ui;
|
||||
switches.meter = flag("VOELIN_METER");
|
||||
switches
|
||||
}
|
||||
@@ -133,13 +168,17 @@ mod tests {
|
||||
let s = env(&[
|
||||
("VOELIN_OPEN", "swatch"),
|
||||
("VOELIN_DEMO_UI", "1"),
|
||||
("VOELIN_DEMO_SERVER", "2"),
|
||||
("VOELIN_DEMO_TALK", "10"),
|
||||
("VOELIN_DEV_THEME", "light"),
|
||||
("VOELIN_FONT_SCALE", "1.25"),
|
||||
("VOELIN_WINDOW_SIZE", "1440x960"),
|
||||
("VOELIN_METER", "1"),
|
||||
]);
|
||||
assert_eq!(s.open, Page::Swatch);
|
||||
assert!(s.demo_ui);
|
||||
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.font_scale, Some(1.25));
|
||||
assert_eq!(s.window, Some((1440.0, 960.0)));
|
||||
@@ -154,6 +193,8 @@ mod tests {
|
||||
("VOELIN_FONT_SCALE", "9"),
|
||||
("VOELIN_WINDOW_SIZE", "10x10"),
|
||||
("VOELIN_DEMO_UI", "0"),
|
||||
("VOELIN_DEMO_SERVER", "7"),
|
||||
("VOELIN_DEMO_TALK", "fast"),
|
||||
("VOELIN_METER", "0"),
|
||||
]);
|
||||
assert_eq!(s, Switches::default());
|
||||
|
||||
@@ -12,7 +12,9 @@ pub mod dev;
|
||||
pub mod engine;
|
||||
pub mod fonts;
|
||||
pub mod meter;
|
||||
pub mod pictures;
|
||||
pub mod shell;
|
||||
pub mod signals;
|
||||
pub mod swatch;
|
||||
pub mod theme;
|
||||
pub mod view;
|
||||
|
||||
@@ -41,6 +41,41 @@ 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,
|
||||
}
|
||||
|
||||
impl Panes {
|
||||
/// The counters with the names the meter reports them under.
|
||||
pub fn named(&self) -> [(&'static str, Counter); 6] {
|
||||
[
|
||||
("rail", self.rail.clone()),
|
||||
("topbar", self.topbar.clone()),
|
||||
("sidebar", self.sidebar.clone()),
|
||||
("tree", self.tree.clone()),
|
||||
("main", self.main.clone()),
|
||||
("members", self.members.clone()),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/// The app's own numbers the meter reports besides the process's.
|
||||
#[derive(Clone, Default, Debug)]
|
||||
pub struct Counters {
|
||||
@@ -50,6 +85,8 @@ pub struct Counters {
|
||||
pub ticks: Counter,
|
||||
/// Windows drawn (frames, per second).
|
||||
pub renders: Counter,
|
||||
/// Renders of each pane of the window (per second).
|
||||
pub panes: Panes,
|
||||
/// Jobs other threads handed to the foreground through
|
||||
/// [`crate::app::Later`] (per second).
|
||||
pub later_jobs: Counter,
|
||||
@@ -194,12 +231,15 @@ pub fn start(counters: Counters) {
|
||||
tracing::warn!(target: "voelin_gpui::meter", "the meter reads /proc/self; there is none here");
|
||||
return;
|
||||
};
|
||||
let rated = [
|
||||
let rated: Vec<(&str, Counter)> = [
|
||||
("engine_events", counters.engine_events.clone()),
|
||||
("ticks", counters.ticks.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();
|
||||
tracing::info!(target: "voelin_gpui::meter", "meter on: one line a second (VOELIN_METER)");
|
||||
loop {
|
||||
@@ -232,6 +272,17 @@ pub fn start(counters: Counters) {
|
||||
mod tests {
|
||||
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"]);
|
||||
let seen: Vec<u64> = named.iter().map(|(_, counter)| counter.get()).collect();
|
||||
assert_eq!(seen, [0, 0, 0, 0, 0, 1], "the counters are the panes' own");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn groups_drop_trailing_numbers() {
|
||||
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,13 @@
|
||||
//! ([`crate::app::AppState`]) for what the callback did in Slint: key bindings
|
||||
//! and menus come to the same handlers later.
|
||||
//!
|
||||
//! The callbacks of `bind/servers.rs` that are not here belong to the slices
|
||||
//! after this one: `search_members`, `show_voice_view`, `join_channel`,
|
||||
//! `join_with_password`, `toggle_collapse`, `open_client` and
|
||||
//! `client_audio_changed` to the channel tree and the voice page, and `copied`
|
||||
//! (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: `show_voice_view` to the voice
|
||||
//! page, `client_audio_changed` to the dialogs, and `copied` (the toast that
|
||||
//! follows a copy) to whichever copies: [`Invite`] sets it itself.
|
||||
|
||||
use gpui_kit::{Action, actions};
|
||||
|
||||
@@ -36,6 +37,10 @@ actions!(
|
||||
OpenSearch,
|
||||
/// The settings buttons: the settings come with their slice, today it is logged.
|
||||
OpenSettings,
|
||||
/// `join_with_password`: the password prompt's Join, with what it holds.
|
||||
SubmitChannelPassword,
|
||||
/// Close the password prompt without joining.
|
||||
CancelChannelPassword,
|
||||
]
|
||||
);
|
||||
|
||||
@@ -86,3 +91,72 @@ pub struct PushToTalk {
|
||||
/// Transmitting from now on.
|
||||
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,449 @@
|
||||
//! 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, 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};
|
||||
use super::widgets::{Avatar, banner_scrim, icon, live_badge, small_picture};
|
||||
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;
|
||||
|
||||
/// 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) => {
|
||||
let new = model.read(cx).rows().clone();
|
||||
this.apply(changes, new);
|
||||
}
|
||||
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::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
|
||||
}
|
||||
|
||||
/// Take the new rows in, 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;
|
||||
|
||||
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…",
|
||||
Emptiness::Connect => "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 row = div()
|
||||
.id(("tree-channel", id))
|
||||
.debug_selector(move || format!("tree-channel-{id}"))
|
||||
.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 tint of our own channel.
|
||||
.when_some(banner, |row, key| {
|
||||
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)),
|
||||
)
|
||||
})
|
||||
})
|
||||
.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()),
|
||||
)
|
||||
.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)),
|
||||
),
|
||||
)
|
||||
.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
|
||||
//! 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
|
||||
//! state and tells the window only when what it shows changed.
|
||||
//! connect, disconnect and edit it. An entity of its own, drawn as a cached
|
||||
//! 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::prelude::FluentBuilder as _;
|
||||
@@ -16,6 +17,8 @@ use voelin_ui_vm::servers::logic;
|
||||
use super::actions::{AddServer, ConnectVoice, DisconnectVoice, EditServer};
|
||||
use super::widgets::{Avatar, Presence, icon, panel, tagged};
|
||||
use crate::app::AppState;
|
||||
use crate::meter::Counters;
|
||||
use crate::signals::Area;
|
||||
use crate::theme::{VoelinTheme, hsla};
|
||||
|
||||
/// What the main area shows.
|
||||
@@ -51,21 +54,25 @@ fn state_words(status: &str) -> &'static str {
|
||||
/// The main area.
|
||||
pub struct MainPanel {
|
||||
state: MainState,
|
||||
_subscription: Subscription,
|
||||
counters: Counters,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
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 {
|
||||
let state = MainState::of(app.read(cx));
|
||||
let subscription = cx.observe(app, |this: &mut Self, app, cx| {
|
||||
let (state, counters, signals) = {
|
||||
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));
|
||||
if state != this.state {
|
||||
this.state = state;
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
Self { state, _subscription: subscription }
|
||||
Self { state, counters, _subscriptions: subscriptions }
|
||||
}
|
||||
|
||||
/// What it shows now.
|
||||
@@ -76,6 +83,7 @@ impl MainPanel {
|
||||
|
||||
impl Render for MainPanel {
|
||||
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 (c, m) = (&theme.colors, &theme.metrics);
|
||||
let body = match &self.state {
|
||||
@@ -165,7 +173,7 @@ impl Render for MainPanel {
|
||||
.text_center()
|
||||
.text_size(px(m.font_body))
|
||||
.text_color(hsla(c.text_muted))
|
||||
.child("Its channels and its chat come with the next slices."),
|
||||
.child("Its chat and its voice page come with the next slices."),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
@@ -205,13 +213,8 @@ impl Render for MainPanel {
|
||||
)
|
||||
}
|
||||
};
|
||||
panel(&theme)
|
||||
.id("main")
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.h_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.child(body)
|
||||
// The root of a cached pane takes the size its place gives it: laid out
|
||||
// on its own, `flex_1` would be as wide as its contents.
|
||||
panel(&theme).id("main").size_full().items_center().justify_center().child(body)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,626 @@
|
||||
//! 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). It is the pane a talker redraws: a person's row has the
|
||||
//! speaking ring, "Speaking" and the bars, and nothing else of the window is
|
||||
//! told. [`MemberCardView`] is the card, a card over the window with a scrim
|
||||
//! that a click outside closes; its buttons (the volume, 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::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};
|
||||
use super::tree_model::{Emptiness, TreeEvent, TreeModel};
|
||||
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.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) => {
|
||||
let new = model.read(cx).people().clone();
|
||||
this.apply(changes, new);
|
||||
}
|
||||
TreeEvent::Lists => {
|
||||
let model = model.read(cx);
|
||||
let now = (model.total(), model.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::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
|
||||
}
|
||||
|
||||
/// Whether the search box is shown.
|
||||
pub fn searching(&self) -> bool {
|
||||
self.searching
|
||||
}
|
||||
|
||||
/// Take the new rows in, 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;
|
||||
|
||||
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::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.
|
||||
pub struct MemberCardView {
|
||||
card: Option<MemberCard>,
|
||||
/// How wide the members panel is: the card stands beside it.
|
||||
panel_width: f32,
|
||||
_subscription: Subscription,
|
||||
}
|
||||
|
||||
impl MemberCardView {
|
||||
/// A card that follows `model`, beside a panel `panel_width` pixels wide.
|
||||
pub fn new(model: &Entity<TreeModel>, panel_width: f32, cx: &mut Context<Self>) -> Self {
|
||||
let card = model.read(cx).card().cloned();
|
||||
let subscription = cx.subscribe(model, |this: &mut Self, model, event: &TreeEvent, cx| {
|
||||
if matches!(event, TreeEvent::Card) {
|
||||
this.card = model.read(cx).card().cloned();
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
Self { card, panel_width, _subscription: subscription }
|
||||
}
|
||||
|
||||
/// 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)
|
||||
}
|
||||
|
||||
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);
|
||||
// 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()
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,33 @@
|
||||
//! 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 sidebar, the main area, the server form and the toast, each an entity
|
||||
//! that observes the root state ([`crate::app::AppState`]) and tells the window
|
||||
//! only when what it shows changed (the window then draws every part), and the
|
||||
//! actions the user's moves are ([`actions`]). [`crate::view::MainView`] puts
|
||||
//! them in the window.
|
||||
//! that listens to the per-area signals of the root state
|
||||
//! ([`crate::signals`]) and tells the window only when what it shows changed,
|
||||
//! and the actions the user's moves are ([`actions`]). The rail, the top bar
|
||||
//! and the main area 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;
|
||||
mod channels;
|
||||
mod form;
|
||||
mod main_panel;
|
||||
mod members;
|
||||
mod password;
|
||||
mod rail;
|
||||
mod sidebar;
|
||||
mod toast;
|
||||
mod topbar;
|
||||
mod tree_model;
|
||||
pub mod widgets;
|
||||
|
||||
pub use channels::ChannelTree;
|
||||
pub use form::ServerForm;
|
||||
pub use main_panel::{MainPanel, MainState};
|
||||
pub use members::{MemberCardView, MembersPane};
|
||||
pub use password::ChannelPassword;
|
||||
pub use rail::{RailView, ServerRail};
|
||||
pub use sidebar::{Sidebar, SidebarView};
|
||||
pub use toast::{TOAST_TIME, Toast};
|
||||
pub use topbar::TopBar;
|
||||
pub use tree_model::{Emptiness, TreeEvent, TreeModel};
|
||||
@@ -0,0 +1,153 @@
|
||||
//! 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.
|
||||
|
||||
use gpui_kit::component::Disableable as _;
|
||||
use gpui_kit::component::button::{Button, ButtonVariants as _};
|
||||
use gpui_kit::component::input::{Escape, Input, InputEvent, InputState};
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::{
|
||||
App, AppContext as _, Context, Entity, FontWeight, InteractiveElement as _, IntoElement,
|
||||
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 prompt for the password of one channel.
|
||||
pub struct ChannelPassword {
|
||||
channel: String,
|
||||
wrong: bool,
|
||||
input: Entity<InputState>,
|
||||
}
|
||||
|
||||
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 }
|
||||
}
|
||||
|
||||
/// 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("ChannelPassword")
|
||||
// The field has the keys, and its Escape has nothing to undo and
|
||||
// passes the key on: it closes the prompt.
|
||||
.on_action(cx.listener(|_, _: &Escape, window, cx| {
|
||||
window.dispatch_action(Box::new(CancelChannelPassword), cx)
|
||||
}))
|
||||
.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")
|
||||
.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
|
||||
//! selection, the add-server button and the settings button (`ServerRail` of
|
||||
//! `ui/shells/desktop.slint`). An entity of its own: it observes the root
|
||||
//! state and tells the window only when the servers it lists changed.
|
||||
//! `ui/shells/desktop.slint`). An entity of its own, drawn as a cached pane:
|
||||
//! 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::{
|
||||
@@ -14,6 +15,8 @@ use voelin_ui_vm::servers::logic;
|
||||
use super::actions::{AddServer, EditServer, OpenSettings, SelectServer};
|
||||
use super::widgets::{Avatar, IconButton, Presence};
|
||||
use crate::app::AppState;
|
||||
use crate::meter::Counters;
|
||||
use crate::signals::Area;
|
||||
use crate::theme::{VoelinTheme, hsla};
|
||||
|
||||
/// What the rail shows: the servers in order, and which is on screen.
|
||||
@@ -38,21 +41,25 @@ impl RailView {
|
||||
/// The rail.
|
||||
pub struct ServerRail {
|
||||
view: RailView,
|
||||
_subscription: Subscription,
|
||||
counters: Counters,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
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 {
|
||||
let view = RailView::of(app.read(cx));
|
||||
let subscription = cx.observe(app, |this: &mut Self, app, cx| {
|
||||
let (view, counters, signals) = {
|
||||
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));
|
||||
if view != this.view {
|
||||
this.view = view;
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
Self { view, _subscription: subscription }
|
||||
Self { view, counters, _subscriptions: subscriptions }
|
||||
}
|
||||
|
||||
/// What it shows now.
|
||||
@@ -160,6 +167,7 @@ fn server(theme: &VoelinTheme, item: &ServerItem, selected: bool) -> impl IntoEl
|
||||
|
||||
impl Render for ServerRail {
|
||||
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 (c, m) = (&theme.colors, &theme.metrics);
|
||||
let current = self.view.current;
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
//! 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
|
||||
//! (the next slice), the voice card while voice is connecting or connected, and
|
||||
//! the user's own card with the voice buttons. An entity of its own: it
|
||||
//! observes the root state and tells the window only when what it shows changed.
|
||||
//! `shells/common.slint`): the server on screen, its channel tree
|
||||
//! ([`super::ChannelTree`], a cached pane of its own), the voice card while
|
||||
//! 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::{
|
||||
Context, Entity, FontWeight, InteractiveElement as _, IntoElement, MouseButton, MouseUpEvent,
|
||||
ParentElement as _, Render, StatefulInteractiveElement as _, Styled as _, Subscription, Window,
|
||||
div, px,
|
||||
ParentElement as _, Render, StatefulInteractiveElement as _, StyleRefinement, Styled as _,
|
||||
Subscription, Window, div, px,
|
||||
};
|
||||
use voelin_core::TransmitMode;
|
||||
use voelin_ui_vm::Rgb;
|
||||
@@ -19,8 +20,11 @@ use voelin_ui_vm::servers::logic;
|
||||
use super::actions::{
|
||||
DisconnectVoice, Invite, OpenSettings, PushToTalk, SetInputMuted, SetOutputMuted,
|
||||
};
|
||||
use super::channels::ChannelTree;
|
||||
use super::widgets::{Avatar, IconButton, Presence, card, icon, panel};
|
||||
use crate::app::AppState;
|
||||
use crate::meter::Counters;
|
||||
use crate::signals::Area;
|
||||
use crate::theme::{VoelinTheme, hsla};
|
||||
|
||||
/// What the sidebar shows.
|
||||
@@ -81,23 +85,32 @@ impl SidebarView {
|
||||
/// The sidebar.
|
||||
pub struct Sidebar {
|
||||
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.
|
||||
holding: bool,
|
||||
_subscription: Subscription,
|
||||
counters: Counters,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl Sidebar {
|
||||
/// A sidebar that follows `app`.
|
||||
pub fn new(app: &Entity<AppState>, cx: &mut Context<Self>) -> Self {
|
||||
let view = SidebarView::of(app.read(cx));
|
||||
let subscription = cx.observe(app, |this: &mut Self, app, cx| {
|
||||
let view = SidebarView::of(app.read(cx));
|
||||
if view != this.view {
|
||||
this.view = view;
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
Self { view, holding: false, _subscription: subscription }
|
||||
/// A sidebar that follows the server on screen and the voice state in
|
||||
/// `app`, with `tree` between its cards.
|
||||
pub fn new(app: &Entity<AppState>, tree: Entity<ChannelTree>, cx: &mut Context<Self>) -> Self {
|
||||
let (view, counters, signals) = {
|
||||
let state = app.read(cx);
|
||||
(SidebarView::of(state), state.counters().clone(), state.signals().clone())
|
||||
};
|
||||
let subscriptions =
|
||||
signals.watch(app, &[Area::Servers, Area::Toolbar], cx, |this: &mut Self, app, cx| {
|
||||
let view = SidebarView::of(app.read(cx));
|
||||
if view != this.view {
|
||||
this.view = view;
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
Self { view, tree, holding: false, counters, _subscriptions: subscriptions }
|
||||
}
|
||||
|
||||
/// What it shows now.
|
||||
@@ -154,36 +167,6 @@ fn server_card(theme: &VoelinTheme, view: &SidebarView, item: &ServerItem) -> im
|
||||
)
|
||||
}
|
||||
|
||||
/// Where the channel tree goes: the next slice.
|
||||
fn channels(theme: &VoelinTheme, has_server: bool) -> impl IntoElement {
|
||||
let (c, m) = (&theme.colors, &theme.metrics);
|
||||
div()
|
||||
.id("sidebar-channels")
|
||||
.flex_1()
|
||||
.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.
|
||||
fn voice_card(
|
||||
theme: &VoelinTheme,
|
||||
@@ -400,6 +383,7 @@ fn name_initials(name: &str) -> String {
|
||||
|
||||
impl Render for Sidebar {
|
||||
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 m = &theme.metrics;
|
||||
let view = &self.view;
|
||||
@@ -413,7 +397,8 @@ impl Render for Sidebar {
|
||||
.when_some(view.server.as_ref(), |sidebar, 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| {
|
||||
sidebar.child(voice_card(&theme, view, cx))
|
||||
})
|
||||
|
||||
@@ -11,6 +11,8 @@ use gpui_kit::{
|
||||
use super::actions::{OpenSearch, OpenSettings};
|
||||
use super::widgets::{IconButton, icon};
|
||||
use crate::app::AppState;
|
||||
use crate::meter::Counters;
|
||||
use crate::signals::Area;
|
||||
use crate::theme::{VoelinTheme, hsla};
|
||||
|
||||
/// 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.
|
||||
pub struct TopBar {
|
||||
title: String,
|
||||
_subscription: Subscription,
|
||||
counters: Counters,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
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 {
|
||||
let shown = title(app.read(cx));
|
||||
let subscription = cx.observe(app, |this: &mut Self, app, cx| {
|
||||
let (shown, counters, signals) = {
|
||||
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));
|
||||
if shown != this.title {
|
||||
this.title = shown;
|
||||
cx.notify();
|
||||
}
|
||||
});
|
||||
Self { title: shown, _subscription: subscription }
|
||||
Self { title: shown, counters, _subscriptions: subscriptions }
|
||||
}
|
||||
|
||||
/// The title it shows now.
|
||||
@@ -49,6 +55,7 @@ impl TopBar {
|
||||
|
||||
impl Render for TopBar {
|
||||
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 (c, m) = (&theme.colors, &theme.metrics);
|
||||
div()
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
//! 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`]): 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 tree does not mark who is talking.** Its rows are built with
|
||||
//! `talking` cleared: a talker changes the rows of the members panel (and the
|
||||
//! sidebar's own card), not the tree's, which therefore is not drawn again
|
||||
//! with every start and stop of someone's voice. The Slint tree draws speaking
|
||||
//! bars on the row; docs/ui.md records the difference.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use gpui_kit::{Context, Entity, EventEmitter, Subscription};
|
||||
use voelin_core::ObserveState;
|
||||
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 and its presence is on the way.
|
||||
Loading,
|
||||
/// Nothing is known of the server until it is connected.
|
||||
Connect,
|
||||
}
|
||||
|
||||
impl Emptiness {
|
||||
/// Why the lists of the server on screen are empty.
|
||||
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 => Self::Loading,
|
||||
_ => Self::Connect,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What changed in the model, as the panes need it.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum TreeEvent {
|
||||
/// The tree's rows: the operations from the old rows to
|
||||
/// [`TreeModel::rows`].
|
||||
Rows(Changes),
|
||||
/// The members panel's rows: the operations from the old rows to
|
||||
/// [`TreeModel::people`].
|
||||
People(Changes),
|
||||
/// 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::total`]).
|
||||
Lists,
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
rows: Arc<Vec<TreeItem>>,
|
||||
people: Arc<Vec<MemberItem>>,
|
||||
total: i32,
|
||||
card: Option<MemberCard>,
|
||||
selected: Option<ChannelId>,
|
||||
emptiness: Emptiness,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
}
|
||||
|
||||
impl EventEmitter<TreeEvent> for TreeModel {}
|
||||
|
||||
/// Everything the model keeps, as the state gives it now.
|
||||
struct Snapshot {
|
||||
rows: Vec<TreeItem>,
|
||||
people: Vec<MemberItem>,
|
||||
total: i32,
|
||||
card: Option<MemberCard>,
|
||||
selected: Option<ChannelId>,
|
||||
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 (mut rows, people, total) = match logic::tree_view(vm, false) {
|
||||
Some(tree) => (tree.rows, tree.server_members, tree.member_total),
|
||||
None => (Vec::new(), Vec::new(), 0),
|
||||
};
|
||||
for row in &mut rows {
|
||||
row.talking = false;
|
||||
}
|
||||
Self {
|
||||
rows,
|
||||
people,
|
||||
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,
|
||||
&[Area::Tree, Area::Toolbar, Area::MemberCard],
|
||||
cx,
|
||||
|this: &mut Self, _, cx| this.refresh(cx),
|
||||
);
|
||||
Self {
|
||||
app: app.clone(),
|
||||
rows: Arc::new(snapshot.rows),
|
||||
people: Arc::new(snapshot.people),
|
||||
total: snapshot.total,
|
||||
card: snapshot.card,
|
||||
selected: snapshot.selected,
|
||||
emptiness: snapshot.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
|
||||
}
|
||||
|
||||
/// 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 lists are empty, were they.
|
||||
pub fn emptiness(&self) -> Emptiness {
|
||||
self.emptiness
|
||||
}
|
||||
|
||||
/// Build the rows again, and tell the panes what differs.
|
||||
fn refresh(&mut self, cx: &mut Context<Self>) {
|
||||
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 lists = (self.emptiness, self.total) != (new.emptiness, new.total);
|
||||
(self.emptiness, self.total) = (new.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));
|
||||
}
|
||||
if !people.is_empty() {
|
||||
cx.emit(TreeEvent::People(people));
|
||||
}
|
||||
if lists {
|
||||
cx.emit(TreeEvent::Lists);
|
||||
}
|
||||
if card {
|
||||
cx.emit(TreeEvent::Card);
|
||||
}
|
||||
if selection {
|
||||
cx.emit(TreeEvent::Selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,16 @@
|
||||
//! `shells/common.slint`'s `Panel`.
|
||||
|
||||
use gpui_kit::{
|
||||
App, ClickEvent, FontWeight, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
RenderOnce, SharedString, StatefulInteractiveElement as _, Styled as _, Window, div, img, px,
|
||||
svg,
|
||||
AnyElement, App, Background, ClickEvent, FontWeight, InteractiveElement as _, IntoElement,
|
||||
ParentElement as _, RenderOnce, SharedString, StatefulInteractiveElement as _, Styled as _,
|
||||
Window, div, linear_color_stop, linear_gradient, px, svg,
|
||||
};
|
||||
use gpui_kit::{ElementId, ObjectFit, StyledImage as _};
|
||||
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::{VoelinTheme, hsla};
|
||||
@@ -34,6 +37,8 @@ pub enum Presence {
|
||||
Info,
|
||||
/// Not connected.
|
||||
Offline,
|
||||
/// Their sound is off (a person who does not hear).
|
||||
Dnd,
|
||||
}
|
||||
|
||||
impl Presence {
|
||||
@@ -58,6 +63,7 @@ impl Presence {
|
||||
Self::Idle => Some(c.idle),
|
||||
Self::Info => Some(c.info),
|
||||
Self::Offline => Some(c.offline),
|
||||
Self::Dnd => Some(c.dnd),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,11 +73,46 @@ pub fn tint(color: Rgb) -> Rgba {
|
||||
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),
|
||||
/// else the initials on `tint`, square with rounded corners for a server
|
||||
/// and round for a person, with a presence dot and a green ring while the
|
||||
/// person's voice goes out. Pictures other than files of the cache are drawn
|
||||
/// as initials until the slices that decode them (the chat's, the members').
|
||||
/// else the initials on `tint` (one letter under 28 pixels), square with
|
||||
/// rounded corners for a server and round for a person, with a presence dot and
|
||||
/// a green ring while the person's voice goes out. The picture is keyed by the
|
||||
/// 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)]
|
||||
pub struct Avatar {
|
||||
id: ElementId,
|
||||
@@ -129,10 +170,7 @@ impl RenderOnce for Avatar {
|
||||
let theme = VoelinTheme::global(cx);
|
||||
let (c, m) = (&theme.colors, &theme.metrics);
|
||||
let radius = if self.square { m.radius_lg } else { self.size / 2.0 };
|
||||
let picture = match &*self.image {
|
||||
ImageSource::File { path, .. } if self.image.size().width > 0 => Some(path.clone()),
|
||||
_ => None,
|
||||
};
|
||||
let key = PictureKey::of(&self.image);
|
||||
let face = div()
|
||||
.size(px(self.size))
|
||||
.flex_none()
|
||||
@@ -141,16 +179,19 @@ impl RenderOnce for Avatar {
|
||||
.flex()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.bg(hsla(if picture.is_some() { c.surface_3 } else { tint(self.tint) }));
|
||||
let face = match picture {
|
||||
Some(path) => face.child(img(path).size_full().object_fit(ObjectFit::Cover)),
|
||||
None => face.child(
|
||||
div()
|
||||
.text_size(px(self.size * 0.38))
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
.text_color(hsla(Rgba(0xffff_ffff)))
|
||||
.child(self.initials),
|
||||
),
|
||||
.bg(hsla(if key.is_some() { c.surface_3 } else { tint(self.tint) }));
|
||||
let face = match key {
|
||||
Some(key) => face.child(picture(key).size_full().object_fit(ObjectFit::Cover)),
|
||||
None => {
|
||||
let (letters, size) = initials_for(&self.initials, self.size);
|
||||
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();
|
||||
if self.speaking {
|
||||
@@ -356,3 +397,136 @@ pub fn card(theme: &VoelinTheme, alpha: u8) -> gpui_kit::Div {
|
||||
pub fn tagged(selector: &'static str, element: impl IntoElement) -> impl IntoElement {
|
||||
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 {
|
||||
let c = &theme.colors;
|
||||
let bar = move |height: f32| {
|
||||
div()
|
||||
.w(px(size * 3.0 / 14.0))
|
||||
.h(px(size * height))
|
||||
.rounded(px(size / 9.0))
|
||||
.bg(hsla(c.success))
|
||||
};
|
||||
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())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::theme::Choice;
|
||||
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
+939
-23
File diff suppressed because it is too large.
Load diff
@@ -119,6 +119,56 @@ impl Refresh {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
*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.
|
||||
|
||||
@@ -59,7 +59,7 @@ impl fmt::Debug for ImageSource {
|
||||
|
||||
/// 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.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub struct Stamp {
|
||||
len: u64,
|
||||
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,
|
||||
/// and its people lead the members panel.
|
||||
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());
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// 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
|
||||
|
||||
@@ -25,6 +25,7 @@ use std::time::Instant;
|
||||
use tracing::{debug, info, warn};
|
||||
use voelin_core::stream::PeerConfig;
|
||||
use voelin_core::{Command, IdentityBlob, ObserveState};
|
||||
use voelin_model::ChannelId;
|
||||
use voelin_store::{Bookmark, QueryTransport, Secrets, Store};
|
||||
|
||||
use super::logic::{self, CREATED_IDENTITY, GatewayFound, ObservePlan};
|
||||
@@ -147,6 +148,67 @@ pub fn connect_voice_to<L>(
|
||||
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`]),
|
||||
/// 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
|
||||
@@ -356,9 +418,13 @@ pub fn delete_bookmark<L: Lines>(
|
||||
mod tests {
|
||||
use voelin_store::{MemorySecrets, QueryConfig};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use voelin_core::VoiceState;
|
||||
|
||||
use super::*;
|
||||
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.
|
||||
struct Rig {
|
||||
@@ -482,6 +548,115 @@ mod tests {
|
||||
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
|
||||
/// one on screen, and has its gateway looked up (it has none to observe
|
||||
/// through yet).
|
||||
|
||||
@@ -10,6 +10,7 @@ use tracing::warn;
|
||||
use voelin_audio::process::NoiseLevel;
|
||||
use voelin_core::settings::{Key, Kind, Settings};
|
||||
use voelin_core::{AudioSettings, TransmitMode};
|
||||
use voelin_model::ChannelId;
|
||||
|
||||
use crate::bridge::AudioForm;
|
||||
|
||||
@@ -173,6 +174,55 @@ pub static UI_WINDOW: Key<Option<WindowState>> = Key::new(
|
||||
)
|
||||
.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.
|
||||
pub fn appearance_keys() -> [&'static dyn voelin_core::settings::Setting; 6] {
|
||||
[
|
||||
@@ -750,6 +800,35 @@ mod tests {
|
||||
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]
|
||||
fn voice_compact_key() {
|
||||
let settings = voelin_core::settings::Settings::in_memory();
|
||||
|
||||
@@ -4,16 +4,18 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub use voelin_model::channel_title;
|
||||
use voelin_model::{
|
||||
BannerMode, ChannelId, ChannelInfo, ClientInfo, GroupInfo, Presence, Spacer, TreeRow, badges,
|
||||
tree_rows,
|
||||
BannerMode, ChannelInfo, ClientInfo, GroupInfo, Presence, Spacer, TreeRow, badges, tree_rows,
|
||||
};
|
||||
pub use voelin_model::{ChannelId, channel_title};
|
||||
|
||||
use voelin_core::{Contact, Relation};
|
||||
|
||||
use crate::avatar;
|
||||
use crate::bridge::{BadgeItem, MemberItem, TreeItem};
|
||||
use crate::bridge::{BadgeItem, MemberCard, MemberItem, TreeItem};
|
||||
use crate::image::ImageRef;
|
||||
use crate::settings::ClientPlaybackMap;
|
||||
use crate::state::SessionView;
|
||||
|
||||
/// A banner mode as the UI takes it (`TreeItem.banner-mode`).
|
||||
pub fn banner_mode(mode: BannerMode) -> i32 {
|
||||
@@ -54,6 +56,47 @@ pub fn badge_items(guids: &[String], pictures: &HashMap<String, PathBuf>) -> Vec
|
||||
.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.
|
||||
pub struct TreeInput<'a> {
|
||||
/// 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]
|
||||
fn channel_paths() {
|
||||
let mut p = presence();
|
||||
|
||||
@@ -426,23 +426,22 @@ impl App {
|
||||
self.state.own_uids = uids;
|
||||
}
|
||||
|
||||
/// The identity servers see us as on `bookmark` (the one place that
|
||||
/// picks it): the bookmark's own if it names one that exists, else the
|
||||
/// store's default.
|
||||
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 bookmark names, if it names one.
|
||||
fn named_identity(&self, bookmark: Option<i64>) -> Option<i64> {
|
||||
bookmark.and_then(|b| self.bookmark(b)).and_then(|b| b.identity)
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
self.identity_id_for(bookmark)
|
||||
.and_then(|id| self.store.identity(id).ok())
|
||||
.unwrap_or_else(|| self.identity.clone())
|
||||
self.store.identity_for(self.named_identity(bookmark), &self.identity)
|
||||
}
|
||||
|
||||
/// The store's default identity (`Store::default_identity`).
|
||||
|
||||
+29
-15
@@ -39,21 +39,35 @@ 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,
|
||||
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
|
||||
uncached child view on every frame), the eleven callbacks of `bind/servers.rs` as actions through
|
||||
`voelin-ui-vm`'s logic and the engine's commands, the window's size and
|
||||
position kept in `ui.window`, the engine-event task in steps and a tick that
|
||||
draws nothing. What it shows, what it costs idle and what it leaves to the
|
||||
slices after it are in docs/ui.md, "The desktop shell"; the next slice is the
|
||||
channel tree and the members. The shell was reviewed and gated the same day (an
|
||||
Opus gate: no blocker and no major, six minors), and the minors are closed on
|
||||
`phase5/gpui-shell-minors`: the records that said the parts draw only when what
|
||||
they show changed are corrected (a part tells the window, and the window draws
|
||||
every part, as gpui-pre 0.3.10 renders every uncached child view on every
|
||||
frame), a window left maximized is maximized again on X11, the pictures are
|
||||
1440 by 960, the connect test sends no DNS query, the sequences both front ends
|
||||
ran are shared in `voelin-ui-vm`, and the `ui.window` row is in the settings
|
||||
table; the gate's four risks of the shell are in docs/ui.md, "For the next
|
||||
slices".
|
||||
uncached child view on every frame), the eleven callbacks of `bind/servers.rs`
|
||||
as actions through `voelin-ui-vm`'s logic and the engine's commands, the
|
||||
window's size and position kept in `ui.window`, the engine-event task in steps
|
||||
and a tick that draws nothing. What it shows, what it costs idle and what it
|
||||
leaves to the slices after it are in docs/ui.md, "The desktop shell"; the next
|
||||
slice is the channel tree and the members. The shell was reviewed and gated the
|
||||
same day (an Opus gate: no blocker and no major, six minors), and the minors are
|
||||
closed on `phase5/gpui-shell-minors`: the records that said the parts draw only
|
||||
when what they show changed are corrected (a part tells the window, and the
|
||||
window draws every part, as gpui-pre 0.3.10 renders every uncached child view on
|
||||
every frame), a window left maximized is maximized again on X11, the pictures
|
||||
are 1440 by 960, the connect test sends no DNS query, the sequences both front
|
||||
ends ran are shared in `voelin-ui-vm`, and the `ui.window` row is in the
|
||||
settings table; the gate's four risks of the shell are in docs/ui.md, "For the
|
||||
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. The next slice is the voice page and the
|
||||
call bar.
|
||||
|
||||
| Spike | The plan's no-go | Seen (software rendering, see Setup) | Verdict |
|
||||
|---|---|---|---|
|
||||
|
||||
+393
-90
@@ -662,6 +662,7 @@ live when they change (settings page, `--set`, another window):
|
||||
| `ui.image_cache_mb` | megabytes | 256 | decoded images kept in memory (0: none) |
|
||||
| `ui.members_width` | pixels | 280 | width of the members panel (dragging its edge sets it) |
|
||||
| `ui.window` | JSON `{width, height, x?, y?, maximized}` | none | where the main window was when the last run ended: its size (the one it returns to when `maximized`), its position where the platform tells one (Wayland does not: no `x` and `y`), and whether it was maximized; the next run opens there. Read at start, not applied live; written by the GPUI front end only (the Slint app neither registers nor reads it) |
|
||||
| `ui.tree` | JSON by server id: `{"<id>": {collapsed, selected}}` | none | what each server's channel tree remembers: the channels folded shut (`collapsed`, channel ids) and the channel last selected (`selected`), under the id of the server's bookmark; a server with nothing folded or selected has no entry. Read at start, written at every fold, unfold and selection (not with the sample servers); written by the GPUI front end only (the Slint app neither registers nor reads it: its tree forgets both when it ends) |
|
||||
| `ui.voice_compact` | bool | false | the voice channel view's smaller stage (its Smaller stage / Larger stage button sets it; windows under 800 px tall always have it) |
|
||||
| `ui.image_preview_kb` | kilobytes | 8192 | pictures linked in chat (files and `[img]`) up to this size show as pictures (0: never) |
|
||||
| `notify.mentions`, `notify.private_messages`, `notify.pokes`, `notify.event_reminders`, `notify.friends_online` | off / app / desktop | desktop (friends: app) | what the bell and the desktop say about each kind |
|
||||
@@ -986,12 +987,20 @@ crates/voelin-gpui/
|
||||
default identity; what the engine is handed (history, settings)
|
||||
app.rs AppState, the root Entity: the voelin-ui-vm state and Social, the
|
||||
backend, the three loops (events in batches, a quiet tick, Later)
|
||||
and the callbacks of the Slint `bind/servers.rs` that the shell has
|
||||
(over `voelin_ui_vm::servers::sequence`, which Slint calls too)
|
||||
and the callbacks of the Slint `bind/servers.rs` that the shell, the
|
||||
channel tree and the members have (over `voelin_ui_vm::servers::
|
||||
{logic, sequence}`, which Slint calls too)
|
||||
signals.rs `Update.refresh` as per-area signals: entities with a generation
|
||||
that the panes observe
|
||||
pictures.rs the engine's pictures on screen: decoded per file and stamp, the
|
||||
copies of a file written again dropped
|
||||
view.rs MainView, the window's root view: the shell or the swatch, the
|
||||
handlers of the actions, the server form, the title, the window's place
|
||||
shell/ the desktop shell (below): rail.rs, sidebar.rs, topbar.rs,
|
||||
main_panel.rs, form.rs, toast.rs, actions.rs, widgets.rs
|
||||
handlers of the actions, the server form, the password prompt, the
|
||||
title, the window's place
|
||||
shell/ the desktop shell and its panes (below): rail.rs, sidebar.rs,
|
||||
topbar.rs, main_panel.rs, channels.rs (the tree), members.rs (the
|
||||
panel and its card), tree_model.rs, password.rs, form.rs, toast.rs,
|
||||
actions.rs, widgets.rs
|
||||
swatch.rs the swatch page (every token, widgets, icons)
|
||||
theme/ VoelinTheme: tokens.rs, components.rs, slint_parity.rs (test)
|
||||
fonts.rs Inter, from crates/voelin-ui/ui/assets/fonts
|
||||
@@ -1007,9 +1016,12 @@ crates/voelin-gpui/
|
||||
the engine's commands go out, the status line is set (the toast shows it),
|
||||
what is to be kept goes to the store and the settings (a bookmark, the UI's
|
||||
settings, the audio settings, the clients' volumes), a changed `ui.theme` or
|
||||
`ui.font_scale` reaches the theme, the warnings are logged; the rest (what to
|
||||
redraw, the notices, the pictures to decode, the streams' capture and
|
||||
decoder) is for the slices that have those parts. Three loops start with it
|
||||
`ui.font_scale` reaches the theme, the warnings are logged, the pictures the
|
||||
engine wrote again are dropped from the decoded ones, and the flags of what to
|
||||
redraw (`Update.refresh`) are raised as per-area signals once per batch
|
||||
([The channel tree and the members](#the-channel-tree-and-the-members)); the
|
||||
rest (the notices, the streams' capture and decoder) is for the slices that
|
||||
have those parts. Three loops start with it
|
||||
and end when the entity is released: **the engine's events** (a foreground
|
||||
task awaits the tokio receiver, takes what is queued, up to 64 events, in one
|
||||
update with one `cx.notify()`, and yields to GPUI's executor before the next
|
||||
@@ -1022,9 +1034,10 @@ crates/voelin-gpui/
|
||||
thread (or the gateway lookup on the engine's runtime) holds a `Later` and
|
||||
calls `later.run(|app, cx| ...)`, a queue a third foreground task drains with
|
||||
the entity, as `later(|app| ...)` does in Slint. The root notifies on every
|
||||
batch and every move of the user's; the views compare what they would show
|
||||
with what they showed and tell the window only when it differs
|
||||
([The desktop shell](#the-desktop-shell)).
|
||||
batch and every move of the user's (the window's title and the toast follow
|
||||
it); the panes listen to the signals, compare what they would show with what
|
||||
they showed and tell the window only when it differs ([The desktop
|
||||
shell](#the-desktop-shell)).
|
||||
- **Tests**: the unit tests need no display (GPUI's test platform, `#[gpui::test]`, with
|
||||
`gpui-pre`'s `test-support` as a dev-dependency beside gpui-kit's own pin: its
|
||||
`test-support` feature would make Cargo lock the unused `gpui-fast` backend and
|
||||
@@ -1037,8 +1050,13 @@ crates/voelin-gpui/
|
||||
shell on a drawn window that the tests click (a server added is in
|
||||
the rail, a click selects it and titles the window, an engine event updates the
|
||||
rail and the cards, the form adds and removes, the toast goes, an idle window is
|
||||
not told), a connect through a real engine that has no connector (it answers
|
||||
that none serves the address, which reaches the status line), the store on a
|
||||
not told), the channel tree and the members panel on the sample server's
|
||||
events (the rows, folds kept in the settings and found by the next run, a
|
||||
double-click that joins, the password prompt, a move and a mute as their
|
||||
exact row operations, a talker that redraws the members panel and no other
|
||||
pane, the member card, an avatar written again), a connect through a real
|
||||
engine that has no connector (it answers that none serves the address, which
|
||||
reaches the status line), the store on a
|
||||
directory of its own, the theme (it reaches gpui-component, follows the window's
|
||||
appearance and the text size), the Slint file's tokens equal the Rust ones
|
||||
(below), the icons and fonts load. `tests/launch_failure.rs` starts the built
|
||||
@@ -1097,11 +1115,13 @@ anyway).
|
||||
| Switch | Does |
|
||||
|---|---|
|
||||
| `VOELIN_OPEN=swatch` | the swatch page in place of the shell; the Slint front end's other pages are not here yet and are named in a warning |
|
||||
| `VOELIN_DEMO_UI=1` | the Slint front end's sample servers (`voelin_ui_vm::dev::logic`) in place of the stored ones, through the app's own events (the first is connected, the second observed); nothing is sent to the engine or kept in the store, the window's place included, and the servers cannot be changed |
|
||||
| `VOELIN_DEMO_UI=1` | the Slint front end's sample servers (`voelin_ui_vm::dev::logic`) in place of the stored ones, through the app's own events (the first is connected, with its channels, people and their pictures, the second observed); nothing is sent to the engine or kept in the store, the window's place and what the trees remember included, and the servers cannot be changed. The pictures are files of a folder of the state's own in the temporary directory, removed when the window closes (a killed run leaves it) |
|
||||
| `VOELIN_DEMO_SERVER=2` | with the sample servers, the one on screen, counting from 0: the first (the default) is connected and populated, the second observed (its tree says it is loading), the third not connected (its tree says to connect) |
|
||||
| `VOELIN_DEMO_TALK=10` | with the sample servers, one sample person starts or stops talking this many times a second (a rate from 0.1 to 100), 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 settings' `ui.theme` |
|
||||
| `VOELIN_FONT_SCALE=1.25` | the text size factor, in place of the settings' `ui.font_scale` |
|
||||
| `VOELIN_WINDOW_SIZE=1440x960` | the window's size, in place of the remembered one (`ui.window`), which it then leaves alone: the window's place is not kept while it is set |
|
||||
| `VOELIN_METER=1` | the cost meter: once a second a log line (`voelin_gpui::meter`) with the process's CPU, the CPU of each group of threads (`llvmpipe` is the software renderer, work a GPU takes over; `voelin-gpui` is GPUI's thread), the resident memory, the app's own counters per second (engine events, ticks, renders: one render is one pass of the window's root view, a frame; `Later` jobs) and the voice connections up |
|
||||
| `VOELIN_METER=1` | the cost meter: once a second a log line (`voelin_gpui::meter`) with the process's CPU, the CPU of each group of threads (`llvmpipe` is the software renderer, work a GPU takes over; `voelin-gpui` is GPUI's thread), the resident memory, the app's own counters per second (engine events, ticks, renders: one render is one pass of the window's root view, a frame; the renders of each pane, `rail`, `topbar`, `sidebar`, `tree`, `main` and `members`; `Later` jobs) and the voice connections up |
|
||||
|
||||
Screenshots are made headless, the way `scripts/shots.sh` makes the Slint
|
||||
ones: `scripts/gpui-shot.sh out.png swatch 1440x960` runs the binary under
|
||||
@@ -1156,17 +1176,18 @@ the picture was taken as `nova`).
|
||||

|
||||
|
||||
What is on screen, each part an entity of `crates/voelin-gpui/src/shell/` that
|
||||
observes the root state, makes its view of it (`voelin_ui_vm::servers::logic`:
|
||||
`rail`, `toolbar`) and tells the window only when the view differs from the one
|
||||
it showed (`cx.notify()`): an engine event about a talker, a setting that is not
|
||||
the theme's or a tick tells no part, so the window is not drawn at all (the
|
||||
`what_changes_nothing_shown_draws_nothing` test counts the parts told). A part
|
||||
that is told tells the window, and **the window draws every part**: in gpui-pre
|
||||
0.3.10 a child view embedded with `.child(entity)` is rendered again on every
|
||||
frame (only `Entity::cached` and `AnyView::cached`, which need a definite size,
|
||||
reuse a subtree until its entity is notified), so the parts' comparison saves the
|
||||
frames of a window nobody changes, not the work inside a frame ("For the next
|
||||
slices" says what the heavy panes do about it).
|
||||
listens to the signals of its area (the next section), makes its view of the
|
||||
state (`voelin_ui_vm::servers::logic`: `rail`, `toolbar`) and tells the window
|
||||
only when the view differs from the one it showed (`cx.notify()`): an engine
|
||||
event about a talker, a setting that is not the theme's or a tick tells no part,
|
||||
so the window is not drawn at all (the `what_changes_nothing_shown_draws_nothing`
|
||||
test counts the parts told). In gpui-pre 0.3.10 a child view embedded with
|
||||
`.child(entity)` is rendered again on every frame; only `Entity::cached`, which
|
||||
needs a size of its own, reuses a subtree until its entity is notified. Slice 1
|
||||
embedded every part uncached, so a part that was told made the window draw every
|
||||
part; since slice 2 the rail, the top bar, the main area, the channel tree and
|
||||
the members panel are cached and only the sidebar's cards and the toast are
|
||||
rendered with every frame ([what a change costs](#what-a-change-costs)).
|
||||
|
||||
- **The rail** (`rail.rs`): the app's mark, then the saved servers as 46 pixel
|
||||
rounded squares (the server's icon from the engine's cache, else its initials
|
||||
@@ -1178,15 +1199,15 @@ slices" says what the heavy panes do about it).
|
||||
"Voelin"), the search box and the settings button, which log that their
|
||||
slices are to come (`OpenSearch`, `OpenSettings`).
|
||||
- **The sidebar** (`sidebar.rs`): the server on screen (name, "9 online · 9
|
||||
channels" once its presence is known, else its address), the place of the
|
||||
channel tree (slice 2), the voice card while voice is connecting or connected
|
||||
channels" once its presence is known, else its address), the channel tree
|
||||
(slice 2), the voice card while voice is connecting or connected
|
||||
(the channel we are in, copy an invite, disconnect, and Hold to talk when the
|
||||
transmit mode is push-to-talk) and the user's card (nickname, Online,
|
||||
Observing or Offline, the microphone and sound buttons, which work with
|
||||
voice).
|
||||
- **The main area** (`main_panel.rs`): "No server selected" with an Add a server
|
||||
button, or the server on screen (name, address, its state) with Connect or
|
||||
Disconnect and Edit, until the pages of the next slices come.
|
||||
Disconnect and Edit, until the voice page and the chat come.
|
||||
- **The server form** (`form.rs`), in the place of the main area until the
|
||||
dialogs slice: address (all a server needs), name (empty: the server's own),
|
||||
nickname (the default identity's, else the system user's) and the server's
|
||||
@@ -1219,12 +1240,12 @@ front end](#shared-with-the-slint-front-end)):
|
||||
| `delete_bookmark` | `DeleteServer { id }` | `CloseSession`, the secrets and the store, `logic::forget_server` |
|
||||
| `invite` | `Invite` | `logic::invite_link`, the link on the clipboard, the status line's note |
|
||||
|
||||
The others of that file are the next slices': `search_members`,
|
||||
`show_voice_view`, `join_channel`, `join_with_password`, `toggle_collapse`,
|
||||
`open_client` and `client_audio_changed` (the channel tree, the members, the
|
||||
voice page), and `copied`, which the Slint toast of a copy needs and `Invite`
|
||||
does for itself. `AddServer`, `CancelServerForm`, `OpenSearch` and
|
||||
`OpenSettings` are the shell's own.
|
||||
The others of that file: `join_channel`, `join_with_password`, `toggle_collapse`,
|
||||
`search_members` and `open_client` are slice 2's ([the channel tree and the
|
||||
members](#the-channel-tree-and-the-members)); `show_voice_view` is the voice
|
||||
page's (slice 3), `client_audio_changed` the dialogs', and `copied`, which the
|
||||
Slint toast of a copy needs, `Invite` does for itself. `AddServer`,
|
||||
`CancelServerForm`, `OpenSearch` and `OpenSettings` are the shell's own.
|
||||
|
||||
#### Shared with the Slint front end
|
||||
|
||||
@@ -1234,24 +1255,34 @@ wrappers, so its call sites are unchanged):
|
||||
|
||||
- **`voelin_ui_vm::servers::sequence`**: `connect_voice_to`, `connect_voice`,
|
||||
`observe`, `discover_gateway`, `gateway_found`, `select_server`,
|
||||
`save_bookmark`, `save_and_connect`, `delete_bookmark`, `bookmark_form` and
|
||||
`default_nickname`. Each is a transition over the state, the `Cx` and a
|
||||
`Backing` (the store, the secrets and the identity a connection is made
|
||||
with), so the engine's commands, the status line, what is to be kept and the
|
||||
gateways to look up (`Update::discover`) go out through the update, and
|
||||
each front end's `perform` and its tests handle them as they handle every
|
||||
other transition's (the GPUI tests see the commands as `take_sent`, and the
|
||||
sample servers' are dropped there). `transition_with` of each front end hands
|
||||
the `Backing` over: the GPUI root state's and the Slint `App`'s own fields.
|
||||
`stream_peer` is the one input a front end gives (the Slint one's
|
||||
`video.peer_config`; this one passes none).
|
||||
`save_bookmark`, `save_and_connect`, `delete_bookmark`, `bookmark_form`,
|
||||
`default_nickname` and, since the channel tree, `join_channel` and
|
||||
`join_with_password` (over `connect_into`). Each is a transition over the
|
||||
state, the `Cx` and a `Backing` (the store, the secrets and the identity a
|
||||
connection is made with), so the engine's commands, the status line, what is
|
||||
to be kept and the gateways to look up (`Update::discover`) go out through the
|
||||
update, and each front end's `perform` and its tests handle them as they
|
||||
handle every other transition's (the GPUI tests see the commands as
|
||||
`take_sent`, and the sample servers' are dropped there). `transition_with` of
|
||||
each front end hands the `Backing` over: the GPUI root state's and the Slint
|
||||
`App`'s own fields. `stream_peer` is the one input a front end gives (the
|
||||
Slint one's `video.peer_config`; this one passes none).
|
||||
- **`voelin_ui_vm::settings::open_settings`** and `register_keys`: the settings
|
||||
service on `client.db` with the UI's keys, `config.toml`, `VOELIN_SETTING_*`
|
||||
and `--set`; each front end registers its own key (`ui.window` here, the
|
||||
Stream Studio's `studio.ui` there) through the function it passes.
|
||||
- **`voelin_store::FallbackSecrets`** (the keyring first, memory where it
|
||||
refuses) and **`Store::identity_for`** (the identity a bookmark names, else
|
||||
the default, else the one made at start).
|
||||
the default, else the one made at start); the Slint settings page's own copy
|
||||
of the identity choice calls the store's since the tree slice.
|
||||
- **`voelin_ui_vm::tree::member_card`** (the card over a member row),
|
||||
**`servers::logic::open_member`**, `Refresh::merge` (the flags of a batch of
|
||||
events) and the `ui.tree` key (`settings::UI_TREE`, `TreeState`: the channels
|
||||
each server's tree has folded and the one selected, written by the GPUI front
|
||||
end like `ui.window` and not read by the Slint one). Slint's `bind/servers.rs`
|
||||
and `members.rs` keep their own versions of the joins, the card and the open
|
||||
card, since `voelin-ui` is edited only for the identity helper in this round
|
||||
("For the next slices").
|
||||
|
||||
Left as copies, because they need the toolkit, the runtime or a front end's own
|
||||
state: the thread hop of the gateway lookup (`look_up_gateway`: each front end
|
||||
@@ -1290,20 +1321,23 @@ managers, places new windows itself; Wayland tells no position at all, so none
|
||||
is kept there), maximized if it was. **Maximized** is asked for twice: GPUI
|
||||
asks when it creates the window (`WindowBounds::Maximized`: a Wayland
|
||||
compositor is expected to honour that, which was not run here), and the window
|
||||
asks again when its first frame is drawn if it is not maximized by then (`MainView`: `Window::zoom_window`, which
|
||||
toggles on X11, hence the check), because an X11 window manager manages a window
|
||||
only from its map, so the early request is lost (openbox: the window opened at
|
||||
its restored size). Until the window has been seen maximized, what it reports
|
||||
is the place it opened with and is not kept, so a run that ends before the
|
||||
window manager answers, or one whose window manager never maximizes (a tiling
|
||||
one), leaves `maximized: true` as it found it; once it has been seen maximized,
|
||||
what the window reports is the user's (restoring it is kept). A maximized
|
||||
window is kept with the size it returns to (X11 reports the screen's; Wayland
|
||||
the size it returns to). The `maximized` request itself needs a real window:
|
||||
GPUI's test platform has no zoom, so the tests count the request and report the
|
||||
window manager's answer themselves; it was seen at run time under openbox
|
||||
(below). A development switch that sets the size or the sample data leaves the
|
||||
setting alone.
|
||||
asks again when its first frame is drawn if it is not maximized by then
|
||||
(`MainView`: `Window::zoom_window`, which toggles on X11, hence the check),
|
||||
because an X11 window manager manages a window only from its map, so the early
|
||||
request is lost (openbox: the window opened at its restored size). The first two
|
||||
windowed reports of a window opened to be maximized (the place it opened with,
|
||||
and the configure an X11 window manager may send when it maps the window) are
|
||||
not kept, so a run that ends before the window manager answers leaves
|
||||
`maximized: true` as it found it; the reports after them are the user's, kept
|
||||
whether or not the window was seen maximized (a resize before the window
|
||||
manager answered, or under one that never maximizes, a tiling one, is kept),
|
||||
and once it has been seen maximized what it reports is the user's too
|
||||
(restoring it is kept). A maximized window is kept with the size it returns to
|
||||
(X11 reports the screen's; Wayland the size it returns to). The `maximized`
|
||||
request itself needs a real window: GPUI's test platform has no zoom, so the
|
||||
tests count the request and report the window manager's answer themselves; it
|
||||
was seen at run time under openbox (below). A development switch that sets the
|
||||
size or the sample data leaves the setting alone.
|
||||
|
||||
Seen at run time (the debug build of the commit that made it, Xvfb `:143` of
|
||||
3840 by 2160 with openbox and Mesa's lavapipe, a state directory under the
|
||||
@@ -1367,6 +1401,259 @@ two seconds. (The close found a panic in the foundation's wait for the engine's
|
||||
closes, which no run had reached; it is fixed and a test calls the wait from
|
||||
the GPUI thread.)
|
||||
|
||||
### The channel tree and the members
|
||||
|
||||
Slice 2 of plan section 6 step 3: the sidebar's channel tree and the members
|
||||
panel of the server on screen, with the callbacks of the Slint
|
||||
`bind/servers.rs` that belong to them, on the same `voelin-ui-vm` rows
|
||||
(`servers::logic::tree_view`) as the Slint front end.
|
||||
|
||||
| An empty server (not connected) | A server on screen |
|
||||
|---|---|
|
||||
|  |  |
|
||||
|  |  |
|
||||
|
||||
The pictures are the shell at 1440 by 960 under `scripts/gpui-shot.sh` (the
|
||||
recipe above, on a display of its own, with the state under the checkout's
|
||||
`.scratch/`): the right ones are the first sample server (`VOELIN_DEMO_UI=1`:
|
||||
nine people in four groups and the streaming section, nested channels with a
|
||||
centred, a right-aligned and a line spacer, banners, icons, badges, a locked
|
||||
channel), the left ones the third (`VOELIN_DEMO_SERVER=2`: not connected, so
|
||||
its tree and its panel say to connect). The two of the first sample server were
|
||||
taken again for the review's fixes (the release build of `bad5312`, lavapipe
|
||||
through Vulkan on Xvfb `:201` of 3840 by 2160 with openbox, 1440 by 960): the
|
||||
banner rows, Raid Night and Music, are under the veil, and the avatars of the
|
||||
tree show one letter.
|
||||
|
||||
What is on screen:
|
||||
|
||||
- **The channel tree** (`channels.rs`, in the sidebar between the server card
|
||||
and the voice card): the channels of the server with the people in them as
|
||||
`voelin_ui_vm::tree::rows` makes them, nested 14 pixels a level. A channel
|
||||
row has its icon (the server's own picture, else a speaker, else a lock), its
|
||||
name as the server set it out (a spacer is centred, right-aligned or a line
|
||||
cut where the row ends), its lock at the end when it has an icon of its own,
|
||||
how many are in it ("3" or "3/50", with a users mark on ours), the chevron,
|
||||
the banner picture behind it and our channel highlighted. The banner has the
|
||||
veil of `components/banner-picture.slint` over it (`widgets::banner_scrim`:
|
||||
the surface colour, 74 % opaque on the left to 66 % on the right, under the
|
||||
tint of our channel), so the name keeps more than 4.5 to 1 against any
|
||||
picture in both themes (a test states it for the weakest end over a black
|
||||
and a white picture). A person's row has their avatar (the first letter
|
||||
only, at half the size, under 28 pixels as `avatar.slint` does), name (ours
|
||||
in the accent colour, someone away muted), badges, a
|
||||
LIVE tag while they stream, the marks of local mute (or volume) and of their
|
||||
microphone and sound, "away", and the icons of their groups. A click selects a
|
||||
channel, a double-click joins it, the chevron folds it, a right-click offers
|
||||
Join channel, Fold or unfold and Edit channel (logged: the channel editor is a
|
||||
slice of its own) and, on a person, Show the card, Volume… (logged: the volume
|
||||
dialog) and Move to my channel (logged: the engine has no command for moving
|
||||
another client); a click on a person is the volume dialog's, logged too.
|
||||
- **The members panel** (`members.rs`, as wide as `ui.members_width`, 280 by
|
||||
default, for a server on screen): "Members — 9", a search, and everyone in
|
||||
sections, each with its heading and count: the people streaming first, then
|
||||
each server group in the server's order. A person has their avatar with the
|
||||
presence dot (away, sound off, there) and the green ring while they talk,
|
||||
their name with the crown of an admin group, the star of a priority speaker,
|
||||
the flag of a channel commander, the record mark and up to three badges, what
|
||||
they do ("Speaking" with its bars, "Streaming", "Away: brb", "In Lobby"), a
|
||||
moderator's role, LIVE, the mute marks and the hand of a person who needs talk
|
||||
power. The search narrows the sections to the names it matches.
|
||||
- **The member card**: a click on a person opens their card over the panel with
|
||||
a scrim a click outside closes: name, status, description, groups, badges (what
|
||||
each is for on hover), talk power and country. It follows the person while it
|
||||
is open and goes when they leave.
|
||||
- **The password prompt**: joining a channel that has a password and whose
|
||||
password was not given this connection asks for it (a card over the window,
|
||||
Enter joins); a password the server refuses asks again, in words. As in the
|
||||
Slint dialog, Join is off and Enter does nothing while the field is empty
|
||||
(the prompt stays), and Escape closes it without joining.
|
||||
|
||||
#### Per-area signals and cached panes
|
||||
|
||||
The foundation's and the shell's reviews left the design for this slice: a
|
||||
change of the channel tree must not draw the rail, and a talker must not draw
|
||||
the tree. Two parts of it came from reading gpui-pre 0.3.10 and were checked by
|
||||
the tests:
|
||||
|
||||
- **`Update.refresh` is raised as signals** (`signals.rs`). The root state
|
||||
turns the flags of an update into entities with a generation, one per area
|
||||
(servers, toolbar, tree, member card), once per batch of engine events and
|
||||
once per transition, and the rail, the top bar, the sidebar and the tree
|
||||
model listen to their areas instead of asking the root whether anything
|
||||
changed for them. The flags of areas that have no pane yet (chat, streams,
|
||||
...) are dropped, as `perform` dropped all of them before.
|
||||
- **Panes are cached** (`Entity::cached`, which needs a size of its own): the
|
||||
rail, the top bar, the main area, the channel tree and the members panel are
|
||||
rendered again only when their entity was notified, which the meter counts
|
||||
(`rail`, `topbar`, `sidebar`, `tree`, `main` and `members` per second beside
|
||||
the window's frames). Three rules came with it. A cached pane's root must be
|
||||
`size_full` (laid out on its own it is as large as its contents, which showed
|
||||
as a main area as wide as its text). The ancestors of a notified view are
|
||||
notified too, and a view rendered again renders the cached views inside it
|
||||
again (its `refreshing` mode ignores their caches), so cached panes are
|
||||
siblings under uncached containers (`MainView` and the plain divs): the tree
|
||||
is cached inside the sidebar, which is not, and the sidebar is rendered with
|
||||
every frame. A per-row entity inside a pane buys nothing for the same reason
|
||||
(a row's notify makes the pane render, and the pane's render makes the cached
|
||||
rows render), so the unit is the pane and a virtual list keeps what it builds
|
||||
to the rows in view.
|
||||
- **A narrow model between the state and the panes** (`tree_model.rs`): one
|
||||
entity builds the rows for both panes on the tree, toolbar and member-card
|
||||
signals, compares them with the rows it had (`voelin_ui_vm::list::diff`, the
|
||||
operations the Slint front end applies to its `VecModel`) and emits what
|
||||
differs. A pane applies the operations to its list state (`gpui::ListState`:
|
||||
a person who joins is a row inserted and the scroll stays where it was), and a
|
||||
change that moves none of the rows of a pane emits nothing to it.
|
||||
- **The tree carries no `talking`.** Its rows are built with the flag cleared,
|
||||
so someone who starts or stops talking changes the members panel (and the
|
||||
sidebar's own card when it is us) and not the tree: its pane is not rendered
|
||||
(the `a_talker_does_not_draw_the_tree_again` test counts it). The Slint tree
|
||||
draws speaking bars on the row, which would redraw the tree with every start
|
||||
and stop of someone's voice; this front end leaves them to the members panel.
|
||||
|
||||
#### What a change costs
|
||||
|
||||
`VOELIN_METER=1`, release build of `faef132`, 1440 by 960 on Mesa 26.2.5's
|
||||
lavapipe through Vulkan on Xvfb `:151` and `:152` with openbox, the first sample
|
||||
server on screen (nine people, nine channels), the machine's other jobs at a
|
||||
load average of 38 to 100 (the first run, of the tree committed as `aa640cf`,
|
||||
which was built just before that commit, at 21 to 43, is below); the first 15
|
||||
seconds of 75 left out, 60 samples of one second (59 for the second run: the
|
||||
loaded machine left a second out); CPU in percent of one core, whose resolution
|
||||
is the 1 % of a clock tick; renders per second as the meter counts them (the
|
||||
window's frames, and each pane's passes):
|
||||
|
||||
| | CPU, mean (max) | Of it `llvmpipe` | GPUI's thread | Resident memory | Window frames a second | Rendered a second: rail, top bar, sidebar, tree, main, members |
|
||||
|---|---|---|---|---|---|---|
|
||||
| Idle, the first sample server on screen | 0.5 % (2 %) | none above 0.5 % | under 1 % (the tick) | 220.0 MiB | 0.0 | 0, 0, 0, 0, 0, 0 |
|
||||
| A sample person starts or stops talking 10 times a second (`VOELIN_DEMO_TALK=10`) | 97.1 % (106 %) | 90.8 % | 5.0 % | 226.7 MiB | 9.7 | 0, 0, 9.7, 0, 0, 9.7 |
|
||||
|
||||
A window nobody touches is not drawn, with the tree and the panel on screen as
|
||||
before (the shell alone was 192.7 MiB; the pictures and the two panes' state
|
||||
are the difference, not itemized). Someone who talks is one engine event and so
|
||||
one frame: the members panel is the only pane that is rendered for it, and the
|
||||
sidebar, which every frame renders (its cards are small and have no size of
|
||||
their own to cache at); the rail, the top bar, the main area and the tree are
|
||||
not rendered at all in the 570 events of the run. GPUI's own thread spends 5 %
|
||||
of a core on the 9.7 frames a second (the first run, of the `aa640cf` tree on a
|
||||
quieter machine, 3.4 % at 10.0 frames, with `llvmpipe` at 100.9 % and 105.4 % in
|
||||
all; the loaded machine starved the process of a frame in ten).
|
||||
The rest is the software device: `llvmpipe` draws the whole 1440 by 960 window
|
||||
again for every frame, about 90 ms of CPU a frame on this machine, which a GPU
|
||||
does; so the figure that says what a talker costs the app is the thread's, and
|
||||
the one that says what a window nobody touches costs is the idle row. (The
|
||||
Slint tree draws speaking bars on its rows; with them the tree pane would be
|
||||
rendered for each of those frames too, which is why this one does not: not
|
||||
measured.)
|
||||
|
||||
**Again after the review's fixes** (the banner veil, one letter on small avatars
|
||||
and the password prompt change what a row draws, not when a pane is rendered):
|
||||
the same two runs on the release build of `bad5312`, Xvfb `:211` and `:212` of
|
||||
3840 by 2160 with openbox, the machine at a load average of 23 to 40, 60 samples
|
||||
each. Idle: 0.6 % (2 %), 219.9 MiB, no pane rendered and no frame. A sample
|
||||
person talking 10 times a second: 106.4 % (111 %) in all, `llvmpipe` 102.3 %,
|
||||
GPUI's thread 3.1 %, 225.9 MiB, 10.0 frames a second, rendered per second 0, 0,
|
||||
10.0, 0, 0, 10.0 (the sidebar and the members panel only, as above).
|
||||
|
||||
**Seen against a server** (the TeamSpeak 3 development server of
|
||||
`dev/docker-compose.yml`, 3.13.8, release build of the tree committed as
|
||||
`aa640cf` (built just before that commit, whose own changes to the tests came
|
||||
after; the fixup `faef132` touches the sample pictures and two small things the
|
||||
run did not meet), Xvfb `:160` of its own with openbox, lavapipe, no sound card,
|
||||
the state under the checkout's `.scratch/`; a spacer heading, a sub-channel, a
|
||||
channel with a password and one limited to five clients were made over
|
||||
ServerQuery for the run and deleted after it): the form's Save and connect shows
|
||||
the real tree (Default Channel with our client, "1 online · 7 channels", the
|
||||
lock, "0/5") and the panel ("Members — 1", "Guest — 1"). A double-click on a
|
||||
channel moved the client there (`clientlist -voice` over ServerQuery: channel
|
||||
4); the locked channel asked for its password, the server refused a wrong one
|
||||
and the prompt asked again in words, the right one moved the client (channel 6);
|
||||
a click on the person opened their card with their group. What was folded and
|
||||
selected was in `ui.tree` and found by the next two processes (the fold of one
|
||||
channel and the selection of another, after a restart and a reconnect). Closing
|
||||
the window with Alt+F4 ended the app with exit status 0 and left no ghost client
|
||||
on the server. The machine's load average was 355 to 497 from other builds while
|
||||
the closes were timed (7 s from the key to the exit, 14 s against TeamSpeak 6),
|
||||
so no bound is taken from them. Against the TeamSpeak 6 server (6.0.0-beta13.1)
|
||||
the same form shows "1 online · 1 channel", the tree and the panel, and the
|
||||
close ends with status 0; its ghosts were not looked for (its ServerQuery is
|
||||
SSH).
|
||||
|
||||
**Against the servers again after the review's fixes** (release build of
|
||||
`bad5312`, Xvfb `:221` of 3000 by 1800 with openbox, lavapipe, the state under
|
||||
the checkout's `.scratch/`; over ServerQuery an `Open Room` with a sub-channel
|
||||
`Child`, a `[cspacer]Heading`, a `Locked Room` with a password and `Five Max`
|
||||
limited to five clients were made for the run and deleted after it): the
|
||||
TeamSpeak 3 server's tree and panel ("1 online · 6 channels", the lock, "0/5",
|
||||
"Members — 1"); a double-click on Open Room moved the client there
|
||||
(`clientlist -voice`: channel 2); on Locked Room the prompt opened with Join
|
||||
dimmed, Enter on the empty field kept it open and moved nothing, Escape closed
|
||||
it (still channel 2); opened again, a wrong password was refused by the server
|
||||
and the prompt asked again in words, the right one moved the client (channel 4).
|
||||
Alt+F4 ended the app with status 0, 3.3 s after the key, and left no ghost
|
||||
client on the server. Against the TeamSpeak 6 server the form showed "1 online ·
|
||||
1 channel", the tree and the panel, and the close ended with status 0.
|
||||
|
||||
#### The callbacks and the properties
|
||||
|
||||
The plan counts "about 13 properties and 6 callbacks" for the two panes. The
|
||||
tables list every property and callback of the Slint `Bridge` (and of `Nav`,
|
||||
whose functions call it) that `screens/channels.slint` and
|
||||
`screens/members.slint` use, and the password dialog's, each with what takes it
|
||||
here or the slice that will: 12 properties and 9 callbacks of the `Bridge` and
|
||||
3 functions of `Nav` in the two files, the `members` property that the voice
|
||||
page reads, and `join_with_password` of `dialogs.slint`. The 13 properties are
|
||||
the first 13 of the second table, up to `server_banner`, each name counted once;
|
||||
the 6 callbacks are the first six rows of the first (the sixth only logs), the
|
||||
seventh standing in for the chat. The callbacks are GPUI actions
|
||||
(`shell/actions.rs`) handled by `MainView` as the shell's are, over
|
||||
`voelin-ui-vm`'s `servers::logic` and `servers::sequence`:
|
||||
|
||||
| Slint callback (used by) | Action | What it does, or the slice that takes it |
|
||||
|---|---|---|
|
||||
| `join_channel` (`channels.slint`) | `JoinChannel { channel }` | `sequence::join_channel`: `Command::MoveToChannel` with voice up, the password prompt for a locked channel unless its password was given this connection, a connect into the channel (by its id) without voice |
|
||||
| `join_with_password` (`dialogs.slint`, `ChannelPasswordDialog`) | `SubmitChannelPassword`, `CancelChannelPassword` | the prompt's Join, `sequence::join_with_password` with what its field holds (an empty field joins nothing and leaves the prompt open); its Cancel, and Escape |
|
||||
| `toggle_collapse` (`channels.slint`) | `ToggleChannel { channel }` | `logic::toggle_collapse`, kept for the server in `ui.tree` |
|
||||
| `search_members` (`members.slint`) | `SearchMembers { text }` | `logic::search_members` |
|
||||
| `open_member` (`members.slint`) | `OpenMember { client }` | `logic::open_member` (-1 closes the card) |
|
||||
| `open_client` (`channels.slint`, through `Nav.open_client`, which says whether the dialog opened) | `OpenClient { client }` | logged: the person's volume dialog comes with the dialogs slice (9) |
|
||||
| `open_channel_chat` (`channels.slint`, a click on a channel's row) | `SelectChannel { channel }` | selects the channel, kept in `ui.tree`; it opens the channel's chat with the chat slice (4) |
|
||||
| `connect_voice` (`channels.slint`, the server card's Connect) | `ConnectVoice` | slice 1 (the shell) |
|
||||
| `Nav.add_server`, `Nav.edit_server` (`channels.slint`, the server card's menu) | `AddServer`, `EditServer { id }` | slice 1 (the shell) |
|
||||
| `watch_client` (`channels.slint`, the LIVE tag of a person who streams) | none | the tag is drawn and not clickable: the stream viewer, slice 6 |
|
||||
| `member_action("mute")` and `member_volume` (`members.slint`, the card's mute button and volume slider) | none | the card has no buttons yet: the person's volume, with `open_client` and `client_audio_changed`, the dialogs slice (9) |
|
||||
| `member_action("watch")` | none | the stream viewer, slice 6 |
|
||||
| `member_action("message")` | none | the chat, slice 4 |
|
||||
| `member_action("poke")` | none | the poke dialog, the dialogs slice (9) |
|
||||
| `member_action("friend")`, `member_action("blocked")` | none | friends, slice 7 |
|
||||
| (no Slint counterpart: the context menus) | `EditChannel`, `MoveClient` | logged: the channel editor, and a command for moving a client |
|
||||
|
||||
| Slint property (used by) | Here |
|
||||
|---|---|
|
||||
| `tree` (`channels.slint`) | `TreeModel::rows`, the `talking` flag cleared |
|
||||
| `server_members` (`members.slint`) | `TreeModel::people` |
|
||||
| `member_total` (`members.slint`) | `TreeModel::total` ("Members — N") |
|
||||
| `member_card` (`members.slint`) | `TreeModel::card` (`voelin_ui_vm::tree::member_card`), shown by `MemberCardView` |
|
||||
| `members` (the people in our channel: the voice page, not the two files) | built by `tree_view` and not shown: the voice page (slice 3) draws it |
|
||||
| `current_server` (`channels.slint`) | `AppState::vm.current` (slice 1) |
|
||||
| `observing` (`channels.slint`, `members.slint`) | `SidebarView::observing` (slice 1: the user's card says Observing); here also `Emptiness`, the words of a list with nothing in it ("No server yet.", "Loading the channels…", "Connect to see the channels.") |
|
||||
| `server_title`, `server_icon`, `server_stats` (`channels.slint`, the server card) | slice 1: the sidebar's server card (`ServerItem`'s name and icon, `SidebarView::stats`, "9 online · 9 channels") |
|
||||
| `voice_connected`, `voice_connecting` (`channels.slint`, the server card and its Connect) | slice 1: `SidebarView::voice_connected` and `voice_connecting`, the voice card ("Voice Connected", "Connecting…") |
|
||||
| `server_banner` (`channels.slint`, the server card's picture) | not drawn: the sidebar's server card has no banner behind it. The same `BannerPicture` and veil (`widgets::banner_scrim`, which the tree's rows use) would do; it comes with the slice that lays the sidebar's cards again, the voice page and call bar (3) |
|
||||
| `Nav.right_panel_width`, `Nav.right_panel_open` (the frame, `desktop.slint`, not the two files) | `ui.members_width`, read at start (no resize handle yet), and the panel is there while a server is on screen (the pins and topics drawers that share it come with the chat) |
|
||||
|
||||
`show_voice_view` (the voice page) and `client_audio_changed` (the volume
|
||||
dialog) are the other server callbacks of the Bridge that these panes will meet
|
||||
later; neither file uses them.
|
||||
|
||||
What differs from the Slint tree and panel, beside the tree's talkers above:
|
||||
the speaking bars stand still (nothing here may draw the window with the clock);
|
||||
the lists scroll with the wheel and have no scrollbar; a click on a channel
|
||||
selects it where Slint opens its chat; the card has no buttons; the members
|
||||
panel has no resize handle; the fill spacer's line is drawn with the channel's
|
||||
own characters, as the rows give it; the sidebar's server card has no banner.
|
||||
|
||||
### The theme
|
||||
|
||||
Two layers (docs/design/gpui-spikes.md, "The theme against Theme tokens"):
|
||||
@@ -1428,13 +1715,19 @@ Slint `Bridge` (`ui/bridge.slint:801-1206`; properties / callbacks):
|
||||
1. the **desktop shell** (done, [above](#the-desktop-shell)): the server rail,
|
||||
the sidebar, the top bar, the empty main area, window state (about 13 / 11,
|
||||
`bind/servers.rs`), the store and the settings opened as in Slint's `run()`;
|
||||
2. **next: the channel tree and the members** (about 13 / 6): the sidebar's
|
||||
placeholder becomes `logic::tree_view`'s rows (`TreeItem`, `MemberItem`), the
|
||||
callbacks `join_channel`, `join_with_password`, `toggle_collapse`,
|
||||
`search_members`, `show_voice_view`, `open_client` and `client_audio_changed`
|
||||
become actions beside the shell's, and the password prompt the transitions ask
|
||||
for (`Update::password`, which the root state only logs today) gets its dialog;
|
||||
3. the voice page and the call bar (6 / 6);
|
||||
2. the **channel tree and the members** (done,
|
||||
[above](#the-channel-tree-and-the-members); about 13 / 6):
|
||||
`logic::tree_view`'s rows (`TreeItem`, `MemberItem`) in the sidebar and the
|
||||
members panel, the callbacks `join_channel`, `join_with_password`,
|
||||
`toggle_collapse`, `search_members` and `open_member` as actions beside the
|
||||
shell's (`open_client` logged), and the password prompt the transitions ask
|
||||
for;
|
||||
3. **next: the voice page and the call bar** (6 / 6): the people of our
|
||||
channel (`TreeView::members`, built and not shown yet), `show_voice_view`,
|
||||
the voice card's controls, the sidebar's server card with the banner behind
|
||||
it (`server_banner`, which the tree slice left out:
|
||||
[the table](#the-callbacks-and-the-properties)), and the release guard of
|
||||
Hold to talk (below);
|
||||
4. chat, the composer and emoji (about 19 / 18, and the `Emoji` global 3 / 3):
|
||||
first the two open choices of the report that it touches
|
||||
(design/gpui-spikes.md, "Open choices for step 3"): emoji (the one-line
|
||||
@@ -1462,28 +1755,38 @@ entries); the in-window keys as GPUI key bindings and the global ones through
|
||||
What the foundation's review and the Opus gate (2026-10-27) found and left to
|
||||
the slices that meet it; none of it is a defect of what exists today.
|
||||
|
||||
- **A part's notify draws the whole window, and `Update.refresh` is not used
|
||||
yet.** The root notifies on every batch and each part compares the whole view
|
||||
it would show with the one it showed; a part that differs tells the window,
|
||||
and the window renders every uncached child view (gpui-pre 0.3.10: only
|
||||
`Entity::cached` and `AnyView::cached` skip one). With a rail, a sidebar and a
|
||||
top bar that costs little; the channel tree and the members of slice 2 (and
|
||||
later the chat's list and the stream tiles) are heavy, and one talker's
|
||||
indicator must not render the rail and the chat. Slice 2 embeds the heavy panes
|
||||
with `Entity::cached` (a definite size is needed: the pane's bounds come from
|
||||
its place in the layout) and turns `Update.refresh` (`voelin_ui_vm::host::
|
||||
Refresh`: `servers`, `toolbar`, `tree`, `chat`, ...; `perform` drops it today)
|
||||
into per-area signals, a generation or a flag per pane that its entity
|
||||
observes, so that a change of the tree or the members notifies those panes and
|
||||
not the rail and the chat.
|
||||
- **`Update.reloaded` is ignored, and `img()` caches by path.** `perform` drops
|
||||
`Update.reloaded` (the pictures the engine wrote again, whose decoded copies a
|
||||
front end drops). GPUI's `img()` caches what it decoded per source in the
|
||||
asset cache, so a picture rewritten into the same cache file (a server icon or
|
||||
an avatar that changed) stays stale on screen. The slice that shows engine
|
||||
pictures (slice 2: avatars, the tree's icons) drops the decoded copy for each
|
||||
path of `reloaded` (`ImageSource::remove_asset`, and `drop_image` for what the
|
||||
atlas holds) or keys the image by something that changes with the file.
|
||||
- **Settled by the tree slice: the panes, the signals and the pictures.**
|
||||
`Update.refresh` is raised as per-area signals, the rail, the top bar, the
|
||||
main area, the tree and the members panel are cached panes, and the pictures
|
||||
the engine writes again are keyed by their file's stamp and the copies of the
|
||||
old ones dropped (`signals.rs`, `pictures.rs`; [the channel tree and the
|
||||
members](#the-channel-tree-and-the-members)). A slice that adds a heavy pane
|
||||
(the chat's list, the stream tiles) gives it an entity of its own, a size of
|
||||
its own and a signal of its own, embeds it cached as a sibling of the other
|
||||
panes (a cached view inside a view that renders again is rendered again), and
|
||||
raises its flag from `Signals::areas`. A new area is one more variant of
|
||||
`signals::Area`.
|
||||
- **A click renders every pane; a hover only the pane it is over.** In gpui-pre
|
||||
0.3.10 pressing a clickable element and releasing it call `window.refresh()`
|
||||
(`elements/div.rs`), which ignores every cache for that frame, so a click on a
|
||||
row draws the cached panes as well (on the test platform one click was three
|
||||
frames and two renders of each pane; the
|
||||
`a_click_renders_every_pane_and_a_hover_only_the_pane_it_is_over` test holds
|
||||
it). A `hover` style notifies the entity that holds the element, so a pointer
|
||||
that moves onto another row renders the tree and nothing cached beside it.
|
||||
What the caches save is the stream of engine events (a talker, a join), not
|
||||
the user's own clicks.
|
||||
- **The tree's and the panel's lists have no scrollbar and the panel no resize
|
||||
handle**; the wheel scrolls (`gpui::ListState`), as the voice page's and the
|
||||
chat's lists will have to as well, with gpui-component's scrollbar if it fits
|
||||
a `ListState`, and `ui.members_width` is read at start.
|
||||
- **Three copies stay in the Slint crate**, because `voelin-ui` is not edited
|
||||
beyond the identity helper in this round: `connect_into` and the two joins of
|
||||
`bind/servers.rs` (the shared ones are `sequence::join_channel`,
|
||||
`join_with_password` and its `connect_into`), the card `refresh_member_card`
|
||||
builds inline (`tree::member_card`), and `open_member` setting the session's
|
||||
field (`logic::open_member`). They go with Slint (step 9), or each is a call
|
||||
of the shared one when the Slint crate is next touched.
|
||||
- **`SettingChanged` for the audio and the playback keys is not reloaded.**
|
||||
`AppState::setting_changed` follows `ui.theme` and `ui.font_scale` only; the
|
||||
Slint front end also reloads `audio` (unless the page has unsaved edits) and
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 144 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 153 KiB |
Reference in new issue
Block a user