diff --git a/crates/voelin-ui-vm/Cargo.toml b/crates/voelin-ui-vm/Cargo.toml index 17f3587..5eebc51 100644 --- a/crates/voelin-ui-vm/Cargo.toml +++ b/crates/voelin-ui-vm/Cargo.toml @@ -29,14 +29,13 @@ roxmltree = { version = "0.21", default-features = false, features = ["std"] } miniz_oxide = "0.8" # Grapheme clusters for emoji in chat text. unicode-segmentation = "1.13" +# The sample pictures of the demo data (VOELIN_DEMO_UI) and the tests. +png = "0.18" voelin-audio = { path = "../voelin-audio", default-features = false } voelin-core = { path = "../voelin-core", default-features = false, features = ["media"] } voelin-gateway-proto = { path = "../voelin-gateway-proto" } voelin-model = { path = "../voelin-model" } voelin-store = { path = "../voelin-store" } -[dev-dependencies] -png = "0.18" - [lints] workspace = true diff --git a/crates/voelin-ui/src/dev.rs b/crates/voelin-ui-vm/src/dev/logic.rs similarity index 61% rename from crates/voelin-ui/src/dev.rs rename to crates/voelin-ui-vm/src/dev/logic.rs index 3903cab..7d0a7e3 100644 --- a/crates/voelin-ui/src/dev.rs +++ b/crates/voelin-ui-vm/src/dev/logic.rs @@ -1,77 +1,19 @@ -//! Development switches (environment variables), for trying screens and -//! taking screenshots without a server: -//! -//! - `VOELIN_DATA_DIR=`: the database (app.rs). -//! - `VOELIN_AUTOCONNECT=voice|observe`: connect the first bookmark on start. -//! - `VOELIN_SCREENSHOT=`: save the window after -//! `VOELIN_SCREENSHOT_DELAY` seconds (default 4) and exit. -//! - `VOELIN_WINDOW_SIZE=x`: the window's size (e.g. `390x844` for the -//! phone layout). -//! - `VOELIN_DEMO_UI=1`: sample servers, channels, chat (two pages of older -//! messages answer scrolling up) and streams, no server needed (nothing is -//! stored). -//! - `VOELIN_DEMO_STREAM=1`: a local test stream in the viewer. -//! - `VOELIN_OPEN=[,...]`: open screens on start: `home`, -//! `server` (`server:chat`: its server chat), `settings[:
]` -//! (voice, keybinds, streaming, privacy, appearance, or 0-4), `about`, -//! `share`, `bookmark` (add a server, also `join`; -//! `bookmark:edit` the current one, Advanced open), -//! `emoji` (the picker), `client` (the volume dialog of the first other -//! client once connected), `panel` / `no-panel` (the members panel), -//! `voice` (the voice channel view; on the phone its own screen; -//! `voice:compact` with the smaller stage, not stored), -//! `more` (after `voice` on the phone: the voice screen's More menu, -//! opened once the screen is laid out), -//! `members` (the phone's members page), `notification` (a tapped voice -//! notification), `shared:` (text shared to the app on Android), -//! `pins`, `topics` (the drawers), -//! `topic:` (a topic's messages), `member` (the member card of the -//! first other client), `poke` (the poke dialog: for the contact shown -//! after `friends`, else for the first other client, its card open), -//! `channel-password` (the password dialog of the first locked channel, -//! the sample's Officers; `channel-password:wrong` as after a refused -//! one), `actions` (the last message's actions, as if hovered), -//! `first-run` (home's banner as before the first server, over the -//! sample data), -//! `unread` (the current chat read up to five messages before its end: -//! the "New" divider, scrolled up to; `unread:end` ten messages before, -//! at the list's end, under the bar that counts the new messages), -//! `link-confirm[:]` (the question before a masked link opens, by -//! default the sample's raid board), `link:` (a TeamSpeak link -//! opened: the server dialog filled in from it, or in voice on its -//! server a move into its channel), `watch` (the first stream; with -//! sample data the local test pattern in its place), `theatre` (after -//! `watch`: in theatre mode), `popout` (`watch` in a window of its own), -//! `tab:` (phone layout); `friends[:]`, -//! `messages[:]` (a private chat), `inbox` (offline messages), -//! `library`, `events`, `event-form`, `search[:]`, -//! `notifications` (the bell), `offline` (an offline message), `picture` -//! (a chat picture opened large), `camera` (the settings' camera -//! preview); settings sections also `account`, -//! `profiles` (also `identities`), `devices`, `notifications`, -//! `integrations`, `advanced` (5-10); -//! `studio[:]`: the Stream Studio (with `VOELIN_DEMO_UI` a demo -//! studio from synthetic sources), `studio:window` in a window of its own, -//! `studio:live` going live (also with a screen opened after it: -//! `studio:live,server,voice` shows our stream's card with the studio's -//! picture), `studio:record`, or a dialog: `studio:source`, -//! `studio:audio`, `studio:camera`, `studio:scene`, `studio:settings`. -//! A screenshot also saves the studio's window, or the stream's -//! (`-window.png`), and draws it over the main window. -//! - `VOELIN_AUTOWATCH=1`: watch the first stream that shows up. -//! - `VOELIN_AUTOSHARE=test-pattern`: share the test pattern (accepting -//! everyone) once connected to a TeamSpeak 6 server. +//! Sample data of `VOELIN_DEMO_UI`: servers, channels, people, chats, +//! contacts, notices and pictures, as plain values and as the events a +//! server would send. A front end feeds the events to +//! [`crate::events::handle`], so the screens are filled by the same code +//! that fills them from a real server; nothing here touches the engine, +//! the store or a toolkit. The pictures are PNG bytes the front end saves +//! where it wants. +use std::path::PathBuf; use std::sync::Arc; -use std::time::Duration; -use anyhow::Result; -use slint::{ComponentHandle, Rgba8Pixel, SharedPixelBuffer}; use voelin_core::gateway::Pin; use voelin_core::stream::{StreamInfo, StreamKind}; use voelin_core::{ - BackendInfo, Contact, Event, GatewayUpdate, HistoryMessage, HistorySource, JoinFailure, - ObserveState, OfflineMessageInfo, Relation, SessionState, Source, VoiceState, + BackendInfo, Contact, Event, GatewayUpdate, HistoryMessage, HistorySource, ObserveState, + OfflineMessageInfo, Relation, SessionState, Source, VoiceState, }; use voelin_gateway_proto::{ Action, Attendee, ConfigEntry, ConfigSource, EventInfo, EventKind, EventSpec, PermRule, @@ -79,426 +21,19 @@ use voelin_gateway_proto::{ feature, }; use voelin_model::{ - BannerMode, Capabilities, ChannelInfo, ChatMessage, ChatTarget, ClientInfo, GroupInfo, Presence, + BannerMode, Capabilities, ChannelId, ChannelInfo, ChatMessage, ChatTarget, ClientInfo, + GroupInfo, Presence, }; use voelin_store::{Bookmark, MessageSource}; -use crate::app::{App, Bridge, MainWindow, MobileTab, Nav, Page, SettingsSection, with_app}; +use crate::bridge::RecordingItem; use crate::settings::LastVoice; -use crate::vm::bridge::RecordingItem; +use crate::social::logic::Social; +use crate::social::{NoticeKind, NoticeRequest, NoticeTarget}; +use crate::state::{AppState, Lines}; -/// The switches read at start. -#[derive(Clone, Debug, Default)] -pub(crate) struct Switches { - pub demo_stream: bool, - pub demo_ui: bool, - pub autoshare: bool, - pub open_client: bool, - open: Vec, - autoconnect: Option, - screenshot: Option, - screenshot_delay: u64, - window_size: Option<(f32, f32)>, -} - -fn flag(name: &str) -> bool { - std::env::var(name).is_ok_and(|v| v == "1") -} - -/// `390x844` → (390, 844). -fn parse_size(text: &str) -> Option<(f32, f32)> { - let (w, h) = text.split_once(['x', 'X'])?; - Some((w.trim().parse().ok()?, h.trim().parse().ok()?)) -} - -impl Switches { - pub fn from_env() -> Self { - let open: Vec = std::env::var("VOELIN_OPEN") - .unwrap_or_default() - .split(',') - .map(|s| s.trim().to_owned()) - .filter(|s| !s.is_empty()) - .collect(); - Self { - demo_stream: flag("VOELIN_DEMO_STREAM"), - demo_ui: flag("VOELIN_DEMO_UI"), - autoshare: std::env::var("VOELIN_AUTOSHARE").is_ok_and(|v| v == "test-pattern"), - open_client: open.iter().any(|o| o == "client"), - open, - autoconnect: std::env::var("VOELIN_AUTOCONNECT").ok(), - screenshot: std::env::var_os("VOELIN_SCREENSHOT").map(Into::into), - screenshot_delay: std::env::var("VOELIN_SCREENSHOT_DELAY") - .ok() - .and_then(|d| d.parse().ok()) - .unwrap_or(4), - window_size: std::env::var("VOELIN_WINDOW_SIZE").ok().as_deref().and_then(parse_size), - } - } -} - -fn section(name: &str) -> SettingsSection { - match name { - "1" | "keybinds" | "ptt" => SettingsSection::Keybinds, - "2" | "streaming" => SettingsSection::Streaming, - "3" | "privacy" => SettingsSection::Privacy, - "4" | "appearance" => SettingsSection::Appearance, - "5" | "account" => SettingsSection::Account, - "6" | "profiles" | "identities" => SettingsSection::Profiles, - "7" | "devices" => SettingsSection::Devices, - "8" | "notifications" => SettingsSection::Notifications, - "9" | "integrations" => SettingsSection::Integrations, - "10" | "advanced" => SettingsSection::Advanced, - _ => SettingsSection::Voice, - } -} - -fn mobile_tab(name: &str) -> MobileTab { - match name { - "home" => MobileTab::Home, - "servers" => MobileTab::Servers, - "activity" => MobileTab::Activity, - "you" => MobileTab::You, - _ => MobileTab::Chat, - } -} - -/// Timers that must live while the window runs. -pub(crate) struct Running { - _screenshot: Option, - _resize: Option, - _scroll: Option, - _more: Option, -} - -/// Apply the switches once the app is set up. -pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running { - if let Some((w, h)) = switches.window_size { - ui.window().set_size(slint::LogicalSize::new(w, h)); - } - if switches.demo_ui { - with_app(demo_ui); - } - match switches.autoconnect.as_deref() { - Some("voice") => { - with_app(|app| app.connect_voice()); - } - Some("observe") => { - with_app(|app| { - if let Some(id) = app.state.current { - app.observe(id); - } - }); - } - _ => {} - } - let nav = ui.global::