diff --git a/Cargo.lock b/Cargo.lock index a7e39ff..515ee26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9276,6 +9276,7 @@ dependencies = [ "anyhow", "chrono", "dirs", + "miniz_oxide 0.8.9", "png", "serde", "serde_json", @@ -9285,6 +9286,7 @@ dependencies = [ "tracing", "tracing-subscriber", "tsclientlib", + "unicode-segmentation", "voelin-audio", "voelin-core", "voelin-model", diff --git a/README.md b/README.md index b93745e..3d1ac09 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,8 @@ Done so far (milestones M0–M4 and the first part of M5 of [the plan](docs/arch - `crates/voelin-ui` (`voelin`): Slint desktop app: servers, channel tree with talking indicators, chat tabs (own channel via voice, other channels via relay), connect / observe invisibly, mute, push-to-talk (in the window and as a global hotkey), audio settings with a level meter, per-client volume, and on - TeamSpeak 6 streams: watch in a viewer, share the screen with sound + TeamSpeak 6 streams: watch in a viewer, share the screen with sound. Desktop and phone layouts + from one design system, dark and light themes, text size, emoji ([docs/ui.md](docs/ui.md)) - `crates/voelin-stream`: TeamSpeak 6 streams: stream commands and notifications, JSON signalling, WebRTC peers (str0m) with host and STUN candidates. A live test streams VP8 + Opus between two clients through a TS6 server @@ -58,11 +59,14 @@ Done so far (milestones M0–M4 and the first part of M5 of [the plan](docs/arch Screen sharing works between our clients through a TeamSpeak 6 server (VP8 video, Opus audio); interop with the official TeamSpeak 6 client is not verified yet. -| Connected with voice | Observing invisibly through the gateway | +The UI (design system, desktop and phone layouts, emoji, how to add a screen) is described in +[docs/ui.md](docs/ui.md). Screenshots with sample data (`VOELIN_DEMO_UI=1`): + +| Server, chat and people in the channel | Watching a stream | |---|---| -| ![voice](docs/screenshots/desktop-voice.png) | ![observe](docs/screenshots/desktop-observe.png) | -| **Watching a stream** | **Sharing the screen** | -| ![viewer](docs/screenshots/desktop-stream-viewer.png) | ![share](docs/screenshots/desktop-share-dialog.png) | +| ![server](docs/screenshots/desktop-server.png) | ![viewer](docs/screenshots/desktop-stream-viewer.png) | +| **Settings** | **Phone layout** | +| ![settings](docs/screenshots/desktop-settings-voice.png) | ![phone](docs/screenshots/mobile-chat.png) | ## Try it @@ -102,8 +106,10 @@ Other commands: `voelinctl identity new`, `voelinctl versions`, `voelinctl conne Development switches of the desktop app (environment variables): `VOELIN_DATA_DIR` (database), `VOELIN_AUTOCONNECT=voice|observe`, `VOELIN_SCREENSHOT=` (with `VOELIN_SCREENSHOT_DELAY`), -`VOELIN_DEMO_STREAM=1` (a local test stream in the viewer, no server needed), -`VOELIN_OPEN=share|settings[:]|about|client`, `VOELIN_AUTOWATCH=1`, `VOELIN_AUTOSHARE=test-pattern`. +`VOELIN_WINDOW_SIZE=x`, `VOELIN_DEMO_UI=1` (sample servers and chat, no server needed), +`VOELIN_DEMO_STREAM=1` (a local test stream in the viewer), +`VOELIN_OPEN=home|settings[:
]|about|share|bookmark|emoji|client|tab:` (comma-separated), +`VOELIN_AUTOWATCH=1`, `VOELIN_AUTOSHARE=test-pattern`; details in [docs/ui.md](docs/ui.md). Ready-made packages (Linux `.tar.gz`/`.deb`/Flatpak, Windows zip and installer, Android APK, and the `tsgw` gateway for Linux servers) come from the release workflow (version tags, or run by @@ -123,6 +129,7 @@ the same terms in `Cargo.toml`. Third-party notices: [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md), generated from `Cargo.lock` by `scripts/notices.sh` and shown in the app's About page. The UI toolkit, Slint, is used under its royalty-free license, which requires an attribution in the -About page. +About page. The UI bundles the Inter font (SIL OFL 1.1), Lucide icons (ISC) and Twemoji +graphics (CC-BY 4.0); `scripts/notices.sh` appends their notices from `about-assets.md`. Security issues: see [SECURITY.md](SECURITY.md). Releases: [docs/release.md](docs/release.md). diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 9979541..ab3db9d 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -11634,3 +11634,164 @@ bzip2/libbzip2 version 1.1.0 of 6 September 2010 -------------------------------------------------------------------------- ```` + +## Bundled fonts, icons and emoji + + + +The user interface bundles these assets (in crates/voelin-ui): + +- Inter (the UI font), Copyright (c) 2016 The Inter Project Authors, under + the SIL Open Font License 1.1 (OFL-1.1; text below). +- Lucide icons (lucide-static 1.48.0), Copyright (c) Lucide Icons and + Contributors, under the ISC License; the icons derived from Feather are + Copyright (c) 2013-present Cole Bemis, under the MIT License (texts below). +- Twemoji 15.0 (the emoji images): Twemoji graphics by Twitter, Inc and other + contributors, licensed under CC-BY 4.0 + (https://creativecommons.org/licenses/by/4.0/). The SVG files are packed + into one archive; their content is unchanged. + +### OFL-1.1 (Inter) + +````text +Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION AND CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. +```` + +### ISC and MIT (Lucide, Feather) + +````text +ISC License + +Copyright (c) 2026 Lucide Icons and Contributors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +--- + +The following Lucide icons are derived from the Feather project: + +airplay, alert-circle, alert-octagon, alert-triangle, aperture, arrow-down-circle, arrow-down-left, arrow-down-right, arrow-down, arrow-left-circle, arrow-left, arrow-right-circle, arrow-right, arrow-up-circle, arrow-up-left, arrow-up-right, arrow-up, at-sign, calendar, cast, check, chevron-down, chevron-left, chevron-right, chevron-up, chevrons-down, chevrons-left, chevrons-right, chevrons-up, circle, clipboard, clock, code, columns, command, compass, corner-down-left, corner-down-right, corner-left-down, corner-left-up, corner-right-down, corner-right-up, corner-up-left, corner-up-right, crosshair, database, divide-circle, divide-square, dollar-sign, download, external-link, feather, frown, hash, headphones, help-circle, info, italic, key, layout, life-buoy, link-2, link, loader, lock, log-in, log-out, maximize, meh, minimize, minimize-2, minus-circle, minus-square, minus, monitor, moon, more-horizontal, more-vertical, move, music, navigation-2, navigation, octagon, pause-circle, percent, plus-circle, plus-square, plus, power, radio, rss, search, server, share, shopping-bag, sidebar, smartphone, smile, square, table-2, tablet, target, terminal, trash-2, trash, triangle, tv, type, upload, x-circle, x-octagon, x-square, x, zoom-in, zoom-out + +The MIT License (MIT) (for the icons listed above) + +Copyright (c) 2013-present Cole Bemis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +```` diff --git a/about-assets.md b/about-assets.md new file mode 100644 index 0000000..5a84f3e --- /dev/null +++ b/about-assets.md @@ -0,0 +1,161 @@ + +## Bundled fonts, icons and emoji + + + +The user interface bundles these assets (in crates/voelin-ui): + +- Inter (the UI font), Copyright (c) 2016 The Inter Project Authors, under + the SIL Open Font License 1.1 (OFL-1.1; text below). +- Lucide icons (lucide-static 1.48.0), Copyright (c) Lucide Icons and + Contributors, under the ISC License; the icons derived from Feather are + Copyright (c) 2013-present Cole Bemis, under the MIT License (texts below). +- Twemoji 15.0 (the emoji images): Twemoji graphics by Twitter, Inc and other + contributors, licensed under CC-BY 4.0 + (https://creativecommons.org/licenses/by/4.0/). The SVG files are packed + into one archive; their content is unchanged. + +### OFL-1.1 (Inter) + +````text +Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION AND CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. +```` + +### ISC and MIT (Lucide, Feather) + +````text +ISC License + +Copyright (c) 2026 Lucide Icons and Contributors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +--- + +The following Lucide icons are derived from the Feather project: + +airplay, alert-circle, alert-octagon, alert-triangle, aperture, arrow-down-circle, arrow-down-left, arrow-down-right, arrow-down, arrow-left-circle, arrow-left, arrow-right-circle, arrow-right, arrow-up-circle, arrow-up-left, arrow-up-right, arrow-up, at-sign, calendar, cast, check, chevron-down, chevron-left, chevron-right, chevron-up, chevrons-down, chevrons-left, chevrons-right, chevrons-up, circle, clipboard, clock, code, columns, command, compass, corner-down-left, corner-down-right, corner-left-down, corner-left-up, corner-right-down, corner-right-up, corner-up-left, corner-up-right, crosshair, database, divide-circle, divide-square, dollar-sign, download, external-link, feather, frown, hash, headphones, help-circle, info, italic, key, layout, life-buoy, link-2, link, loader, lock, log-in, log-out, maximize, meh, minimize, minimize-2, minus-circle, minus-square, minus, monitor, moon, more-horizontal, more-vertical, move, music, navigation-2, navigation, octagon, pause-circle, percent, plus-circle, plus-square, plus, power, radio, rss, search, server, share, shopping-bag, sidebar, smartphone, smile, square, table-2, tablet, target, terminal, trash-2, trash, triangle, tv, type, upload, x-circle, x-octagon, x-square, x, zoom-in, zoom-out + +The MIT License (MIT) (for the icons listed above) + +Copyright (c) 2013-present Cole Bemis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +```` diff --git a/crates/voelin-ui/Cargo.toml b/crates/voelin-ui/Cargo.toml index eae00d1..c10e18b 100644 --- a/crates/voelin-ui/Cargo.toml +++ b/crates/voelin-ui/Cargo.toml @@ -20,11 +20,15 @@ path = "src/main.rs" anyhow = "1.0.104" chrono = { version = "0.4.45", default-features = false, features = ["clock"] } dirs = "6" +# Twemoji archive blocks (raw deflate); already used by png. +miniz_oxide = "0.8" png = "0.18" serde = { version = "1", features = ["derive"] } tokio = { version = "1.53.1", features = ["rt-multi-thread", "macros", "time", "sync"] } tracing = "0.1.44" tracing-subscriber = { version = "0.3.23", features = ["env-filter"] } +# Grapheme clusters for emoji in chat text. +unicode-segmentation = "1.13" voelin-audio = { path = "../voelin-audio" } voelin-core = { path = "../voelin-core", default-features = false, features = ["audio-device"] } voelin-model = { path = "../voelin-model" } @@ -43,10 +47,12 @@ voelin-platform = { path = "../voelin-platform" } voelin-store = { path = "../voelin-store", features = ["keyring"] } # Android (voelin-android): no keyring backend (the app passes Keystore-backed -# secrets), no winit/femtovg (the app picks Slint's Android backend), stream -# media through MediaCodec and the app's capture source. +# secrets), no winit/femtovg, stream media through MediaCodec and the app's +# capture source. Slint's Android backend (the one the app runs) also brings +# the SVG and image decoders the icons and emoji need, so this crate builds +# alone for Android too. [target.'cfg(target_os = "android")'.dependencies] -slint = { version = "1.18", default-features = false, features = ["std", "compat-1-2", "renderer-software"] } +slint = { version = "1.18", default-features = false, features = ["std", "compat-1-2", "renderer-software", "backend-android-activity-06"] } voelin-core = { path = "../voelin-core", default-features = false, features = ["media"] } [dev-dependencies] diff --git a/crates/voelin-ui/assets/README.md b/crates/voelin-ui/assets/README.md new file mode 100644 index 0000000..0819924 --- /dev/null +++ b/crates/voelin-ui/assets/README.md @@ -0,0 +1,12 @@ +# Bundled assets + +- `twemoji.bin`: the Twemoji 15.0 SVGs (3720 emoji, from the `@twemoji/svg` + 15.0.0 package) packed by `scripts/pack-twemoji.py` into blocks of raw + deflate with an index; `src/emoji.rs` reads it. Twemoji graphics by Twitter, + Inc and other contributors, licensed under CC-BY 4.0 + (https://creativecommons.org/licenses/by/4.0/). The files are unchanged + apart from surrounding whitespace. + +The fonts (Inter, SIL OFL 1.1) and icons (Lucide, ISC) that the Slint files +import are under `ui/assets/`, each with its license. All three are credited +in `THIRD_PARTY_NOTICES.md` and the About page. diff --git a/crates/voelin-ui/assets/twemoji.bin b/crates/voelin-ui/assets/twemoji.bin new file mode 100644 index 0000000..a56c44e Binary files /dev/null and b/crates/voelin-ui/assets/twemoji.bin differ diff --git a/crates/voelin-ui/build.rs b/crates/voelin-ui/build.rs index 1f01446..eeb57f5 100644 --- a/crates/voelin-ui/build.rs +++ b/crates/voelin-ui/build.rs @@ -1,7 +1,7 @@ fn main() { slint_build::compile_with_config( "ui/app.slint", - slint_build::CompilerConfiguration::new().with_style("fluent-dark".into()), + slint_build::CompilerConfiguration::new().with_style("fluent".into()), ) .expect("slint compile"); } diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index 9db99c9..18eff60 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -1,7 +1,10 @@ -//! Application state on the UI thread, wired to the engine. +//! Application state on the UI thread, wired to the engine: setup, the +//! event loop glue and the state the screens share. //! -//! Streams (the streams panel, sharing, the viewer) are in `streams.rs`, -//! the settings page's data in `settings.rs`. +//! The screens' logic is elsewhere: servers and the channel tree in +//! `servers.rs`, chat in `chat.rs`, streams in `streams.rs`, the settings +//! page in `settings_page.rs` and `appearance.rs`, the view models in `vm/`, +//! callbacks in `bind/`, development switches in `dev.rs`. use std::cell::RefCell; use std::collections::{HashMap, HashSet}; @@ -11,27 +14,23 @@ use std::sync::Arc; use std::time::Duration; use anyhow::{Context, Result}; -use slint::{ComponentHandle, ModelRc, SharedString, VecModel}; +use slint::{ComponentHandle, ModelRc, VecModel}; use tokio::runtime::Runtime; use tracing::warn; use voelin_core::settings::{AUDIO, CRASH_REPORTS, Settings}; use voelin_core::stream::StreamInfo; -use voelin_core::{ - AudioSettings, Command, Engine, Event, ObserveState, SessionState, Source, VoiceOptions, - VoiceState, -}; -use voelin_model::{ - Capabilities, ChannelId, ChatMessage, ChatTarget, Presence, TreeRow, tree_rows, -}; -use voelin_platform::{crash, notices}; -use voelin_store::{Bookmark, MemorySecrets, QueryConfig, QueryTransport, Secrets, Store}; +use voelin_core::{AudioSettings, Command, Engine, Event, SessionState, VoiceState}; +use voelin_model::{Capabilities, ChannelId, ChatTarget, Presence}; +use voelin_platform::crash; +use voelin_store::{Bookmark, MemorySecrets, Secrets, Store}; use crate::hotkey::GlobalPtt; use crate::settings::{ - self, CLIENT_PLAYBACK, ClientPlayback, ClientPlaybackMap, DeviceChoices, UI, UiSettings, + CLIENT_PLAYBACK, ClientPlaybackMap, DeviceChoices, UI, UiSettings, appearance_keys, }; use crate::streams::{Share, Watch}; use crate::video::Video; +use crate::vm::chat::Previous; slint::include_modules!(); @@ -46,6 +45,9 @@ fn open_settings(dir: &Path, overrides: &[String]) -> Settings { }); prefs.register(&UI); prefs.register(&CLIENT_PLAYBACK); + for key in appearance_keys() { + prefs.register(key); + } let config = std::env::var_os("VOELIN_CONFIG") .map(PathBuf::from) .or_else(|| Some(dir.join("config.toml")).filter(|p| p.exists())); @@ -105,11 +107,21 @@ impl Secrets for FallbackSecrets { } } -struct Tab { - target: ChatTarget, - title: String, - lines: Vec, - unread: i32, +/// A chat of a session: its lines are the model the chat view shows while +/// the tab is selected, so a new message is one row appended. +pub(crate) struct Tab { + pub target: ChatTarget, + pub title: String, + pub lines: Rc>, + /// The last message, for grouping the next one. + pub last: Option, + pub unread: i32, +} + +impl Tab { + pub fn new(target: ChatTarget, title: String) -> Self { + Self { target, title, lines: Rc::new(VecModel::default()), last: None, unread: 0 } + } } /// What we know about one server session. @@ -117,16 +129,16 @@ pub(crate) struct SessionView { pub state: SessionState, pub capabilities: Capabilities, pub presence: Arc, - collapsed: HashSet, - talking: HashSet, - tabs: Vec, - current_tab: usize, + pub collapsed: HashSet, + pub talking: HashSet, + pub tabs: Vec, + pub current_tab: usize, /// The own channel's tab was focused for this voice connection. - focused_own_channel: bool, + pub focused_own_channel: bool, /// The streams in our channel (TeamSpeak 6). pub streams: Vec, /// Clients whose stored volume was sent for this voice connection. - applied_playback: HashSet, + pub applied_playback: HashSet, } impl Default for SessionView { @@ -137,12 +149,7 @@ impl Default for SessionView { presence: Arc::default(), collapsed: HashSet::new(), talking: HashSet::new(), - tabs: vec![Tab { - target: ChatTarget::Server, - title: "Server".into(), - lines: Vec::new(), - unread: 0, - }], + tabs: vec![Tab::new(ChatTarget::Server, "Server".into())], current_tab: 0, focused_own_channel: false, streams: Vec::new(), @@ -164,32 +171,75 @@ impl SessionView { .get(&client) .map_or_else(|| format!("client {client}"), |c| c.nickname.clone()) } + + /// Unread messages in all chats. + pub fn unread(&self) -> i32 { + self.tabs.iter().map(|t| t.unread).sum() + } +} + +/// The models the Bridge shows, created once and updated row by row +/// (`vm::list::sync`). +pub(crate) struct Models { + pub servers: Rc>, + pub tree: Rc>, + pub members: Rc>, + pub tabs: Rc>, + pub streams: Rc>, + pub viewers: Rc>, + /// Shown when there is no chat. + pub no_chat: Rc>, +} + +impl Models { + fn new(bridge: &Bridge) -> Self { + let models = Self { + servers: Rc::default(), + tree: Rc::default(), + members: Rc::default(), + tabs: Rc::default(), + streams: Rc::default(), + viewers: Rc::default(), + no_chat: Rc::default(), + }; + bridge.set_servers(ModelRc::from(models.servers.clone())); + bridge.set_tree(ModelRc::from(models.tree.clone())); + bridge.set_members(ModelRc::from(models.members.clone())); + bridge.set_tabs(ModelRc::from(models.tabs.clone())); + bridge.set_streams(ModelRc::from(models.streams.clone())); + bridge.set_share_viewers(ModelRc::from(models.viewers.clone())); + bridge.set_messages(ModelRc::from(models.no_chat.clone())); + models + } } pub(crate) struct App { pub ui: slint::Weak, - store: Store, - secrets: Box, + pub store: Store, + pub secrets: Box, pub engine: Engine, - identity: tsclientlib::Identity, - bookmarks: Vec, + pub identity: tsclientlib::Identity, + pub bookmarks: Vec, pub current: Option, pub sessions: HashMap, - status: String, + pub models: Models, + pub status: String, + /// The top bar's search: filters the channel tree. + pub tree_filter: String, /// The settings service (shared with the engine); `settings`, `audio` /// and `playback` are working copies of its keys. pub prefs: Settings, pub settings: UiSettings, - audio: AudioSettings, + pub audio: AudioSettings, /// Audio settings changed since they were last stored. - audio_dirty: bool, - inputs: DeviceChoices, - outputs: DeviceChoices, - playback: ClientPlaybackMap, + pub audio_dirty: bool, + pub inputs: DeviceChoices, + pub outputs: DeviceChoices, + pub playback: ClientPlaybackMap, /// The client in the volume dialog: session, client id, unique id. - playback_dialog: Option<(i64, u16, Option)>, - mic_test: bool, - ptt: GlobalPtt, + pub playback_dialog: Option<(i64, u16, Option)>, + pub mic_test: bool, + pub ptt: GlobalPtt, pub video: Video, /// Our stream. pub share: Option, @@ -202,12 +252,14 @@ pub(crate) struct App { pub stream_volume: f32, /// `VOELIN_DEMO_STREAM`: the viewer shows a local test stream. pub demo: bool, + /// `VOELIN_DEMO_UI`: sample servers, channels and chat (dev.rs). + pub demo_ui: bool, /// `VOELIN_AUTOSHARE=test-pattern`: share the test pattern once streams work. pub autoshare: bool, /// `VOELIN_OPEN=client`: open the volume dialog of the first other client. - open_client_pending: bool, + pub open_client_pending: bool, /// The notices are in the About page's model. - notices_loaded: bool, + pub notices_loaded: bool, } thread_local! { @@ -304,14 +356,8 @@ pub fn run(options: RunOptions) -> Result<()> { }; let HostedEngine { engine, runtime, mut events } = hosted; - // Development switches: VOELIN_DATA_DIR isolates the database, - // VOELIN_AUTOCONNECT=voice|observe connects the first bookmark on start, - // VOELIN_SCREENSHOT= saves the window after VOELIN_SCREENSHOT_DELAY seconds and exits, - // VOELIN_DEMO_STREAM=1 shows a local test stream in the viewer, - // VOELIN_OPEN=share|settings[:]|about|client opens that on start (client: the - // volume dialog of the first other client once connected), VOELIN_AUTOWATCH=1 - // watches the first stream that shows up, VOELIN_AUTOSHARE=test-pattern shares - // the test pattern (accepting everyone) once connected to a TeamSpeak 6 server. + // VOELIN_DATA_DIR isolates the database; the other development + // switches are in dev.rs. let dir: PathBuf = match (options.data_dir, std::env::var_os("VOELIN_DATA_DIR")) { (Some(dir), _) => dir, (None, Some(dir)) => dir.into(), @@ -339,8 +385,10 @@ pub fn run(options: RunOptions) -> Result<()> { engine.send(Command::SetAudioSettings(Box::new(audio.clone()))); let ui = MainWindow::new()?; - ui.global::().set_app_name(voelin_platform::APP_NAME.into()); - ui.global::().set_app_version(env!("CARGO_PKG_VERSION").into()); + let bridge = ui.global::(); + bridge.set_app_name(voelin_platform::APP_NAME.into()); + bridge.set_app_version(env!("CARGO_PKG_VERSION").into()); + let models = Models::new(&bridge); // Wayland and X11 find the desktop file (and icon) by this id. #[cfg(not(target_os = "android"))] if let Err(e) = slint::set_xdg_app_id(voelin_platform::APP_ID) { @@ -356,7 +404,7 @@ pub fn run(options: RunOptions) -> Result<()> { ptt.set(Some(settings.ptt_key.clone())); } let video = Video::new(&dir, settings.openh264); - let demo = std::env::var("VOELIN_DEMO_STREAM").is_ok_and(|v| v == "1"); + let switches = crate::dev::Switches::from_env(); let app = App { ui: ui.as_weak(), store, @@ -366,7 +414,9 @@ pub fn run(options: RunOptions) -> Result<()> { current: bookmarks.first().map(|b| b.id), bookmarks, sessions: HashMap::new(), - status: "Ready".into(), + models, + status: String::new(), + tree_filter: String::new(), prefs, settings, audio, @@ -383,14 +433,16 @@ pub fn run(options: RunOptions) -> Result<()> { share_error: String::new(), watch: None, stream_volume: 100.0, - demo, - autoshare: std::env::var("VOELIN_AUTOSHARE").is_ok_and(|v| v == "test-pattern"), - open_client_pending: std::env::var("VOELIN_OPEN").is_ok_and(|v| v == "client"), + demo: switches.demo_stream, + demo_ui: switches.demo_ui, + autoshare: switches.autoshare, + open_client_pending: switches.open_client, notices_loaded: false, }; APP.with(|a| *a.borrow_mut() = Some(app)); - wire_callbacks(&ui); + crate::bind::wire(&ui); with_app(|app| { + app.apply_appearance(); app.refresh_all(); app.refresh_settings_flags(); app.refresh_crash_notice(); @@ -416,44 +468,7 @@ pub fn run(options: RunOptions) -> Result<()> { with_app(|app| app.tick()); }); - match std::env::var("VOELIN_AUTOCONNECT").as_deref() { - Ok("voice") => { - with_app(|app| app.connect_voice()); - } - Ok("observe") => { - with_app(|app| app.toggle_observe()); - } - _ => {} - } - match std::env::var("VOELIN_OPEN").as_deref() { - Ok("share") => ui.invoke_open_share_dialog(), - Ok("about") => { - with_app(|app| app.load_notices()); - ui.set_show_about(true); - } - Ok(open) if open.starts_with("settings") => { - with_app(|app| app.open_settings()); - let tab = open.strip_prefix("settings:").and_then(|t| t.parse().ok()); - ui.set_settings_tab(tab.unwrap_or(0)); - ui.set_settings_open(true); - } - _ => {} - } - let _screenshot_timer = std::env::var_os("VOELIN_SCREENSHOT").map(|path| { - let delay = - std::env::var("VOELIN_SCREENSHOT_DELAY").ok().and_then(|d| d.parse().ok()).unwrap_or(4); - let weak = ui.as_weak(); - let timer = slint::Timer::default(); - timer.start(slint::TimerMode::SingleShot, Duration::from_secs(delay), move || { - if let Some(ui) = weak.upgrade() { - if let Err(e) = save_screenshot(&ui, std::path::Path::new(&path)) { - eprintln!("screenshot failed: {e}"); - } - let _ = ui.hide(); - } - }); - timer - }); + let _dev = crate::dev::start(&ui, &switches); ui.run()?; // With our own engine, leave servers properly, so no ghost client stays @@ -466,12 +481,12 @@ pub fn run(options: RunOptions) -> Result<()> { } app.watch = None; app.share = None; - if own { + if own && !app.demo_ui { for id in app.sessions.keys() { app.engine.send(Command::CloseSession { session: *id as u64 }); } } - own && !app.sessions.is_empty() + own && !app.sessions.is_empty() && !app.demo_ui }); APP.with(|a| a.borrow_mut().take()); if let Some(runtime) = own_runtime { @@ -483,175 +498,8 @@ pub fn run(options: RunOptions) -> Result<()> { Ok(()) } -fn wire_callbacks(ui: &MainWindow) { - let bridge = ui.global::(); - bridge.on_select_server(|id| { - with_app(|app| { - app.current = Some(id as i64); - app.refresh_all(); - }); - }); - bridge.on_connect_voice(|| { - with_app(|app| app.connect_voice()); - }); - bridge.on_disconnect_voice(|| { - with_app(|app| app.command(|session| Command::DisconnectVoice { session })); - }); - bridge.on_toggle_observe(|| { - with_app(|app| app.toggle_observe()); - }); - bridge.on_join_channel(|cid| { - with_app(|app| { - app.command(|session| Command::MoveToChannel { - session, - channel: cid as ChannelId, - password: None, - }) - }); - }); - bridge.on_open_channel_chat(|cid| { - with_app(|app| app.open_chat(ChatTarget::Channel(cid as ChannelId), true)); - }); - bridge.on_toggle_collapse(|cid| { - with_app(|app| { - if let Some(view) = app.view_mut() { - let cid = cid as ChannelId; - if !view.collapsed.remove(&cid) { - view.collapsed.insert(cid); - } - } - app.refresh_tree(); - }); - }); - bridge.on_select_tab(|i| { - with_app(|app| { - if let Some(view) = app.view_mut() { - view.current_tab = i as usize; - if let Some(tab) = view.tabs.get_mut(i as usize) { - tab.unread = 0; - } - } - app.refresh_chat(); - }); - }); - bridge.on_close_tab(|i| { - with_app(|app| app.close_tab(i as usize)); - }); - bridge.on_send_message(|text| { - with_app(|app| app.send_message(text.to_string())); - }); - bridge.on_set_input_muted(|muted| { - with_app(|app| app.command(|session| Command::SetInputMuted { session, muted })); - }); - bridge.on_set_output_muted(|muted| { - with_app(|app| app.command(|session| Command::SetOutputMuted { session, muted })); - }); - bridge.on_push_to_talk(|on| { - with_app(|app| app.command(|session| Command::SetTransmitting { session, on })); - }); - bridge.on_edit_bookmark(|id| with_app(|app| app.bookmark_form(id as i64)).unwrap_or_default()); - bridge.on_save_bookmark(|form| { - with_app(|app| app.save_bookmark(form)); - }); - bridge.on_delete_bookmark(|id| { - with_app(|app| app.delete_bookmark(id as i64)); - }); - - // Streams. - bridge.on_open_share(|| with_app(|app| app.open_share()).unwrap_or_default()); - bridge.on_start_share(|form| { - with_app(|app| app.start_share(form)); - }); - bridge.on_stop_share(|| { - with_app(|app| app.stop_share()); - }); - bridge.on_respond_viewer(|viewer, accept| { - with_app(|app| app.respond_viewer(viewer as u16, accept)); - }); - bridge.on_kick_viewer(|viewer| { - with_app(|app| app.kick_viewer(viewer as u16)); - }); - bridge.on_watch_stream(|id| { - with_app(|app| app.watch_stream(id.to_string())); - }); - bridge.on_show_viewer(|| { - with_app(|app| app.show_viewer(true)); - }); - bridge.on_hide_viewer(|| { - with_app(|app| app.show_viewer(false)); - }); - bridge.on_leave_stream(|| { - with_app(|app| app.leave_stream()); - }); - bridge.on_set_stream_volume(|volume| { - with_app(|app| app.set_stream_volume(volume)); - }); - bridge.on_toggle_fullscreen(|| { - with_app(|app| app.toggle_fullscreen()); - }); - - // Settings. - bridge.on_open_settings(|| { - with_app(|app| app.open_settings()); - }); - bridge.on_close_settings(|| { - with_app(|app| app.close_settings()); - }); - bridge.on_audio_changed(|form| { - with_app(|app| app.audio_changed(&form)); - }); - bridge.on_toggle_mic_test(|| { - with_app(|app| app.set_mic_test(!app.mic_test)); - }); - bridge.on_apply_ptt(|enabled, key| { - with_app(|app| app.apply_ptt(enabled, key.to_string())); - }); - bridge.on_set_h264(|enabled| { - with_app(|app| app.set_h264(enabled)); - }); - bridge.on_download_h264(|| { - with_app(|app| app.download_h264()); - }); - bridge.on_open_client(|id| with_app(|app| app.open_client(id as u16)).unwrap_or(false)); - bridge.on_client_audio_changed(|form| { - with_app(|app| app.client_playback_changed(&form)); - }); - - // Crash reports and notices. - bridge.on_set_crash_reports(|enabled| { - with_app(|app| app.set_crash_reports(enabled)); - }); - bridge.on_open_crash_folder(|| { - with_app(|app| { - let result = crash::dir().ok_or_else(|| "no crash report folder".to_owned()); - if let Err(e) = result.and_then(|dir| open_path(&dir).map_err(|e| e.to_string())) { - app.set_status(format!("Cannot open the crash report folder: {e}")); - } - }); - }); - bridge.on_delete_crash_reports(|| { - with_app(|app| { - match crash::clear() { - Ok(n) => app.set_status(format!("Deleted {n} crash reports")), - Err(e) => app.set_status(format!("Cannot delete the crash reports: {e}")), - } - app.refresh_crash_notice(); - }); - }); - bridge.on_dismiss_crash_notice(|| { - with_app(|app| { - if let Some(ui) = app.ui.upgrade() { - ui.global::().set_crash_notice(SharedString::new()); - } - }); - }); - bridge.on_open_about(|| { - with_app(|app| app.load_notices()); - }); -} - /// Open a file or folder with the desktop's default application. -fn open_path(path: &Path) -> std::io::Result<()> { +pub(crate) fn open_path(path: &Path) -> std::io::Result<()> { #[cfg(windows)] let mut command = std::process::Command::new("explorer"); #[cfg(target_os = "macos")] @@ -664,28 +512,12 @@ fn open_path(path: &Path) -> std::io::Result<()> { Ok(()) } -fn save_screenshot(ui: &MainWindow, path: &std::path::Path) -> Result<()> { - let image = ui.window().take_snapshot()?; - let file = std::io::BufWriter::new(std::fs::File::create(path)?); - let mut encoder = png::Encoder::new(file, image.width(), image.height()); - encoder.set_color(png::ColorType::Rgba); - encoder.set_depth(png::BitDepth::Eight); - encoder.write_header()?.write_image_data(image.as_bytes())?; - Ok(()) -} - -fn time_of(ts_ms: i64) -> String { - chrono::DateTime::from_timestamp_millis(ts_ms) - .map(|t| t.with_timezone(&chrono::Local).format("%H:%M").to_string()) - .unwrap_or_default() -} - pub(crate) fn model(items: Vec) -> ModelRc { ModelRc::from(Rc::new(VecModel::from(items))) } impl App { - fn view_mut(&mut self) -> Option<&mut SessionView> { + pub fn view_mut(&mut self) -> Option<&mut SessionView> { let id = self.current?; Some(self.sessions.entry(id).or_default()) } @@ -698,8 +530,10 @@ impl App { self.bookmarks.iter().find(|b| b.id == id) } + /// Send a command for the current session. Not for the sample + /// sessions of VOELIN_DEMO_UI: the engine would open them for real. pub fn command(&self, f: impl FnOnce(u64) -> Command) { - if let Some(id) = self.current { + if let Some(id) = self.current.filter(|_| !self.demo_ui) { self.engine.send(f(id as u64)); } } @@ -732,230 +566,12 @@ impl App { } } else if key == CLIENT_PLAYBACK.name() { self.playback = self.prefs.get(&CLIENT_PLAYBACK); + } else if appearance_keys().iter().any(|k| k.name() == key) { + self.apply_appearance(); } } - fn connect_voice(&mut self) { - let Some(b) = self.current.and_then(|id| self.bookmark(id)).cloned() else { return }; - let mut options = VoiceOptions::new(&b.address, &b.nickname); - options.identity = Some(self.identity.clone()); - options.server_password = self.secrets.get(&b.server_password_key()).ok().flatten(); - options.channel = b.default_channel.clone(); - options.audio = true; - options.stream_peer = self.video.peer_config(options.stream_peer); - self.engine - .send(Command::ConnectVoice { session: b.id as u64, options: Box::new(options) }); - self.set_status(format!("Connecting to {}…", b.address)); - } - - fn toggle_observe(&mut self) { - let Some(b) = self.current.and_then(|id| self.bookmark(id)).cloned() else { return }; - let session = b.id as u64; - let observing = - self.sessions.get(&b.id).is_some_and(|v| v.state.observe != ObserveState::Off); - if observing { - self.engine.send(Command::StopObserving { session }); - return; - } - if let Some(url) = &b.gateway_url { - self.engine.send(Command::ObserveGateway { - session, - url: url.clone(), - identity: Box::new(self.identity.clone()), - }); - } else if let Some(q) = &b.query { - let secret = self.secrets.get(&b.query_password_key()).ok().flatten(); - let transport = match q.transport { - QueryTransport::Raw => voelin_query::Transport::Raw, - QueryTransport::Ssh => voelin_query::Transport::Ssh, - QueryTransport::Http => voelin_query::Transport::Http, - }; - let connect = voelin_query::Connect { - transport, - addr: format!("{}:{}", q.host, q.port), - user: q.user.clone(), - secret, - server_port: q.server_port, - server_id: None, - line: Default::default(), - }; - self.engine.send(Command::ObserveQuery { session, connect: Box::new(connect) }); - } - self.set_status("Observing invisibly…"); - } - - fn open_chat(&mut self, target: ChatTarget, focus: bool) { - let Some(id) = self.current else { return }; - let title = match &target { - ChatTarget::Channel(cid) => { - let name = self - .sessions - .get(&id) - .and_then(|v| v.presence.channels.get(cid).map(|c| c.name.clone())); - format!("#{}", name.unwrap_or_else(|| cid.to_string())) - } - ChatTarget::Server => "Server".into(), - ChatTarget::Private(uid) => format!("@{uid}"), - }; - let view = self.sessions.entry(id).or_default(); - let index = match view.tabs.iter().position(|t| t.target == target) { - Some(i) => i, - None => { - view.tabs.push(Tab { target: target.clone(), title, lines: Vec::new(), unread: 0 }); - self.engine.send(Command::OpenChat { session: id as u64, target }); - view.tabs.len() - 1 - } - }; - if focus { - view.current_tab = index; - view.tabs[index].unread = 0; - } - self.refresh_chat(); - } - - fn close_tab(&mut self, index: usize) { - let Some(id) = self.current else { return }; - let view = self.sessions.entry(id).or_default(); - if index == 0 || index >= view.tabs.len() { - return; - } - let tab = view.tabs.remove(index); - view.current_tab = view.current_tab.min(view.tabs.len() - 1); - self.engine.send(Command::CloseChat { session: id as u64, target: tab.target }); - self.refresh_chat(); - } - - fn send_message(&mut self, text: String) { - let Some(id) = self.current else { return }; - let Some(view) = self.sessions.get(&id) else { return }; - let target = view.tabs[view.current_tab].target.clone(); - self.engine.send(Command::SendChat { session: id as u64, target, text }); - } - - fn bookmark_form(&self, id: i64) -> BookmarkForm { - let Some(b) = self.bookmark(id) else { - return BookmarkForm { - id: -1, - nickname: std::env::var("USER").unwrap_or_default().into(), - query_transport: "none".into(), - query_user: "serveradmin".into(), - ..Default::default() - }; - }; - let secret = |key: String| -> SharedString { - self.secrets.get(&key).ok().flatten().unwrap_or_default().into() - }; - let (transport, addr, user) = match &b.query { - Some(q) => ( - match q.transport { - QueryTransport::Raw => "raw", - QueryTransport::Ssh => "ssh", - QueryTransport::Http => "http", - }, - format!("{}:{}", q.host, q.port), - q.user.clone(), - ), - None => ("none", String::new(), "serveradmin".to_string()), - }; - BookmarkForm { - id: b.id as i32, - name: b.name.clone().into(), - address: b.address.clone().into(), - nickname: b.nickname.clone().into(), - server_password: secret(b.server_password_key()), - gateway_url: b.gateway_url.clone().unwrap_or_default().into(), - query_transport: transport.into(), - query_addr: addr.into(), - query_user: user.into(), - query_password: secret(b.query_password_key()), - } - } - - fn save_bookmark(&mut self, form: BookmarkForm) { - let query = match form.query_transport.as_str() { - "none" | "" => None, - t => { - let (host, port) = form - .query_addr - .rsplit_once(':') - .map_or((form.query_addr.to_string(), None), |(h, p)| { - (h.to_string(), p.parse().ok()) - }); - let transport = match t { - "raw" => QueryTransport::Raw, - "http" => QueryTransport::Http, - _ => QueryTransport::Ssh, - }; - let default_port = match transport { - QueryTransport::Raw => 10011, - QueryTransport::Ssh => 10022, - QueryTransport::Http => 10080, - }; - Some(QueryConfig { - transport, - host, - port: port.unwrap_or(default_port), - user: form.query_user.to_string(), - server_port: None, - }) - } - }; - let mut bookmark = Bookmark { - id: form.id as i64, - name: if form.name.is_empty() { - form.address.to_string() - } else { - form.name.to_string() - }, - address: form.address.to_string(), - nickname: form.nickname.to_string(), - identity: None, - default_channel: None, - gateway_url: Some(form.gateway_url.to_string()).filter(|u| !u.is_empty()), - query, - client_version: None, - }; - let result = if bookmark.id < 0 { - self.store.add_bookmark(&bookmark).map(|id| bookmark.id = id) - } else { - self.store.update_bookmark(&bookmark) - }; - if let Err(e) = result { - self.set_status(format!("Could not save: {e}")); - return; - } - for (key, value) in [ - (bookmark.server_password_key(), &form.server_password), - (bookmark.query_password_key(), &form.query_password), - ] { - let result = if value.is_empty() { - self.secrets.delete(&key) - } else { - self.secrets.set(&key, value) - }; - if let Err(e) = result { - warn!(%e, "could not store secret"); - } - } - self.current = Some(bookmark.id); - self.bookmarks = self.store.bookmarks().unwrap_or_default(); - self.refresh_all(); - } - - fn delete_bookmark(&mut self, id: i64) { - self.engine.send(Command::CloseSession { session: id as u64 }); - if let Some(b) = self.bookmark(id).cloned() { - let _ = self.secrets.delete(&b.server_password_key()); - let _ = self.secrets.delete(&b.query_password_key()); - } - let _ = self.store.delete_bookmark(id); - self.sessions.remove(&id); - self.bookmarks = self.store.bookmarks().unwrap_or_default(); - self.current = self.bookmarks.first().map(|b| b.id); - self.refresh_all(); - } - - fn handle_event(&mut self, event: Event) { + pub(crate) fn handle_event(&mut self, event: Event) { match event { Event::State { session, state } => { let id = session as i64; @@ -983,8 +599,12 @@ impl App { } self.refresh_servers(); self.refresh_toolbar(); + self.refresh_tree(); self.refresh_streams(); self.autoshare(); + if self.open_client_pending && self.current == Some(id) { + self.open_first_client(); + } } Event::ServerInfo { session, name, flavor, capabilities } => { self.sessions.entry(session as i64).or_default().capabilities = capabilities; @@ -1003,6 +623,7 @@ impl App { self.sessions.entry(session as i64).or_default().presence = presence; self.apply_client_playback(session as i64); if self.current == Some(session as i64) { + self.refresh_toolbar(); self.refresh_tree(); self.refresh_chat(); self.refresh_streams(); @@ -1037,6 +658,8 @@ impl App { self.set_status(format!("Microphone test: {message}")) } Event::Chat { session, message } => self.add_message(session as i64, message), + // The sample sessions of VOELIN_DEMO_UI are unknown to the engine. + Event::Error { .. } if self.demo_ui => {} Event::Error { message, .. } => self.set_status(message), Event::SettingChanged { key } => self.setting_changed(&key), Event::SettingRejected { key, message } => { @@ -1046,48 +669,6 @@ impl App { } } - fn add_message(&mut self, id: i64, message: ChatMessage) { - let current = self.current == Some(id); - let view = self.sessions.entry(id).or_default(); - let index = match view.tabs.iter().position(|t| t.target == message.target) { - Some(i) => i, - None => { - let title = match &message.target { - ChatTarget::Channel(cid) => format!( - "#{}", - view.presence - .channels - .get(cid) - .map(|c| c.name.clone()) - .unwrap_or_else(|| cid.to_string()) - ), - ChatTarget::Private(_) => format!("@{}", message.author_name), - ChatTarget::Server => "Server".into(), - }; - view.tabs.push(Tab { - target: message.target.clone(), - title, - lines: Vec::new(), - unread: 0, - }); - view.tabs.len() - 1 - } - }; - let tab = &mut view.tabs[index]; - tab.lines.push(ChatLine { - author: message.author_name.into(), - text: message.text.into(), - time: time_of(message.ts_ms).into(), - relayed: message.via_relay, - }); - if !(current && view.current_tab == index) { - tab.unread += 1; - } - if current { - self.refresh_chat(); - } - } - /// Once a second. fn tick(&mut self) { self.tick_streams(); @@ -1096,396 +677,11 @@ impl App { } } - fn refresh_all(&mut self) { + pub fn refresh_all(&mut self) { self.refresh_servers(); self.refresh_toolbar(); self.refresh_tree(); self.refresh_chat(); self.refresh_streams(); } - - fn refresh_servers(&self) { - let Some(ui) = self.ui.upgrade() else { return }; - let bridge = ui.global::(); - let items = self - .bookmarks - .iter() - .map(|b| { - let state = self.sessions.get(&b.id).map(|v| v.state.clone()).unwrap_or_default(); - let status = match (state.voice, state.observe) { - (VoiceState::Connected, _) => "connected", - (VoiceState::Connecting, _) | (_, ObserveState::Connecting) => "connecting", - (_, ObserveState::Observing) => "observing", - _ => "offline", - }; - ServerItem { - id: b.id as i32, - name: b.name.clone().into(), - address: b.address.clone().into(), - status: status.into(), - } - }) - .collect(); - bridge.set_servers(model(items)); - bridge.set_current_server(self.current.map_or(-1, |id| id as i32)); - } - - fn refresh_toolbar(&self) { - let Some(ui) = self.ui.upgrade() else { return }; - let bridge = ui.global::(); - let bookmark = self.current.and_then(|id| self.bookmark(id)); - let state = self.view().map(|v| v.state.clone()).unwrap_or_default(); - bridge.set_server_title( - bookmark.map_or("No server selected".into(), |b| b.name.clone()).into(), - ); - bridge.set_voice_connected(state.voice == VoiceState::Connected); - bridge.set_voice_connecting(state.voice == VoiceState::Connecting); - bridge.set_observing(state.observe != ObserveState::Off); - bridge.set_can_observe( - bookmark.is_some_and(|b| b.gateway_url.is_some() || b.query.is_some()), - ); - bridge.set_input_muted(state.input_muted); - bridge.set_output_muted(state.output_muted); - bridge.set_transmitting(state.transmitting); - bridge.set_presence_source( - match state.presence_source { - Some(Source::Voice) => "live (voice)", - Some(Source::Gateway) => "invisible (gateway)", - Some(Source::Query) => "invisible (query)", - None => "", - } - .into(), - ); - bridge.set_status_text(self.status.clone().into()); - if state.voice != VoiceState::Connected { - bridge.set_input_level(-100.0); - bridge.set_input_sending(false); - } - } - - fn refresh_tree(&self) { - let Some(ui) = self.ui.upgrade() else { return }; - let Some(view) = self.view() else { - ui.global::().set_tree(model(Vec::new())); - return; - }; - let own_channel = view.state.own_channel; - let rows = tree_rows(&view.presence, &|cid| view.collapsed.contains(&cid)) - .into_iter() - .map(|row| match row { - TreeRow::Channel { depth, channel } => TreeItem { - is_channel: true, - depth: depth as i32, - id: channel.id as i32, - name: channel.name.clone().into(), - own: own_channel == Some(channel.id), - locked: channel.has_password, - collapsed: view.collapsed.contains(&channel.id), - local_volume: 100, - ..Default::default() - }, - TreeRow::Client { depth, client } => { - let playback = client - .uid - .as_ref() - .and_then(|uid| self.playback.get(uid)) - .copied() - .unwrap_or_default(); - TreeItem { - is_channel: false, - depth: depth as i32, - id: client.id as i32, - name: client.nickname.clone().into(), - own: false, - talking: view.talking.contains(&client.id) || client.talking == Some(true), - muted: client.input_muted, - sound_off: client.output_muted, - away: client.away.is_some(), - streaming: client.streaming == Some(true), - local_muted: playback.muted, - local_volume: (playback.volume * 100.0).round() as i32, - myself: view.state.own_client == Some(client.id), - ..Default::default() - } - } - }) - .collect(); - ui.global::().set_tree(model(rows)); - } - - fn refresh_chat(&self) { - let Some(ui) = self.ui.upgrade() else { return }; - let bridge = ui.global::(); - let Some(view) = self.view() else { - bridge.set_tabs(model(vec![ChatTab { title: "Server".into(), ..Default::default() }])); - bridge.set_messages(model(Vec::new())); - return; - }; - let tabs = view - .tabs - .iter() - .map(|t| ChatTab { - title: t.title.clone().into(), - kind: matches!(t.target, ChatTarget::Channel(_)) as i32, - id: match t.target { - ChatTarget::Channel(cid) => cid as i32, - _ => 0, - }, - unread: t.unread, - }) - .collect(); - bridge.set_tabs(model(tabs)); - bridge.set_current_tab(view.current_tab as i32); - bridge.set_messages(model(view.tabs[view.current_tab].lines.clone())); - } - - // Settings page. - - fn open_settings(&mut self) { - let list = |devices: voelin_audio::Result>, - input: bool| { - let devices = devices.unwrap_or_else(|e| { - warn!("cannot list audio devices: {e}"); - Vec::new() - }); - devices - .into_iter() - .map(|d| { - let default = if input { d.default_input } else { d.default_output }; - (d.id, d.name, default) - }) - .collect::>() - }; - let inputs = list(voelin_audio::device::input_devices(), true); - let outputs = list(voelin_audio::device::output_devices(), false); - self.inputs = DeviceChoices::new(&inputs, self.audio.input_device.as_deref()); - self.outputs = DeviceChoices::new(&outputs, self.audio.output_device.as_deref()); - let Some(ui) = self.ui.upgrade() else { return }; - let bridge = ui.global::(); - let names = |c: &DeviceChoices| model(c.names.iter().map(SharedString::from).collect()); - bridge.set_input_devices(names(&self.inputs)); - bridge.set_output_devices(names(&self.outputs)); - bridge.set_audio(settings::audio_form(&self.audio, &self.inputs, &self.outputs)); - bridge.set_global_ptt(self.settings.global_ptt); - bridge.set_ptt_key(self.settings.ptt_key.clone().into()); - bridge.set_h264_enabled(self.settings.openh264); - self.refresh_h264(); - } - - fn close_settings(&mut self) { - self.set_mic_test(false); - self.save_audio(); - } - - fn audio_changed(&mut self, form: &AudioForm) { - let audio = settings::apply_audio_form(form, &self.audio, &self.inputs, &self.outputs); - if audio == self.audio { - return; - } - self.audio = audio; - self.audio_dirty = true; - self.engine.send(Command::SetAudioSettings(Box::new(self.audio.clone()))); - } - - fn save_audio(&mut self) { - if !self.audio_dirty { - return; - } - self.audio_dirty = false; - if let Err(e) = self.prefs.set(&AUDIO, self.audio.clone()) { - warn!(%e, "could not store audio settings"); - } - } - - fn set_mic_test(&mut self, on: bool) { - if self.mic_test == on { - return; - } - self.mic_test = on; - self.engine.send(Command::TestMicrophone { on }); - if let Some(ui) = self.ui.upgrade() { - let bridge = ui.global::(); - bridge.set_mic_test(on); - if !on { - bridge.set_input_level(-100.0); - } - } - } - - fn apply_ptt(&mut self, enabled: bool, key: String) { - let key = key.trim().to_owned(); - self.settings.global_ptt = enabled; - if !key.is_empty() { - self.settings.ptt_key = key.clone(); - } - self.store_settings(); - self.ptt.set((enabled && !key.is_empty()).then_some(key)); - } - - fn set_ptt_status(&mut self, status: String) { - if let Some(ui) = self.ui.upgrade() { - ui.global::().set_ptt_status(status.into()); - } - } - - fn set_h264(&mut self, enabled: bool) { - self.settings.openh264 = enabled; - self.store_settings(); - self.video.set_h264(enabled); - self.refresh_h264(); - } - - fn download_h264(&mut self) { - let runtime = self.engine.runtime().clone(); - self.video.download_h264(&runtime, |download| { - later(move |app| { - app.video.downloaded(download, app.settings.openh264); - app.refresh_h264(); - }); - }); - self.refresh_h264(); - } - - fn refresh_h264(&self) { - let Some(ui) = self.ui.upgrade() else { return }; - let bridge = ui.global::(); - let (loaded, status) = self.video.h264_status(); - bridge.set_h264_loaded(loaded); - bridge.set_h264_busy(status.starts_with("Downloading")); - bridge.set_h264_status(status.into()); - } - - /// Switches the About page and the settings show. - fn refresh_settings_flags(&self) { - let Some(ui) = self.ui.upgrade() else { return }; - let bridge = ui.global::(); - bridge.set_h264_enabled(self.settings.openh264); - bridge.set_h264_attribution(notices::OPENH264_ATTRIBUTION.into()); - bridge.set_crash_reports(self.settings.crash_reports); - } - - fn set_crash_reports(&mut self, enabled: bool) { - self.settings.crash_reports = enabled; - // Also in the blob, for older versions. - self.store_settings(); - if let Err(e) = self.prefs.set(&CRASH_REPORTS, enabled) { - warn!(%e, "could not store the crash report setting"); - } - crash::set_enabled(enabled); - } - - /// A notice while crash reports are on disk. - fn refresh_crash_notice(&self) { - let Some(ui) = self.ui.upgrade() else { return }; - let text = match crash::pending_reports() { - Ok(reports) if !reports.is_empty() => { - let newest = &reports[reports.len() - 1]; - let saved = match reports.len() { - 1 => "1 crash report is saved".to_owned(), - n => format!("{n} crash reports are saved"), - }; - format!("The app crashed earlier ({}). {saved} on this device.", newest.summary) - } - _ => String::new(), - }; - ui.global::().set_crash_notice(text.into()); - } - - /// The third-party notices, one model entry per line. - fn load_notices(&mut self) { - if self.notices_loaded { - return; - } - let Some(ui) = self.ui.upgrade() else { return }; - let lines: Vec = notices::text().lines().map(SharedString::from).collect(); - ui.global::().set_notices(model(lines)); - self.notices_loaded = true; - } - - // Local volume and mute of clients. - - /// Fill the volume dialog for `client` of the current session. - fn open_client(&mut self, client: u16) -> bool { - let Some(id) = self.current else { return false }; - let Some(info) = self.view().and_then(|v| v.presence.clients.get(&client)).cloned() else { - return false; - }; - let playback = - info.uid.as_ref().and_then(|uid| self.playback.get(uid)).copied().unwrap_or_default(); - self.playback_dialog = Some((id, client, info.uid.clone())); - if let Some(ui) = self.ui.upgrade() { - ui.global::().set_client_audio(ClientAudio { - id: client as i32, - name: info.nickname.into(), - volume: playback.volume * 100.0, - muted: playback.muted, - }); - } - true - } - - fn client_playback_changed(&mut self, form: &ClientAudio) { - let Some((session, client, uid)) = self.playback_dialog.clone() else { return }; - let playback = - ClientPlayback { volume: (form.volume / 100.0).clamp(0.0, 4.0), muted: form.muted }; - let session = session as u64; - self.engine.send(Command::SetClientVolume { session, client, volume: playback.volume }); - self.engine.send(Command::SetClientMuted { session, client, muted: playback.muted }); - // Kept by unique id; clients without one only for this connection. - if let Some(uid) = uid { - if playback.is_default() { - self.playback.remove(&uid); - } else { - self.playback.insert(uid, playback); - } - if let Err(e) = self.prefs.set(&CLIENT_PLAYBACK, self.playback.clone()) { - warn!(%e, "could not store client volumes"); - } - } - self.refresh_tree(); - } - - /// `VOELIN_OPEN=client`: the volume dialog of the first client that is not us. - fn open_first_client(&mut self) { - let Some(view) = self.view().filter(|v| v.state.own_client.is_some()) else { return }; - let own = view.state.own_client; - let mut others: Vec<_> = - view.presence.clients.values().filter(|c| Some(c.id) != own && !c.is_query).collect(); - others.sort_by_key(|c| c.id); - let Some(id) = others.first().map(|c| c.id) else { return }; - self.open_client_pending = false; - if self.open_client(id) - && let Some(ui) = self.ui.upgrade() - { - ui.set_client_open(true); - } - } - - /// Send the stored volumes of clients that appeared in a voice session. - fn apply_client_playback(&mut self, session: i64) { - let Some(view) = self.sessions.get_mut(&session) else { return }; - if view.state.voice != VoiceState::Connected - || view.state.presence_source != Some(Source::Voice) - { - return; - } - let presence = view.presence.clone(); - view.applied_playback.retain(|id| presence.clients.contains_key(id)); - for client in presence.clients.values() { - if !view.applied_playback.insert(client.id) { - continue; - } - let stored = client.uid.as_ref().and_then(|uid| self.playback.get(uid)); - let Some(playback) = stored else { continue }; - let (s, c) = (session as u64, client.id); - self.engine.send(Command::SetClientVolume { - session: s, - client: c, - volume: playback.volume, - }); - if playback.muted { - self.engine.send(Command::SetClientMuted { session: s, client: c, muted: true }); - } - } - } } diff --git a/crates/voelin-ui/src/appearance.rs b/crates/voelin-ui/src/appearance.rs new file mode 100644 index 0000000..8f82162 --- /dev/null +++ b/crates/voelin-ui/src/appearance.rs @@ -0,0 +1,56 @@ +//! Appearance settings (`ui.theme`, `ui.font_scale`, `ui.narrow_breakpoint`, +//! `ui.image_cache_mb`): applied to the Theme and Nav globals and the image +//! cache whenever they change, from the settings page or elsewhere. + +use slint::ComponentHandle; +use tracing::warn; + +use crate::app::{App, AppearanceForm, Bridge, Nav, Theme}; +use crate::images; +use crate::settings::{ + ThemeChoice, UI_FONT_SCALE, UI_IMAGE_CACHE_MB, UI_NARROW_BREAKPOINT, UI_THEME, +}; + +impl App { + /// Show the current values of the appearance keys. + pub(crate) fn apply_appearance(&self) { + let theme = self.prefs.get(&UI_THEME); + let scale = self.prefs.get(&UI_FONT_SCALE); + let breakpoint = self.prefs.get(&UI_NARROW_BREAKPOINT); + let cache_mb = self.prefs.get(&UI_IMAGE_CACHE_MB); + images::set_budget_mb(cache_mb); + let Some(ui) = self.ui.upgrade() else { return }; + let t = ui.global::(); + t.set_mode(theme.as_str().into()); + t.set_font_scale(scale); + ui.global::