From d1450439d51d0c25ecee71471e42af5ea04eca6d Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 27 Nov 2026 16:21:26 +0300 Subject: [PATCH] Render channel commander status and confirm self-only changes --- CHANGELOG.md | 2 + FEATURE_COMPATIBILITY.md | 2 + core/src/menu_session.rs | 2 +- core/tests/bridge_smoke.rs | 6 + docs/mobile-port-progress.md | 2 + native/src/app/runtime/controller.rs | 3 + native/src/app/runtime/mod.rs | 8 +- native/src/app/runtime/model.rs | 26 +- native/src/app/server_actions/context.rs | 24 ++ native/src/smoke.rs | 1 + native/src/smoke/channel_commander.rs | 181 ++++++++++++++ native/src/smoke/participant_commander.rs | 284 ++++++++++++++++++++++ native/src/smoke/tabs.rs | 11 +- native/src/ui/application.rs | 5 +- native/src/ui/shell.rs | 10 +- native/src/ui/shell/forms.rs | 2 +- native/src/ui/shell/types.rs | 2 +- native/src/ui/theme.rs | 5 + native/ui/shell.slint | 125 ++++++---- native/ui/theme.slint | 3 + 20 files changed, 640 insertions(+), 64 deletions(-) create mode 100644 native/src/smoke/channel_commander.rs create mode 100644 native/src/smoke/participant_commander.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index ef9bde5..3091dc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Channel commanders have a separate indicator in the detailed tree. The compact tree uses the saved commander lamp setting. Only the user's own row offers a commander change, and its confirmation reflects the current server flag. + - Participant volume changes while dragging the fader; releasing it saves the gain by UID. Mute stays local to the connection. Reset removes the saved modifier and unmutes the participant. - The participant menu reads the selected client's capabilities on opening. Late replies cannot change a closed or reopened menu, and unavailable server actions stay disabled. diff --git a/FEATURE_COMPATIBILITY.md b/FEATURE_COMPATIBILITY.md index e8d58e8..9ca9d8e 100644 --- a/FEATURE_COMPATIBILITY.md +++ b/FEATURE_COMPATIBILITY.md @@ -2,6 +2,8 @@ ## Current Windows account-free checkpoint (2026-11-26) +**Channel commander on Windows:** Slint rendering tests verified the compact lamp versus separate icon, the detailed-tree icon, and preference persistence in English/dark and Russian/light fixtures. On private beta14 the other guest's menu had no commander action. The server refused the self change with PermissionsClientInsufficient; both flags remained off and the old confirmation could not affect the replacement identity. Four native checks and two core checks passed. A successful authorized commander change on beta14 remains unverified. + **Participant volume:** On private beta14 the Slint fader applied -10 dB during the drag without saving it, then persisted it on release. Muting the peer did not change the listener's own gain. Reconnecting the listener restored -10 dB for the peer without restoring mute; Reset returned the gain to 0 dB and removed the stored modifier. Twelve native checks covered ordering, persistence and error handling. Three core tests covered two-speaker Opus mixing, stale queued audio and reused client numbers. No physical capture or playback device was used. **Participant context on Windows:** On private beta14, two muted guests opened the self and peer menus on both tabs. Poke, volume, Connection Info and group availability matched independently queried capabilities for the selected client ID, UID and generation. The test inspected an eligible group choice without submitting it. Escape preserved selection and whisper targeting. A separate popup test verified one request per opening and rejection of stale responses after reopening. Five native and two core checks passed. diff --git a/core/src/menu_session.rs b/core/src/menu_session.rs index 41d82a6..49928b1 100644 --- a/core/src/menu_session.rs +++ b/core/src/menu_session.rs @@ -13,7 +13,7 @@ impl Session { pub(super) async fn client_action(&mut self, id: &str, request: ActionRequest) -> Result, ErrorObj> { let c=self.connected_conn()?; - if request.generation!=c.generation{return Err(menu::bad("connection changed; reopen the menu"));} + if request.generation!=c.generation{return Err(ErrorObj::new(ErrorCode::TargetChanged,"connection changed; reopen the menu"));} let book=c.con.get_state().map_err(|e|lib_error(ErrorCode::NotConnected,&e))?; let context=c.permissions.context(book,&request.target,c.generation)?; let key=request.action.key(); diff --git a/core/tests/bridge_smoke.rs b/core/tests/bridge_smoke.rs index c0bb658..968f780 100644 --- a/core/tests/bridge_smoke.rs +++ b/core/tests/bridge_smoke.rs @@ -267,6 +267,12 @@ fn client_menu_commands_are_validated_and_never_fake_success_offline() { } let (r,_)=core.request("invalid-stats","client_action",json!({"client_id":42,"uid":"fixture","generation":9_007_199_254_740_992u64,"action":"connection_info"})); assert_eq!(r["error"]["code"],"bad_request","{r}"); + for flag in [None,Some(json!(1)),Some(Value::Null)] { + let mut args=json!({"client_id":42,"uid":"fixture","generation":1,"action":"commander"}); + if let Some(flag)=flag {args["enabled"]=flag;} + let (reply,_) = core.request("invalid-commander","client_action",args); + assert_eq!(reply["error"]["code"],"bad_request","{reply}"); + } let actions=[ json!({"action":"poke","message":"fixture"}),json!({"action":"connection_info"}), json!({"action":"commander","enabled":true}),json!({"action":"server_group","group_id":6,"enabled":true}), diff --git a/docs/mobile-port-progress.md b/docs/mobile-port-progress.md index 339d69f..e132f4d 100644 --- a/docs/mobile-port-progress.md +++ b/docs/mobile-port-progress.md @@ -4,6 +4,8 @@ ## Возврат к разработке на ПК, 2026-11-26 +Windows, база `d9570f3`: закрыт `preference:channelCommanderAsLamp` по отрисовке Slint и восстановлению настройки. Для `client-action:commander` проверены меню собственной строки, отказ гостю на beta14 и устаревшее подтверждение; положительное изменение флага не подтверждено. Прошли четыре нативные и две проверки ядра. Стенд остановлен. + Windows, база `b266f4f`: закрыты `preload:setClientVolume` и `client-action:volume`. На beta14 проверены движение ползунка, сохранение при отпускании, локальный mute, переподключение и сброс. Прошли 12 нативных и три проверки ядра. Два источника Opus проверялись отдельно в микшере, без физических устройств. Стенд остановлен. Windows, база `62bb67b`: закрыт `command:client_context`. На beta14 доступность действий и групп в меню обоих клиентов совпала с ответами ядра. Повторное открытие и устаревшие ответы проверены отдельно. Прошли пять нативных и две проверки ядра. Права не менялись; стенд остановлен. diff --git a/native/src/app/runtime/controller.rs b/native/src/app/runtime/controller.rs index cd9ee4d..47243ed 100644 --- a/native/src/app/runtime/controller.rs +++ b/native/src/app/runtime/controller.rs @@ -45,6 +45,9 @@ pub(super) fn require_server_editor_target(ctx: &RuntimeServices, target: &Targe .and_then(|session| session.server.as_ref()).ok_or_else(changed)?; match (operation, &target.entity) { (Operation::SetNickname, Entity::Connection) => Ok(()), + (Operation::ClientCommander, Entity::Client { id, uid, .. }) if *id != 0 && !uid.is_empty() + && server["own_client_id"].as_u64() == Some(u64::from(*id)) && server["clients"].as_array().is_some_and(|rows| + rows.iter().any(|row| row["id"] == *id && row["uid"].as_str() == Some(uid.as_str()))) => Ok(()), (Operation::ServerEdit, Entity::Server { uid }) if !uid.is_empty() && server["server"]["uid"].as_str() == Some(uid.as_str()) => Ok(()), (Operation::ChannelEdit, Entity::Channel { id }) if *id != 0 diff --git a/native/src/app/runtime/mod.rs b/native/src/app/runtime/mod.rs index 903ba15..a8db75e 100644 --- a/native/src/app/runtime/mod.rs +++ b/native/src/app/runtime/mod.rs @@ -199,7 +199,7 @@ async fn run(config:AppConfig,runtime:Weak,mut commands:mpsc::Receiv continue; } if matches!(prompts.front(), Some(Dialog::ServerEditor { form, submitting: true, .. }) - if form.operation == Operation::ClientPoke && form.id == editor_id && form.target == target) { continue; } + if matches!(form.operation,Operation::ClientPoke|Operation::ClientCommander) && form.id == editor_id && form.target == target) { continue; } if prompts.front().is_some_and(|dialog|dialog.form().id==editor_id&&(matches!(dialog,Dialog::Prompt(_))||dialog.form().target==target)){ if let Some(Dialog::Prompt(prompt))=prompts.pop_front(){let _=prompt.answer.send(Err(ServiceError::new("cancelled","Dialog cancelled")));} project_dialog(&mut state,&prompts); @@ -214,9 +214,13 @@ async fn run(config:AppConfig,runtime:Weak,mut commands:mpsc::Receiv } }, RuntimeCommand::Shell(ShellAction::Submit{operation:Operation::ClientVolume,..})=>{}, - RuntimeCommand::Shell(ShellAction::Submit{editor_id,target,operation,values,confirmation}) if forms::tracks_server_ack(operation)=>{ + RuntimeCommand::Shell(ShellAction::Submit{editor_id,target,operation,mut values,confirmation}) if forms::tracks_server_ack(operation)=>{ let (Some(owner), Some(Dialog::ServerEditor { form, ui_generation, submitting })) = (&owner, prompts.front_mut()) else { continue }; if *submitting || form.id != editor_id || form.target != target || form.operation != operation || owner.ctx.require_ui_generation(*ui_generation).is_err() { continue } + if operation==Operation::ClientCommander { + let Some(field)=form.fields.iter().find(|f|f.id=="enabled" && !f.enabled) else{continue}; + values.insert("enabled".into(),field.value.clone()); + } if let Some(expected) = &form.confirmation { if expected != &confirmation { let message = state.snapshot.catalog.format("native.form.confirm", &[("target", expected)]); diff --git a/native/src/app/runtime/model.rs b/native/src/app/runtime/model.rs index 8d37df7..603f811 100644 --- a/native/src/app/runtime/model.rs +++ b/native/src/app/runtime/model.rs @@ -573,14 +573,17 @@ impl TreeProjection<'_> { row.muted=client["input_muted"]==true||client["input_hardware"]==false; row.talking=self.talking.contains(&client_id); let talk_power=if client["is_talker"]==true{Operation::TalkRevoke}else{Operation::TalkGrant}; - row.actions=actions(&target,&[Operation::ClientPoke,Operation::ClientVolume,Operation::ClientConnectionInfo,Operation::ClientServerGroupAdd,Operation::ClientServerGroupRemove,Operation::ClientChannelGroupSet,Operation::ClientPermissions,Operation::ClientChannelPermissionSet,Operation::ClientChannelPermissionRemove,Operation::ClientWhisperAdd,Operation::ClientKickChannel,Operation::ClientKickServer,Operation::ClientBan,Operation::ClientInfo,Operation::ClientPrivateChat,Operation::ClientMove,Operation::ClientCommander,Operation::ClientAvatarChoose,Operation::ClientAvatarDelete,talk_power,Operation::ContactAdd],self.catalog); + let own=client["is_self"]==true||index.own_client==Some(u64::from(client_id)); + let operations=[Operation::ClientCommander,Operation::ClientPoke,Operation::ClientVolume,Operation::ClientConnectionInfo,Operation::ClientServerGroupAdd,Operation::ClientServerGroupRemove,Operation::ClientChannelGroupSet,Operation::ClientPermissions,Operation::ClientChannelPermissionSet,Operation::ClientChannelPermissionRemove,Operation::ClientWhisperAdd,Operation::ClientKickChannel,Operation::ClientKickServer,Operation::ClientBan,Operation::ClientInfo,Operation::ClientPrivateChat,Operation::ClientMove,Operation::ClientAvatarChoose,Operation::ClientAvatarDelete,talk_power,Operation::ContactAdd]; + row.actions=actions(&target,&operations[usize::from(!own)..],self.catalog); let appearance=TreeAppearance::Client { - own: client["is_self"]==true||index.own_client==Some(u64::from(client_id)), + own, contact: false, deafened: client["output_muted"]==true||client["output_hardware"]==false, away: client["away"]==true, recording: client["is_recording"]==true, streaming: client["is_streaming"]==true, + commander: client["is_channel_commander"]==true, }; self.tree.push(TreeEntry {row,appearance}); } @@ -939,6 +942,25 @@ mod tests { assert_eq!(index.clients[&2].visible.iter().map(|(id,_,_)|*id).collect::>(),[5,4,3,2,1]); } + #[test] + fn tree_projects_commander_for_any_client_but_only_self_has_the_action() { + let server=json!({"own_client_id":1,"own_channel_id":7,"channels":[{"id":7,"parent_id":0}],"clients":[ + {"id":1,"uid":"own","channel_id":7,"is_channel_commander":true}, + {"id":2,"uid":"peer","channel_id":7,"is_channel_commander":true}, + {"id":3,"uid":"other","channel_id":7} + ]}); + let key=SessionKey{connection_id:"commander".into(),session:1,generation:1}; + let mut tree=Vec::new(); + project_server_tree(&mut tree,&server,&key,&BTreeSet::from([2]),None,&HashSet::new(),true,&Catalog::default()); + for (id, own, commander, talking) in [("client:1:own",true,true,false),("client:2:peer",false,true,true),("client:3:other",false,false,false)] { + let entry=tree.iter().find(|entry|entry.row.id==id).unwrap(); + assert!(matches!(entry.appearance,TreeAppearance::Client{own:actual_own,commander:actual_commander,..} + if actual_own==own && actual_commander==commander)); + assert_eq!(entry.row.talking,talking); + assert_eq!(entry.row.actions.iter().any(|action|action.operation==Operation::ClientCommander),own); + } + } + #[test] fn client_menu_offers_the_current_talk_action_without_a_request() { let mut server=json!({"own_client_id":1,"own_channel_id":10,"channels":[{"id":10,"parent_id":0}],"clients":[ diff --git a/native/src/app/server_actions/context.rs b/native/src/app/server_actions/context.rs index 61e9cd2..c1153ae 100644 --- a/native/src/app/server_actions/context.rs +++ b/native/src/app/server_actions/context.rs @@ -106,6 +106,13 @@ pub fn client_context(t:&Target,reply:&Value,c:&Catalog)->Result> { let mut a=Action::new(key,op,t.clone(),c); a.enabled=allowed(capabilities.get(key))==Some(true); if !a.enabled{a.reason=c.text("admin.denied");} + if op==Operation::ClientCommander && a.enabled { + if let (Some(form),Some(active),Some(true))=(&mut a.form,reply["is_channel_commander"].as_bool(),reply["is_self"].as_bool()) { + let field=form.fields.iter_mut().find(|f|f.id=="enabled").ok_or_else(||bad("Missing commander confirmation"))?; + field.value=FieldValue::Bool(!active);field.enabled=false; + form.description=c.text(if active{"clientMenu.disableCommander"}else{"clientMenu.enableCommander"}); + } else {a.enabled=false;a.reason=c.text("admin.denied");} + } if a.enabled { if let Some(form)=&mut a.form { fill_client_choices(form,reply)?; } } actions.push(a); } @@ -177,6 +184,23 @@ mod tests { "channel_groups":[{"id":12,"name":"Unavailable","member":false,"can_set":{}}]}) } + #[test] + fn commander_confirmation_captures_the_opposite_self_flag() { + let catalog=Catalog::default(); + for current in [true,false] { + let mut wire=reply();wire["is_self"]=true.into();wire["is_channel_commander"]=current.into(); + wire["permissions"]=json!([]); + wire["capabilities"]["commander"]=json!({"allowed":true}); + let action=client_context(&target(),&wire,&catalog).unwrap().into_iter().find(|a|a.operation==Operation::ClientCommander).unwrap(); + assert!(action.enabled); + let form=action.form.unwrap(); + assert_eq!(form.description,catalog.text(if current{"clientMenu.disableCommander"}else{"clientMenu.enableCommander"})); + assert!(form.fields.iter().any(|f|f.id=="enabled"&&!f.enabled&&f.value==FieldValue::Bool(!current))); + wire["is_self"]=false.into(); + assert!(!client_context(&target(),&wire,&catalog).unwrap().into_iter().find(|a|a.operation==Operation::ClientCommander).unwrap().enabled); + } + } + #[test] fn client_menu_uses_only_explicit_capabilities_and_eligible_groups() { use Operation::*; diff --git a/native/src/smoke.rs b/native/src/smoke.rs index 91577c2..a077eb7 100644 --- a/native/src/smoke.rs +++ b/native/src/smoke.rs @@ -13,6 +13,7 @@ mod focus; #[cfg(all(test, windows))] mod download_folder; #[cfg(all(test, windows))] mod contact_edit; #[cfg(all(test,not(any(target_os="android",target_os="ios"))))] mod theme_selection; +#[cfg(all(test,not(any(target_os="android",target_os="ios"))))] mod channel_commander; #[cfg(all(test,not(any(target_os="android",target_os="ios"))))] mod speaker_gain; #[cfg(feature="webrtc")] pub mod media; use std::{cell::RefCell, fs, path::PathBuf, rc::Rc, sync::Arc, time::{Duration, Instant}}; diff --git a/native/src/smoke/channel_commander.rs b/native/src/smoke/channel_commander.rs new file mode 100644 index 0000000..643115a --- /dev/null +++ b/native/src/smoke/channel_commander.rs @@ -0,0 +1,181 @@ +use super::{SmokeResult, focus, headless, identities::{row, run_ui, wait}, key_profiles::until}; +use crate::{AppConfig, AppRuntime, AppWindow, SettingsBridge, ShellBridge, Theme, + services::{profile::ProfileServices, profile_import::initialize_native_root}, ui::settings::Category}; +use i_slint_core::{accessibility::AccessibleStringProperty, items::AccessibleRole, lengths::LogicalRect}; +use serde_json::json; +use slint::{ComponentHandle, Model, PhysicalSize}; + +const PREF: &str = "channelCommanderAsLamp"; +const SWITCH: &str = "settings.appearance.server.show.channel.commander"; +const COMMANDER: &str = "Commander QA"; +const LISTENER: &str = "Listener"; + +#[derive(Clone, Copy)] +enum Treatment { Badge, IdleLamp, TalkingLamp } + +fn pixels_in(pixels: &slint::SharedPixelBuffer, bounds: LogicalRect) -> impl Iterator { + let stride = pixels.width() as usize * 4; + let left = bounds.min_x().ceil() as usize; + let right = bounds.max_x().floor() as usize; + let top = bounds.min_y().ceil() as usize; + let bottom = bounds.max_y().floor() as usize; + (top..bottom).flat_map(move |y| pixels.as_bytes()[y * stride + left * 4..y * stride + right * 4].chunks_exact(4)) +} + +fn observe(ui: &AppWindow, dark: bool, label: &str, compact: bool, treatment: Treatment) -> SmokeResult<()> { + let window = ui.window(); + let pixels = window.take_snapshot().map_err(|e| e.to_string())?; + let bounds = |label: &str| { + let item = focus::visible_selector(ui, label, AccessibleRole::ListItem)?; + headless::visible_bounds(window, &item).ok_or_else(|| format!("tree row {label:?} is clipped")) + }; + let commander = bounds(&format!("{COMMANDER}, {label}"))?; + let listener = bounds(LISTENER)?; + assert_eq!(commander.size.height, if compact { 28.0 } else { 40.0 }); + assert_eq!(commander.size, listener.size); + + let mut badge = None; + let mut lamp = None; + let mut listener_avatar = None; + headless::visit_named_items(window, |id, item| { + let Some(rect) = headless::visible_bounds(window, item) else { return; }; + if commander.contains(rect.center()) { + if id == "parity-tree-commander-icon" { badge = Some(rect); } + if id == "parity-tree-commander-lamp" { lamp = Some(rect); } + } + if listener.contains(rect.center()) { + assert!(!matches!(id, "parity-tree-commander-icon" | "parity-tree-commander-lamp")); + if id == "parity-tree-avatar" { listener_avatar = Some(rect); } + } + })?; + + let listener_avatar = listener_avatar.ok_or("normal client avatar is missing")?; + let gold = [218, 165, 32, 255]; + assert!(!pixels_in(&pixels, listener_avatar).any(|p| p == gold)); + match treatment { + Treatment::Badge => { + assert!(lamp.is_none(), "badge mode also rendered a commander lamp"); + let rect = badge.ok_or("commander badge is missing")?; + assert!(rect.min_x() > listener_avatar.max_x() && rect.max_x() <= commander.max_x()); + let ink = if dark { [255, 255, 255, 255] } else { [26, 26, 26, 255] }; + assert!(pixels_in(&pixels, rect).any(|p| p == ink), "commander insignia did not paint"); + } + Treatment::IdleLamp | Treatment::TalkingLamp => { + assert!(badge.is_none(), "lamp mode also rendered a commander badge"); + let rect = lamp.ok_or("commander lamp is missing")?; + assert_eq!(rect.size, listener_avatar.size); + if matches!(treatment, Treatment::IdleLamp) { + assert!(pixels_in(&pixels, rect).any(|p| p == gold), "idle commander lamp is not gold"); + } else { + // Use the opaque interior, not antialiased boundaries or unpainted gradient endpoints. + let (low, high, blue) = if dark { (135, 183, 0..=0) } else { (91, 132, 36..=46) }; + let (min, max) = pixels_in(&pixels, rect) + .filter(|p| (low..=high).contains(&p[1]) && blue.contains(&p[2])) + .fold((u8::MAX, 0), |(min, max), p| (min.min(p[1]), max.max(p[1]))); + assert!(max.saturating_sub(min) >= 8, "talking commander lamp lacks the stock gradient: {min}..{max}"); + } + } + } + Ok(()) +} + +async fn appearance(runtime: &AppRuntime, ui: &AppWindow) -> SmokeResult<()> { + let shell = ui.global::(); + shell.invoke_navigate(3); + until("rendered settings", || shell.get_destination() == 3).await?; + let appearance = runtime.snapshot().catalog.text(Category::Appearance.key()); + focus::open_category(ui, &appearance)?; + until("rendered Appearance page", || ui.global::().get_appearance_page()).await +} + +async fn switch(runtime: &AppRuntime, ui: &AppWindow, label: &str, checked: bool, toggle: bool) -> SmokeResult<()> { + appearance(runtime, ui).await?; + until("localized commander switch", || focus::visible_selector(ui, label, AccessibleRole::Checkbox).is_ok()).await?; + let item = focus::visible_selector(ui, label, AccessibleRole::Checkbox)?; + let expected = if checked { "true" } else { "false" }; + assert_eq!(item.accessible_string_property(AccessibleStringProperty::Checked).unwrap().as_str(), expected); + if toggle { + focus::activate(item)?; // Actual Slint Toggle accessibility action, not a bridge/model write. + until("saved commander preference", || { + runtime.snapshot().settings.prefs[PREF] == !checked + && ui.global::().get_channel_commander_as_lamp() != checked + }).await?; + let item = focus::visible_selector(ui, label, AccessibleRole::Checkbox)?; + assert_ne!(item.accessible_string_property(AccessibleStringProperty::Checked).unwrap().as_str(), expected); + } + Ok(()) +} + +async fn return_to_tree(ui: &AppWindow) -> SmokeResult<()> { + let shell = ui.global::(); + shell.invoke_navigate(0); + until("rendered server tree", || shell.get_destination() == 0).await +} + +#[test] +fn commander_lamp_appearance_persists_in_both_languages_and_themes() { + if !headless::install_for_test() { return; } + let temp = tempfile::tempdir().unwrap(); + for (language, switch_label, badge_label) in [ + ("en", "Show Channel Commander as Lamp", "Channel Commander"), + ("ru", "Отмечать Командира канала лампочкой", "Командир канала"), + ] { + for (theme, dark) in [("dark", true), ("light", false)] { + let root = temp.path().join(format!("{language}-{theme}")); + initialize_native_root(&root).unwrap(); + let mut profile = ProfileServices::open(&root).unwrap(); + profile.identities.onboard("Owner").unwrap(); + profile.prefs.set(json!({"language":language,"theme":theme,"treeStyle":"compact","serverPaneWidth":220})).unwrap(); + drop(profile); + let config = AppConfig::isolated(root); + for restarted in [false, true] { + run_ui(&config, async move |runtime, ui| { + // Tall enough to reach the localized Appearance switch without hitting a scrollbar. + ui.window().set_size(PhysicalSize::new(1280, 1100)); + wait(runtime, "disconnected profile", |s| (s.settings.loaded && !s.connections.connections.is_empty()).then_some(())).await?; + assert_eq!(runtime.snapshot().settings.prefs["language"], language); + assert_eq!(runtime.snapshot().settings.prefs[PREF], !restarted); + assert_eq!(runtime.snapshot().catalog.text(SWITCH), switch_label); + let owner = runtime.services.lock().unwrap().upgrade().ok_or("runtime closed")?; + let manager = &owner.connected.connections; + let key = manager.key("c1").await.map_err(|e| e.to_string())?; + manager.fixture_control(&key, json!({"event":"snapshot","generation":key.generation, + "server":{"uid":"Fixture=","name":"Fixture"},"own_client_id":1,"own_channel_id":7, + "channels":[{"id":7,"parent_id":0,"name":"Lobby"}],"clients":[ + {"id":1,"uid":"Owner=","nickname":"Owner","channel_id":7,"input_muted":true,"output_muted":true}, + {"id":2,"uid":"Commander=","nickname":COMMANDER,"channel_id":7,"is_channel_commander":true}, + {"id":3,"uid":"Listener=","nickname":LISTENER,"channel_id":7} + ]})).await.map_err(|e| e.to_string())?; + let shell = ui.global::(); + until("projected commander on compact tree", || shell.get_compact_tree() + && shell.get_tree().iter().any(|item| item.title == COMMANDER && item.commander)).await?; + assert_eq!(ui.global::().get_dark(), dark); + observe(ui, dark, badge_label, true, if restarted { Treatment::Badge } else { Treatment::IdleLamp })?; + if !restarted { + manager.fixture_control(&key, json!({"event":"talking","generation":key.generation,"client_id":2,"talking":true})) + .await.map_err(|e| e.to_string())?; + until("commander starts talking", || shell.get_tree().iter().any(|item| item.commander && item.talking)).await?; + observe(ui, dark, badge_label, true, Treatment::TalkingLamp)?; + switch(runtime, ui, switch_label, true, true).await?; + return_to_tree(ui).await?; + observe(ui, dark, badge_label, true, Treatment::Badge)?; + } else { + switch(runtime, ui, switch_label, false, false).await?; + let selector = row(ui, "treeStyle").ok_or("missing Tree Style setting")?; + ui.global::().invoke_choice_value(selector.token, 1); + until("detailed preference applied", || !shell.get_compact_tree()).await?; + return_to_tree(ui).await?; + observe(ui, dark, badge_label, false, Treatment::Badge)?; + switch(runtime, ui, switch_label, false, true).await?; + return_to_tree(ui).await?; + observe(ui, dark, badge_label, false, Treatment::Badge)?; + } + manager.fixture_control(&key, json!({"event":"state","state":"disconnected","generation":key.generation})) + .await.map_err(|e| e.to_string())?; + until("closed synthetic roster", || !runtime.snapshot().connections.any_active()).await?; + Ok(()) + }).unwrap_or_else(|error| panic!("{language}/{theme}, restarted={restarted}: {error}")); + } + } + } +} diff --git a/native/src/smoke/participant_commander.rs b/native/src/smoke/participant_commander.rs new file mode 100644 index 0000000..e97b47c --- /dev/null +++ b/native/src/smoke/participant_commander.rs @@ -0,0 +1,284 @@ +//! Channel commander through the native desktop menu and the two muted beta14 sessions. +use super::*; +use crate::{ + DialogBridge, + app::{connections::ConnectionState, runtime::context::{RuntimeServices, changed}}, + smoke::{focus, key_profiles::until}, + ui::shell::{Entity, FieldValue, Form, Operation, forms}, +}; +use i_slint_core::items::{AccessibleRole, ComplexText, SimpleText}; +use serde_json::Value; +use teamspeach_core::menu::{Action, ActionRequest, Target}; + +const SELF: usize = 1; +const PEER: usize = 0; +const OPERATION: Operation = Operation::ClientCommander; + +#[test] +#[ignore = "requires exclusive use of private beta14 at 127.0.0.1:19987"] +fn participant_commander_confirms_self_and_rejects_stale_beta14_guest() { + headless::install().unwrap(); + run_muted_beta14_participant_fixture(ParticipantFixture::Commander); +} + +struct Guests { + clients: [u16; 2], + uids: [String; 2], + identities: [String; 2], + channel: u64, + input_owner: Option, +} + +impl Guests { + fn target(&self, guest: usize) -> Target { + Target { client_id: self.clients[guest], uid: self.uids[guest].clone() } + } + + fn flags(&self, runtime: &AppRuntime, tabs: &[SessionKey; 2]) -> SmokeResult<[[bool; 2]; 2]> { + let state = runtime.snapshot(); + if state.connections.input_id != self.input_owner || state.connections.capture.is_some() + || state.audio_input_active || state.audio_output_active || state.audio_input_starts != 0 || state.audio_output_starts != 0 + || state.voice.as_ref().is_some_and(|voice| !voice.muted || !voice.deafened || voice.transmitting) + { + return Err("commander workflow changed microphone ownership or started audio".into()); + } + let mut observed = [[false; 2]; 2]; + for (view, key) in tabs.iter().enumerate() { + let tab = state.connections.get(&key.connection_id).filter(|tab| { + tab.key == *key && tab.is_connected() && tab.identity_id.as_deref() == Some(self.identities[view].as_str()) + && tab.audio.input_muted && tab.audio.output_muted && !tab.audio.transmitting + && tab.input_enabled == (self.input_owner.as_ref() == Some(&key.connection_id)) + }).ok_or("commander workflow changed a guest identity, session, or mute state")?; + let server = tab.server.as_deref().ok_or("missing beta14 server snapshot")?; + if server["own_client_id"] != self.clients[view] || server["own_channel_id"] != self.channel { + return Err("commander workflow changed a guest's client ID or joined channel".into()); + } + let rows = server["clients"].as_array().filter(|rows| rows.len() == 2).ok_or("expected exactly two beta14 guests")?; + for (guest, name) in BETA14_PARTICIPANTS.iter().enumerate() { + let row = rows.iter().find(|row| row["id"] == self.clients[guest] && row["uid"] == self.uids[guest].as_str() + && row["nickname"] == *name && row["channel_id"] == self.channel && row["input_muted"] == true && row["output_muted"] == true) + .ok_or("the exact muted guest was not in the same channel on both tabs")?; + observed[view][guest] = row["is_channel_commander"].as_bool().ok_or("server snapshot omitted commander flag")?; + } + } + Ok(observed) + } + + async fn expect_flags(&self, runtime: &AppRuntime, tabs: &[SessionKey; 2], enabled: bool) -> SmokeResult<()> { + let expected = [[false, enabled]; 2]; + until("both beta14 server rosters report the exact commander flags", || { + match self.flags(runtime, tabs) { Ok(flags) => flags == expected, Err(_) => true } + }).await?; + if self.flags(runtime, tabs)? != expected { return Err("commander flags changed after readback".into()); } + Ok(()) + } + + async fn context(&self, owner: &RuntimeServices, tabs: &[SessionKey; 2], view: usize, enabled: bool) -> SmokeResult { + pace_beta14().await?; + let key = &tabs[view]; + let reply = owner.request(key, Command::ClientContext(self.target(SELF))).await.map_err(|e| format!("commander readback: {}: {}", e.code, e.message))?; + if reply["generation"] != key.generation || reply["client_id"] != self.clients[SELF] || reply["uid"] != self.uids[SELF].as_str() + || reply["is_self"] != (view == SELF) || reply["channel_id"] != self.channel || reply["is_channel_commander"] != enabled + { + return Err(format!("commander readback on tab {} had the wrong target or flag (expected {enabled})", view + 1)); + } + Ok(reply) + } +} + +fn rendered_form_text(ui: &AppWindow, title: &str, value: &str) -> bool { + let Ok(form) = focus::visible_selector(ui, title, AccessibleRole::Form) else { return false; }; + let mut pending: Vec<_> = form.first_child().into_iter().collect(); + while let Some(item) = pending.pop() { + pending.extend(item.next_sibling()); + pending.extend(item.first_child()); + if headless::visible_bounds(ui.window(), &item).is_some() + && (item.downcast::().is_some_and(|text| text.as_pin_ref().text() == value) + || item.downcast::().is_some_and(|text| text.as_pin_ref().text() == value)) + { + return true; + } + } + false +} + +async fn open_self(runtime: &AppRuntime, ui: &AppWindow, key: &SessionKey, guests: &Guests, enabled: bool) -> SmokeResult> { + view_muted_beta14_tab(runtime, ui, key, SELF).await?; + await_beta14_participant(runtime, key, SELF, guests.clients[SELF], &guests.uids[SELF], true).await?; + let catalog = runtime.snapshot().catalog; + let title = catalog.text(forms::label_key(OPERATION)); + let name = BETA14_PARTICIPANTS[SELF]; + let row_label = if enabled { format!("{name}, {title}") } else { name.into() }; + until("rendered own guest with the current commander state", || focus::visible_selector(ui, &row_label, AccessibleRole::ListItem).is_ok()).await?; + pace_beta14().await?; + open_tree_info_menu(ui, &row_label)?; + let action = await_tree_menu_action(ui, name, &title, &catalog.text("native.status.loading")).await?; + let item = rendered_tree_menu_action(ui, name, &title).await?; + if !action.enabled { + let denied = catalog.text("admin.denied"); + if action.reason.as_str() != denied || item.accessible_string_property(Property::Enabled).as_deref() != Some("false") + || item.accessible_string_property(Property::Description).as_deref() != Some(denied.as_str()) + { + return Err("disabled own commander action did not render its permission refusal".into()); + } + dismiss_tree_menu(ui).await?; + return Ok(None); + } + // Opening the tracked editor makes its own server context request. + pace_beta14().await?; + focus::activate(item)?; + let dialog = ui.global::(); + let desired = !enabled; + let description = catalog.text(if desired { "clientMenu.enableCommander" } else { "clientMenu.disableCommander" }); + until("rendered commander confirmation with the inverse server flag", || { + dialog.get_visible() && !dialog.get_busy() && dialog.get_error().is_empty() && dialog.get_title() == title + && dialog.get_description() == description && rendered_form_text(ui, &title, &description) + }).await?; + let capture = runtime.snapshot().dialog.clone().ok_or("commander confirmation was not captured")?; + if capture.operation != OPERATION || capture.target.session.as_ref() != Some(key) + || !matches!(&capture.target.entity, Entity::Client { id, uid, channel_id } + if *id == guests.clients[SELF] && uid == &guests.uids[SELF] && *channel_id == guests.channel) + || !capture.fields.iter().any(|field| field.id == "enabled" && field.value == FieldValue::Bool(desired) && !field.enabled) + || !dialog.get_fields().iter().any(|field| field.id == "enabled" && field.checked == desired && !field.enabled) + { + return Err("commander form did not retain the exact self target and read-only desired flag".into()); + } + Ok(Some(capture)) +} + +async fn submit(ui: &AppWindow, capture: &Form) -> SmokeResult> { + let dialog = ui.global::(); + rendered_form_button(ui, &capture.title, dialog.get_submit_label().as_str())?; + until("commander command acknowledgement or visible refusal", || !dialog.get_visible() + || (!dialog.get_busy() && !dialog.get_error().is_empty())).await?; + if !dialog.get_visible() { return Ok(None); } + let error = dialog.get_error().to_string(); + if !rendered_form_text(ui, &capture.title, &error) { return Err(format!("commander error did not render: {error}")); } + Ok(Some(error)) +} + +async fn cancel(runtime: &AppRuntime, ui: &AppWindow, capture: &Form) -> SmokeResult<()> { + let dialog = ui.global::(); + rendered_form_button(ui, &capture.title, dialog.get_cancel_label().as_str())?; + until("captured commander confirmation cancelled", || !dialog.get_visible() && runtime.snapshot().dialog.is_none()).await +} + +async fn verify_views(runtime: &AppRuntime, ui: &AppWindow, owner: &RuntimeServices, tabs: &[SessionKey; 2], guests: &Guests, enabled: bool) -> SmokeResult<()> { + guests.expect_flags(runtime, tabs, enabled).await?; + let shell = ui.global::(); + for view in [SELF, PEER] { + guests.context(owner, tabs, view, enabled).await?; + view_muted_beta14_tab(runtime, ui, &tabs[view], view).await?; + until("both rendered guest rows reflect the server commander flags", || { + BETA14_PARTICIPANTS.iter().enumerate().all(|(guest, name)| { + shell.get_tree().iter().any(|row| row.title == *name && row.commander == (guest == SELF && enabled)) + }) + }).await?; + } + guests.expect_flags(runtime, tabs, enabled).await +} + +pub(super) async fn exercise(runtime: &AppRuntime, ui: &AppWindow, owner: &RuntimeServices, tabs: &mut [SessionKey; 2], + clients: [u16; 2], uids: [String; 2], identities: &[String; 2], replacement_identity: &str) -> SmokeResult<()> { + let state = runtime.snapshot(); + let server = state.connections.get(&tabs[SELF].connection_id).and_then(|tab| tab.server.as_deref()).ok_or("missing own beta14 server snapshot")?; + let channel = server["own_channel_id"].as_u64().filter(|channel| *channel != 0).ok_or("missing beta14 guest channel")?; + let mut guests = Guests { clients, uids, identities: identities.clone(), channel, input_owner: state.connections.input_id.clone() }; + if guests.input_owner.as_ref() == Some(&tabs[SELF].connection_id) { return Err("replacement guest must not own the muted microphone".into()); } + guests.expect_flags(runtime, tabs, false).await?; + + // View the expected initiator as a peer, wait for the real context, and independently inspect its self-only guard. + view_muted_beta14_tab(runtime, ui, &tabs[PEER], PEER).await?; + await_beta14_participant(runtime, &tabs[PEER], SELF, guests.clients[SELF], &guests.uids[SELF], false).await?; + let catalog = runtime.snapshot().catalog; + let title = catalog.text(forms::label_key(OPERATION)); + let name = BETA14_PARTICIPANTS[SELF]; + pace_beta14().await?; + open_tree_info_menu(ui, name)?; + await_tree_menu_action(ui, name, &catalog.text(forms::label_key(Operation::ClientPoke)), &catalog.text("native.status.loading")).await?; + let shell = ui.global::(); + if shell.get_menu_actions().iter().any(|action| action.label == title) || ui.global::().get_visible() { + return Err("another participant was offered a commander toggle".into()); + } + dismiss_tree_menu(ui).await?; + let peer = guests.context(owner, tabs, PEER, false).await?; + if peer["capabilities"]["commander"]["allowed"] != false || peer["capabilities"]["commander"]["reason"] != "self_only" { + return Err("server-backed client context did not reject another participant's commander action".into()); + } + guests.expect_flags(runtime, tabs, false).await?; + + let mut refusal = None; + let stale = if let Some(first) = open_self(runtime, ui, &tabs[SELF], &guests, false).await? { + guests.expect_flags(runtime, tabs, false).await?; + pace_beta14().await?; + match submit(ui, &first).await? { + None => { + verify_views(runtime, ui, owner, tabs, &guests, true).await?; + let off = open_self(runtime, ui, &tabs[SELF], &guests, true).await?.ok_or("commander off became unavailable after enabling")?; + guests.expect_flags(runtime, tabs, true).await?; + pace_beta14().await?; + if let Some(error) = submit(ui, &off).await? { return Err(format!("server refused commander off after enabling: {error}")); } + verify_views(runtime, ui, owner, tabs, &guests, false).await?; + open_self(runtime, ui, &tabs[SELF], &guests, false).await? + .map(Some).ok_or("commander confirmation became unavailable before stale target test")? + } + Some(error) if error.contains("PermissionsClientInsufficient") || error == "server permission hint denies this action" => { + cancel(runtime, ui, &first).await?; + verify_views(runtime, ui, owner, tabs, &guests, false).await?; + refusal = Some(error); + open_self(runtime, ui, &tabs[SELF], &guests, false).await? + } + Some(error) => return Err(format!("unexpected commander refusal: {error}")), + } + } else { + let reply = guests.context(owner, tabs, SELF, false).await?; + if reply["capabilities"]["commander"]["allowed"] != false || reply["capabilities"]["commander"]["reason"] != "permission_denied" { + return Err("own commander menu was disabled without an explicit guest permission denial".into()); + } + refusal = Some(format!("{} (permission_denied)", catalog.text("admin.denied"))); + None + }; + + let old = tabs[SELF].clone(); + let old_target = guests.target(SELF); + pace_beta14().await?; + owner.request(&old, Command::Disconnect { message: None }).await.map_err(|e| e.message)?; + until("commander guest departed while the other guest stayed connected", || { + let state = runtime.snapshot(); + state.connections.get(&old.connection_id).is_some_and(|tab| tab.state == ConnectionState::Disconnected) + && state.connections.get(&tabs[PEER].connection_id).and_then(|tab| tab.server.as_deref()) + .and_then(|server| server["clients"].as_array()).is_some_and(|rows| !rows.iter().any(|row| row["uid"] == old_target.uid.as_str())) + }).await?; + pace_beta14().await?; + let idle = owner.connected.connections.key(&old.connection_id).await.map_err(|e| e.to_string())?; + (tabs[SELF], guests.clients[SELF]) = connect_muted_beta14(owner, &idle, replacement_identity).await?; + let replacement = await_muted_beta14_roster(runtime, tabs, guests.clients).await?; + if tabs[SELF] == old || replacement[SELF] == old_target.uid || replacement[PEER] != guests.uids[PEER] { + return Err("commander guest was not replaced by a distinct same-name identity on a new session".into()); + } + guests.uids = replacement; + guests.identities[SELF] = replacement_identity.into(); + guests.expect_flags(runtime, tabs, false).await?; + if let Some(capture) = &stale { + let retained = runtime.snapshot().dialog.as_ref().is_some_and(|form| form.id == capture.id && form.target == capture.target); + if !retained { return Err("stale commander confirmation lost its original captured target".into()); } + let error=submit(ui,capture).await?.ok_or("stale commander confirmation was accepted")?; + if error != catalog.text("native.form.changed") && error != changed().message { + return Err(format!("unexpected stale commander refusal: {error}")); + } + cancel(runtime, ui, capture).await?; + } else { + // A known-denied menu cannot open an editor; the original core command still must not reach the replacement. + let denied = owner.request(&old, Command::ClientAction(ActionRequest { target: old_target, generation: old.generation, + action: Action::Commander { enabled: true } })).await.err().ok_or("stale commander request reached the replacement")?; + if denied.code != changed().code || denied.message != changed().message { return Err(format!("unexpected stale commander refusal: {}", denied.message)); } + } + verify_views(runtime, ui, owner, tabs, &guests, false).await?; + if let Some(error) = refusal { + let path = if stale.is_some() { "stale confirmation rejected" } else { "stale session rejected; no confirmation was available" }; + eprintln!("beta14 Slint commander: guest refusal: {error}; flags remained off; {path}"); + } else { + eprintln!("beta14 Slint commander: self enable and disable acknowledged and read back on both tabs; peer action absent; stale confirmation rejected without changing either flag"); + } + Ok(()) +} diff --git a/native/src/smoke/tabs.rs b/native/src/smoke/tabs.rs index 2536f45..824eb89 100644 --- a/native/src/smoke/tabs.rs +++ b/native/src/smoke/tabs.rs @@ -677,12 +677,16 @@ fn participant_context_menu_projects_muted_beta14_capabilities() { #[cfg(target_os = "windows")] #[derive(Clone, Copy, PartialEq, Eq)] -enum ParticipantFixture { Info, Statistics, Poke, Context, Volume } +enum ParticipantFixture { Info, Statistics, Poke, Context, Volume, Commander } #[cfg(target_os = "windows")] #[path = "participant_gain.rs"] mod participant_gain; +#[cfg(target_os = "windows")] +#[path = "participant_commander.rs"] +mod participant_commander; + #[cfg(target_os = "windows")] fn run_muted_beta14_participant_fixture(scenario: ParticipantFixture) { use super::key_profiles::until; @@ -707,6 +711,9 @@ fn run_muted_beta14_participant_fixture(scenario: ParticipantFixture) { })).unwrap(); profile.identities.create("Replacement QA", BETA14_PARTICIPANTS[1]).unwrap().uid }); + let replacement = if scenario == ParticipantFixture::Commander { + Some(profile.identities.create("Commander Replacement QA", BETA14_PARTICIPANTS[1]).unwrap().uid) + } else { replacement }; (identities, replacement) }; run_ui(&AppConfig { network_enabled: true, ..AppConfig::isolated(root) }, async move |runtime, ui| { @@ -733,6 +740,8 @@ fn run_muted_beta14_participant_fixture(scenario: ParticipantFixture) { replacement.as_deref().ok_or("missing replacement guest identity")?).await, ParticipantFixture::Context => return exercise_beta14_participant_context(runtime, ui, &owner, &tabs, clients, &uids).await, ParticipantFixture::Volume => return participant_gain::exercise(runtime, ui, &owner, &mut tabs, clients, &uids, &identities[0]).await, + ParticipantFixture::Commander => return participant_commander::exercise(runtime, ui, &owner, &mut tabs, clients, uids, &identities, + replacement.as_deref().ok_or("missing commander replacement guest identity")?).await, ParticipantFixture::Info => {}, } diff --git a/native/src/ui/application.rs b/native/src/ui/application.rs index 0674a86..e3d03d7 100644 --- a/native/src/ui/application.rs +++ b/native/src/ui/application.rs @@ -47,7 +47,7 @@ pub fn bind(runtime:Arc,generation:u64)->Result{ + shell::ShellAction::Submit{ref editor_id, ref target, operation:shell::Operation::ClientPoke|shell::Operation::ClientCommander,..}=>{ let (id,target)=(editor_id.clone(),target.clone()); let command=crate::app::runtime::RuntimeCommand::AttachmentShell{action,ui_generation:generation}; if let Err(error)=runtime.enqueue(command) { @@ -76,7 +76,7 @@ pub fn bind(runtime:Arc,generation:u64)->Result{ @@ -140,6 +140,7 @@ fn update(ui:&AppWindow,runtime:&AppRuntime,bindings:&mut Bindings,generation:u6 let width=|key:&str,default:i32|snapshot.settings.prefs[key].as_f64().filter(|n|*n>0.).map_or(default,|n|n as i32); ui.global::().set_bookmarks_collapsed(snapshot.settings.prefs["savedServersCollapsed"]==true); ui.global::().set_compact_tree(snapshot.settings.prefs["treeStyle"]=="compact"); + ui.global::().set_channel_commander_as_lamp(snapshot.settings.prefs["channelCommanderAsLamp"]!=false); let panes=(width("sidebarWidth",270),width("serverPaneWidth",500));if bindings.panes!=Some(panes){ui.global::().set_sidebar_width(panes.0 as f32);ui.global::().set_server_width(panes.1 as f32);bindings.panes=Some(panes);}bindings.revision=snapshot.revision;} let mut new_frames=Vec::new(); #[cfg(feature="webrtc")] diff --git a/native/src/ui/shell.rs b/native/src/ui/shell.rs index eb2c139..aa365b4 100644 --- a/native/src/ui/shell.rs +++ b/native/src/ui/shell.rs @@ -21,7 +21,7 @@ impl Editor { self.form=form; } fn can_cancel(&self) -> bool { - if let Some(volume)=&self.volume { !volume.closing } else { !self.form.busy || self.form.operation != Operation::ClientPoke } + if let Some(volume)=&self.volume { !volume.closing } else { !self.form.busy || !matches!(self.form.operation,Operation::ClientPoke|Operation::ClientCommander) } } } @@ -241,9 +241,10 @@ fn tree_rows(state:&mut State,entries:&[TreeEntry])->Vec { row.joined=joined;row.password=password;row.full=full;row.moderated=moderated; row.spacer=match spacer_align{None=>0,Some(SpacerAlign::Left)=>1,Some(SpacerAlign::Center)=>2,Some(SpacerAlign::Right)=>3}; } - TreeAppearance::Client{own,contact,deafened,away,recording,streaming}=>{ + TreeAppearance::Client{own,contact,deafened,away,recording,streaming,commander}=>{ row.kind=2; row.own=own;row.contact=contact;row.deafened=deafened;row.away=away;row.recording=recording;row.streaming=streaming; + row.commander=commander; } } row @@ -439,7 +440,7 @@ pub fn bind(ui:&AppWindow,emit:Arc)->ShellBinding else if cfg!(any(target_os="android",target_os="ios")){e(ShellAction::Invoke{target:action.target.clone(),operation:Operation::StreamPopout});} else if let Err(error)=open_popout(&ui,&mut s,&stream){ui.global::().set_error(error.into());} } - }else if matches!(action.operation,Operation::ClientPoke|Operation::ClientVolume) { + }else if matches!(action.operation,Operation::ClientPoke|Operation::ClientCommander|Operation::ClientVolume) { e(ShellAction::Invoke{target:action.target,operation:action.operation}); }else if let Some(form)=action.form{s.editor=Some(Editor::new(form));project_editor(&ui,&mut s);} else{e(ShellAction::Invoke{target:action.target,operation:action.operation});} @@ -680,6 +681,7 @@ impl ShellBinding { b.set_stages(strings(["native.shell.details","native.shell.chat","native.shell.streams"].map(|k|c.text(k)))); b.set_label_back(c.text("native.navigation.back").into());b.set_label_more(c.text("native.action.more").into());b.set_label_close(c.text("native.action.close").into());b.set_label_loading(c.text("native.status.loading").into());b.set_label_empty(c.text("native.status.empty").into());b.set_label_tree_empty(c.text("ui.channels.will.appear.after.you.connect.to").into());b.set_label_stream_empty(c.text("native.stream.empty").into());b.set_label_stream_waiting(c.text("native.stream.waiting").into());b.set_label_mute(c.text("ui.microphone").into());b.set_label_deafen(c.text("ui.mute.audio").into());b.set_label_ptt(c.text("native.voice.hold").into());b.set_label_bookmarks(c.text("ui.saved.servers").into());b.set_label_search(c.text("native.action.search").into());b.set_label_next(c.text("native.action.next").into());b.set_label_previous(c.text("native.action.previous").into());b.set_label_volume(c.text("native.stream.volume").into());b.set_label_resize(c.text("native.shell.resize").into()); b.set_label_connections(c.text("ui.connections.title").into());b.set_label_new_connection(c.text("ui.connections.new").into());b.set_label_away(c.text("ui.away").into());b.set_label_password(c.text("ui.password.protected").into());b.set_label_capture(c.text("broadcast.open").into());b.set_label_create_channel(c.text(forms::label_key(Operation::ChannelCreate)).into()); + b.set_label_commander(c.text("clientMenu.commander").into()); b.set_has_voice(p.voice.is_some());if let Some(v)=&p.voice{b.set_voice_title(v.title.clone().into());b.set_voice_status(v.status.clone().into());b.set_muted(v.muted);b.set_deafened(v.deafened);b.set_transmitting(v.transmitting);b.set_away(v.away);b.set_ptt_enabled(v.ptt_enabled);} if let Some(form)=p.dialog.as_ref().or(p.profile_form.as_ref()) { // Repeated snapshots must neither reopen a dismissed prompt nor reset a tracked draft. @@ -839,7 +841,7 @@ mod tests { selected:true,microphone_owner:false,connected:true,unread:0,actions:vec![]}], tree:vec![TreeEntry{row:Entry{id:"peer".into(),target:target.clone(),title:"Peer".into(),subtitle:String::new(), actions,depth:0,selected:false,expanded:false,expandable:false,talking:false,muted:false,unread:0,waveform:vec![]}, - appearance:TreeAppearance::Client{own,contact:false,deafened:false,away:false,recording:false,streaming:false}}], + appearance:TreeAppearance::Client{own,contact:false,deafened:false,away:false,recording:false,streaming:false,commander:false}}], ..ShellPresentation::default()}); target }; diff --git a/native/src/ui/shell/forms.rs b/native/src/ui/shell/forms.rs index 2477b7e..0a40b41 100644 --- a/native/src/ui/shell/forms.rs +++ b/native/src/ui/shell/forms.rs @@ -3,7 +3,7 @@ use super::super::i18n::Catalog; use teamspeach_core::menu::{MAX_POKE_BYTES, valid_poke_message}; pub(crate) fn tracks_server_ack(operation: Operation) -> bool { - matches!(operation, Operation::ChannelEdit | Operation::ServerEdit | Operation::SetNickname | Operation::ClientPoke) + matches!(operation, Operation::ChannelEdit | Operation::ServerEdit | Operation::SetNickname | Operation::ClientPoke | Operation::ClientCommander) } pub fn label_key(operation: Operation) -> &'static str { diff --git a/native/src/ui/shell/types.rs b/native/src/ui/shell/types.rs index 4e48172..e4b3fc3 100644 --- a/native/src/ui/shell/types.rs +++ b/native/src/ui/shell/types.rs @@ -141,7 +141,7 @@ pub struct Entry { pub enum TreeAppearance { Server, Channel { joined: bool, password: bool, full: bool, moderated: bool, spacer_align: Option }, - Client { own: bool, contact: bool, deafened: bool, away: bool, recording: bool, streaming: bool }, + Client { own: bool, contact: bool, deafened: bool, away: bool, recording: bool, streaming: bool, commander: bool }, } #[derive(Clone, Copy, Debug)] diff --git a/native/src/ui/theme.rs b/native/src/ui/theme.rs index 028df00..74be3a8 100644 --- a/native/src/ui/theme.rs +++ b/native/src/ui/theme.rs @@ -49,6 +49,11 @@ pub(super) fn apply_controls(theme: &Theme<'_>, snapshot: &Snapshot) { theme.set_toggle_checked(css_color("--presence-online").unwrap_or_else(|| { if dark { rgb(23, 247, 141) } else { theme.get_success() } })); + theme.set_commander(css_color("--tsv-commander-color").unwrap_or_else(|| rgb(218, 165, 32))); + theme.set_commander_talking_start(css_color("--tsv-client-commander-talking--gradient-start") + .unwrap_or_else(|| if dark { rgb(255, 183, 0) } else { rgb(251, 132, 46) })); + theme.set_commander_talking_stop(css_color("--tsv-client-commander-talking--gradient-stop") + .unwrap_or_else(|| if dark { rgb(189, 135, 0) } else { rgb(176, 91, 36) })); theme.set_button_fill(css_color("--tsv-button-filled-bg").map_or_else(|| theme.get_stock_button_fill(), slint::Brush::SolidColor)); theme.set_destructive_fill(css_color("--tsv-button-filled-destructive-bg").map_or_else(|| theme.get_stock_destructive_fill(), slint::Brush::SolidColor)); theme.set_button_hover(css_color("--tsv-button-filled-hover-bg").unwrap_or_else(|| { diff --git a/native/ui/shell.slint b/native/ui/shell.slint index 5c671f7..1116e9c 100644 --- a/native/ui/shell.slint +++ b/native/ui/shell.slint @@ -8,6 +8,7 @@ export struct ShellRow { id: string, key: string, title: string, subtitle: string, depth: int, selected: bool, expanded: bool, expandable: bool, talking: bool, muted: bool, unread: string, kind: int, joined: bool, password: bool, full: bool, moderated: bool, spacer: int, own: bool, contact: bool, deafened: bool, away: bool, recording: bool, streaming: bool, + commander: bool, waveform: [int], } export struct ShellTab { id: string, title: string, selected: bool, microphone-owner: bool, connected: bool, unread: string } @@ -16,6 +17,7 @@ export struct ShellInfo { label: string, value: string } export struct ShellStream { id: string, title: string, status: string, frame: image, has-frame: bool, volume: float, actions: [ShellCommand] } export global ShellBridge { in-out property compact-tree; + in-out property channel-commander-as-lamp: true; in-out property <[ShellTab]> tabs; in-out property <[ShellRow]> tree; in-out property <[ShellRow]> bookmarks; @@ -90,6 +92,7 @@ export global ShellBridge { in-out property label-connections; in-out property label-new-connection; in-out property label-away; + in-out property label-commander; in-out property label-password; in-out property label-capture; in-out property label-create-channel; @@ -148,51 +151,6 @@ component RecordingWaveform inherits Rectangle { } } -component EntryRow inherits Rectangle { - in property item; - function context-menu() { ShellBridge.context(root.item.id, (root.absolute-position.x + 20px) / 1px, (root.absolute-position.y + root.height / 2) / 1px); } - height: max(44px, Theme.touch-target); - border-radius: 9px; - background: item.selected ? Theme.contrast : (touch.has-hover ? Theme.bg : transparent); - border-width: item.selected || focus.has-focus ? 1.5px : 0px; - border-color: Theme.tint; - accessible-role: list-item; - accessible-label: item.title + ". " + item.subtitle; - accessible-item-selectable: true; - accessible-item-selected: item.selected; - accessible-expandable: item.expandable; - accessible-expanded: item.expanded; - accessible-action-expand => { if root.item.expandable { ShellBridge.expand(root.item.id); } } - accessible-action-default => { ShellBridge.select(root.item.id); } - HorizontalLayout { - padding-left: 10px + root.item.depth * 14px; padding-right: 4px; spacing: 8px; - if root.item.expandable: ActionButton { width: 44px; text: root.item.expanded ? ShellBridge.label-close : ShellBridge.label-more; clicked => { ShellBridge.expand(root.item.id); } } - Rectangle { width: 6px; height: 6px; border-radius: 3px; background: root.item.talking ? Theme.success : (root.item.muted ? Theme.error : Theme.muted); } - VerticalLayout { - spacing: 0px; alignment: center; - Text { text: root.item.title; color: Theme.fg; font-size: Theme.font-size; overflow: elide; } - if root.item.subtitle != "": Text { text: root.item.subtitle; color: Theme.muted; font-size: Theme.font-size * 0.86; overflow: elide; } - } - if root.item.waveform.length > 0: parity-recording-waveform := RecordingWaveform { - width: min(130px, root.width / 3); - peaks: root.item.waveform; - } - if root.item.unread != "": Text { text: root.item.unread; color: Theme.tint; vertical-alignment: center; } - ActionButton { text: ShellBridge.label-more; width: 70px; clicked => { root.context-menu(); } } - } - focus := FocusScope { key-pressed(e) => { if e.text == "\n" { ShellBridge.select(root.item.id); return accept; } if e.text == Key.F10 && e.modifiers.shift { root.context-menu(); return accept; } return reject; } } - // Explicit overflow is always available on touch; right click never selects a row. - touch := TouchArea { - x: root.item.expandable ? 54px + root.item.depth * 14px : 0px; - width: max(0px,parent.width - self.x - 78px); - clicked => { focus.focus(); ShellBridge.select(root.item.id); } - pointer-event(e) => { - if e.button == PointerEventButton.right && e.kind == PointerEventKind.down { ShellBridge.context(root.item.id, (self.absolute-position.x + self.mouse-x) / 1px, (self.absolute-position.y + self.mouse-y) / 1px); } - if e.button == PointerEventButton.left && e.kind == PointerEventKind.down { ShellBridge.row-press(root.item.id,true,(self.absolute-position.x + self.mouse-x) / 1px,(self.absolute-position.y + self.mouse-y) / 1px); } - if e.kind == PointerEventKind.up || e.kind == PointerEventKind.cancel || (e.kind == PointerEventKind.move && (abs((self.mouse-x - self.pressed-x)/1px)>8 || abs((self.mouse-y - self.pressed-y)/1px)>8)) { ShellBridge.row-press(root.item.id,false,0,0); } - } - } -} global ShellColors { out property bar: Theme.dark ? #121a2c : Theme.shaded; @@ -212,6 +170,9 @@ global ShellColors { out property tree: @linear-gradient(25deg, Theme.dark ? #252f44 : #e1e3ed 0%, Theme.dark ? #2e374c : Theme.bg 60%); out property banner: @linear-gradient(180deg, (Theme.dark ? #0b1124 : Theme.contrast).with-alpha(0.9), (Theme.dark ? #222c41 : Theme.deviant).with-alpha(0.9)); out property channel: @linear-gradient(90deg, Theme.dark ? #192031 : #a9bee1 50%, Theme.dark ? #1d263a : #8391b3 100%); + out property commander-idle: Theme.high-contrast ? Theme.fg : Theme.commander; + out property commander-talking: Theme.high-contrast ? Theme.success : + @linear-gradient(203deg, Theme.commander-talking-start, Theme.commander-talking-stop); } component CommandList inherits VerticalLayout { @@ -253,12 +214,13 @@ component StreamTile inherits Rectangle { component ShellGlyph inherits Rectangle { in property glyph; in property ink: Theme.fg; + in property paint: root.ink; width: 22px; height: 22px; if root.glyph == 2: Rectangle { border-radius: self.width / 2; background: Theme.dark ? #202d31 : #c9d9e5; } Path { width: 100%; height: 100%; viewbox-width: 24; viewbox-height: 24; - stroke: root.ink; stroke-width: 1.5px; - fill: root.glyph == 2 ? root.ink : transparent; + stroke: root.glyph == 31 ? transparent : root.paint; stroke-width: 1.5px; + fill: root.glyph == 2 || root.glyph == 31 ? root.paint : transparent; commands: root.glyph == 0 ? "M12 2 L21 7 V17 L12 22 L3 17 V7 Z M3 10 L12 15 L21 10 M3 14 L12 19 L21 14 M3 7 L12 12 L21 7" : root.glyph == 1 ? "M12 2 L21 7 V17 L12 22 L3 17 V7 Z M12 2 V12 L21 17 M12 12 L3 17" : root.glyph == 2 ? "M12 5 A3 3 0 1 0 12 11 A3 3 0 1 0 12 5 Z M7 17 C7 12 17 12 17 17 C17 21 7 21 7 17 Z" : @@ -288,10 +250,65 @@ component ShellGlyph inherits Rectangle { root.glyph == 27 ? "M12 3 A9 9 0 1 0 12 21 A9 9 0 1 0 12 3 Z M12 7 V17 M7 12 H17" : root.glyph == 28 ? "M3 5 H9 L11 8 H21 V20 H3 Z" : root.glyph == 29 ? "M14 6 L8 12 L14 18" : + // Native star and double chevron, based on the pinned ChannelCommander silhouette. + root.glyph == 31 ? "M5.5 6 L7 9.5 L11 10 L8 12.8 L8.8 17 L5.5 15 L2 17 L2.8 12.8 L0 10 L4 9.5 Z M11 6 H14 L17.5 12 L14 18 H11 L14.5 12 Z M17 6 H20 L23.5 12 L20 18 H17 L20.5 12 Z" : "M12 4 A8 8 0 1 0 12 20 A8 8 0 1 0 12 4 Z M12 9 A3 3 0 1 0 12 15 A3 3 0 1 0 12 9 Z"; } } +component EntryRow inherits Rectangle { + in property item; + private property commander-lamp: root.item.commander && ShellBridge.compact-tree && ShellBridge.channel-commander-as-lamp; + function context-menu() { ShellBridge.context(root.item.id, (root.absolute-position.x + 20px) / 1px, (root.absolute-position.y + root.height / 2) / 1px); } + height: max(44px, Theme.touch-target); + border-radius: 9px; + background: item.selected ? Theme.contrast : (touch.has-hover ? Theme.bg : transparent); + border-width: item.selected || focus.has-focus ? 1.5px : 0px; + border-color: Theme.tint; + accessible-role: list-item; + accessible-label: item.commander && item.subtitle == "" ? item.title + ", " + ShellBridge.label-commander : + item.title + ". " + item.subtitle + (item.commander ? ", " + ShellBridge.label-commander : ""); + accessible-item-selectable: true; + accessible-item-selected: item.selected; + accessible-expandable: item.expandable; + accessible-expanded: item.expanded; + accessible-action-expand => { if root.item.expandable { ShellBridge.expand(root.item.id); } } + accessible-action-default => { ShellBridge.select(root.item.id); } + HorizontalLayout { + padding-left: 10px + root.item.depth * 14px; padding-right: 4px; spacing: 8px; + if root.item.expandable: ActionButton { width: 44px; text: root.item.expanded ? ShellBridge.label-close : ShellBridge.label-more; clicked => { ShellBridge.expand(root.item.id); } } + Rectangle { + width: 6px; height: 6px; border-radius: 3px; + background: root.commander-lamp ? (root.item.talking && !root.item.muted ? ShellColors.commander-talking : ShellColors.commander-idle) : + root.item.talking ? Theme.success : root.item.muted ? Theme.error : Theme.muted; + } + VerticalLayout { + spacing: 0px; alignment: center; + Text { text: root.item.title; color: Theme.fg; font-size: Theme.font-size; overflow: elide; } + if root.item.subtitle != "": Text { text: root.item.subtitle; color: Theme.muted; font-size: Theme.font-size * 0.86; overflow: elide; } + } + if root.item.waveform.length > 0: parity-recording-waveform := RecordingWaveform { + width: min(130px, root.width / 3); + peaks: root.item.waveform; + } + if root.item.commander && !root.commander-lamp: ShellGlyph { glyph: 31; width: 17px; height: 17px; } + if root.item.unread != "": Text { text: root.item.unread; color: Theme.tint; vertical-alignment: center; } + ActionButton { text: ShellBridge.label-more; width: 70px; clicked => { root.context-menu(); } } + } + focus := FocusScope { key-pressed(e) => { if e.text == "\n" { ShellBridge.select(root.item.id); return accept; } if e.text == Key.F10 && e.modifiers.shift { root.context-menu(); return accept; } return reject; } } + // Explicit overflow is always available on touch; right click never selects a row. + touch := TouchArea { + x: root.item.expandable ? 54px + root.item.depth * 14px : 0px; + width: max(0px,parent.width - self.x - 78px); + clicked => { focus.focus(); ShellBridge.select(root.item.id); } + pointer-event(e) => { + if e.button == PointerEventButton.right && e.kind == PointerEventKind.down { ShellBridge.context(root.item.id, (self.absolute-position.x + self.mouse-x) / 1px, (self.absolute-position.y + self.mouse-y) / 1px); } + if e.button == PointerEventButton.left && e.kind == PointerEventKind.down { ShellBridge.row-press(root.item.id,true,(self.absolute-position.x + self.mouse-x) / 1px,(self.absolute-position.y + self.mouse-y) / 1px); } + if e.kind == PointerEventKind.up || e.kind == PointerEventKind.cancel || (e.kind == PointerEventKind.move && (abs((self.mouse-x - self.pressed-x)/1px)>8 || abs((self.mouse-y - self.pressed-y)/1px)>8)) { ShellBridge.row-press(root.item.id,false,0,0); } + } + } +} + component DesktopMenuEntry inherits Rectangle { in property command; property label-height: 30px; @@ -367,6 +384,8 @@ component DesktopTreeRow inherits Rectangle { property channel: root.item.kind == 1; property client: root.item.kind == 2; property compact-client: root.client && ShellBridge.compact-tree; + private property commander-lamp: root.compact-client && root.item.commander && ShellBridge.channel-commander-as-lamp; + private property commander-icon: root.client && root.item.commander && !root.commander-lamp; property spacer: root.item.spacer > 0; property indent: min(max(0px, self.width - 90px), min(item.depth, 4) * 10px + max(item.depth - 4, 0) * 5px); property row-hover: parity-tree-hit.has-hover || more.hovered || (root.item.expandable && arrow.hovered); @@ -375,7 +394,7 @@ component DesktopTreeRow inherits Rectangle { property has-banner-tools: ShellBridge.save-bookmark-command != "" || ShellBridge.server-chat-command != ""; height: root.server ? 100px : root.channel ? 44px : root.compact-client ? 28px : 40px; accessible-role: list-item; - accessible-label: root.item.title + (root.item.password ? ", " + ShellBridge.label-password : "") + (root.item.away ? ", " + ShellBridge.label-away : ""); + accessible-label: root.item.title + (root.item.password ? ", " + ShellBridge.label-password : "") + (root.item.away ? ", " + ShellBridge.label-away : "") + (root.item.commander ? ", " + ShellBridge.label-commander : ""); accessible-item-selectable: true; accessible-item-selected: root.item.selected; accessible-expandable: root.item.expandable; @@ -397,13 +416,18 @@ component DesktopTreeRow inherits Rectangle { border-radius: 100px; border-width: 1px; border-color: @linear-gradient(90deg, ShellColors.subtitle, ShellColors.subtitle.with-alpha(0)); } - if !root.spacer: ShellGlyph { + if !root.spacer && !root.commander-lamp: parity-tree-avatar := ShellGlyph { glyph: root.channel ? 19 : root.item.kind; ink: root.client ? (root.item.talking && !root.item.muted ? Theme.success : root.item.away ? ShellColors.subtitle : Theme.dark ? #a3b4b3 : #445d77) : root.channel ? (root.item.full ? Theme.error : root.item.password ? Theme.warning : Theme.dark ? #dbeaf7 : #445d77) : Theme.fg; x: root.indent + (root.server ? 30px : root.client ? 25px : 20px); y: root.server ? 28px : (root.height - self.height) / 2; width: root.server ? 55px : root.client && !root.compact-client ? 33px : 22px; height: self.width; } + if root.commander-lamp: parity-tree-commander-lamp := ShellGlyph { + glyph: 2; + paint: root.item.talking && !root.item.muted ? ShellColors.commander-talking : ShellColors.commander-idle; + x: root.indent + 25px; y: (root.height - self.height) / 2; + } title := Text { x: root.indent + (root.server ? 105px : root.spacer ? 20px : root.compact-client ? 57px : root.client ? 68px : 52px); y: root.server ? 17px : 0px; @@ -416,13 +440,14 @@ component DesktopTreeRow inherits Rectangle { vertical-alignment: center; overflow: elide; } status := Rectangle { - property marks: (root.item.password ? 1 : 0) + (root.item.moderated ? 1 : 0) + (root.item.muted ? 1 : 0) + (root.item.deafened ? 1 : 0) + (root.item.away ? 1 : 0) + (root.item.recording ? 1 : 0) + (root.item.streaming ? 1 : 0); + property marks: (root.commander-icon ? 1 : 0) + (root.item.password ? 1 : 0) + (root.item.moderated ? 1 : 0) + (root.item.muted ? 1 : 0) + (root.item.deafened ? 1 : 0) + (root.item.away ? 1 : 0) + (root.item.recording ? 1 : 0) + (root.item.streaming ? 1 : 0); x: max(0px, (root.item.expandable ? arrow.x : root.width - 20px) - self.width - 4px); y: (root.height - self.height) / 2; width: self.marks > 0 ? 10px + self.marks * 17px + (self.marks - 1) * 4px : 0px; height: 23px; border-radius: 7px; background: self.marks == 0 ? transparent : (Theme.dark ? #222a3b : Theme.contrast); HorizontalLayout { y: (parent.height - self.height) / 2; height: 17px; padding-left: 5px; padding-right: 5px; spacing: 4px; alignment: start; + if root.commander-icon: parity-tree-commander-icon := ShellGlyph { glyph: 31; width: 17px; height: 17px; } if root.item.password: ShellGlyph { glyph: 14; ink: Theme.warning; width: 17px; height: 17px; } if root.item.moderated: Text { width: 17px; text: "M"; color: Theme.fg; font-size: 13px; vertical-alignment: center; horizontal-alignment: center; } if root.item.muted: ShellGlyph { glyph: 25; ink: Theme.error; width: 17px; height: 17px; } diff --git a/native/ui/theme.slint b/native/ui/theme.slint index c03f3c2..b366095 100644 --- a/native/ui/theme.slint +++ b/native/ui/theme.slint @@ -30,6 +30,9 @@ export global Theme { in property settings-highlight: dark ? #282f40 : deviant; in property error-light: dark ? #ff8282 : #da4d4d; in property toggle-checked: dark ? #17f78d : #01c00b; + in property commander: #daa520; + in property commander-talking-start: dark ? #ffb700 : #fb842e; + in property commander-talking-stop: dark ? #bd8700 : #b05b24; in property button-hover: dark ? #1c82cc : #32729b4d; in property destructive-hover: dark ? #f84e4e : #df0f0f4d; in property normal-weight: 450;