voelin-gpui: the transmit mode, the volumes and the stage follow the settings

SettingChanged is no longer ignored for the keys the voice page depends on, as
the Slint front end's setting_changed reads them again: `audio` (the transmit
mode: the voice card has Hold to talk for push-to-talk and says "Voice
activity" or "Open microphone" for the other modes, where it had a button or
nothing), `client_playback` (the clients' volumes: the tree and the card show
who is muted) and `ui.voice_compact` (the voice page's stage). The areas that
show them are raised; the development switches keep what they set, and the
sample servers' stage is not read back.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-28 10:15:31 +03:00
1 parent 0b55811e5a
commit 04223a785c
3 files changed
+131 -9

No files matched your search

+23 -6
View File
@@ -660,7 +660,7 @@ impl AppState {
/// ([`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,
mut refresh,
status,
commands,
persist,
@@ -696,7 +696,7 @@ impl AppState {
}
// What the front end keeps itself comes before the drawing.
if let Some(Event::SettingChanged { key }) = rest {
self.setting_changed(&key, cx);
refresh.merge(self.setting_changed(&key, cx));
}
refresh
}
@@ -740,16 +740,33 @@ impl AppState {
}
}
/// A setting changed, maybe elsewhere (a command, another window): take
/// the values the window keeps copies of. Today that is what the theme
/// follows; the development switches keep what they set.
fn setting_changed(&mut self, key: &str, cx: &mut Context<Self>) {
/// A setting changed, maybe elsewhere (a command, another window, the
/// config file): take the values the window keeps copies of, and say which
/// areas show them. What the theme follows is applied (the development
/// switches keep what they set); the audio settings (the transmit mode
/// decides whether the voice card has Hold to talk), the clients' volumes
/// (the tree and the card show who is muted) and the smaller stage of the
/// voice page are read again, as the Slint front end's `setting_changed`
/// does.
fn setting_changed(&mut self, key: &str, cx: &mut Context<Self>) -> Refresh {
let mut refresh = Refresh::default();
if key == UI_THEME.name() || key == UI_FONT_SCALE.name() {
let (choice, scale) = appearance(&self.backend.prefs, &self.switches);
let appearance = cx.window_appearance();
VoelinTheme::set_choice(cx, choice, appearance);
VoelinTheme::set_font_scale(cx, scale);
} else if key == AUDIO.name() && !self.vm.audio_dirty {
self.vm.audio = self.backend.prefs.get(&AUDIO);
refresh.toolbar = true;
} else if key == CLIENT_PLAYBACK.name() {
self.vm.playback = self.backend.prefs.get(&CLIENT_PLAYBACK);
refresh.tree = true;
refresh.member_card = true;
} else if key == UI_VOICE_COMPACT.name() && !self.switches.demo_ui {
// The stage's own observer (MainView's) hears the root notify.
self.voice_compact = self.backend.prefs.get(&UI_VOICE_COMPACT);
}
refresh
}
/// The once-a-second work: what the Slint front end's `App::tick` will be
+35 -1
View File
@@ -58,6 +58,9 @@ pub struct SidebarView {
pub transmitting: bool,
/// The transmit mode is push-to-talk, so the card has a hold-to-talk button.
pub hold_to_talk: bool,
/// How our voice is sent, as the audio settings say: the card has the
/// button for push-to-talk and says the mode otherwise.
pub transmit: TransmitMode,
}
impl SidebarView {
@@ -83,6 +86,7 @@ impl SidebarView {
output_muted: card.output_muted,
transmitting: card.transmitting,
hold_to_talk: app.vm.audio.transmit == TransmitMode::PushToTalk,
transmit: app.vm.audio.transmit,
}
}
}
@@ -205,7 +209,17 @@ fn server_card(theme: &VoelinTheme, view: &SidebarView, item: &ServerItem) -> im
)
}
/// "Voice Connected" and our channel, disconnect and hold to talk.
/// How our voice is sent, in words, for the modes that have no button.
fn transmit_words(mode: TransmitMode) -> &'static str {
match mode {
TransmitMode::PushToTalk => "Push to talk",
TransmitMode::VoiceActivation => "Voice activity",
TransmitMode::Continuous => "Open microphone",
}
}
/// "Voice Connected" and our channel, disconnect, and Hold to talk in the
/// push-to-talk mode (the other modes say themselves).
fn voice_card(
theme: &VoelinTheme,
view: &SidebarView,
@@ -273,6 +287,26 @@ fn voice_card(
}),
),
)
.when(view.voice_connected && !view.hold_to_talk, |card| {
card.child(
div()
.id("transmit-mode")
.debug_selector(|| "transmit-mode".into())
.h(px(m.control_height_sm))
.flex()
.flex_row()
.items_center()
.justify_center()
.gap(px(m.space_2))
.child(icon("mic", m.icon_sm, c.text_muted))
.child(
div()
.text_size(px(m.font_sm))
.text_color(hsla(c.text_muted))
.child(transmit_words(view.transmit)),
),
)
})
.when(view.voice_connected && view.hold_to_talk, |card| {
card.child(
div()
+73 -2
View File
@@ -9,10 +9,13 @@ use std::sync::Arc;
use gpui::{TestAppContext, VisualTestContext};
use gpui_kit::{MouseButton, px, size};
use voelin_core::{Command, Event, SessionState, VoiceState};
use voelin_core::settings::AUDIO;
use voelin_core::{AudioSettings, Command, Event, SessionState, TransmitMode, VoiceState};
use voelin_ui_vm::bridge::MemberItem;
use voelin_ui_vm::dev::logic as sample;
use voelin_ui_vm::settings::UI_VOICE_COMPACT;
use voelin_ui_vm::settings::{
CLIENT_PLAYBACK, ClientPlayback, ClientPlaybackMap, UI_VOICE_COMPACT,
};
use super::tests::{Shell, at, click, frame, open, sample_server};
use crate::backend::Backend;
@@ -497,3 +500,71 @@ fn the_global_hotkey_is_not_cut_by_the_window_losing_the_focus(cx: &mut TestAppC
shell.app.update(cx, |app, cx| app.hotkey_transmit(false, cx));
assert_eq!(transmits(&shell, cx), [false], "the key's release ends it");
}
/// A setting changed elsewhere (a command, the config file) reaches the window.
fn setting_changed(shell: &Shell, cx: &mut VisualTestContext, key: &str) {
shell.events.send(Event::SettingChanged { key: key.into() }).unwrap();
frame(cx);
}
/// The voice card follows the transmit mode the audio settings give: the button
/// for push-to-talk, the mode in words for the others, live when the setting
/// changes elsewhere.
#[gpui::test]
fn the_voice_card_follows_the_transmit_mode_the_settings_give(cx: &mut TestAppContext) {
let (shell, cx) = tall(cx, Switches::default());
assert!(at(cx, "hold-to-talk").is_some() && at(cx, "transmit-mode").is_none(), "push-to-talk");
for (mode, words) in [
(TransmitMode::VoiceActivation, "Voice activity"),
(TransmitMode::Continuous, "Open microphone"),
] {
let audio = AudioSettings { transmit: mode, ..Default::default() };
shell.app.read_with(cx, |app, _| app.backend().prefs.set(&AUDIO, audio).unwrap());
setting_changed(&shell, cx, AUDIO.name());
assert!(at(cx, "hold-to-talk").is_none(), "{mode:?}: no button");
assert!(at(cx, "transmit-mode").is_some(), "{mode:?}: it says {words}");
let seen = shell.view.read_with(cx, |view, cx| view.sidebar_view(cx).transmit);
assert_eq!(seen, mode);
}
shell
.app
.read_with(cx, |app, _| app.backend().prefs.set(&AUDIO, AudioSettings::default()).unwrap());
setting_changed(&shell, cx, AUDIO.name());
assert!(at(cx, "hold-to-talk").is_some() && at(cx, "transmit-mode").is_none(), "back");
}
/// A person's volume changed elsewhere shows in the tree and on the card, and
/// the smaller stage chosen elsewhere reaches the page.
#[gpui::test]
fn a_volume_and_a_stage_changed_elsewhere_reach_the_window(cx: &mut TestAppContext) {
let (shell, cx) = on_the_voice_page(cx, Switches::default());
let row = |shell: &Shell, cx: &mut VisualTestContext| {
shell.view.read_with(cx, |view, cx| {
view.tree_model()
.read(cx)
.rows()
.iter()
.find(|r| !r.is_channel && r.id == 3)
.cloned()
.unwrap()
})
};
assert!(!row(&shell, cx).local_muted);
let playback = ClientPlaybackMap::from([(
"demo-3".to_owned(),
ClientPlayback { volume: 1.5, muted: true },
)]);
shell.app.read_with(cx, |app, _| app.backend().prefs.set(&CLIENT_PLAYBACK, playback).unwrap());
setting_changed(&shell, cx, CLIENT_PLAYBACK.name());
let kairo = row(&shell, cx);
assert!(kairo.local_muted, "Kairo is muted for us now");
assert_eq!(kairo.local_volume, 150);
let compact = |shell: &Shell, cx: &mut VisualTestContext| {
shell.view.read_with(cx, |view, cx| view.voice_page().read(cx).compact_shown())
};
assert!(!compact(&shell, cx));
shell.app.read_with(cx, |app, _| app.backend().prefs.set(&UI_VOICE_COMPACT, true).unwrap());
setting_changed(&shell, cx, UI_VOICE_COMPACT.name());
assert!(compact(&shell, cx), "the page is on the smaller stage");
}