//! 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. 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, }; use voelin_gateway_proto::{ Action, Attendee, ConfigEntry, ConfigSource, EventInfo, EventKind, EventSpec, PermRule, PermRuleInfo, ReactionCount, RsvpStatus, StreamEntry, StreamSource, TopicInfo, UserRef, feature, }; use voelin_model::{ BannerMode, Capabilities, 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::settings::LastVoice; use crate::vm::bridge::RecordingItem; /// 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::