Honor the channel background preference in the desktop tree
Gate the default fills without changing the stock gradients or row outlines. Verify rendered pixels, independent rows, profile reopening, and rejected preference writes.
This commit is contained in:
1 parent
8fb4356c91
commit
5b55d159f7
5 files changed
+260
-2
No files matched your search
@@ -17,6 +17,7 @@ mod focus;
|
||||
#[cfg(all(test,not(any(target_os="android",target_os="ios"))))] mod display_size;
|
||||
#[cfg(all(test,not(any(target_os="android",target_os="ios"))))] mod language;
|
||||
#[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 channel_background;
|
||||
#[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}};
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
use super::{SmokeResult, focus, headless, identities::run_ui, key_profiles::until, screenshot};
|
||||
use crate::{AppConfig, AppRuntime, AppWindow, SettingsBridge, ShellBridge, Theme,
|
||||
app::runtime::model::Snapshot, services::{profile::ProfileServices, profile_import::initialize_native_root},
|
||||
ui::settings::Category};
|
||||
use i_slint_core::{accessibility::AccessibleStringProperty as Prop, items::AccessibleRole, lengths::LogicalRect};
|
||||
use serde_json::{Value, json};
|
||||
use slint::{ComponentHandle, PhysicalSize, Rgba8Pixel, SharedPixelBuffer};
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
const PREF: &str = "showChannelBackground";
|
||||
const LABEL: &str = "settings.appearance.server.show.channel.bg";
|
||||
const ROWS: [&str; 5] = ["Lobby", "Other room", "Owner", "Background QA", "Divider"];
|
||||
|
||||
struct TreeFrame {
|
||||
pixels: SharedPixelBuffer<Rgba8Pixel>,
|
||||
rows: [LogicalRect; ROWS.len()],
|
||||
}
|
||||
|
||||
impl TreeFrame {
|
||||
fn capture(ui: &AppWindow, path: Option<PathBuf>) -> SmokeResult<Self> {
|
||||
let mut rows = [None; ROWS.len()];
|
||||
headless::visit_named_items(ui.window(), |id, item| {
|
||||
if id != "parity-tree-row" { return; }
|
||||
let Some(label) = item.accessible_string_property(Prop::Label) else { return; };
|
||||
if let Some(index) = ROWS.iter().position(|name| *name == label.as_str()) {
|
||||
rows[index] = headless::visible_bounds(ui.window(), item);
|
||||
}
|
||||
})?;
|
||||
if let Some(index) = rows.iter().position(Option::is_none) { return Err(format!("missing desktop tree row {:?}", ROWS[index])); }
|
||||
let rows = rows.map(Option::unwrap);
|
||||
assert_eq!(rows.map(|row| row.size.height), [44., 44., 40., 100., 44.]);
|
||||
let pixels = ui.window().take_snapshot().map_err(|e| e.to_string())?;
|
||||
assert_eq!(pixels.width(), ui.window().size().width);
|
||||
assert_eq!(pixels.height(), ui.window().size().height);
|
||||
assert!(rows.iter().all(|row| row.min_x() >= 0. && row.min_y() >= 0.
|
||||
&& row.max_x() <= pixels.width() as f32 && row.max_y() <= pixels.height() as f32));
|
||||
if let Some(path) = path {
|
||||
image::save_buffer(path, pixels.as_bytes(), pixels.width(), pixels.height(), image::ColorType::Rgba8)
|
||||
.map_err(|e| e.to_string())?;
|
||||
}
|
||||
Ok(Self { pixels, rows })
|
||||
}
|
||||
|
||||
fn row_pixels(&self, index: usize) -> impl Iterator<Item = &[u8]> {
|
||||
let row = self.rows[index];
|
||||
let stride = self.pixels.width() as usize * 4;
|
||||
let x = row.min_x().ceil() as usize * 4..row.max_x().floor() as usize * 4;
|
||||
(row.min_y().ceil() as usize..row.max_y().floor() as usize)
|
||||
.map(move |y| &self.pixels.as_bytes()[y * stride + x.start..y * stride + x.end])
|
||||
}
|
||||
|
||||
fn sample(&self, index: usize, fraction: f32, dy: f32) -> [u8; 3] {
|
||||
let row = self.rows[index];
|
||||
let x = (row.min_x() + row.size.width * fraction) as usize;
|
||||
let y = (row.min_y() + dy) as usize;
|
||||
let offset = 4 * (y * self.pixels.width() as usize + x);
|
||||
self.pixels.as_bytes()[offset..offset + 3].try_into().unwrap()
|
||||
}
|
||||
|
||||
fn check_selection(&self, dark: bool) {
|
||||
let tint = if dark { [21, 136, 250] } else { [34, 101, 143] };
|
||||
assert_eq!(self.sample(0, 0.42, 7.), tint, "selected channel outline did not paint");
|
||||
}
|
||||
|
||||
fn check_fill(&self, dark: bool, enabled: bool) {
|
||||
for index in 0..2 {
|
||||
let left = self.sample(index, 0.42, 22.);
|
||||
let right = self.sample(index, 0.85, 22.);
|
||||
if enabled {
|
||||
let plateau = if dark { [25, 32, 49] } else { [169, 190, 225] };
|
||||
assert!(delta(left, plateau) <= 2, "unexpected stock channel plateau {left:?}");
|
||||
assert!(delta(left, right) >= if dark { 4 } else { 20 }, "missing horizontal gradient: {left:?}, {right:?}");
|
||||
} else {
|
||||
// The rows have a transparent top inset even when highlighted (4 px).
|
||||
assert!(delta(left, self.sample(index, 0.42, 2.)) <= 3, "channel left fill still paints: {left:?}");
|
||||
assert!(delta(right, self.sample(index, 0.85, 2.)) <= 3, "channel right fill still paints: {right:?}");
|
||||
}
|
||||
println!("{}: enabled={enabled} fill={left:?}->{right:?}", ROWS[index]);
|
||||
}
|
||||
}
|
||||
|
||||
fn compare(&self, other: &Self, error_offset: Option<f32>) {
|
||||
let offset = error_offset.unwrap_or_default();
|
||||
for (index, label) in ROWS.into_iter().enumerate() {
|
||||
let a = self.rows[index];
|
||||
let b = other.rows[index];
|
||||
assert_eq!((a.size, a.min_x(), a.min_y() + offset), (b.size, b.min_x(), b.min_y()),
|
||||
"changed row geometry beyond the error banner: {label}");
|
||||
let max_delta = self.row_pixels(index).zip(other.row_pixels(index))
|
||||
.flat_map(|(a, b)| a.iter().zip(b).map(|(a, b)| a.abs_diff(*b))).max().unwrap();
|
||||
if error_offset.is_some() {
|
||||
// The banner shortens the tree's gradient area. Permit only raster rounding.
|
||||
assert!(max_delta <= 1, "failed write changed paint on {label}: {max_delta}");
|
||||
} else if matches!(index, 2 | 3) {
|
||||
assert_eq!(max_delta, 0, "changed independent control region {label}");
|
||||
} else {
|
||||
assert!(max_delta > 4, "disabled background did not change {label}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn delta(a: [u8; 3], b: [u8; 3]) -> u8 {
|
||||
a.into_iter().zip(b).map(|(a, b)| a.abs_diff(b)).max().unwrap()
|
||||
}
|
||||
|
||||
async fn switch(runtime: &AppRuntime, ui: &AppWindow, checked: bool) -> SmokeResult<i_slint_core::item_tree::ItemRc> {
|
||||
let shell = ui.global::<ShellBridge>();
|
||||
let catalog = runtime.snapshot().catalog;
|
||||
if shell.get_destination() != 3 {
|
||||
// Routing back to the same tree is separate from interacting with the preference.
|
||||
shell.invoke_navigate(3);
|
||||
until("Settings navigation", || shell.get_destination() == 3).await?;
|
||||
}
|
||||
let page = catalog.text(Category::Appearance.key());
|
||||
if !ui.global::<SettingsBridge>().get_appearance_page() {
|
||||
focus::open_category(ui, &page)?;
|
||||
until("Appearance category", || ui.global::<SettingsBridge>().get_appearance_page()).await?;
|
||||
}
|
||||
let label = catalog.text(LABEL);
|
||||
until("rendered channel background switch", || focus::visible_selector(ui, &label, AccessibleRole::Checkbox).is_ok()).await?;
|
||||
let toggle = focus::visible_selector(ui, &label, AccessibleRole::Checkbox)?;
|
||||
assert_eq!(toggle.accessible_string_property(Prop::Checked).unwrap().as_str(), if checked { "true" } else { "false" });
|
||||
let subtitle = catalog.text(if checked { "settings.appearance.server.show.channel.bg.enabled" } else { "settings.appearance.server.show.channel.bg.disabled" });
|
||||
focus::visible_selector(ui, &subtitle, AccessibleRole::Text)?;
|
||||
Ok(toggle)
|
||||
}
|
||||
|
||||
async fn toggle(runtime: &AppRuntime, ui: &AppWindow, checked: bool, error: Option<&str>) -> SmokeResult<()> {
|
||||
let control = switch(runtime, ui, checked).await?;
|
||||
let serial = runtime.snapshot().settings_completed + 1;
|
||||
focus::activate(control)?;
|
||||
until("channel background save receipt", || runtime.snapshot().settings_completed >= serial).await?;
|
||||
let state = runtime.snapshot();
|
||||
assert_eq!(state.settings_completed, serial);
|
||||
assert_eq!(state.last_error.as_ref().map(|e| e.code.as_str()), error);
|
||||
switch(runtime, ui, if error.is_some() { checked } else { !checked }).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn session_state(snapshot: &Snapshot) -> (Option<u64>, Option<&str>, Option<&str>, Option<&crate::ui::chat::ConversationTarget>) {
|
||||
(snapshot.connections.get("c1").and_then(|session| session.selected_channel_id),
|
||||
snapshot.connections.viewed_id.as_deref(), snapshot.connections.input_id.as_deref(),
|
||||
snapshot.chat.conversation.as_ref().map(|c| &c.target))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn channel_background_updates_pixels_and_survives_failed_save_and_restart() {
|
||||
if !headless::install_for_test() { return; }
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let evidence = std::env::var_os("TEAMSPEACH_CHANNEL_BACKGROUND_EVIDENCE").map(PathBuf::from);
|
||||
for language in ["en", "ru"] {
|
||||
for (theme, dark) in [("dark", true), ("light", false)] {
|
||||
let name = format!("{language}-{theme}");
|
||||
let root = temp.path().join(&name);
|
||||
initialize_native_root(&root).unwrap();
|
||||
let baseline = {
|
||||
let mut profile = ProfileServices::open(&root).unwrap();
|
||||
profile.identities.onboard("Owner").unwrap();
|
||||
profile.prefs.set(json!({"language":language, "theme":theme, "serverPaneWidth":500})).unwrap();
|
||||
profile.prefs.get()
|
||||
};
|
||||
let config = AppConfig::isolated(root.clone());
|
||||
for reopened in [false, true] {
|
||||
let prefs = root.join("prefs.json");
|
||||
let before = baseline.clone();
|
||||
let prefix = name.clone();
|
||||
let evidence = evidence.clone();
|
||||
run_ui(&config, async move |runtime, ui| {
|
||||
ui.window().set_size(PhysicalSize::new(1280, 1100));
|
||||
until("isolated tab", || {
|
||||
let s = runtime.snapshot(); s.settings.loaded && s.catalog.language.code() == language
|
||||
&& !s.connections.connections.is_empty() && ui.global::<Theme>().get_dark() == dark
|
||||
}).await?;
|
||||
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":"BackgroundFixture=","name":ROWS[3]},"own_client_id":1,"own_channel_id":7,
|
||||
"channels":[{"id":7,"parent_id":0,"name":ROWS[0]},{"id":8,"parent_id":0,"name":ROWS[1]},
|
||||
{"id":9,"parent_id":0,"name":"[spacer]Divider","channel_type":"permanent"}],
|
||||
"clients":[{"id":1,"uid":"Owner=","nickname":ROWS[2],"channel_id":7,"input_muted":true,"output_muted":true}]
|
||||
})).await.map_err(|e| e.to_string())?;
|
||||
until("projected tree and channel conversation", || {
|
||||
let state=runtime.snapshot();
|
||||
state.chat.conversation.is_some() && ROWS.iter().all(|label| focus::visible_selector(ui, label, AccessibleRole::ListItem).is_ok())
|
||||
}).await?;
|
||||
let selected = focus::visible_selector(ui, ROWS[0], AccessibleRole::ListItem)?;
|
||||
focus::activate(selected)?;
|
||||
until("explicitly selected channel", || focus::visible_selector(ui, ROWS[0], AccessibleRole::ListItem)
|
||||
.is_ok_and(|row| row.accessible_string_property(Prop::ItemSelected).is_some_and(|value| value == "true"))).await?;
|
||||
let initial = runtime.snapshot();
|
||||
assert_eq!(session_state(&initial).0, Some(7));
|
||||
let tree = |tag| TreeFrame::capture(ui, evidence.as_ref().map(|dir| dir.join(format!("{prefix}-{tag}.png"))));
|
||||
let initial_tree = tree(if reopened { "restored-off" } else { "initial-on" })?;
|
||||
initial_tree.check_fill(dark, !reopened);
|
||||
initial_tree.check_selection(dark);
|
||||
let old_bytes = fs::read(&prefs).map_err(|e| e.to_string())?;
|
||||
let old_disk: Value = serde_json::from_slice(&old_bytes).map_err(|e| e.to_string())?;
|
||||
let blocker = prefs.with_extension("json.tmp");
|
||||
if reopened { fs::create_dir(&blocker).map_err(|e| e.to_string())?; }
|
||||
let changed = toggle(runtime, ui, !reopened, reopened.then_some("io")).await;
|
||||
if reopened { fs::remove_dir(blocker).map_err(|e| e.to_string())?; }
|
||||
changed?;
|
||||
if let Some(dir) = evidence.as_deref() {
|
||||
screenshot(ui, dir, &format!("{prefix}-{}.png", if reopened { "rejected-setting" } else { "saved-setting" }))?;
|
||||
}
|
||||
let disk = fs::read(&prefs).map_err(|e| e.to_string())?;
|
||||
let mut expected = before;
|
||||
expected[PREF] = false.into();
|
||||
assert_eq!(runtime.snapshot().settings.prefs, expected);
|
||||
if reopened { assert_eq!(disk, old_bytes); }
|
||||
let mut expected_disk = old_disk;
|
||||
expected_disk[PREF] = false.into();
|
||||
assert_eq!(serde_json::from_slice::<Value>(&disk).map_err(|e| e.to_string())?, expected_disk);
|
||||
let shell = ui.global::<ShellBridge>();
|
||||
shell.invoke_navigate(0);
|
||||
until("returned to the same native tree", || shell.get_destination() == 0
|
||||
&& focus::visible_selector(ui, ROWS[0], AccessibleRole::ListItem).is_ok()).await?;
|
||||
let after = tree(if reopened { "rejected-off" } else { "saved-off" })?;
|
||||
after.check_fill(dark, false);
|
||||
after.check_selection(dark);
|
||||
let error_offset = if reopened {
|
||||
let mut error = None;
|
||||
headless::visit_named_items(ui.window(), |id, item| {
|
||||
if id == "parity-shell-error" { error = headless::visible_bounds(ui.window(), item); }
|
||||
})?;
|
||||
Some(error.ok_or("missing visible failed-save banner")?.size.height)
|
||||
} else { None };
|
||||
initial_tree.compare(&after, error_offset);
|
||||
assert_eq!(session_state(&runtime.snapshot()), session_state(&initial));
|
||||
let selected = focus::visible_selector(ui, ROWS[0], AccessibleRole::ListItem)?;
|
||||
assert_eq!(selected.accessible_string_property(Prop::ItemSelected).unwrap().as_str(), "true");
|
||||
if reopened {
|
||||
ui.window().set_size(PhysicalSize::new(900, 800));
|
||||
let narrow = tree("narrow-off")?;
|
||||
assert!(narrow.rows[0].size.width < after.rows[0].size.width);
|
||||
narrow.check_fill(dark, false);
|
||||
narrow.check_selection(dark);
|
||||
}
|
||||
manager.fixture_control(&key, json!({"event":"state","state":"disconnected","generation":key.generation}))
|
||||
.await.map_err(|e| e.to_string())?;
|
||||
until("synthetic roster released", || !runtime.snapshot().connections.any_active()).await?;
|
||||
println!("{prefix}: reopened={reopened}; channel fills checked against backdrop; client and server pixels unchanged");
|
||||
Ok(())
|
||||
}).unwrap_or_else(|error| panic!("{name}, reopened={reopened}: {error}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,7 @@ fn update(ui:&AppWindow,runtime:&AppRuntime,bindings:&mut Bindings,generation:u6
|
||||
ui.global::<ShellBridge>().set_bookmarks_collapsed(snapshot.settings.prefs["savedServersCollapsed"]==true);
|
||||
ui.global::<ShellBridge>().set_compact_tree(snapshot.settings.prefs["treeStyle"]=="compact");
|
||||
ui.global::<ShellBridge>().set_channel_commander_as_lamp(snapshot.settings.prefs["channelCommanderAsLamp"]!=false);
|
||||
ui.global::<ShellBridge>().set_show_channel_background(snapshot.settings.prefs["showChannelBackground"]!=false);
|
||||
let panes=(width("sidebarWidth",270),width("serverPaneWidth",500));if bindings.panes!=Some(panes){ui.global::<ShellBridge>().set_sidebar_width(panes.0 as f32);ui.global::<ShellBridge>().set_server_width(panes.1 as f32);bindings.panes=Some(panes);}bindings.revision=snapshot.revision;}
|
||||
let mut new_frames=Vec::new();
|
||||
#[cfg(feature="webrtc")]
|
||||
|
||||
@@ -18,6 +18,7 @@ export struct ShellStream { id: string, title: string, status: string, frame: im
|
||||
export global ShellBridge {
|
||||
in-out property <bool> compact-tree;
|
||||
in-out property <bool> channel-commander-as-lamp: true;
|
||||
in-out property <bool> show-channel-background: true;
|
||||
in-out property <[ShellTab]> tabs;
|
||||
in-out property <[ShellRow]> tree;
|
||||
in-out property <[ShellRow]> bookmarks;
|
||||
@@ -413,7 +414,10 @@ component DesktopTreeRow inherits Rectangle {
|
||||
width: max(0px, root.width - self.x - (root.channel && root.highlighted ? 7px : 10px));
|
||||
height: root.server ? 74px : root.height - 2 * self.y;
|
||||
border-radius: root.server ? 10px : root.channel ? 9px : 100px;
|
||||
background: root.server ? ShellColors.banner : root.spacer ? @linear-gradient(-115deg, Theme.deviant, Theme.dark ? #374263 : Theme.contrast) : root.channel ? ShellColors.channel : transparent;
|
||||
background: root.server ? ShellColors.banner : root.spacer
|
||||
? (ShellBridge.show-channel-background || root.highlighted || root.item.selected || focus.has-focus
|
||||
? @linear-gradient(-115deg, Theme.deviant, Theme.dark ? #374263 : Theme.contrast) : transparent)
|
||||
: root.channel && ShellBridge.show-channel-background ? ShellColors.channel : transparent;
|
||||
border-width: root.item.selected || focus.has-focus || (root.highlighted && root.channel) ? (root.server ? 1px : 1.5px) : root.item.full || root.item.password ? 2px : 0px;
|
||||
border-color: root.item.selected || focus.has-focus ? ShellColors.selection-tint : root.highlighted ? ShellColors.subtitle : root.item.full ? Theme.error : root.item.password ? Theme.warning : ShellColors.subtitle;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user