voelin-gpui: VOELIN_DEMO_SERVER, the logged Move to my channel, and what a click costs

- VOELIN_DEMO_SERVER=<0..2> puts another sample server on screen: the second
  is observed and the third is not connected, both with empty trees, which is
  how the pictures of an empty server are made.
- The person's context menu offers Move to my channel; the engine has no
  command to move another client, so the action is logged.
- A test that holds what the caches cannot save: pressing and releasing a
  clickable element refresh the window, so a click renders every pane, and a
  hover renders only the pane the pointer is over.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-28 00:14:46 +03:00
1 parent 26302bcdde
commit aa640cf2b0
5 files changed
+119 -4

No files matched your search

+25
View File
@@ -418,6 +418,12 @@ impl AppState {
// settings and bookmarks are not kept. // settings and bookmarks are not kept.
self.log_warnings(update.warnings); 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.vm.status.clear();
self.counters.connections.set(self.connections() as u64); self.counters.connections.set(self.connections() as u64);
} }
@@ -1714,6 +1720,25 @@ mod tests {
assert!(!folder.exists(), "removed with the state"); assert!(!folder.exists(), "removed with the state");
} }
/// `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 /// With `VOELIN_DEMO_TALK` a sample person starts and stops talking at the
/// rate asked, through the events a server would send. /// rate asked, through the events a server would send.
#[gpui::test] #[gpui::test]
+16
View File
@@ -9,6 +9,9 @@
//! skipped. //! skipped.
//! - `VOELIN_DEMO_UI=1`: the Slint front end's sample servers, shown through //! - `VOELIN_DEMO_UI=1`: the Slint front end's sample servers, shown through
//! the app's own events; nothing is sent to the engine or kept in the store. //! the app's own events; 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 //! - `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 //! starts and stops talking this many times a second, through the app's own
//! events (what the meter measures while someone talks). //! events (what the meter measures while someone talks).
@@ -39,6 +42,9 @@ pub struct Switches {
pub open: Page, pub open: Page,
/// Show the sample servers instead of the stored ones. /// Show the sample servers instead of the stored ones.
pub demo_ui: bool, pub demo_ui: bool,
/// 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 /// How many times a second a sample person starts or stops talking (with
/// the sample servers), when the switch names a rate. /// the sample servers), when the switch names a rate.
pub demo_talk: Option<f32>, pub demo_talk: Option<f32>,
@@ -57,6 +63,7 @@ impl Default for Switches {
Self { Self {
open: Page::Shell, open: Page::Shell,
demo_ui: false, demo_ui: false,
demo_server: None,
demo_talk: None, demo_talk: None,
theme: None, theme: None,
font_scale: None, font_scale: None,
@@ -104,6 +111,12 @@ impl Switches {
None => tracing::warn!("VOELIN_WINDOW_SIZE={text}: WIDTHxHEIGHT, such as 1440x960"), None => tracing::warn!("VOELIN_WINDOW_SIZE={text}: WIDTHxHEIGHT, such as 1440x960"),
} }
} }
if let Some(text) = get("VOELIN_DEMO_SERVER") {
match text.trim().parse::<usize>() {
Ok(place) if place < 3 => switches.demo_server = Some(place),
_ => tracing::warn!("VOELIN_DEMO_SERVER={text}: 0, 1 or 2 (a sample server)"),
}
}
if let Some(text) = get("VOELIN_DEMO_TALK") { if let Some(text) = get("VOELIN_DEMO_TALK") {
match text.trim().parse::<f32>() { match text.trim().parse::<f32>() {
Ok(rate) if (0.1..=100.0).contains(&rate) => switches.demo_talk = Some(rate), Ok(rate) if (0.1..=100.0).contains(&rate) => switches.demo_talk = Some(rate),
@@ -146,6 +159,7 @@ mod tests {
let s = env(&[ let s = env(&[
("VOELIN_OPEN", "swatch"), ("VOELIN_OPEN", "swatch"),
("VOELIN_DEMO_UI", "1"), ("VOELIN_DEMO_UI", "1"),
("VOELIN_DEMO_SERVER", "2"),
("VOELIN_DEMO_TALK", "10"), ("VOELIN_DEMO_TALK", "10"),
("VOELIN_DEV_THEME", "light"), ("VOELIN_DEV_THEME", "light"),
("VOELIN_FONT_SCALE", "1.25"), ("VOELIN_FONT_SCALE", "1.25"),
@@ -154,6 +168,7 @@ mod tests {
]); ]);
assert_eq!(s.open, Page::Swatch); assert_eq!(s.open, Page::Swatch);
assert!(s.demo_ui); assert!(s.demo_ui);
assert_eq!(s.demo_server, Some(2));
assert_eq!(s.demo_talk, Some(10.0)); assert_eq!(s.demo_talk, Some(10.0));
assert_eq!(s.theme, Some(Choice::Light)); assert_eq!(s.theme, Some(Choice::Light));
assert_eq!(s.font_scale, Some(1.25)); assert_eq!(s.font_scale, Some(1.25));
@@ -169,6 +184,7 @@ mod tests {
("VOELIN_FONT_SCALE", "9"), ("VOELIN_FONT_SCALE", "9"),
("VOELIN_WINDOW_SIZE", "10x10"), ("VOELIN_WINDOW_SIZE", "10x10"),
("VOELIN_DEMO_UI", "0"), ("VOELIN_DEMO_UI", "0"),
("VOELIN_DEMO_SERVER", "7"),
("VOELIN_DEMO_TALK", "fast"), ("VOELIN_DEMO_TALK", "fast"),
("VOELIN_METER", "0"), ("VOELIN_METER", "0"),
]); ]);
+9
View File
@@ -127,6 +127,15 @@ pub struct EditChannel {
pub channel: u64, 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, /// `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. /// which is a dialog of its own slice: today it is logged.
#[derive(Clone, Debug, PartialEq, Action)] #[derive(Clone, Debug, PartialEq, Action)]
+3 -1
View File
@@ -26,7 +26,7 @@ use voelin_ui_vm::bridge::TreeItem;
use voelin_ui_vm::tree::ChannelId; use voelin_ui_vm::tree::ChannelId;
use super::actions::{ use super::actions::{
EditChannel, JoinChannel, OpenClient, OpenMember, SelectChannel, ToggleChannel, EditChannel, JoinChannel, MoveClient, OpenClient, OpenMember, SelectChannel, ToggleChannel,
}; };
use super::tree_model::{Emptiness, TreeEvent, TreeModel}; use super::tree_model::{Emptiness, TreeEvent, TreeModel};
use super::widgets::{Avatar, icon, live_badge, small_picture}; use super::widgets::{Avatar, icon, live_badge, small_picture};
@@ -364,6 +364,8 @@ fn client_row(theme: &VoelinTheme, item: &TreeItem) -> AnyElement {
.context_menu(move |menu, _, _| { .context_menu(move |menu, _, _| {
menu.menu("Show the card", Box::new(OpenMember { client: id as i32 })) menu.menu("Show the card", Box::new(OpenMember { client: id as i32 }))
.menu("Volume…", Box::new(OpenClient { client: id as u16 })) .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() .into_any_element()
} }
+66 -3
View File
@@ -18,9 +18,10 @@ use crate::dev::Page;
use crate::meter::Counters; use crate::meter::Counters;
use crate::shell::actions::{ use crate::shell::actions::{
AddServer, CancelChannelPassword, CancelServerForm, ConnectVoice, DeleteServer, AddServer, CancelChannelPassword, CancelServerForm, ConnectVoice, DeleteServer,
DisconnectVoice, EditChannel, EditServer, Invite, JoinChannel, OpenClient, OpenMember, DisconnectVoice, EditChannel, EditServer, Invite, JoinChannel, MoveClient, OpenClient,
OpenSearch, OpenSettings, PushToTalk, SaveAndConnect, SaveServer, SearchMembers, SelectChannel, OpenMember, OpenSearch, OpenSettings, PushToTalk, SaveAndConnect, SaveServer, SearchMembers,
SelectServer, SetInputMuted, SetOutputMuted, SubmitChannelPassword, ToggleChannel, SelectChannel, SelectServer, SetInputMuted, SetOutputMuted, SubmitChannelPassword,
ToggleChannel,
}; };
use crate::shell::{ use crate::shell::{
ChannelPassword, ChannelTree, Emptiness, MainPanel, MemberCardView, MembersPane, ServerForm, ChannelPassword, ChannelTree, Emptiness, MainPanel, MemberCardView, MembersPane, ServerForm,
@@ -313,6 +314,13 @@ impl MainView {
); );
} }
fn move_client(&mut self, action: &MoveClient, _: &mut Window, _: &mut Context<Self>) {
tracing::info!(
client = action.client,
"moving a client needs a command the engine does not have yet"
);
}
fn search_members(&mut self, action: &SearchMembers, _: &mut Window, cx: &mut Context<Self>) { fn search_members(&mut self, action: &SearchMembers, _: &mut Window, cx: &mut Context<Self>) {
self.app.update(cx, |app, cx| app.search_members(action.text.clone(), cx)); self.app.update(cx, |app, cx| app.search_members(action.text.clone(), cx));
} }
@@ -446,6 +454,7 @@ impl Render for MainView {
.on_action(cx.listener(Self::toggle_channel)) .on_action(cx.listener(Self::toggle_channel))
.on_action(cx.listener(Self::edit_channel)) .on_action(cx.listener(Self::edit_channel))
.on_action(cx.listener(Self::open_client)) .on_action(cx.listener(Self::open_client))
.on_action(cx.listener(Self::move_client))
.on_action(cx.listener(Self::search_members)) .on_action(cx.listener(Self::search_members))
.on_action(cx.listener(Self::open_member)) .on_action(cx.listener(Self::open_member))
.on_action(cx.listener(Self::submit_channel_password)) .on_action(cx.listener(Self::submit_channel_password))
@@ -521,6 +530,7 @@ mod tests {
use crate::backend::testing::TempDir; use crate::backend::testing::TempDir;
use crate::dev::Switches; use crate::dev::Switches;
use crate::pictures::PictureKey; use crate::pictures::PictureKey;
use crate::shell::actions::{EditChannel, MoveClient, OpenClient};
use crate::shell::{RailView, TreeEvent}; use crate::shell::{RailView, TreeEvent};
use crate::theme::Choice; use crate::theme::Choice;
use crate::window_bounds; use crate::window_bounds;
@@ -1428,6 +1438,59 @@ mod tests {
assert!(cx.update(|_, cx| crate::pictures::is_cached(&second, cx)), "the new one is drawn"); assert!(cx.update(|_, cx| crate::pictures::is_cached(&second, cx)), "the new one is drawn");
} }
/// What the context menus offer that has no slice yet (the channel editor,
/// a person's volume dialog, moving a client) is logged and sends nothing.
#[gpui::test]
fn the_menu_entries_of_later_slices_are_logged_and_send_nothing(cx: &mut TestAppContext) {
let (shell, cx) = open(cx, Backend::in_memory().unwrap(), Switches::default());
sample_server(&shell, cx);
shell.app.read_with(cx, |app, _| app.take_sent());
cx.dispatch_action(EditChannel { channel: 2 });
cx.dispatch_action(OpenClient { client: 3 });
cx.dispatch_action(MoveClient { client: 3 });
frame(cx);
assert!(shell.app.read_with(cx, |app, _| app.take_sent()).is_empty());
// A click on a person is the volume dialog's: logged too, and not on us.
click(cx, "tree-client-3");
click(cx, "tree-client-1");
assert!(shell.app.read_with(cx, |app, _| app.take_sent()).is_empty());
}
/// What the caches cannot save: GPUI refreshes the window (every view renders
/// again, cached ones too) when a clickable element is pressed and when it is
/// released, so a click renders every pane; a pointer that moves onto another
/// row renders only the pane that holds the row.
#[gpui::test]
fn a_click_renders_every_pane_and_a_hover_only_the_pane_it_is_over(cx: &mut TestAppContext) {
let (shell, cx) = open(cx, Backend::in_memory().unwrap(), Switches::default());
sample_server(&shell, cx);
let panes = &shell.counters.panes;
let seen = || {
[&panes.rail, &panes.topbar, &panes.sidebar, &panes.tree, &panes.main, &panes.members]
.map(|pane| pane.get())
};
let before = seen();
click(cx, "tree-channel-6");
let after = seen();
assert!(
before.iter().zip(&after).all(|(before, after)| after > before),
"every pane: {before:?} -> {after:?}"
);
// A pointer onto a row of the tree: the tree, and nothing cached beside it.
let before = seen();
let position = at(cx, "tree-channel-8").expect("a row").center();
cx.simulate_mouse_move(position, None, Default::default());
frame(cx);
let after = seen();
assert_eq!(after[3], before[3] + 1, "the tree: {before:?} -> {after:?}");
assert_eq!(
[after[0], after[1], after[4], after[5]],
[before[0], before[1], before[4], before[5]],
"not the rail, the top bar, the main area or the members panel"
);
}
/// The plus of the rail opens the form; Save with an address adds the /// The plus of the rail opens the form; Save with an address adds the
/// server, selects it and closes the form. /// server, selects it and closes the form.
#[gpui::test] #[gpui::test]