feat(client): redesign native UI, themes, settings and avatars
Separate conversation drafts and voice view state, add native settings and restricted CSS themes, implement validated avatar cropping, and refresh dependencies with documented desktop compatibility backports.
This commit is contained in:
parent
44d284a568
commit
8e5ab56611
276 changed files with 53546 additions and 3399 deletions
238
src/ui/appearance/bindings.rs
Normal file
238
src/ui/appearance/bindings.rs
Normal file
|
|
@ -0,0 +1,238 @@
|
|||
use std::cell::RefCell;
|
||||
use std::path::Path;
|
||||
use std::rc::Rc;
|
||||
|
||||
use slint::ComponentHandle;
|
||||
|
||||
use super::{AppearancePreferences, Rgba, ThemeSpec, default_theme_path, parse_css};
|
||||
use crate::AppState;
|
||||
use crate::ui::slint::{MainWindow, Theme, UnlockWindow};
|
||||
|
||||
fn mix(a: Rgba, b: Rgba) -> Rgba {
|
||||
Rgba(
|
||||
((u16::from(a.0) * 7 + u16::from(b.0)) / 8) as u8,
|
||||
((u16::from(a.1) * 7 + u16::from(b.1)) / 8) as u8,
|
||||
((u16::from(a.2) * 7 + u16::from(b.2)) / 8) as u8,
|
||||
255,
|
||||
)
|
||||
}
|
||||
|
||||
macro_rules! apply_palette {
|
||||
($global:expr, $spec:expr) => {{
|
||||
let theme = $global;
|
||||
let spec = $spec;
|
||||
let c = spec.colors;
|
||||
theme.set_bg_base(c[0].color());
|
||||
theme.set_bg_surface(c[1].color());
|
||||
theme.set_bg_rail(c[2].color());
|
||||
theme.set_bg_hover(c[3].color());
|
||||
theme.set_bg_elevated(c[4].color());
|
||||
theme.set_bg_interactive(c[5].color());
|
||||
theme.set_selected(c[6].color());
|
||||
theme.set_border(c[7].color());
|
||||
theme.set_accent(c[8].color());
|
||||
theme.set_text_primary(c[9].color());
|
||||
theme.set_text_secondary(c[10].color());
|
||||
theme.set_text_muted(c[11].color());
|
||||
theme.set_text_disabled(c[12].color());
|
||||
theme.set_danger(c[13].color());
|
||||
theme.set_success(c[14].color());
|
||||
theme.set_font_size(spec.font_size);
|
||||
theme.set_avatar_bg(mix(c[4], c[8]).color());
|
||||
theme.set_voice_bg(mix(c[1], c[14]).color());
|
||||
theme.set_overlay(Rgba(0, 0, 0, if spec.is_light() { 80 } else { 145 }).color());
|
||||
theme.set_on_accent(
|
||||
if spec.is_light() {
|
||||
Rgba(255, 255, 255, 255)
|
||||
} else {
|
||||
Rgba(35, 30, 25, 255)
|
||||
}
|
||||
.color(),
|
||||
);
|
||||
}};
|
||||
}
|
||||
|
||||
pub fn apply_main(window: &MainWindow, spec: &ThemeSpec) {
|
||||
apply_palette!(window.global::<Theme>(), spec);
|
||||
}
|
||||
pub fn apply_unlock(window: &UnlockWindow, spec: &ThemeSpec) {
|
||||
apply_palette!(window.global::<Theme>(), spec);
|
||||
}
|
||||
|
||||
pub fn restore(window: &MainWindow, prefs: &AppearancePreferences) {
|
||||
if let Ok(spec) = prefs.resolve() {
|
||||
apply_main(window, &spec);
|
||||
}
|
||||
window.set_theme_mode(prefs.mode.as_str().into());
|
||||
window.set_text_size(prefs.font_size);
|
||||
window.set_theme_preview(false);
|
||||
window.set_theme_error("".into());
|
||||
window.set_theme_status("".into());
|
||||
}
|
||||
|
||||
fn report(window: &MainWindow, result: Result<(), String>) {
|
||||
if let Err(error) = result {
|
||||
window.set_theme_error(error.into());
|
||||
window.set_theme_status("".into());
|
||||
}
|
||||
}
|
||||
|
||||
fn commit(
|
||||
window: &MainWindow,
|
||||
state: &Rc<RefCell<AppState>>,
|
||||
prefs: AppearancePreferences,
|
||||
persist: bool,
|
||||
) -> Result<(), String> {
|
||||
let spec = prefs.resolve()?;
|
||||
if persist {
|
||||
prefs
|
||||
.save()
|
||||
.map_err(|error| format!("Не удалось сохранить настройки темы: {error}"))?;
|
||||
}
|
||||
state.borrow_mut().ui.appearance = prefs.clone();
|
||||
apply_main(window, &spec);
|
||||
window.set_theme_mode(prefs.mode.as_str().into());
|
||||
window.set_text_size(spec.font_size);
|
||||
window.set_theme_preview(false);
|
||||
window.set_theme_error("".into());
|
||||
window.set_theme_status("Тема сохранена и применяется ко всему приложению.".into());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn preview(window: &MainWindow, css: &str) -> Result<(), String> {
|
||||
let spec = parse_css(css)?;
|
||||
apply_main(window, &spec);
|
||||
window.set_text_size(spec.font_size);
|
||||
window.set_theme_preview(true);
|
||||
window.set_theme_error("".into());
|
||||
window.set_theme_status("Предпросмотр. Нажми «Применить», чтобы сохранить. Закрытие настроек вернёт сохранённую тему.".into());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn wire(window: &MainWindow, state: &Rc<RefCell<AppState>>, persist: bool) {
|
||||
let prefs = state.borrow().ui.appearance.clone();
|
||||
restore(window, &prefs);
|
||||
window.set_theme_css(prefs.custom_css.as_str().into());
|
||||
window.set_theme_file_path(default_theme_path().to_string_lossy().as_ref().into());
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let state = state.clone();
|
||||
window.on_theme_selected(move |mode| {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
if mode == "custom" {
|
||||
window.set_theme_mode("custom".into());
|
||||
window.set_theme_error("".into());
|
||||
window.set_theme_status(
|
||||
"Измени CSS, затем открой предпросмотр или примени тему.".into(),
|
||||
);
|
||||
} else {
|
||||
let mut prefs = state.borrow().ui.appearance.clone();
|
||||
prefs.mode = mode.to_string();
|
||||
report(&window, commit(&window, &state, prefs, persist));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let state = state.clone();
|
||||
window.on_text_size_changed(move |size| {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
if !size.is_finite() || !(12.0..=22.0).contains(&size) {
|
||||
report(
|
||||
&window,
|
||||
Err("Размер текста должен быть от 12px до 22px.".into()),
|
||||
);
|
||||
return;
|
||||
}
|
||||
if window.get_theme_mode() == "custom" {
|
||||
match parse_css(window.get_theme_css().as_str()) {
|
||||
Ok(mut spec) => {
|
||||
spec.font_size = size;
|
||||
let css = spec.to_css();
|
||||
window.set_theme_css(css.as_str().into());
|
||||
report(&window, preview(&window, &css));
|
||||
}
|
||||
Err(error) => report(&window, Err(error)),
|
||||
}
|
||||
} else {
|
||||
let mut prefs = state.borrow().ui.appearance.clone();
|
||||
prefs.font_size = size;
|
||||
report(&window, commit(&window, &state, prefs, persist));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
window.on_preview_theme(move |css| {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
report(&window, preview(&window, css.as_str()));
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let state = state.clone();
|
||||
window.on_apply_theme(move |css| {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
let result = parse_css(css.as_str()).and_then(|spec| {
|
||||
let prefs = AppearancePreferences {
|
||||
mode: "custom".into(),
|
||||
custom_css: css.to_string(),
|
||||
font_size: spec.font_size,
|
||||
};
|
||||
commit(&window, &state, prefs, persist)
|
||||
});
|
||||
report(&window, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let state = state.clone();
|
||||
window.on_reset_theme(move || {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
let prefs = AppearancePreferences::default();
|
||||
let css = prefs.custom_css.clone();
|
||||
let result = commit(&window, &state, prefs, persist);
|
||||
if result.is_ok() {
|
||||
window.set_theme_css(css.into());
|
||||
}
|
||||
report(&window, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
window.on_import_theme(move |path| {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
let result = super::storage::import_css(Path::new(path.as_str())).and_then(|css| {
|
||||
window.set_theme_css(css.as_str().into());
|
||||
window.set_theme_mode("custom".into());
|
||||
preview(&window, &css)
|
||||
});
|
||||
report(&window, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let state = state.clone();
|
||||
window.on_export_theme(move |path| {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
let result = if window.get_theme_mode() == "custom" {
|
||||
parse_css(window.get_theme_css().as_str())
|
||||
} else {
|
||||
state.borrow().ui.appearance.resolve()
|
||||
}
|
||||
.and_then(|spec| super::storage::export_css(Path::new(path.as_str()), &spec));
|
||||
if result.is_ok() {
|
||||
window.set_theme_error("".into());
|
||||
window.set_theme_status("CSS сохранён в указанный локальный файл.".into());
|
||||
}
|
||||
report(&window, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
158
src/ui/appearance/css.rs
Normal file
158
src/ui/appearance/css.rs
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use super::{COLOR_TOKENS, Rgba, ThemeSpec};
|
||||
|
||||
pub const MAX_CSS_BYTES: usize = 16 * 1024;
|
||||
|
||||
pub(super) fn parse_color(text: &str) -> Result<Rgba, String> {
|
||||
let hex = text
|
||||
.strip_prefix('#')
|
||||
.ok_or("Цвет должен начинаться с #.")?;
|
||||
if !hex.bytes().all(|b| b.is_ascii_hexdigit()) {
|
||||
return Err(format!("Некорректный цвет: {text}"));
|
||||
}
|
||||
let byte =
|
||||
|s: &str| u8::from_str_radix(s, 16).map_err(|_| format!("Некорректный цвет: {text}"));
|
||||
match hex.len() {
|
||||
3 | 4 => {
|
||||
let values = hex
|
||||
.bytes()
|
||||
.map(|b| match b.to_ascii_lowercase() {
|
||||
b'0'..=b'9' => (b - b'0') * 17,
|
||||
lower => (lower - b'a' + 10) * 17,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
Ok(Rgba(
|
||||
values[0],
|
||||
values[1],
|
||||
values[2],
|
||||
values.get(3).copied().unwrap_or(255),
|
||||
))
|
||||
}
|
||||
6 | 8 => Ok(Rgba(
|
||||
byte(&hex[0..2])?,
|
||||
byte(&hex[2..4])?,
|
||||
byte(&hex[4..6])?,
|
||||
if hex.len() == 8 {
|
||||
byte(&hex[6..8])?
|
||||
} else {
|
||||
255
|
||||
},
|
||||
)),
|
||||
_ => Err(format!(
|
||||
"Цвет {text}: нужны 3, 4, 6 или 8 шестнадцатеричных цифр."
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn strip_comments(css: &str) -> Result<String, String> {
|
||||
let mut rest = css;
|
||||
let mut result = String::new();
|
||||
while let Some(start) = rest.find("/*") {
|
||||
result.push_str(&rest[..start]);
|
||||
let tail = &rest[start + 2..];
|
||||
let end = tail.find("*/").ok_or("Комментарий CSS не закрыт.")?;
|
||||
result.push(' ');
|
||||
rest = &tail[end + 2..];
|
||||
}
|
||||
result.push_str(rest);
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
/// Parse the deliberately restricted native-theme CSS format; never fetch or execute CSS.
|
||||
pub fn parse_css(css: &str) -> Result<ThemeSpec, String> {
|
||||
if css.len() > MAX_CSS_BYTES {
|
||||
return Err("Файл темы слишком большой: максимум 16 КБ.".into());
|
||||
}
|
||||
let stripped = strip_comments(css)?;
|
||||
let root = stripped
|
||||
.trim()
|
||||
.strip_prefix(":root")
|
||||
.ok_or("Тема должна содержать один блок :root { … }. ")?
|
||||
.trim();
|
||||
let body = root
|
||||
.strip_prefix('{')
|
||||
.and_then(|s| s.strip_suffix('}'))
|
||||
.ok_or("Ожидается один блок :root { … }. ")?;
|
||||
if body.contains(['{', '}']) {
|
||||
return Err("Поддерживается только один блок :root без вложенных правил.".into());
|
||||
}
|
||||
let mut theme = ThemeSpec::builtin("dark");
|
||||
let mut seen = HashSet::new();
|
||||
for declaration in body.split(';').map(str::trim).filter(|s| !s.is_empty()) {
|
||||
let (name, value) = declaration
|
||||
.split_once(':')
|
||||
.ok_or("После имени переменной нужен знак :.")?;
|
||||
let (name, value) = (name.trim(), value.trim());
|
||||
if !seen.insert(name) {
|
||||
return Err(format!("Переменная {name} указана дважды."));
|
||||
}
|
||||
if name == "--vnox-font-size" {
|
||||
let number = value
|
||||
.strip_suffix("px")
|
||||
.ok_or("Размер текста задаётся в px, например 16px.")?;
|
||||
let size: f32 = number
|
||||
.trim()
|
||||
.parse()
|
||||
.map_err(|_| "Некорректный размер текста.")?;
|
||||
if !size.is_finite() || !(12.0..=22.0).contains(&size) {
|
||||
return Err("Размер текста должен быть от 12px до 22px.".into());
|
||||
}
|
||||
theme.font_size = size;
|
||||
} else if let Some(index) = COLOR_TOKENS.iter().position(|token| *token == name) {
|
||||
theme.colors[index] = parse_color(value).map_err(|e| format!("{name}: {e}"))?;
|
||||
} else {
|
||||
return Err(format!(
|
||||
"Неподдерживаемая переменная {name}. Веб-селекторы, url() и @import не поддерживаются."
|
||||
));
|
||||
}
|
||||
}
|
||||
if seen.is_empty() {
|
||||
return Err("Добавь хотя бы одну переменную --vnox-… в блок :root.".into());
|
||||
}
|
||||
Ok(theme)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parses_native_variables_comments_and_rgba_without_changing_defaults() {
|
||||
let theme = parse_css("/* custom */ :root { --vnox-bg: #123; --vnox-border: #abcd; --vnox-text: #f0eeeaff; --vnox-font-size: 18px; }").unwrap();
|
||||
assert_eq!(theme.colors[0], Rgba(17, 34, 51, 255));
|
||||
assert_eq!(theme.colors[7], Rgba(170, 187, 204, 221));
|
||||
assert_eq!(theme.colors[9], Rgba(240, 238, 234, 255));
|
||||
assert_eq!(theme.font_size, 18.0);
|
||||
assert_eq!(theme.colors[1], ThemeSpec::builtin("dark").colors[1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_executable_external_unknown_and_malformed_input() {
|
||||
for invalid in [
|
||||
"@import 'https://example.com/x.css';",
|
||||
"body { color: #fff; }",
|
||||
":root { --vnox-bg: url(file:///etc/passwd); }",
|
||||
":root { --typo: #fff; }",
|
||||
":root { --vnox-bg: #ggg; }",
|
||||
":root { --vnox-bg: #fff; --vnox-bg: #000; }",
|
||||
":root { --vnox-font-size: NaNpx; }",
|
||||
":root { --vnox-font-size: 200px; }",
|
||||
":root { --vnox-font-size: 1rem; }",
|
||||
":root {}",
|
||||
":root { --vnox-bg: #fff; } body {}",
|
||||
"/* unfinished",
|
||||
] {
|
||||
assert!(parse_css(invalid).is_err(), "must reject {invalid}");
|
||||
}
|
||||
assert!(parse_css(&"x".repeat(MAX_CSS_BYTES + 1)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn built_in_themes_roundtrip_without_color_or_alpha_loss() {
|
||||
for mode in ["light", "dark", "black"] {
|
||||
let theme = ThemeSpec::builtin(mode);
|
||||
assert_eq!(parse_css(&theme.to_css()).unwrap(), theme);
|
||||
}
|
||||
}
|
||||
}
|
||||
125
src/ui/appearance/mod.rs
Normal file
125
src/ui/appearance/mod.rs
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
mod bindings;
|
||||
mod css;
|
||||
mod storage;
|
||||
|
||||
pub use bindings::restore as bindings_restore;
|
||||
pub use bindings::{apply_unlock, wire};
|
||||
pub use css::{MAX_CSS_BYTES, parse_css};
|
||||
pub use storage::{AppearancePreferences, default_theme_path};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Rgba(pub u8, pub u8, pub u8, pub u8);
|
||||
|
||||
impl Rgba {
|
||||
pub fn color(self) -> slint::Color {
|
||||
slint::Color::from_argb_u8(self.3, self.0, self.1, self.2)
|
||||
}
|
||||
|
||||
pub fn css(self) -> String {
|
||||
if self.3 == 255 {
|
||||
format!("#{:02x}{:02x}{:02x}", self.0, self.1, self.2)
|
||||
} else {
|
||||
format!("#{:02x}{:02x}{:02x}{:02x}", self.0, self.1, self.2, self.3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ThemeSpec {
|
||||
pub colors: [Rgba; 15],
|
||||
pub font_size: f32,
|
||||
}
|
||||
|
||||
pub const COLOR_TOKENS: [&str; 15] = [
|
||||
"--vnox-bg",
|
||||
"--vnox-surface",
|
||||
"--vnox-rail",
|
||||
"--vnox-hover",
|
||||
"--vnox-elevated",
|
||||
"--vnox-input",
|
||||
"--vnox-selected",
|
||||
"--vnox-border",
|
||||
"--vnox-accent",
|
||||
"--vnox-text",
|
||||
"--vnox-text-secondary",
|
||||
"--vnox-text-muted",
|
||||
"--vnox-text-disabled",
|
||||
"--vnox-danger",
|
||||
"--vnox-success",
|
||||
];
|
||||
|
||||
impl ThemeSpec {
|
||||
pub fn builtin(mode: &str) -> Self {
|
||||
let values = match mode {
|
||||
"light" => [
|
||||
"#f5f4f2",
|
||||
"#eae8e5",
|
||||
"#dedbd6",
|
||||
"#dfdcd7",
|
||||
"#efede9",
|
||||
"#ffffff",
|
||||
"#d8d3cb",
|
||||
"#0000001c",
|
||||
"#78552d",
|
||||
"#292622",
|
||||
"#514b44",
|
||||
"#6b645e",
|
||||
"#756d65",
|
||||
"#b43731",
|
||||
"#3e704d",
|
||||
],
|
||||
"black" => [
|
||||
"#090909",
|
||||
"#111111",
|
||||
"#000000",
|
||||
"#262626",
|
||||
"#181818",
|
||||
"#202020",
|
||||
"#303030",
|
||||
"#ffffff1c",
|
||||
"#d5b58a",
|
||||
"#f0eeee",
|
||||
"#c3bdb7",
|
||||
"#aba39b",
|
||||
"#948a80",
|
||||
"#ee948b",
|
||||
"#a8c1a4",
|
||||
],
|
||||
_ => [
|
||||
"#272729",
|
||||
"#202022",
|
||||
"#151516",
|
||||
"#38383c",
|
||||
"#303033",
|
||||
"#343336",
|
||||
"#3a393c",
|
||||
"#ffffff12",
|
||||
"#d5b58a",
|
||||
"#e9e7e4",
|
||||
"#b8b4b1",
|
||||
"#aaa29b",
|
||||
"#85817f",
|
||||
"#e58b85",
|
||||
"#a8c1a4",
|
||||
],
|
||||
};
|
||||
Self {
|
||||
colors: values.map(|s| css::parse_color(s).expect("built-in hex color")),
|
||||
font_size: 16.0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_light(&self) -> bool {
|
||||
let c = self.colors[0];
|
||||
(u32::from(c.0) * 299 + u32::from(c.1) * 587 + u32::from(c.2) * 114) > 150_000
|
||||
}
|
||||
|
||||
pub fn to_css(&self) -> String {
|
||||
let mut css = String::from(":root {\n");
|
||||
for (name, value) in COLOR_TOKENS.iter().zip(self.colors) {
|
||||
css.push_str(&format!(" {name}: {};\n", value.css()));
|
||||
}
|
||||
css.push_str(&format!(" --vnox-font-size: {}px;\n}}\n", self.font_size));
|
||||
css
|
||||
}
|
||||
}
|
||||
171
src/ui/appearance/storage.rs
Normal file
171
src/ui/appearance/storage.rs
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{MAX_CSS_BYTES, ThemeSpec, parse_css};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct AppearancePreferences {
|
||||
pub mode: String,
|
||||
pub custom_css: String,
|
||||
pub font_size: f32,
|
||||
}
|
||||
|
||||
impl Default for AppearancePreferences {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
mode: "dark".into(),
|
||||
custom_css: ThemeSpec::builtin("dark").to_css(),
|
||||
font_size: 16.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn config_directory() -> PathBuf {
|
||||
dirs::config_dir()
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
.join("vnox")
|
||||
}
|
||||
|
||||
pub fn default_theme_path() -> PathBuf {
|
||||
config_directory().join("custom-theme.css")
|
||||
}
|
||||
|
||||
impl AppearancePreferences {
|
||||
pub fn load() -> Self {
|
||||
Self::load_from(&config_directory().join("appearance.json")).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn load_from(path: &Path) -> anyhow::Result<Self> {
|
||||
let prefs: Self = serde_json::from_slice(&std::fs::read(path)?)?;
|
||||
prefs.resolve().map_err(anyhow::Error::msg)?;
|
||||
if prefs.custom_css.len() > MAX_CSS_BYTES {
|
||||
anyhow::bail!("Theme file is too large");
|
||||
}
|
||||
Ok(prefs)
|
||||
}
|
||||
|
||||
pub fn resolve(&self) -> Result<ThemeSpec, String> {
|
||||
if !["light", "dark", "black", "custom"].contains(&self.mode.as_str()) {
|
||||
return Err("Неизвестная тема.".into());
|
||||
}
|
||||
if !self.font_size.is_finite() || !(12.0..=22.0).contains(&self.font_size) {
|
||||
return Err("Размер текста должен быть от 12px до 22px.".into());
|
||||
}
|
||||
let mut theme = if self.mode == "custom" {
|
||||
parse_css(&self.custom_css)?
|
||||
} else {
|
||||
ThemeSpec::builtin(&self.mode)
|
||||
};
|
||||
theme.font_size = self.font_size;
|
||||
Ok(theme)
|
||||
}
|
||||
|
||||
pub fn save(&self) -> anyhow::Result<()> {
|
||||
self.save_to(&config_directory().join("appearance.json"))
|
||||
}
|
||||
|
||||
fn save_to(&self, path: &Path) -> anyhow::Result<()> {
|
||||
self.resolve().map_err(anyhow::Error::msg)?;
|
||||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
let temporary = path.with_extension(format!("{}.tmp", uuid::Uuid::new_v4()));
|
||||
std::fs::write(&temporary, serde_json::to_vec_pretty(self)?)?;
|
||||
if let Err(error) = std::fs::rename(&temporary, path) {
|
||||
let _ = std::fs::remove_file(&temporary);
|
||||
return Err(error.into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn check_css_path(path: &Path) -> Result<(), String> {
|
||||
if path
|
||||
.extension()
|
||||
.and_then(|s| s.to_str())
|
||||
.is_none_or(|ext| !ext.eq_ignore_ascii_case("css"))
|
||||
{
|
||||
return Err("Укажи путь к файлу с расширением .css.".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn import_css(path: &Path) -> Result<String, String> {
|
||||
check_css_path(path)?;
|
||||
let file =
|
||||
std::fs::File::open(path).map_err(|error| format!("Не удалось открыть тему: {error}"))?;
|
||||
let mut css = String::new();
|
||||
file.take(MAX_CSS_BYTES as u64 + 1)
|
||||
.read_to_string(&mut css)
|
||||
.map_err(|error| format!("Не удалось прочитать CSS: {error}"))?;
|
||||
parse_css(&css)?;
|
||||
Ok(css)
|
||||
}
|
||||
|
||||
pub fn export_css(path: &Path, theme: &ThemeSpec) -> Result<(), String> {
|
||||
check_css_path(path)?;
|
||||
// The path is explicitly provided by the local export action. No network I/O.
|
||||
if let Some(parent) = path.parent().filter(|p| !p.as_os_str().is_empty()) {
|
||||
std::fs::create_dir_all(parent)
|
||||
.map_err(|e| format!("Не удалось создать папку темы: {e}"))?;
|
||||
}
|
||||
std::fs::write(path, theme.to_css())
|
||||
.map_err(|error| format!("Не удалось сохранить CSS: {error}"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn saved_custom_palette_and_text_size_survive_reload() {
|
||||
let directory = std::env::temp_dir().join(format!("vnox-theme-{}", uuid::Uuid::new_v4()));
|
||||
let path = directory.join("appearance.json");
|
||||
let preferences = AppearancePreferences {
|
||||
mode: "custom".into(),
|
||||
custom_css: ":root { --vnox-bg: #101010; --vnox-accent: #aabbcc; }".into(),
|
||||
font_size: 18.0,
|
||||
};
|
||||
preferences.save_to(&path).unwrap();
|
||||
let loaded = AppearancePreferences::load_from(&path).unwrap();
|
||||
assert_eq!(loaded.mode, "custom");
|
||||
assert_eq!(loaded.custom_css, preferences.custom_css);
|
||||
assert_eq!(loaded.resolve().unwrap(), preferences.resolve().unwrap());
|
||||
std::fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_theme_import_export_validates_content_and_extension() {
|
||||
let directory =
|
||||
std::env::temp_dir().join(format!("vnox-theme-file-{}", uuid::Uuid::new_v4()));
|
||||
std::fs::create_dir_all(&directory).unwrap();
|
||||
let path = directory.join("theme.css");
|
||||
let theme = ThemeSpec::builtin("light");
|
||||
export_css(&path, &theme).unwrap();
|
||||
assert_eq!(parse_css(&import_css(&path).unwrap()).unwrap(), theme);
|
||||
std::fs::write(&path, "body { display: none; }").unwrap();
|
||||
assert!(import_css(&path).is_err());
|
||||
assert!(export_css(&directory.join("theme.json"), &theme).is_err());
|
||||
std::fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_persisted_preferences_are_rejected() {
|
||||
let directory =
|
||||
std::env::temp_dir().join(format!("vnox-theme-invalid-{}", uuid::Uuid::new_v4()));
|
||||
std::fs::create_dir_all(&directory).unwrap();
|
||||
let path = directory.join("appearance.json");
|
||||
for content in [
|
||||
"{\"mode\":\"unsupported\"}",
|
||||
"{\"font_size\":200}",
|
||||
"{\"mode\":\"custom\",\"custom_css\":\"@import 'x'\"}",
|
||||
] {
|
||||
std::fs::write(&path, content).unwrap();
|
||||
assert!(AppearancePreferences::load_from(&path).is_err());
|
||||
}
|
||||
std::fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
}
|
||||
174
src/ui/avatar/bindings.rs
Normal file
174
src/ui/avatar/bindings.rs
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
use std::cell::RefCell;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
use sha2::{Digest, Sha256};
|
||||
use slint::ComponentHandle;
|
||||
|
||||
use super::CropSource;
|
||||
use crate::AppState;
|
||||
use crate::ui::slint::MainWindow;
|
||||
|
||||
fn avatar_path(identity: &str) -> PathBuf {
|
||||
// Scope local photos by account; never place untrusted identity text in a path.
|
||||
let name = hex::encode(Sha256::digest(identity.as_bytes()));
|
||||
dirs::config_dir()
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
.join("vnox/avatars")
|
||||
.join(format!("{name}.png"))
|
||||
}
|
||||
|
||||
fn sync_crop(window: &MainWindow, source: &CropSource) {
|
||||
window.set_avatar_zoom(source.zoom);
|
||||
window.set_avatar_offset_x(source.offset_x);
|
||||
window.set_avatar_offset_y(source.offset_y);
|
||||
}
|
||||
|
||||
fn begin_crop(window: &MainWindow, pending: &Rc<RefCell<Option<CropSource>>>, source: CropSource) {
|
||||
window.set_avatar_source(source.ui_image());
|
||||
window.set_avatar_source_width(source.width() as f32);
|
||||
window.set_avatar_source_height(source.height() as f32);
|
||||
sync_crop(window, &source);
|
||||
window.set_avatar_error("".into());
|
||||
*pending.borrow_mut() = Some(source);
|
||||
window.set_avatar_crop_open(true);
|
||||
}
|
||||
|
||||
fn discard_crop(window: &MainWindow, pending: &Rc<RefCell<Option<CropSource>>>) {
|
||||
window.set_avatar_crop_open(false);
|
||||
window.set_avatar_source(slint::Image::default());
|
||||
*pending.borrow_mut() = None;
|
||||
}
|
||||
|
||||
pub fn wire(window: &MainWindow, state: &Rc<RefCell<AppState>>, persist: bool) {
|
||||
let pending = Rc::new(RefCell::new(None::<CropSource>));
|
||||
let path = avatar_path(&state.borrow().identity.pubkey_hex);
|
||||
if persist && path.exists() {
|
||||
match CropSource::load(&path) {
|
||||
Ok(source) => {
|
||||
window.set_own_avatar(source.ui_image());
|
||||
window.set_has_avatar(true);
|
||||
}
|
||||
Err(error) => window.set_avatar_error(error.into()),
|
||||
}
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let pending = pending.clone();
|
||||
window.on_choose_avatar(move || {
|
||||
let weak = weak.clone();
|
||||
let pending = pending.clone();
|
||||
if let Some(window) = weak.upgrade() {
|
||||
window.set_avatar_error("".into());
|
||||
}
|
||||
let task_window = weak.clone();
|
||||
let result = slint::spawn_local(async move {
|
||||
let Some(file) = rfd::AsyncFileDialog::new()
|
||||
.set_title("Выбрать фото профиля")
|
||||
.add_filter("Фото (PNG, JPEG, WebP)", &["png", "jpg", "jpeg", "webp"])
|
||||
.pick_file()
|
||||
.await
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let path = file.path().to_owned();
|
||||
let result = tokio::task::spawn_blocking(move || CropSource::load(&path)).await;
|
||||
if let Some(window) = task_window.upgrade() {
|
||||
match result {
|
||||
Ok(Ok(source)) => begin_crop(&window, &pending, source),
|
||||
Ok(Err(error)) => window.set_avatar_error(error.into()),
|
||||
Err(_) => window.set_avatar_error(
|
||||
"Не удалось обработать фото. Попробуй другое изображение.".into(),
|
||||
),
|
||||
}
|
||||
}
|
||||
});
|
||||
if result.is_err()
|
||||
&& let Some(window) = weak.upgrade()
|
||||
{
|
||||
window.set_avatar_error("Не удалось открыть выбор файла в этом окружении.".into());
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let pending = pending.clone();
|
||||
window.on_avatar_crop_moved(move |x, y| {
|
||||
if let Some(window) = weak.upgrade()
|
||||
&& let Some(source) = pending.borrow_mut().as_mut()
|
||||
{
|
||||
source.adjust(source.zoom, x, y);
|
||||
sync_crop(&window, source);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let pending = pending.clone();
|
||||
window.on_avatar_zoom_changed(move |zoom| {
|
||||
if let Some(window) = weak.upgrade()
|
||||
&& let Some(source) = pending.borrow_mut().as_mut()
|
||||
{
|
||||
source.adjust(zoom, source.offset_x, source.offset_y);
|
||||
sync_crop(&window, source);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let pending = pending.clone();
|
||||
let path = path.clone();
|
||||
window.on_confirm_avatar(move || {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
let result = {
|
||||
let source = pending.borrow();
|
||||
source.as_ref().map(|source| {
|
||||
if persist {
|
||||
source.save_to(&path)
|
||||
} else {
|
||||
Ok(source.cropped_ui_image())
|
||||
}
|
||||
})
|
||||
};
|
||||
if let Some(result) = result {
|
||||
match result {
|
||||
Ok(image) => {
|
||||
window.set_own_avatar(image);
|
||||
window.set_has_avatar(true);
|
||||
window.set_avatar_error("".into());
|
||||
discard_crop(&window, &pending);
|
||||
}
|
||||
Err(error) => window.set_avatar_error(error.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
let pending = pending.clone();
|
||||
window.on_cancel_avatar(move || {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
discard_crop(&window, &pending);
|
||||
window.set_avatar_error("".into());
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = window.as_weak();
|
||||
window.on_remove_avatar(move || {
|
||||
if let Some(window) = weak.upgrade() {
|
||||
if persist
|
||||
&& let Err(error) = std::fs::remove_file(&path)
|
||||
&& error.kind() != std::io::ErrorKind::NotFound
|
||||
{
|
||||
window.set_avatar_error(format!("Не удалось удалить фото: {error}").into());
|
||||
return;
|
||||
}
|
||||
window.set_own_avatar(slint::Image::default());
|
||||
window.set_has_avatar(false);
|
||||
window.set_avatar_error("".into());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
261
src/ui/avatar/crop.rs
Normal file
261
src/ui/avatar/crop.rs
Normal file
|
|
@ -0,0 +1,261 @@
|
|||
use std::io::{Cursor, Read};
|
||||
use std::path::Path;
|
||||
|
||||
use image::{DynamicImage, ImageDecoder, ImageFormat, ImageReader};
|
||||
|
||||
const MAX_FILE_BYTES: usize = 10 * 1024 * 1024;
|
||||
const MAX_DIMENSION: u32 = 4096;
|
||||
const OUTPUT_SIZE: u32 = 256;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CropSource {
|
||||
image: DynamicImage,
|
||||
pub zoom: f32,
|
||||
pub offset_x: f32,
|
||||
pub offset_y: f32,
|
||||
}
|
||||
|
||||
impl CropSource {
|
||||
pub fn load(path: &Path) -> Result<Self, String> {
|
||||
let file =
|
||||
std::fs::File::open(path).map_err(|e| format!("Не удалось открыть фото: {e}"))?;
|
||||
if file.metadata().map_err(|e| e.to_string())?.len() > MAX_FILE_BYTES as u64 {
|
||||
return Err("Фото слишком большое: максимум 10 МБ.".into());
|
||||
}
|
||||
let mut bytes = Vec::new();
|
||||
file.take(MAX_FILE_BYTES as u64 + 1)
|
||||
.read_to_end(&mut bytes)
|
||||
.map_err(|e| e.to_string())?;
|
||||
Self::decode(&bytes)
|
||||
}
|
||||
|
||||
fn decode(bytes: &[u8]) -> Result<Self, String> {
|
||||
if bytes.len() > MAX_FILE_BYTES {
|
||||
return Err("Фото слишком большое: максимум 10 МБ.".into());
|
||||
}
|
||||
let format = image::guess_format(bytes)
|
||||
.map_err(|_| "Не удалось распознать изображение. Выбери PNG, JPEG или WebP.")?;
|
||||
if ![ImageFormat::Png, ImageFormat::Jpeg, ImageFormat::WebP].contains(&format) {
|
||||
return Err(
|
||||
"Поддерживаются только PNG, JPEG и WebP. Анимации и SVG не поддерживаются.".into(),
|
||||
);
|
||||
}
|
||||
reject_animation(bytes, format)?;
|
||||
let mut limits = image::Limits::default();
|
||||
limits.max_image_width = Some(MAX_DIMENSION);
|
||||
limits.max_image_height = Some(MAX_DIMENSION);
|
||||
limits.max_alloc = Some(64 * 1024 * 1024);
|
||||
let mut reader = ImageReader::with_format(Cursor::new(bytes), format);
|
||||
reader.limits(limits);
|
||||
let mut decoder = reader
|
||||
.into_decoder()
|
||||
.map_err(|e| format!("Не удалось прочитать фото: {e}"))?;
|
||||
if decoder.dimensions().0 > MAX_DIMENSION || decoder.dimensions().1 > MAX_DIMENSION {
|
||||
return Err("Сторона изображения должна быть не больше 4096 пикселей.".into());
|
||||
}
|
||||
let orientation = decoder
|
||||
.orientation()
|
||||
.map_err(|e| format!("Не удалось прочитать ориентацию фото: {e}"))?;
|
||||
let mut image = DynamicImage::from_decoder(decoder)
|
||||
.map_err(|e| format!("Не удалось декодировать фото: {e}"))?;
|
||||
image.apply_orientation(orientation);
|
||||
if image.width() == 0 || image.height() == 0 {
|
||||
return Err("Изображение пустое.".into());
|
||||
}
|
||||
Ok(Self {
|
||||
image,
|
||||
zoom: 1.0,
|
||||
offset_x: 0.0,
|
||||
offset_y: 0.0,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn width(&self) -> u32 {
|
||||
self.image.width()
|
||||
}
|
||||
pub fn height(&self) -> u32 {
|
||||
self.image.height()
|
||||
}
|
||||
|
||||
pub fn ui_image(&self) -> slint::Image {
|
||||
to_ui_image(&self.image)
|
||||
}
|
||||
|
||||
pub fn adjust(&mut self, zoom: f32, x: f32, y: f32) {
|
||||
if !zoom.is_finite() || !x.is_finite() || !y.is_finite() {
|
||||
return;
|
||||
}
|
||||
self.zoom = zoom.clamp(1.0, 3.0);
|
||||
let side = self.width().min(self.height()) as f32 / self.zoom;
|
||||
let max_x = (self.width() as f32 / side - 1.0) / 2.0;
|
||||
let max_y = (self.height() as f32 / side - 1.0) / 2.0;
|
||||
self.offset_x = x.clamp(-max_x, max_x);
|
||||
self.offset_y = y.clamp(-max_y, max_y);
|
||||
}
|
||||
|
||||
pub fn cropped_ui_image(&self) -> slint::Image {
|
||||
to_ui_image(&self.cropped())
|
||||
}
|
||||
|
||||
pub fn cropped(&self) -> DynamicImage {
|
||||
let side = (self.width().min(self.height()) as f32 / self.zoom)
|
||||
.round()
|
||||
.max(1.0) as u32;
|
||||
let left = ((self.width() - side) as f32 / 2.0 - self.offset_x * side as f32)
|
||||
.round()
|
||||
.clamp(0.0, (self.width() - side) as f32) as u32;
|
||||
let top = ((self.height() - side) as f32 / 2.0 - self.offset_y * side as f32)
|
||||
.round()
|
||||
.clamp(0.0, (self.height() - side) as f32) as u32;
|
||||
self.image.crop_imm(left, top, side, side).resize_exact(
|
||||
OUTPUT_SIZE,
|
||||
OUTPUT_SIZE,
|
||||
image::imageops::FilterType::Lanczos3,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn save_to(&self, path: &Path) -> Result<slint::Image, String> {
|
||||
let image = self.cropped();
|
||||
let mut encoded = Cursor::new(Vec::new());
|
||||
image
|
||||
.write_to(&mut encoded, ImageFormat::Png)
|
||||
.map_err(|e| format!("Не удалось подготовить аватар: {e}"))?;
|
||||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent).map_err(|e| e.to_string())?;
|
||||
}
|
||||
let temporary = path.with_extension(format!("{}.tmp", uuid::Uuid::new_v4()));
|
||||
std::fs::write(&temporary, encoded.into_inner())
|
||||
.map_err(|e| format!("Не удалось сохранить фото: {e}"))?;
|
||||
if let Err(error) = std::fs::rename(&temporary, path) {
|
||||
let _ = std::fs::remove_file(&temporary);
|
||||
return Err(format!("Не удалось применить аватар: {error}"));
|
||||
}
|
||||
Ok(to_ui_image(&image))
|
||||
}
|
||||
}
|
||||
|
||||
fn reject_animation(bytes: &[u8], format: ImageFormat) -> Result<(), String> {
|
||||
let (mut offset, big_endian) = match format {
|
||||
ImageFormat::Png => (8usize, true),
|
||||
ImageFormat::WebP => (12usize, false),
|
||||
_ => return Ok(()),
|
||||
};
|
||||
while offset.checked_add(8).is_some_and(|end| end <= bytes.len()) {
|
||||
let (length, kind, padding) = if big_endian {
|
||||
let size = u32::from_be_bytes(
|
||||
bytes[offset..offset + 4]
|
||||
.try_into()
|
||||
.map_err(|_| "Повреждённый PNG.")?,
|
||||
) as usize;
|
||||
(size, &bytes[offset + 4..offset + 8], 12usize)
|
||||
} else {
|
||||
let size = u32::from_le_bytes(
|
||||
bytes[offset + 4..offset + 8]
|
||||
.try_into()
|
||||
.map_err(|_| "Повреждённый WebP.")?,
|
||||
) as usize;
|
||||
(size, &bytes[offset..offset + 4], 8usize + size % 2)
|
||||
};
|
||||
if kind == b"acTL" || kind == b"ANIM" || kind == b"ANMF" {
|
||||
return Err("Анимированные изображения не поддерживаются. Выбери обычное фото.".into());
|
||||
}
|
||||
offset = offset
|
||||
.checked_add(length)
|
||||
.and_then(|n| n.checked_add(padding))
|
||||
.ok_or("Повреждённое изображение.")?;
|
||||
if offset > bytes.len() {
|
||||
break;
|
||||
} // The decoder reports truncated image details.
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn to_ui_image(image: &DynamicImage) -> slint::Image {
|
||||
let rgba = image.to_rgba8();
|
||||
let pixels = slint::SharedPixelBuffer::<slint::Rgba8Pixel>::clone_from_slice(
|
||||
rgba.as_raw(),
|
||||
rgba.width(),
|
||||
rgba.height(),
|
||||
);
|
||||
slint::Image::from_rgba8(pixels)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use image::{GenericImageView, Rgba};
|
||||
|
||||
fn encoded(image: &DynamicImage) -> Vec<u8> {
|
||||
let mut bytes = Cursor::new(Vec::new());
|
||||
image.write_to(&mut bytes, ImageFormat::Png).unwrap();
|
||||
bytes.into_inner()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bounded_crop_covers_square_and_pan_direction_matches_preview() {
|
||||
let pixels = image::RgbaImage::from_fn(400, 200, |x, _| {
|
||||
if x < 200 {
|
||||
Rgba([255, 0, 0, 255])
|
||||
} else {
|
||||
Rgba([0, 0, 255, 255])
|
||||
}
|
||||
});
|
||||
let mut source = CropSource::decode(&encoded(&DynamicImage::ImageRgba8(pixels))).unwrap();
|
||||
source.adjust(2.0, 999.0, 999.0);
|
||||
assert_eq!(source.offset_x, 1.5);
|
||||
assert_eq!(source.offset_y, 0.5);
|
||||
let cropped = source.cropped();
|
||||
assert_eq!(cropped.dimensions(), (256, 256));
|
||||
assert_eq!(cropped.get_pixel(128, 128), Rgba([255, 0, 0, 255]));
|
||||
source.adjust(2.0, -999.0, 0.0);
|
||||
assert_eq!(source.cropped().get_pixel(128, 128), Rgba([0, 0, 255, 255]));
|
||||
let before = source.zoom;
|
||||
source.adjust(f32::NAN, 0.0, 0.0);
|
||||
assert_eq!(source.zoom, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_oversized_dimensions_bad_images_and_unsupported_formats() {
|
||||
assert!(CropSource::decode(b"not an image").is_err());
|
||||
assert!(CropSource::decode(b"<svg xmlns='http://www.w3.org/2000/svg'/>").is_err());
|
||||
assert!(CropSource::decode(b"GIF89a").is_err());
|
||||
assert!(
|
||||
CropSource::decode(&vec![0; MAX_FILE_BYTES + 1])
|
||||
.unwrap_err()
|
||||
.contains("10")
|
||||
);
|
||||
let image = DynamicImage::new_rgba8(MAX_DIMENSION + 1, 1);
|
||||
assert!(CropSource::decode(&encoded(&image)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn jpeg_exif_orientation_is_applied_before_crop() {
|
||||
let mut jpeg = Cursor::new(Vec::new());
|
||||
DynamicImage::new_rgb8(2, 3)
|
||||
.write_to(&mut jpeg, ImageFormat::Jpeg)
|
||||
.unwrap();
|
||||
let exif = b"Exif\0\0II\x2a\0\x08\0\0\0\x01\0\x12\x01\x03\0\x01\0\0\0\x06\0\0\0\0\0\0\0";
|
||||
let original = jpeg.into_inner();
|
||||
let mut oriented = original[..2].to_vec();
|
||||
oriented.extend_from_slice(&[0xff, 0xe1]);
|
||||
oriented.extend_from_slice(&((exif.len() + 2) as u16).to_be_bytes());
|
||||
oriented.extend_from_slice(exif);
|
||||
oriented.extend_from_slice(&original[2..]);
|
||||
let source = CropSource::decode(&oriented).unwrap();
|
||||
assert_eq!((source.width(), source.height()), (3, 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_decode_and_cancel_do_not_replace_existing_avatar() {
|
||||
let path = std::env::temp_dir().join(format!("vnox-avatar-{}.png", uuid::Uuid::new_v4()));
|
||||
let initial = CropSource::decode(&encoded(&DynamicImage::new_rgba8(16, 16))).unwrap();
|
||||
initial.save_to(&path).unwrap();
|
||||
let old = std::fs::read(&path).unwrap();
|
||||
assert!(CropSource::decode(b"broken").is_err());
|
||||
let pending = CropSource::decode(&encoded(&DynamicImage::new_rgba8(32, 32))).unwrap();
|
||||
drop(pending); // Cancel discards pending image without a write.
|
||||
assert_eq!(std::fs::read(&path).unwrap(), old);
|
||||
assert_eq!(image::open(&path).unwrap().dimensions(), (256, 256));
|
||||
std::fs::remove_file(path).unwrap();
|
||||
}
|
||||
}
|
||||
5
src/ui/avatar/mod.rs
Normal file
5
src/ui/avatar/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
mod bindings;
|
||||
mod crop;
|
||||
|
||||
pub use bindings::wire;
|
||||
pub use crop::CropSource;
|
||||
212
src/ui/bridge.rs
212
src/ui/bridge.rs
|
|
@ -1,38 +1,82 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use slint::{SharedString, VecModel};
|
||||
use slint::{Model, ModelRc, SharedString, VecModel};
|
||||
|
||||
use crate::ui::state::{ConnState, UiState};
|
||||
|
||||
type MainWindow = crate::ui::slint::MainWindow;
|
||||
type BookmarkItem = crate::ui::slint::BookmarkItem;
|
||||
type ChannelItem = crate::ui::slint::ChannelItem;
|
||||
type DmItem = crate::ui::slint::DmItem;
|
||||
type GuildItem = crate::ui::slint::GuildItem;
|
||||
type MessageItem = crate::ui::slint::MessageItem;
|
||||
type MemberItem = crate::ui::slint::MemberItem;
|
||||
type FriendItem = crate::ui::slint::FriendItem;
|
||||
type VoiceMemberItem = crate::ui::slint::VoiceMemberItem;
|
||||
|
||||
fn replace_model<T: Clone + PartialEq + 'static>(
|
||||
current: ModelRc<T>,
|
||||
items: Vec<T>,
|
||||
set: impl FnOnce(ModelRc<T>),
|
||||
) {
|
||||
if !current.iter().eq(items.iter().cloned()) {
|
||||
set(Rc::new(VecModel::from(items)).into());
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_ts(ts: i64) -> String {
|
||||
let secs = (ts / 1000).abs() % 86400;
|
||||
format!("{:02}:{:02}", secs / 3600, (secs % 3600) / 60)
|
||||
}
|
||||
|
||||
fn set_messages(window: &MainWindow, msgs: &[crate::ui::state::ChatMessage], own_user_id: &str) {
|
||||
fn set_messages(
|
||||
window: &MainWindow,
|
||||
state: &UiState,
|
||||
msgs: &[crate::ui::state::ChatMessage],
|
||||
own_user_id: &str,
|
||||
) {
|
||||
let items: Vec<MessageItem> = msgs
|
||||
.iter()
|
||||
.map(|m| MessageItem {
|
||||
.enumerate()
|
||||
.map(|(index, m)| MessageItem {
|
||||
avatar_text: state
|
||||
.nick_for(&m.sender_id)
|
||||
.chars()
|
||||
.take(2)
|
||||
.collect::<String>()
|
||||
.into(),
|
||||
show_author: index == 0
|
||||
|| msgs[index - 1].sender_id != m.sender_id
|
||||
|| m.timestamp.saturating_sub(msgs[index - 1].timestamp) > 300_000,
|
||||
message_id: SharedString::from(m.message_id.as_str()),
|
||||
sender_id: SharedString::from(m.sender_id.as_str()),
|
||||
sender_name: SharedString::from(m.sender_id.as_str()),
|
||||
sender_name: SharedString::from(state.nick_for(&m.sender_id)),
|
||||
content: SharedString::from(m.content.as_str()),
|
||||
timestamp: SharedString::from(fmt_ts(m.timestamp)),
|
||||
is_own: m.sender_id == own_user_id,
|
||||
edited: m.edited,
|
||||
reply_to: SharedString::from(m.reply_to.as_deref().unwrap_or("")),
|
||||
reply_to: SharedString::from(
|
||||
m.reply_to
|
||||
.as_ref()
|
||||
.map(|id| {
|
||||
msgs.iter()
|
||||
.find(|other| &other.message_id == id)
|
||||
.map(|other| {
|
||||
format!(
|
||||
"{}: {}",
|
||||
state.nick_for(&other.sender_id),
|
||||
other.content.chars().take(90).collect::<String>()
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(|| "Original message unavailable".into())
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
),
|
||||
})
|
||||
.collect();
|
||||
window.set_messages(Rc::new(VecModel::from(items)).into());
|
||||
replace_model(window.get_messages(), items, |model| {
|
||||
window.set_messages(model)
|
||||
});
|
||||
}
|
||||
|
||||
fn set_members_state(window: &MainWindow, state: &UiState, ch_id: &str) {
|
||||
|
|
@ -53,13 +97,16 @@ fn set_members_state(window: &MainWindow, state: &UiState, ch_id: &str) {
|
|||
.map(|p| p.status.as_str())
|
||||
.unwrap_or("offline");
|
||||
MemberItem {
|
||||
avatar_text: nick.chars().take(2).collect::<String>().into(),
|
||||
user_id: SharedString::from(user_id),
|
||||
nickname: SharedString::from(nick.as_str()),
|
||||
status: SharedString::from(status),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
window.set_members(Rc::new(VecModel::from(items)).into());
|
||||
replace_model(window.get_members(), items, |model| {
|
||||
window.set_members(model)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -79,17 +126,15 @@ fn sync_sidebar(window: &MainWindow, state: &UiState, own_nickname: &str) {
|
|||
kind: SharedString::from(c.kind.as_str()),
|
||||
})
|
||||
.collect();
|
||||
window.set_channels(Rc::new(VecModel::from(channels)).into());
|
||||
replace_model(window.get_channels(), channels, |model| {
|
||||
window.set_channels(model)
|
||||
});
|
||||
|
||||
let guilds: Vec<GuildItem> = state
|
||||
.guilds
|
||||
.iter()
|
||||
.map(|g| {
|
||||
let short = if g.name.len() >= 2 {
|
||||
g.name[..2].to_string()
|
||||
} else {
|
||||
g.name.clone()
|
||||
};
|
||||
let short: String = g.name.chars().take(2).collect();
|
||||
GuildItem {
|
||||
guild_id: SharedString::from(g.guild_id.as_str()),
|
||||
name: SharedString::from(g.name.as_str()),
|
||||
|
|
@ -98,18 +143,27 @@ fn sync_sidebar(window: &MainWindow, state: &UiState, own_nickname: &str) {
|
|||
}
|
||||
})
|
||||
.collect();
|
||||
window.set_guilds(Rc::new(VecModel::from(guilds)).into());
|
||||
replace_model(window.get_guilds(), guilds, |model| {
|
||||
window.set_guilds(model)
|
||||
});
|
||||
|
||||
let dms: Vec<SharedString> = state
|
||||
let dms: Vec<DmItem> = state
|
||||
.dm_conversations
|
||||
.iter()
|
||||
.map(|c| SharedString::from(c.other_nickname.as_str()))
|
||||
.map(|c| DmItem {
|
||||
dm_id: c.dm_id.as_str().into(),
|
||||
name: c.other_nickname.as_str().into(),
|
||||
unread: c.unread_count.min(i32::MAX as u32) as i32,
|
||||
})
|
||||
.collect();
|
||||
window.set_dm_conversations(Rc::new(VecModel::from(dms)).into());
|
||||
replace_model(window.get_dm_conversations(), dms, |model| {
|
||||
window.set_dm_conversations(model)
|
||||
});
|
||||
|
||||
window.set_username(SharedString::from(own_nickname));
|
||||
window.set_user_status(SharedString::from("online"));
|
||||
window.set_show_dms(guild_id.is_none() && !state.dm_conversations.is_empty());
|
||||
window.set_show_dms(state.browsing_dms);
|
||||
window.set_active_dm_id(state.active_dm_id.as_deref().unwrap_or("").into());
|
||||
window.set_replying_to_message(SharedString::from(
|
||||
state.replying_to_message.as_deref().unwrap_or(""),
|
||||
));
|
||||
|
|
@ -128,31 +182,55 @@ fn sync_sidebar(window: &MainWindow, state: &UiState, own_nickname: &str) {
|
|||
}
|
||||
|
||||
fn sync_chat(window: &MainWindow, state: &UiState, own_user_id: &str) {
|
||||
if let Some(ch_id) = &state.active_channel {
|
||||
if let Some(ch) = state.channels.iter().find(|c| &c.id == ch_id) {
|
||||
window.set_active_channel_name(SharedString::from(ch.name.as_str()));
|
||||
if ch.kind == "voice" {
|
||||
window.set_show_chat(false);
|
||||
window.set_show_voice(true);
|
||||
window.set_show_friends(false);
|
||||
} else {
|
||||
window.set_show_chat(true);
|
||||
window.set_show_voice(false);
|
||||
window.set_show_friends(false);
|
||||
if let Some(msgs) = state.messages.get(ch_id) {
|
||||
set_messages(window, msgs, own_user_id);
|
||||
} else {
|
||||
window.set_messages(Rc::new(VecModel::from(vec![])).into());
|
||||
}
|
||||
set_members_state(window, state, ch_id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
window.set_show_chat(false);
|
||||
window.set_show_voice(false);
|
||||
window.set_show_friends(true);
|
||||
let dm = state
|
||||
.active_dm_id
|
||||
.as_ref()
|
||||
.and_then(|id| state.dm_conversations.iter().find(|c| &c.dm_id == id));
|
||||
let channel = state
|
||||
.active_channel
|
||||
.as_ref()
|
||||
.and_then(|id| state.channels.iter().find(|c| &c.id == id));
|
||||
window.set_is_dm(dm.is_some());
|
||||
// Encryption is not advertised until the transport has a verified nonce/message-ID contract.
|
||||
window.set_e2ee_enabled(false);
|
||||
window.set_dm_partner_name(dm.map_or("", |c| c.other_nickname.as_str()).into());
|
||||
window.set_show_voice(state.showing_voice);
|
||||
window.set_show_chat(!state.showing_voice && (dm.is_some() || channel.is_some()));
|
||||
window.set_show_friends(!state.showing_voice && dm.is_none() && channel.is_none());
|
||||
if let Some(dm) = dm {
|
||||
window.set_active_channel_name(dm.other_nickname.as_str().into());
|
||||
set_messages(
|
||||
window,
|
||||
state,
|
||||
state
|
||||
.dm_messages
|
||||
.get(&dm.dm_id)
|
||||
.map(Vec::as_slice)
|
||||
.unwrap_or_default(),
|
||||
own_user_id,
|
||||
);
|
||||
replace_model(window.get_members(), Vec::<MemberItem>::new(), |m| {
|
||||
window.set_members(m)
|
||||
});
|
||||
} else if let Some(channel) = channel {
|
||||
window.set_active_channel_name(channel.name.as_str().into());
|
||||
set_messages(
|
||||
window,
|
||||
state,
|
||||
state
|
||||
.messages
|
||||
.get(&channel.id)
|
||||
.map(Vec::as_slice)
|
||||
.unwrap_or_default(),
|
||||
own_user_id,
|
||||
);
|
||||
set_members_state(window, state, &channel.id);
|
||||
}
|
||||
// User edits are immediately written back through input-edited. Only a real
|
||||
// state change (navigation/send/edit) should replace the editor contents.
|
||||
if window.get_input_text().as_str() != state.chat_input {
|
||||
window.set_input_text(state.chat_input.as_str().into());
|
||||
}
|
||||
window.set_input_text(SharedString::from(state.chat_input.as_str()));
|
||||
}
|
||||
|
||||
fn sync_friends(window: &MainWindow, state: &UiState) {
|
||||
|
|
@ -171,7 +249,9 @@ fn sync_friends(window: &MainWindow, state: &UiState) {
|
|||
),
|
||||
})
|
||||
.collect();
|
||||
window.set_friends(Rc::new(VecModel::from(friends)).into());
|
||||
replace_model(window.get_friends(), friends, |model| {
|
||||
window.set_friends(model)
|
||||
});
|
||||
|
||||
let pending: Vec<FriendItem> = state
|
||||
.pending_friend_requests
|
||||
|
|
@ -182,14 +262,18 @@ fn sync_friends(window: &MainWindow, state: &UiState) {
|
|||
status: SharedString::from("pending"),
|
||||
})
|
||||
.collect();
|
||||
window.set_pending_requests(Rc::new(VecModel::from(pending)).into());
|
||||
replace_model(window.get_pending_requests(), pending, |model| {
|
||||
window.set_pending_requests(model)
|
||||
});
|
||||
|
||||
let blocked: Vec<SharedString> = state
|
||||
.blocked_users
|
||||
.iter()
|
||||
.map(|u| SharedString::from(u.as_str()))
|
||||
.collect();
|
||||
window.set_blocked_users(Rc::new(VecModel::from(blocked)).into());
|
||||
replace_model(window.get_blocked_users(), blocked, |model| {
|
||||
window.set_blocked_users(model)
|
||||
});
|
||||
|
||||
window.set_friends_active_tab(SharedString::from(state.friends_tab.as_str()));
|
||||
}
|
||||
|
|
@ -213,13 +297,16 @@ pub fn sync_voice(window: &MainWindow, state: &UiState) {
|
|||
.map(|(id, _)| id.clone())
|
||||
.unwrap_or_else(|| nick.clone());
|
||||
VoiceMemberItem {
|
||||
avatar_text: nick.chars().take(2).collect::<String>().into(),
|
||||
user_id: SharedString::from(user_id.clone()),
|
||||
nickname: SharedString::from(nick.as_str()),
|
||||
speaking: state.last_remote_speaker_id == user_id,
|
||||
speaking: state.remote_speaking && state.last_remote_speaker_id == user_id,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
window.set_voice_members(Rc::new(VecModel::from(members)).into());
|
||||
replace_model(window.get_voice_members(), members, |model| {
|
||||
window.set_voice_members(model)
|
||||
});
|
||||
window.set_mic_enabled(state.mic_enabled);
|
||||
window.set_deafened(state.deafen);
|
||||
|
||||
|
|
@ -227,7 +314,13 @@ pub fn sync_voice(window: &MainWindow, state: &UiState) {
|
|||
if let Some(ch) = state.channels.iter().find(|c| &c.id == channel) {
|
||||
window.set_voice_channel_name(SharedString::from(ch.name.as_str()));
|
||||
}
|
||||
} else {
|
||||
window.set_voice_channel_name("".into());
|
||||
}
|
||||
window.set_voice_connected(matches!(
|
||||
state.voice,
|
||||
crate::ui::state::VoiceUiState::Active { .. }
|
||||
));
|
||||
|
||||
let banner = match (state.local_speaking, state.remote_speaking) {
|
||||
(true, true) => "you and others are talking".to_string(),
|
||||
|
|
@ -250,8 +343,9 @@ pub fn sync_connect(window: &MainWindow, state: &UiState) {
|
|||
address: SharedString::from(bm.address.as_str()),
|
||||
})
|
||||
.collect();
|
||||
window.set_bookmarks(Rc::new(VecModel::from(bookmarks)).into());
|
||||
window.set_address_input(SharedString::from(state.connect_input.as_str()));
|
||||
replace_model(window.get_bookmarks(), bookmarks, |model| {
|
||||
window.set_bookmarks(model)
|
||||
});
|
||||
window.set_status_text(SharedString::from(
|
||||
state.status_msg.as_deref().unwrap_or(""),
|
||||
));
|
||||
|
|
@ -262,34 +356,25 @@ pub fn sync_connect(window: &MainWindow, state: &UiState) {
|
|||
window.set_auto_reconnect(state.auto_reconnect);
|
||||
if let ConnState::Connected { ref node_name, .. } = state.conn {
|
||||
window.set_node_name(SharedString::from(node_name.as_str()));
|
||||
} else {
|
||||
} else if matches!(state.conn, ConnState::Disconnected) {
|
||||
window.set_node_name(SharedString::from(""));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sync_settings(window: &MainWindow, state: &UiState, own_pubkey: &str) {
|
||||
window.set_identity_pubkey(SharedString::from(own_pubkey));
|
||||
window.set_vault_enabled(false);
|
||||
window.set_voice_input_device(SharedString::from(""));
|
||||
window.set_voice_output_device(SharedString::from(""));
|
||||
window.set_vault_enabled(state.vault_enabled);
|
||||
window.set_voice_bitrate(state.voice_bitrate);
|
||||
window.set_vad_mode(state.vad_mode as i32);
|
||||
window.set_volume(state.output_volume);
|
||||
window.set_active_tab(SharedString::from("audio"));
|
||||
window.set_settings_open(state.settings_open);
|
||||
window.set_input_device_index(state.mic_device as i32);
|
||||
window.set_output_device_index(state.output_device as i32);
|
||||
|
||||
window.set_passphrase_modal_open(state.settings_passphrase_open);
|
||||
window.set_passphrase_input(SharedString::from(state.settings_passphrase_input.as_str()));
|
||||
window.set_passphrase_confirm(SharedString::from(
|
||||
state.settings_passphrase_confirm.as_str(),
|
||||
));
|
||||
window.set_passphrase_error(SharedString::from(
|
||||
state.settings_passphrase_error.as_deref().unwrap_or(""),
|
||||
));
|
||||
|
||||
window.set_export_modal_open(state.settings_export_open);
|
||||
window.set_export_pass_input(SharedString::from(state.settings_export_pass.as_str()));
|
||||
window.set_export_pass_confirm(SharedString::from(state.settings_export_confirm.as_str()));
|
||||
window.set_export_output(SharedString::from(
|
||||
state.settings_export_output.as_deref().unwrap_or(""),
|
||||
));
|
||||
|
|
@ -297,9 +382,6 @@ pub fn sync_settings(window: &MainWindow, state: &UiState, own_pubkey: &str) {
|
|||
state.settings_export_error.as_deref().unwrap_or(""),
|
||||
));
|
||||
|
||||
window.set_import_modal_open(state.settings_import_open);
|
||||
window.set_import_keyfile_input(SharedString::from(state.settings_import_input.as_str()));
|
||||
window.set_import_pass_input(SharedString::from(state.settings_import_pass.as_str()));
|
||||
window.set_import_error(SharedString::from(
|
||||
state.settings_import_error.as_deref().unwrap_or(""),
|
||||
));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
pub mod appearance;
|
||||
pub mod avatar;
|
||||
pub mod bridge;
|
||||
pub mod preferences;
|
||||
pub mod slint;
|
||||
pub mod state;
|
||||
pub mod update;
|
||||
|
|
|
|||
51
src/ui/preferences.rs
Normal file
51
src/ui/preferences.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::state::UiState;
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
struct AudioPreferences {
|
||||
input_device: usize,
|
||||
output_device: usize,
|
||||
bitrate: Option<f32>,
|
||||
mode: usize,
|
||||
volume: Option<f32>,
|
||||
}
|
||||
|
||||
fn path() -> PathBuf {
|
||||
dirs::config_dir()
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
.join("vnox/audio.json")
|
||||
}
|
||||
|
||||
pub fn load(state: &mut UiState) {
|
||||
let Ok(text) = std::fs::read_to_string(path()) else {
|
||||
return;
|
||||
};
|
||||
let Ok(prefs) = serde_json::from_str::<AudioPreferences>(&text) else {
|
||||
return;
|
||||
};
|
||||
state.mic_device = prefs.input_device;
|
||||
state.output_device = prefs.output_device;
|
||||
state.voice_bitrate = prefs.bitrate.unwrap_or(64.0).clamp(8.0, 128.0);
|
||||
state.vad_mode = prefs.mode.min(2);
|
||||
state.output_volume = prefs.volume.unwrap_or(90.0).clamp(0.0, 100.0);
|
||||
}
|
||||
|
||||
pub fn save(state: &UiState) -> anyhow::Result<()> {
|
||||
let path = path();
|
||||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
let preferences = AudioPreferences {
|
||||
input_device: state.mic_device,
|
||||
output_device: state.output_device,
|
||||
bitrate: Some(state.voice_bitrate),
|
||||
mode: state.vad_mode,
|
||||
volume: Some(state.output_volume),
|
||||
};
|
||||
std::fs::write(path, serde_json::to_vec_pretty(&preferences)?)?;
|
||||
Ok(())
|
||||
}
|
||||
1
src/ui/slint/assets/vnox-mark.svg
Normal file
1
src/ui/slint/assets/vnox-mark.svg
Normal file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Vnox"><rect width="64" height="64" rx="17" fill="#202022"/><g fill="none" stroke="#dac5a6" stroke-width="5" stroke-linejoin="round" stroke-linecap="round"><path d="M16 20 32 46 48 20"/><path d="M16 20H26M38 20H48"/></g></svg>
|
||||
|
After Width: | Height: | Size: 308 B |
121
src/ui/slint/avatar-cropper.slint
Normal file
121
src/ui/slint/avatar-cropper.slint
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
import { Theme, ActionButton } from "theme.slint";
|
||||
import { AudioSlider } from "controls.slint";
|
||||
|
||||
export component AvatarCropper inherits Rectangle {
|
||||
in property <image> avatar-source;
|
||||
in property <float> source-width: 1;
|
||||
in property <float> source-height: 1;
|
||||
in property <float> offset-x;
|
||||
in property <float> offset-y;
|
||||
in-out property <float> zoom: 1;
|
||||
in property <string> error;
|
||||
callback crop-moved(float, float);
|
||||
callback zoom-changed(float);
|
||||
callback confirm();
|
||||
callback cancel();
|
||||
private property <length> frame-size: Math.min(320px, Math.max(220px, root.height - 350px));
|
||||
private property <float> cover-scale: Math.max(root.frame-size / 1px / Math.max(root.source-width, 1), root.frame-size / 1px / Math.max(root.source-height, 1)) * root.zoom;
|
||||
background: Theme.overlay;
|
||||
TouchArea { }
|
||||
keyboard := FocusScope {
|
||||
init => { self.focus(); }
|
||||
key-pressed(event) => {
|
||||
if event.text == Key.Escape { root.cancel(); return accept; }
|
||||
if event.text == "+" || event.text == "=" { root.set-zoom(root.zoom + 0.1); return accept; }
|
||||
if event.text == "-" { root.set-zoom(root.zoom - 0.1); return accept; }
|
||||
return reject;
|
||||
}
|
||||
Rectangle {
|
||||
width: 440px;
|
||||
height: Math.min(620px, root.height - 24px);
|
||||
x: (root.width - self.width) / 2;
|
||||
y: (root.height - self.height) / 2;
|
||||
background: Theme.bg-surface;
|
||||
border-radius: 12px;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
VerticalLayout {
|
||||
padding: 18px; spacing: 8px; alignment: start;
|
||||
HorizontalLayout {
|
||||
Text { text: "Выбрать область фото"; color: Theme.text-primary; font-size: Theme.font-size + 5px; font-weight: 600; horizontal-stretch: 1; vertical-alignment: center; }
|
||||
ActionButton { text: "×"; width: 30px; quiet: true; clicked => { root.cancel(); } }
|
||||
}
|
||||
Text { text: "Перетащи фото и выбери масштаб."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); }
|
||||
Rectangle { height: 4px; }
|
||||
HorizontalLayout {
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
frame := Rectangle {
|
||||
width: root.frame-size; height: root.frame-size;
|
||||
clip: true; background: Theme.bg-surface;
|
||||
accessible-role: image;
|
||||
accessible-label: "Область фото. Перетаскивай изображение, чтобы изменить кадрирование.";
|
||||
Image {
|
||||
source: root.avatar-source;
|
||||
width: root.source-width * root.cover-scale * 1px;
|
||||
height: root.source-height * root.cover-scale * 1px;
|
||||
x: (frame.width - self.width) / 2 + root.offset-x * frame.width;
|
||||
y: (frame.height - self.height) / 2 + root.offset-y * frame.height;
|
||||
image-fit: fill;
|
||||
}
|
||||
// The mask makes the final circular avatar explicit, independently
|
||||
// of renderer support for rounded clipping of bitmap images.
|
||||
Path {
|
||||
width: parent.width; height: parent.height;
|
||||
viewbox-width: 320; viewbox-height: 320;
|
||||
fill: Theme.bg-surface;
|
||||
fill-rule: evenodd;
|
||||
commands: "M0 0H320V320H0Z M320 160 A160 160 0 1 0 0 160 A160 160 0 1 0 320 160Z";
|
||||
}
|
||||
Rectangle {
|
||||
width: parent.width; height: parent.height;
|
||||
border-radius: parent.width / 2;
|
||||
border-width: 1px; border-color: Theme.border;
|
||||
background: transparent;
|
||||
}
|
||||
drag := TouchArea {
|
||||
property <float> start-x;
|
||||
property <float> start-y;
|
||||
pointer-event(event) => {
|
||||
if event.button == PointerEventButton.left && event.kind == PointerEventKind.down {
|
||||
self.start-x = root.offset-x;
|
||||
self.start-y = root.offset-y;
|
||||
keyboard.focus();
|
||||
}
|
||||
}
|
||||
moved => {
|
||||
if self.pressed {
|
||||
root.crop-moved(self.start-x + (self.mouse-x - self.pressed-x) / frame.width,
|
||||
self.start-y + (self.mouse-y - self.pressed-y) / frame.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
Rectangle { height: 2px; }
|
||||
HorizontalLayout {
|
||||
spacing: 10px;
|
||||
ActionButton { text: "−"; width: 32px; clicked => { root.set-zoom(root.zoom - 0.1); } }
|
||||
AudioSlider { minimum: 1; maximum: 3; value <=> root.zoom; changed(value) => { root.zoom-changed(value); } }
|
||||
ActionButton { text: "+"; width: 32px; clicked => { root.set-zoom(root.zoom + 0.1); } }
|
||||
}
|
||||
HorizontalLayout {
|
||||
Text { text: "Масштаб " + Math.round(root.zoom * 100) + "%"; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 4px, 11px); vertical-alignment: center; horizontal-stretch: 1; }
|
||||
ActionButton { text: "Сбросить кадр"; quiet: true; clicked => { root.crop-moved(0,0); root.set-zoom(1); } }
|
||||
}
|
||||
if root.error != "" : Text { text: root.error; color: Theme.danger; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton { text: "Отмена"; quiet: true; clicked => { root.cancel(); } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
ActionButton { text: "Использовать фото"; active: true; clicked => { root.confirm(); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function set-zoom(value: float) {
|
||||
root.zoom = Math.clamp(value, 1, 3);
|
||||
root.zoom-changed(root.zoom);
|
||||
}
|
||||
}
|
||||
21
src/ui/slint/avatar-view.slint
Normal file
21
src/ui/slint/avatar-view.slint
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { Theme } from "theme.slint";
|
||||
|
||||
export component AvatarView inherits Rectangle {
|
||||
in property <image> source;
|
||||
in property <bool> has-source;
|
||||
in property <string> initials;
|
||||
in property <brush> mask: Theme.bg-base;
|
||||
width: 34px; height: 34px;
|
||||
border-radius: self.width / 2;
|
||||
background: Theme.avatar-bg;
|
||||
clip: true;
|
||||
if root.has-source : Image { source: root.source; width: parent.width; height: parent.height; image-fit: cover; }
|
||||
if !root.has-source : Text { text: root.initials; color: Theme.accent; font-size: Math.max(11px, Theme.font-size - 3px); horizontal-alignment: center; vertical-alignment: center; overflow: elide; }
|
||||
// Explicit mask also works on software renderers that only clip rectangular bounds.
|
||||
Path {
|
||||
width: parent.width; height: parent.height;
|
||||
viewbox-width: 320; viewbox-height: 320;
|
||||
commands: "M0 0H320V320H0Z M320 160 A160 160 0 1 0 0 160 A160 160 0 1 0 320 160Z";
|
||||
fill-rule: evenodd; fill: root.mask;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,81 +1,72 @@
|
|||
import { Theme } from "theme.slint";
|
||||
import { AvatarView } from "avatar-view.slint";
|
||||
import { Theme, ActionButton } from "theme.slint";
|
||||
|
||||
export struct MessageItem {
|
||||
message_id: string,
|
||||
sender_id: string,
|
||||
sender_name: string,
|
||||
content: string,
|
||||
timestamp: string,
|
||||
is_own: bool,
|
||||
edited: bool,
|
||||
reply_to: string,
|
||||
message_id: string, sender_id: string, sender_name: string,
|
||||
content: string, timestamp: string, is_own: bool, edited: bool, reply_to: string, avatar_text: string, show_author: bool,
|
||||
}
|
||||
|
||||
export struct DmConversationItem {
|
||||
dm_id: string,
|
||||
other_user_id: string,
|
||||
other_nickname: string,
|
||||
e2ee_enabled: bool,
|
||||
messages: [MessageItem],
|
||||
dm_id: string, other_user_id: string, other_nickname: string,
|
||||
e2ee_enabled: bool, messages: [MessageItem],
|
||||
}
|
||||
export struct MemberItem { user_id: string, nickname: string, status: string, avatar_text: string }
|
||||
|
||||
export struct MemberItem {
|
||||
user_id: string,
|
||||
nickname: string,
|
||||
status: string,
|
||||
}
|
||||
|
||||
component MessageActions {
|
||||
in-out property <bool> is-own;
|
||||
in-out property <string> msg-id;
|
||||
|
||||
component MessageRow inherits Rectangle {
|
||||
in property <MessageItem> message;
|
||||
in property <bool> actions-enabled: true;
|
||||
in property <image> own-avatar;
|
||||
in property <bool> has-own-avatar;
|
||||
callback react(string, string);
|
||||
callback reply-to-msg(string);
|
||||
callback edit-msg(string);
|
||||
callback delete-msg(string);
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: 4px;
|
||||
Rectangle {
|
||||
width: 24px; height: 24px; border-radius: 4px;
|
||||
background: Theme.bg-interactive;
|
||||
TouchArea { clicked => { react(msg-id, "👍"); } }
|
||||
Text { text: "👍"; font-size: 12px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
min-height: row-content.min-height;
|
||||
preferred-height: row-content.preferred-height;
|
||||
vertical-stretch: 0;
|
||||
background: row-touch.has-hover || row-focus.has-focus ? Theme.bg-hover : transparent;
|
||||
row-touch := TouchArea { }
|
||||
row-focus := FocusScope { }
|
||||
row-content := HorizontalLayout {
|
||||
padding-left: 22px; padding-right: 22px;
|
||||
padding-top: root.message.show_author ? 9px : 2px; padding-bottom: root.message.show_author ? 9px : 2px; spacing: 13px;
|
||||
AvatarView {
|
||||
width: 34px; height: root.message.show_author ? 34px : 0px; visible: root.message.show_author;
|
||||
source: root.own-avatar; has-source: root.has-own-avatar && root.message.is_own;
|
||||
initials: root.message.avatar_text; mask: root.background;
|
||||
}
|
||||
Rectangle {
|
||||
width: 24px; height: 24px; border-radius: 4px;
|
||||
background: Theme.bg-interactive;
|
||||
TouchArea { clicked => { react(msg-id, "❤️"); } }
|
||||
Text { text: "❤️"; font-size: 12px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
VerticalLayout {
|
||||
spacing: 4px;
|
||||
if root.message.reply_to != "" : Text {
|
||||
text: "↳ " + root.message.reply_to;
|
||||
color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.6875); wrap: word-wrap;
|
||||
}
|
||||
if root.message.show_author : HorizontalLayout {
|
||||
spacing: 9px;
|
||||
Text { text: root.message.sender_name; color: Theme.accent; font-size: Math.max(11px, Theme.font-size * 0.875); font-weight: 600; overflow: elide; }
|
||||
Text { text: root.message.timestamp + (root.message.edited ? " · изменено" : ""); color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.6875); }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
Text { text: root.message.content; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.0); wrap: word-wrap; }
|
||||
}
|
||||
Rectangle {
|
||||
width: 24px; height: 24px; border-radius: 4px;
|
||||
background: Theme.bg-interactive;
|
||||
TouchArea { clicked => { react(msg-id, "😂"); } }
|
||||
Text { text: "😂"; font-size: 12px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
Rectangle {
|
||||
width: 24px; height: 24px; border-radius: 4px;
|
||||
background: Theme.bg-interactive;
|
||||
TouchArea { clicked => { reply-to-msg(msg-id); } }
|
||||
Text { text: "↩"; color: Theme.text-secondary; font-size: 12px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
if is-own : Rectangle {
|
||||
width: 24px; height: 24px; border-radius: 4px;
|
||||
background: Theme.bg-interactive;
|
||||
TouchArea { clicked => { edit-msg(msg-id); } }
|
||||
Text { text: "✏"; color: Theme.text-secondary; font-size: 12px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
if is-own : Rectangle {
|
||||
width: 24px; height: 24px; border-radius: 4px;
|
||||
background: Theme.danger;
|
||||
TouchArea { clicked => { delete-msg(msg-id); } }
|
||||
Text { text: "✕"; color: Theme.text-primary; font-size: 12px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
if root.actions-enabled && (row-touch.has-hover || row-focus.has-focus) : Rectangle {
|
||||
x: parent.width - self.width - 16px; y: 0px;
|
||||
width: root.message.is_own ? 245px : 136px; height: 32px;
|
||||
background: Theme.bg-surface; border-radius: 6px;
|
||||
border-width: 1px; border-color: Theme.border;
|
||||
HorizontalLayout {
|
||||
spacing: 3px;
|
||||
ActionButton { text: "👍"; quiet: true; clicked => { root.react(root.message.message_id, "👍"); } }
|
||||
ActionButton { text: "Ответить"; quiet: true; clicked => { root.reply-to-msg(root.message.message_id); } }
|
||||
if root.message.is_own : ActionButton { text: "Править"; quiet: true; clicked => { root.edit-msg(root.message.message_id); } }
|
||||
if root.message.is_own : ActionButton { text: "Удалить"; danger: true; quiet: true; clicked => { root.delete-msg(root.message.message_id); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component ChatPanel {
|
||||
export component ChatPanel inherits Rectangle {
|
||||
in property <image> own-avatar;
|
||||
in property <bool> has-own-avatar;
|
||||
in-out property <string> active-channel-id;
|
||||
in-out property <string> active-channel-name;
|
||||
in-out property <[MessageItem]> messages;
|
||||
|
|
@ -87,7 +78,9 @@ export component ChatPanel {
|
|||
in-out property <string> replying-to-message;
|
||||
in-out property <string> replying-to-sender;
|
||||
in-out property <string> replying-to-content;
|
||||
|
||||
in-out property <bool> members-visible: true;
|
||||
callback input-edited(string);
|
||||
callback toggle-members();
|
||||
callback send-message(string, string);
|
||||
callback load-more(string);
|
||||
callback react(string, string);
|
||||
|
|
@ -95,141 +88,104 @@ export component ChatPanel {
|
|||
callback edit-msg(string);
|
||||
callback delete-msg(string);
|
||||
callback cancel-reply();
|
||||
|
||||
background: Theme.bg-base;
|
||||
VerticalLayout {
|
||||
padding: 0;
|
||||
spacing: 0;
|
||||
|
||||
Rectangle {
|
||||
height: 48px;
|
||||
background: Theme.bg-surface;
|
||||
height: 56px; border-width: 1px; border-color: Theme.border;
|
||||
HorizontalLayout {
|
||||
padding: 8px;
|
||||
spacing: 4px;
|
||||
Text {
|
||||
text: e2ee-enabled ? "🔒 " : "";
|
||||
color: Theme.accent;
|
||||
}
|
||||
Text {
|
||||
text: is-dm ? dm-partner-name : "#" + active-channel-name;
|
||||
color: Theme.text-primary;
|
||||
font-size: 16px;
|
||||
}
|
||||
padding-left: 22px; padding-right: 16px; spacing: 12px;
|
||||
Text { text: root.is-dm ? "@" : "#"; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 1.4375); width: 20px; vertical-alignment: center; }
|
||||
Text { text: root.is-dm ? root.dm-partner-name : root.active-channel-name; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.0); font-weight: 600; overflow: elide; vertical-alignment: center; }
|
||||
if root.e2ee-enabled : Text { text: "Сквозное шифрование"; color: Theme.success; font-size: Math.max(11px, Theme.font-size * 0.6875); }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
if !root.is-dm : ActionButton { text: "Участники"; active: root.members-visible; clicked => { root.toggle-members(); } }
|
||||
}
|
||||
}
|
||||
|
||||
Flickable {
|
||||
HorizontalLayout {
|
||||
spacing: 0;
|
||||
VerticalLayout {
|
||||
for msg in messages: Rectangle {
|
||||
height: 72px;
|
||||
spacing: 0; horizontal-stretch: 1;
|
||||
Flickable {
|
||||
content-width: self.width;
|
||||
VerticalLayout {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
padding-top: 6px;
|
||||
padding-bottom: 6px;
|
||||
spacing: 2px;
|
||||
if msg.reply_to != "" : Text {
|
||||
text: "↳ " + msg.reply_to;
|
||||
color: Theme.text-muted;
|
||||
font-size: 11px;
|
||||
spacing: 0;
|
||||
if root.messages.length == 0 : Text {
|
||||
text: root.is-dm ? "Сообщений пока нет. Напиши первым." : "В этом канале пока нет сообщений.";
|
||||
color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.875); wrap: word-wrap;
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Text {
|
||||
text: msg.sender_name;
|
||||
color: Theme.accent;
|
||||
font-weight: 700;
|
||||
font-size: 13px;
|
||||
}
|
||||
Text {
|
||||
text: msg.timestamp;
|
||||
color: Theme.text-muted;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: msg.content;
|
||||
wrap: word-wrap;
|
||||
color: Theme.text-primary;
|
||||
font-size: 14px;
|
||||
}
|
||||
HorizontalLayout {
|
||||
height: 22px;
|
||||
MessageActions {
|
||||
is-own: msg.is_own;
|
||||
msg-id: msg.message_id;
|
||||
react(id, emoji) => { root.react(id, emoji); }
|
||||
reply-to-msg(id) => { root.reply-to-msg(id); }
|
||||
edit-msg(id) => { root.edit-msg(id); }
|
||||
delete-msg(id) => { root.delete-msg(id); }
|
||||
for msg in root.messages: MessageRow {
|
||||
message: msg;
|
||||
own-avatar: root.own-avatar;
|
||||
has-own-avatar: root.has-own-avatar;
|
||||
actions-enabled: !root.is-dm;
|
||||
react(id, emoji) => { root.react(id, emoji); }
|
||||
reply-to-msg(id) => { root.reply-to-msg(id); }
|
||||
edit-msg(id) => { root.edit-msg(id); }
|
||||
delete-msg(id) => { root.delete-msg(id); }
|
||||
}
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
}
|
||||
}
|
||||
if root.replying-to-message != "" : Rectangle {
|
||||
height: 34px; background: Theme.bg-elevated;
|
||||
HorizontalLayout {
|
||||
padding-left: 16px; padding-right: 16px; spacing: 9px;
|
||||
Text { text: "Ответ " + root.replying-to-sender; color: Theme.accent; font-size: Math.max(11px, Theme.font-size * 0.75); }
|
||||
Text { text: root.replying-to-content; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); horizontal-stretch: 1; overflow: elide; }
|
||||
ActionButton { text: "×"; quiet: true; width: 28px; clicked => { root.cancel-reply(); } }
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
height: 92px;
|
||||
VerticalLayout {
|
||||
padding-left: 20px; padding-right: 20px; padding-top: 8px; spacing: 5px;
|
||||
Rectangle {
|
||||
background: Theme.bg-interactive; border-radius: 9px;
|
||||
border-width: 1px; border-color: Theme.border;
|
||||
HorizontalLayout {
|
||||
padding: 10px; spacing: 10px;
|
||||
editor := TextInput {
|
||||
text <=> root.input-text;
|
||||
single-line: false;
|
||||
color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.9375);
|
||||
horizontal-stretch: 1; wrap: word-wrap;
|
||||
edited => { root.input-edited(self.text); }
|
||||
key-pressed(event) => {
|
||||
if event.text == "\n" && !event.modifiers.shift {
|
||||
root.send-message(root.is-dm ? "" : root.active-channel-id, root.input-text);
|
||||
return accept;
|
||||
}
|
||||
return reject;
|
||||
}
|
||||
}
|
||||
ActionButton {
|
||||
text: "Отправить";
|
||||
clicked => { root.send-message(root.is-dm ? "" : root.active-channel-id, root.input-text); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Text { text: "Enter — отправить · Shift+Enter — новая строка"; color: Theme.text-disabled; font-size: Math.max(11px, Theme.font-size * 0.6875); height: 18px; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if replying-to-message != "" : Rectangle {
|
||||
height: 32px;
|
||||
background: Theme.bg-elevated;
|
||||
HorizontalLayout {
|
||||
padding-left: 8px;
|
||||
padding-right: 8px;
|
||||
spacing: 8px;
|
||||
Rectangle {
|
||||
width: 3px;
|
||||
height: 20px;
|
||||
background: Theme.accent;
|
||||
border-radius: 2px;
|
||||
}
|
||||
Text {
|
||||
text: "Replying to " + replying-to-sender;
|
||||
color: Theme.text-secondary;
|
||||
font-size: 12px;
|
||||
}
|
||||
Text {
|
||||
text: replying-to-content;
|
||||
color: Theme.text-muted;
|
||||
font-size: 12px;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
Rectangle {
|
||||
width: 20px; height: 20px; border-radius: 4px;
|
||||
background: Theme.bg-interactive;
|
||||
TouchArea { clicked => { cancel-reply(); } }
|
||||
Text { text: "✕"; color: Theme.text-muted; font-size: 12px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
height: 48px;
|
||||
background: Theme.bg-surface;
|
||||
HorizontalLayout {
|
||||
padding: 8px;
|
||||
spacing: 8px;
|
||||
TextInput {
|
||||
text <=> input-text;
|
||||
horizontal-stretch: 1;
|
||||
font-size: 14px;
|
||||
}
|
||||
Rectangle {
|
||||
width: 64px;
|
||||
height: 32px;
|
||||
background: Theme.accent;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => {
|
||||
send-message(active-channel-id, input-text);
|
||||
input-text = "";
|
||||
if root.members-visible && !root.is-dm : Rectangle {
|
||||
width: 210px; background: Theme.bg-surface;
|
||||
Flickable {
|
||||
content-width: self.width;
|
||||
VerticalLayout {
|
||||
padding: 16px; spacing: 12px;
|
||||
Text { text: "Участники — " + root.members.length; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); height: 28px; }
|
||||
for member in root.members: HorizontalLayout {
|
||||
height: 38px; spacing: 9px;
|
||||
Rectangle { width: 28px; height: 28px; background: Theme.avatar-bg; border-radius: 11px; Text { text: member.avatar_text; color: Theme.accent; font-size: Math.max(11px, Theme.font-size * 0.6875); horizontal-alignment: center; vertical-alignment: center; } }
|
||||
VerticalLayout {
|
||||
spacing: 1px;
|
||||
Text { text: member.nickname; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.8125); overflow: elide; }
|
||||
Text { text: member.status; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.6875); overflow: elide; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: "Send";
|
||||
color: Theme.text-primary;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,101 +1,88 @@
|
|||
import { Theme } from "theme.slint";
|
||||
import { Button, ListView, LineEdit } from "std-widgets.slint";
|
||||
import { Theme, ActionButton } from "theme.slint";
|
||||
|
||||
export struct BookmarkItem {
|
||||
name: string,
|
||||
address: string,
|
||||
}
|
||||
export struct BookmarkItem { name: string, address: string }
|
||||
|
||||
export component ConnectScreen {
|
||||
export component ConnectScreen inherits Rectangle {
|
||||
in-out property <[BookmarkItem]> bookmarks;
|
||||
in-out property <string> address-input;
|
||||
in-out property <string> status-text;
|
||||
in-out property <bool> connecting;
|
||||
in-out property <bool> auto-reconnect;
|
||||
in-out property <string> node-name;
|
||||
|
||||
callback address-edited(string);
|
||||
callback auto-reconnect-changed(bool);
|
||||
callback connect(string);
|
||||
callback disconnect();
|
||||
callback remove-bookmark(string);
|
||||
callback add-bookmark(string);
|
||||
|
||||
callback open-settings();
|
||||
background: Theme.bg-base;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
spacing: 16px;
|
||||
|
||||
Text { text: "VNOX"; color: Theme.accent; font-size: 36px; font-weight: 700; }
|
||||
Text { text: "Self-hosted voice & chat"; color: Theme.text-secondary; font-size: 14px; }
|
||||
|
||||
padding: 32px; spacing: 22px;
|
||||
HorizontalLayout {
|
||||
LineEdit {
|
||||
text <=> address-input;
|
||||
placeholder-text: "server:7600";
|
||||
width: 300px;
|
||||
}
|
||||
Rectangle {
|
||||
width: 100px;
|
||||
height: 30px;
|
||||
background: Theme.accent;
|
||||
border-radius: 6px;
|
||||
TouchArea {
|
||||
enabled: !connecting;
|
||||
clicked => { connect(address-input); }
|
||||
}
|
||||
Text {
|
||||
text: connecting ? "Connecting..." : "Connect";
|
||||
color: Theme.text-primary;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
Image { source: @image-url("assets/vnox-mark.svg"); width: 32px; height: 32px; image-fit: contain; }
|
||||
Text { text: "Vnox"; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.1875); font-weight: 700; }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
ActionButton { text: "Настройки"; quiet: true; clicked => { root.open-settings(); } }
|
||||
}
|
||||
|
||||
Text { text: status-text; color: Theme.text-muted; }
|
||||
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
HorizontalLayout {
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
Rectangle {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background: auto-reconnect ? Theme.accent : Theme.bg-elevated;
|
||||
border-radius: 3px;
|
||||
border-width: 1px;
|
||||
border-color: Theme.text-muted;
|
||||
TouchArea {
|
||||
clicked => { auto-reconnect = !auto-reconnect; }
|
||||
}
|
||||
}
|
||||
Text { text: "Auto-reconnect"; color: Theme.text-secondary; }
|
||||
}
|
||||
|
||||
Text { text: "Saved Servers"; color: Theme.text-primary; font-size: 16px; }
|
||||
ListView {
|
||||
for bm in bookmarks: Rectangle {
|
||||
height: 40px;
|
||||
HorizontalLayout {
|
||||
padding: 8px;
|
||||
Text { text: bm.name; color: Theme.text-primary; }
|
||||
Text { text: bm.address; color: Theme.text-muted; }
|
||||
width: 540px;
|
||||
background: Theme.bg-surface; border-radius: 14px;
|
||||
VerticalLayout {
|
||||
padding: 28px; spacing: 15px;
|
||||
Text { text: "Подключиться к серверу"; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.5); font-weight: 600; }
|
||||
Text { text: "Введи адрес своего сервера или выбери сохранённый."; color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.8125); wrap: word-wrap; }
|
||||
Text { text: "Адрес сервера"; color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.75); }
|
||||
HorizontalLayout {
|
||||
Button { text: "Connect"; clicked => { connect(bm.address); } }
|
||||
Button { text: "✕"; clicked => { remove-bookmark(bm.address); } }
|
||||
spacing: 9px;
|
||||
Rectangle {
|
||||
height: 40px; background: Theme.bg-interactive; border-radius: 7px;
|
||||
border-width: 1px; border-color: Theme.border;
|
||||
HorizontalLayout {
|
||||
padding: 10px;
|
||||
TextInput {
|
||||
text <=> root.address-input;
|
||||
single-line: true; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875);
|
||||
edited => { root.address-edited(self.text); }
|
||||
accepted => { if !root.connecting { root.connect(root.address-input); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
if !root.connecting : ActionButton { text: "Подключиться"; height: 40px; clicked => { root.connect(root.address-input); } }
|
||||
if root.connecting : ActionButton { text: "Отмена"; height: 40px; clicked => { root.disconnect(); } }
|
||||
}
|
||||
HorizontalLayout {
|
||||
ActionButton { text: root.auto-reconnect ? "✓" : "○"; width: 30px; quiet: true; clicked => { root.auto-reconnect = !root.auto-reconnect; root.auto-reconnect-changed(root.auto-reconnect); } }
|
||||
Text { text: "Переподключаться при потере связи"; color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.75); }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
if root.connecting : Text { text: "Подключение…"; color: Theme.accent; font-size: Math.max(11px, Theme.font-size * 0.8125); }
|
||||
if root.status-text != "" : Text { text: root.status-text; color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.8125); wrap: word-wrap; }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
HorizontalLayout {
|
||||
Text { text: "Сохранённые серверы"; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875); font-weight: 600; }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
ActionButton { text: "+ Сохранить адрес"; quiet: true; clicked => { root.add-bookmark(root.address-input); } }
|
||||
}
|
||||
if root.bookmarks.length == 0 : Text { text: "Сохранённых серверов пока нет."; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); }
|
||||
for server in root.bookmarks: HorizontalLayout {
|
||||
height: 48px; spacing: 8px;
|
||||
VerticalLayout {
|
||||
spacing: 2px; horizontal-stretch: 1;
|
||||
Text { text: server.name; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875); overflow: elide; }
|
||||
Text { text: server.address; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.6875); overflow: elide; }
|
||||
}
|
||||
ActionButton { text: "Войти"; quiet: true; clicked => { if !root.connecting { root.connect(server.address); } } }
|
||||
ActionButton { text: "×"; width: 28px; quiet: true; clicked => { root.remove-bookmark(server.address); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
Button { text: "+ Add Server"; clicked => { add-bookmark(address-input); } }
|
||||
}
|
||||
|
||||
Text { text: node-name; color: Theme.success; }
|
||||
Rectangle {
|
||||
width: 100px;
|
||||
height: 30px;
|
||||
background: Theme.danger;
|
||||
border-radius: 6px;
|
||||
visible: node-name != "";
|
||||
TouchArea { clicked => { disconnect(); } }
|
||||
Text { text: "Disconnect"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
Text { text: "Твой сервер. Твоё сообщество."; color: Theme.text-disabled; font-size: Math.max(11px, Theme.font-size * 0.75); horizontal-alignment: center; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
135
src/ui/slint/controls.slint
Normal file
135
src/ui/slint/controls.slint
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
import { Theme, ActionButton } from "theme.slint";
|
||||
|
||||
export component DeviceSelect inherits Rectangle {
|
||||
in property <[string]> model;
|
||||
in-out property <int> current-index;
|
||||
callback selected(string);
|
||||
height: 34px;
|
||||
background: Theme.bg-interactive;
|
||||
border-radius: 6px;
|
||||
border-width: 1px;
|
||||
border-color: keyboard.has-focus ? Theme.accent : Theme.border;
|
||||
accessible-role: combobox;
|
||||
HorizontalLayout {
|
||||
padding-left: 11px; padding-right: 11px;
|
||||
Text { text: root.model[root.current-index]; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.8125); vertical-alignment: center; overflow: elide; horizontal-stretch: 1; }
|
||||
Text { text: "⌄"; color: Theme.text-muted; width: 16px; vertical-alignment: center; }
|
||||
}
|
||||
TouchArea { clicked => { keyboard.focus(); popup.show(); } }
|
||||
keyboard := FocusScope {
|
||||
key-pressed(event) => {
|
||||
if event.text == " " || event.text == "\n" { popup.show(); return accept; }
|
||||
if event.text == Key.DownArrow || event.text == Key.UpArrow {
|
||||
root.current-index = Math.clamp(root.current-index + (event.text == Key.DownArrow ? 1 : -1), 0, root.model.length - 1);
|
||||
root.selected(root.model[root.current-index]);
|
||||
return accept;
|
||||
}
|
||||
return reject;
|
||||
}
|
||||
}
|
||||
popup := PopupWindow {
|
||||
x: 0px; y: root.height + 3px;
|
||||
width: root.width;
|
||||
height: Math.min(root.model.length * 36px + 12px, 264px);
|
||||
Rectangle {
|
||||
background: Theme.bg-surface; border-radius: 6px;
|
||||
border-width: 1px; border-color: Theme.border;
|
||||
Flickable {
|
||||
content-width: self.width;
|
||||
VerticalLayout {
|
||||
padding: 6px; spacing: 3px;
|
||||
for item[index] in root.model: ActionButton {
|
||||
text: item; active: index == root.current-index;
|
||||
clicked => { root.current-index = index; root.selected(item); popup.close(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component AudioSlider inherits Rectangle {
|
||||
in property <float> minimum: 0;
|
||||
in property <float> maximum: 100;
|
||||
in-out property <float> value;
|
||||
callback changed(float);
|
||||
height: 26px;
|
||||
border-width: keyboard.has-focus ? 1px : 0px;
|
||||
border-color: Theme.accent; border-radius: 5px;
|
||||
Rectangle { x: 8px; y: 11px; width: parent.width - 16px; height: 4px; background: Theme.bg-rail; border-radius: 2px; }
|
||||
Rectangle { x: 8px; y: 11px; width: (parent.width - 16px) * (root.value - root.minimum) / (root.maximum - root.minimum); height: 4px; background: Theme.accent; border-radius: 2px; }
|
||||
Rectangle { x: 1px + (parent.width - 16px) * (root.value - root.minimum) / (root.maximum - root.minimum); y: 5px; width: 16px; height: 16px; border-radius: 8px; background: Theme.text-primary; border-width: 3px; border-color: Theme.accent; }
|
||||
touch := TouchArea {
|
||||
pointer-event(event) => {
|
||||
if event.button == PointerEventButton.left && event.kind == PointerEventKind.down { keyboard.focus(); root.update-value(root.minimum + Math.clamp((self.mouse-x - 8px) / (root.width - 16px), 0, 1) * (root.maximum - root.minimum)); }
|
||||
}
|
||||
moved => { if self.pressed { root.update-value(root.minimum + Math.clamp((self.mouse-x - 8px) / (root.width - 16px), 0, 1) * (root.maximum - root.minimum)); } }
|
||||
}
|
||||
keyboard := FocusScope {
|
||||
key-pressed(event) => {
|
||||
if event.text == Key.LeftArrow || event.text == Key.RightArrow { root.update-value(root.value + (event.text == Key.RightArrow ? 1 : -1)); return accept; }
|
||||
return reject;
|
||||
}
|
||||
}
|
||||
function update-value(value: float) { root.value = Math.clamp(value, root.minimum, root.maximum); root.changed(root.value); }
|
||||
}
|
||||
|
||||
export component ThemeInput inherits Rectangle {
|
||||
in-out property <string> text;
|
||||
in property <string> placeholder-text;
|
||||
in property <InputType> input-type: InputType.text;
|
||||
in property <bool> read-only: false;
|
||||
callback accepted();
|
||||
callback edited(string);
|
||||
height: 38px;
|
||||
background: Theme.bg-interactive;
|
||||
border-radius: 6px;
|
||||
border-width: 1px;
|
||||
border-color: editor.has-focus ? Theme.accent : Theme.border;
|
||||
Text {
|
||||
x: 12px; y: 0px; width: parent.width - 24px; height: parent.height;
|
||||
visible: root.text == "" && !editor.has-focus;
|
||||
text: root.placeholder-text; color: Theme.text-muted;
|
||||
font-size: Math.max(12px, Theme.font-size - 2px); vertical-alignment: center; overflow: elide;
|
||||
}
|
||||
editor := TextInput {
|
||||
x: 12px; y: (parent.height - self.height) / 2;
|
||||
width: parent.width - 24px; height: self.preferred-height;
|
||||
text <=> root.text; input-type: root.input-type; read-only: root.read-only;
|
||||
single-line: true; color: Theme.text-primary;
|
||||
selection-background-color: Theme.selected; selection-foreground-color: Theme.text-primary;
|
||||
font-size: Math.max(12px, Theme.font-size - 2px);
|
||||
accepted => { root.accepted(); }
|
||||
edited => { root.edited(self.text); }
|
||||
}
|
||||
forward-focus: editor;
|
||||
}
|
||||
|
||||
export component ThemeEditor inherits Rectangle {
|
||||
in-out property <string> text;
|
||||
in property <bool> read-only: false;
|
||||
in property <bool> monospace: true;
|
||||
callback edited(string);
|
||||
min-height: 80px;
|
||||
preferred-height: 220px;
|
||||
background: Theme.bg-interactive;
|
||||
border-radius: 7px;
|
||||
border-width: 1px;
|
||||
border-color: editor.has-focus ? Theme.accent : Theme.border;
|
||||
Flickable {
|
||||
x: 12px; y: 10px;
|
||||
width: parent.width - 24px; height: parent.height - 20px;
|
||||
content-width: self.width;
|
||||
content-height: Math.max(self.height, editor.preferred-height);
|
||||
editor := TextInput {
|
||||
width: parent.width; height: Math.max(parent.height, self.preferred-height);
|
||||
text <=> root.text; read-only: root.read-only; single-line: false;
|
||||
color: Theme.text-primary; font-size: Math.max(12px, Theme.font-size - 3px);
|
||||
font-family: root.monospace ? "monospace" : "sans-serif";
|
||||
selection-background-color: Theme.selected; selection-foreground-color: Theme.text-primary;
|
||||
wrap: word-wrap;
|
||||
edited => { root.edited(self.text); }
|
||||
}
|
||||
}
|
||||
forward-focus: editor;
|
||||
}
|
||||
|
|
@ -1,121 +1,89 @@
|
|||
import { Theme } from "theme.slint";
|
||||
import { Theme, ActionButton } from "theme.slint";
|
||||
|
||||
export struct FriendItem {
|
||||
user_id: string,
|
||||
nickname: string,
|
||||
status: string,
|
||||
}
|
||||
export struct FriendItem { user_id: string, nickname: string, status: string }
|
||||
|
||||
export component FriendsPanel {
|
||||
export component FriendsPanel inherits Rectangle {
|
||||
in-out property <[FriendItem]> friends;
|
||||
in-out property <[FriendItem]> pending-requests;
|
||||
in-out property <[string]> blocked-users;
|
||||
in-out property <string> active-tab;
|
||||
in-out property <string> add-friend-input;
|
||||
|
||||
callback tab-changed(string);
|
||||
callback input-edited(string);
|
||||
callback add-friend(string);
|
||||
callback accept-friend(string);
|
||||
callback decline-friend(string);
|
||||
callback remove-friend(string);
|
||||
callback start-dm(string);
|
||||
|
||||
background: Theme.bg-base;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 8px;
|
||||
|
||||
Text {
|
||||
text: "Friends";
|
||||
color: Theme.text-primary;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: 4px;
|
||||
Rectangle {
|
||||
height: 28px;
|
||||
background: Theme.bg-interactive;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => { active-tab = "online"; }
|
||||
}
|
||||
Text { text: "Online"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
Rectangle {
|
||||
height: 28px;
|
||||
background: Theme.bg-interactive;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => { active-tab = "all"; }
|
||||
}
|
||||
Text { text: "All"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
Rectangle {
|
||||
height: 28px;
|
||||
background: Theme.bg-interactive;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => { active-tab = "pending"; }
|
||||
}
|
||||
Text { text: "Pending"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
Rectangle {
|
||||
height: 28px;
|
||||
background: Theme.bg-interactive;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => { active-tab = "blocked"; }
|
||||
}
|
||||
Text { text: "Blocked"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; }
|
||||
spacing: 0;
|
||||
Rectangle {
|
||||
height: 56px; border-width: 1px; border-color: Theme.border;
|
||||
HorizontalLayout {
|
||||
padding-left: 22px; padding-right: 16px; spacing: 10px;
|
||||
Text { text: "Друзья"; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.0); font-weight: 600; }
|
||||
ActionButton { text: "В сети"; active: root.active-tab == "online"; quiet: true; clicked => { root.tab-changed("online"); } }
|
||||
ActionButton { text: "Все"; active: root.active-tab == "all"; quiet: true; clicked => { root.tab-changed("all"); } }
|
||||
ActionButton { text: "Запросы"; active: root.active-tab == "pending"; quiet: true; clicked => { root.tab-changed("pending"); } }
|
||||
ActionButton { text: "Блокировки"; active: root.active-tab == "blocked"; quiet: true; clicked => { root.tab-changed("blocked"); } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
TextInput {
|
||||
text <=> add-friend-input;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
Rectangle {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background: Theme.accent;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => {
|
||||
add-friend(add-friend-input);
|
||||
add-friend-input = "";
|
||||
}
|
||||
}
|
||||
Text { text: "+"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
}
|
||||
|
||||
Flickable {
|
||||
VerticalLayout {
|
||||
for f in friends: Rectangle {
|
||||
height: 48px;
|
||||
VerticalLayout {
|
||||
padding: 22px; spacing: 16px;
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
Rectangle {
|
||||
height: 38px; background: Theme.bg-interactive; border-radius: 7px;
|
||||
HorizontalLayout {
|
||||
padding: 8px;
|
||||
spacing: 8px;
|
||||
Text {
|
||||
text: f.nickname;
|
||||
color: Theme.text-primary;
|
||||
}
|
||||
Text {
|
||||
text: f.status;
|
||||
color: Theme.text-muted;
|
||||
}
|
||||
Rectangle {
|
||||
width: 40px;
|
||||
height: 28px;
|
||||
background: Theme.accent;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => { start-dm(f.user_id); }
|
||||
padding: 10px;
|
||||
TextInput { text <=> root.add-friend-input; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875); single-line: true; edited => { root.input-edited(self.text); } accepted => { root.add-friend(root.add-friend-input); } }
|
||||
}
|
||||
}
|
||||
ActionButton { text: "Добавить по ID"; height: 38px; clicked => { root.add-friend(root.add-friend-input); } }
|
||||
}
|
||||
Text { text: root.active-tab == "pending" ? "Входящие запросы" : root.active-tab == "blocked" ? "Заблокированные пользователи" : root.active-tab == "online" ? "Друзья в сети" : "Все друзья"; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); }
|
||||
Flickable {
|
||||
content-width: self.width;
|
||||
VerticalLayout {
|
||||
spacing: 4px;
|
||||
for friend in root.friends: Rectangle {
|
||||
visible: root.active-tab == "all" || (root.active-tab == "online" && friend.status != "offline" && friend.status != "OFFLINE");
|
||||
height: 58px; border-radius: 7px;
|
||||
background: row-touch.has-hover ? Theme.bg-elevated : transparent;
|
||||
row-touch := TouchArea { }
|
||||
HorizontalLayout {
|
||||
padding: 10px; spacing: 12px;
|
||||
Rectangle { width: 32px; height: 32px; background: Theme.avatar-bg; border-radius: 12px; Text { text: "@"; color: Theme.accent; horizontal-alignment: center; vertical-alignment: center; } }
|
||||
VerticalLayout {
|
||||
spacing: 2px; horizontal-stretch: 1;
|
||||
Text { text: friend.nickname; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875); }
|
||||
Text { text: friend.status; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.6875); }
|
||||
}
|
||||
Text { text: "DM"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; }
|
||||
ActionButton { text: "Написать"; quiet: true; clicked => { root.start-dm(friend.user_id); } }
|
||||
ActionButton { text: "Удалить"; quiet: true; danger: true; clicked => { root.remove-friend(friend.user_id); } }
|
||||
}
|
||||
}
|
||||
for friend in root.pending-requests: Rectangle {
|
||||
visible: root.active-tab == "pending";
|
||||
height: 58px;
|
||||
HorizontalLayout {
|
||||
padding: 10px; spacing: 10px;
|
||||
Text { text: friend.nickname; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875); horizontal-stretch: 1; }
|
||||
ActionButton { text: "Принять"; clicked => { root.accept-friend(friend.user_id); } }
|
||||
ActionButton { text: "Отклонить"; danger: true; quiet: true; clicked => { root.decline-friend(friend.user_id); } }
|
||||
}
|
||||
}
|
||||
for user in root.blocked-users: Rectangle {
|
||||
visible: root.active-tab == "blocked";
|
||||
height: 40px;
|
||||
Text { text: user; color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.8125); overflow: elide; }
|
||||
}
|
||||
if root.friends.length == 0 && (root.active-tab == "all" || root.active-tab == "online") : Text { text: "Список друзей пока пуст. Добавь друга по его ID."; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.875); wrap: word-wrap; }
|
||||
if root.pending-requests.length == 0 && root.active-tab == "pending" : Text { text: "Новых запросов нет."; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.875); }
|
||||
if root.blocked-users.length == 0 && root.active-tab == "blocked" : Text { text: "Список блокировок пуст."; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.875); }
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,42 @@
|
|||
import { Theme } from "theme.slint";
|
||||
import { Sidebar, ChannelItem, GuildItem } from "sidebar.slint";
|
||||
export { UnlockWindow } from "unlock.slint";
|
||||
export { Theme } from "theme.slint";
|
||||
import { Theme, ActionButton } from "theme.slint";
|
||||
import { Sidebar, ChannelItem, GuildItem, DmItem } from "sidebar.slint";
|
||||
import { ChatPanel, MessageItem, MemberItem } from "chat.slint";
|
||||
import { FriendsPanel, FriendItem } from "friends.slint";
|
||||
import { VoicePanel, VoiceMemberItem } from "voice.slint";
|
||||
import { BookmarkItem, ConnectScreen } from "connect.slint";
|
||||
import { SettingsWindow } from "settings.slint";
|
||||
import { AvatarCropper } from "avatar-cropper.slint";
|
||||
|
||||
export component MainWindow inherits Window {
|
||||
in-out property <[ChannelItem]> channels;
|
||||
in-out property <[GuildItem]> guilds;
|
||||
in-out property <[string]> dm-conversations;
|
||||
in-out property <[DmItem]> dm-conversations;
|
||||
in-out property <string> username;
|
||||
in-out property <string> user-status;
|
||||
in-out property <string> active-channel-id;
|
||||
in-out property <int> active-guild-idx;
|
||||
in-out property <bool> show-dms;
|
||||
|
||||
in-out property <image> own-avatar;
|
||||
in-out property <bool> has-avatar;
|
||||
in-out property <bool> avatar-crop-open;
|
||||
in-out property <image> avatar-source;
|
||||
in-out property <float> avatar-source-width: 1;
|
||||
in-out property <float> avatar-source-height: 1;
|
||||
in-out property <float> avatar-zoom: 1;
|
||||
in-out property <float> avatar-offset-x;
|
||||
in-out property <float> avatar-offset-y;
|
||||
in-out property <string> avatar-error;
|
||||
private property <string> pending-delete-id;
|
||||
in-out property <string> active-dm-id;
|
||||
in-out property <bool> voice-connected;
|
||||
in-out property <bool> members-visible: true;
|
||||
in-out property <[string]> input-devices;
|
||||
in-out property <[string]> output-devices;
|
||||
in-out property <int> input-device-index;
|
||||
in-out property <int> output-device-index;
|
||||
in-out property <string> active-channel-name;
|
||||
in-out property <[MessageItem]> messages;
|
||||
in-out property <[MemberItem]> members;
|
||||
|
|
@ -56,6 +77,13 @@ export component MainWindow inherits Window {
|
|||
in-out property <float> voice-bitrate: 64.0;
|
||||
in-out property <int> vad-mode: 0;
|
||||
in-out property <float> volume: 100.0;
|
||||
in-out property <string> theme-mode: "dark";
|
||||
in-out property <string> theme-css;
|
||||
in-out property <string> theme-file-path;
|
||||
in-out property <float> text-size: 16;
|
||||
in-out property <string> theme-error;
|
||||
in-out property <string> theme-status;
|
||||
in-out property <bool> theme-preview;
|
||||
in-out property <string> active-tab: "audio";
|
||||
in-out property <bool> settings-open;
|
||||
|
||||
|
|
@ -75,6 +103,30 @@ export component MainWindow inherits Window {
|
|||
in-out property <string> import-pass-input;
|
||||
in-out property <string> import-error;
|
||||
|
||||
callback choose-avatar();
|
||||
callback remove-avatar();
|
||||
callback avatar-crop-moved(float, float);
|
||||
callback avatar-zoom-changed(float);
|
||||
callback confirm-avatar();
|
||||
callback cancel-avatar();
|
||||
callback theme-selected(string);
|
||||
callback text-size-changed(float);
|
||||
callback preview-theme(string);
|
||||
callback apply-theme(string);
|
||||
callback reset-theme();
|
||||
callback import-theme(string);
|
||||
callback export-theme(string);
|
||||
callback dismiss-status();
|
||||
callback ptt-held(bool);
|
||||
callback input-edited(string);
|
||||
callback address-edited(string);
|
||||
callback auto-reconnect-changed(bool);
|
||||
callback friends-tab-changed(string);
|
||||
callback friend-input-edited(string);
|
||||
callback open-settings();
|
||||
callback show-voice-view();
|
||||
callback show-friends-view();
|
||||
callback audio-settings-changed(int, int, float, int, float);
|
||||
callback channel-selected(string);
|
||||
callback guild-selected(int);
|
||||
callback dm-selected(string);
|
||||
|
|
@ -103,18 +155,25 @@ export component MainWindow inherits Window {
|
|||
callback export-keyfile(string, string);
|
||||
callback import-keyfile(string, string);
|
||||
|
||||
min-width: 900px;
|
||||
min-height: 560px;
|
||||
preferred-width: 1280px;
|
||||
preferred-height: 800px;
|
||||
min-width: 920px;
|
||||
min-height: 640px;
|
||||
title: "Vnox";
|
||||
icon: @image-url("assets/vnox-mark.svg");
|
||||
background: Theme.bg-base;
|
||||
|
||||
|
||||
if node-name == "" : ConnectScreen {
|
||||
bookmarks: root.bookmarks;
|
||||
address-input: root.address-input;
|
||||
address-input <=> root.address-input;
|
||||
status-text: root.status-text;
|
||||
connecting: root.connecting;
|
||||
auto-reconnect: root.auto-reconnect;
|
||||
auto-reconnect <=> root.auto-reconnect;
|
||||
node-name: root.node-name;
|
||||
open-settings => { root.open-settings(); }
|
||||
address-edited(text) => { root.address-edited(text); }
|
||||
auto-reconnect-changed(value) => { root.auto-reconnect-changed(value); }
|
||||
connect(address) => { root.connect(address); }
|
||||
disconnect => { root.disconnect(); }
|
||||
remove-bookmark(address) => { root.remove-bookmark(address); }
|
||||
|
|
@ -125,6 +184,20 @@ export component MainWindow inherits Window {
|
|||
channels: root.channels;
|
||||
guilds: root.guilds;
|
||||
dm-conversations: root.dm-conversations;
|
||||
node-name: root.node-name;
|
||||
active-dm-id: root.active-dm-id;
|
||||
voice-connected: root.voice-connected;
|
||||
voice-channel-name: root.voice-channel-name;
|
||||
mic-enabled: root.mic-enabled;
|
||||
deafened: root.deafened;
|
||||
open-settings => { root.open-settings(); }
|
||||
toggle-mic => { root.toggle-mic(); }
|
||||
toggle-deafen => { root.toggle-deafen(); }
|
||||
leave-voice => { root.leave-voice(); }
|
||||
show-voice => { root.show-voice-view(); }
|
||||
show-friends => { root.show-friends-view(); }
|
||||
own-avatar: root.own-avatar;
|
||||
has-avatar: root.has-avatar;
|
||||
username: root.username;
|
||||
user-status: root.user-status;
|
||||
active-channel-id: root.active-channel-id;
|
||||
|
|
@ -135,13 +208,27 @@ export component MainWindow inherits Window {
|
|||
dm-selected(id) => { root.dm-selected(id); }
|
||||
disconnect => { root.disconnect(); }
|
||||
}
|
||||
chat-panel := ChatPanel {
|
||||
visible: show-chat;
|
||||
active-channel-id: root.active-channel-id;
|
||||
VerticalLayout {
|
||||
spacing: 0;
|
||||
if root.status-text != "" : Rectangle {
|
||||
height: 42px; background: Theme.bg-elevated;
|
||||
HorizontalLayout {
|
||||
padding-left: 16px; padding-right: 10px; spacing: 12px;
|
||||
Text { text: root.status-text; color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.75); wrap: word-wrap; vertical-alignment: center; horizontal-stretch: 1; }
|
||||
ActionButton { text: "×"; width: 28px; quiet: true; clicked => { root.dismiss-status(); } }
|
||||
}
|
||||
}
|
||||
if root.show-chat : ChatPanel {
|
||||
own-avatar: root.own-avatar;
|
||||
has-own-avatar: root.has-avatar;
|
||||
active-channel-id: root.is-dm ? "" : root.active-channel-id;
|
||||
active-channel-name: root.active-channel-name;
|
||||
messages: root.messages;
|
||||
members: root.members;
|
||||
input-text: root.input-text;
|
||||
input-text <=> root.input-text;
|
||||
members-visible: root.members-visible && root.width > 1100px;
|
||||
toggle-members => { root.members-visible = !root.members-visible; }
|
||||
input-edited(text) => { root.input-edited(text); }
|
||||
is-dm: root.is-dm;
|
||||
e2ee-enabled: root.e2ee-enabled;
|
||||
dm-partner-name: root.dm-partner-name;
|
||||
|
|
@ -153,63 +240,86 @@ export component MainWindow inherits Window {
|
|||
react(id, emoji) => { root.react(id, emoji); }
|
||||
reply-to-msg(id) => { root.reply-to-msg(id); }
|
||||
edit-msg(id) => { root.edit-msg(id); }
|
||||
delete-msg(id) => { root.delete-msg(id); }
|
||||
delete-msg(id) => { root.pending-delete-id = id; }
|
||||
cancel-reply => { root.cancel-reply(); }
|
||||
}
|
||||
friends-panel := FriendsPanel {
|
||||
visible: show-friends;
|
||||
if root.show-friends : FriendsPanel {
|
||||
friends: root.friends;
|
||||
pending-requests: root.pending-requests;
|
||||
blocked-users: root.blocked-users;
|
||||
active-tab: root.friends-active-tab;
|
||||
add-friend-input: root.add-friend-input;
|
||||
active-tab <=> root.friends-active-tab;
|
||||
add-friend-input <=> root.add-friend-input;
|
||||
tab-changed(tab) => { root.friends-tab-changed(tab); }
|
||||
input-edited(text) => { root.friend-input-edited(text); }
|
||||
add-friend(id) => { root.add-friend(id); }
|
||||
accept-friend(id) => { root.accept-friend(id); }
|
||||
decline-friend(id) => { root.decline-friend(id); }
|
||||
remove-friend(id) => { root.remove-friend(id); }
|
||||
start-dm(id) => { root.start-dm(id); }
|
||||
}
|
||||
voice-panel := VoicePanel {
|
||||
visible: show-voice;
|
||||
if root.show-voice : VoicePanel {
|
||||
members: root.voice-members;
|
||||
mic-enabled: root.mic-enabled;
|
||||
deafened: root.deafened;
|
||||
channel-name: root.voice-channel-name;
|
||||
activity-banner: root.activity-banner;
|
||||
push-to-talk: root.vad-mode == 0;
|
||||
ptt-held(held) => { root.ptt-held(held); }
|
||||
toggle-mic => { root.toggle-mic(); }
|
||||
toggle-deafen => { root.toggle-deafen(); }
|
||||
leave-voice => { root.leave-voice(); }
|
||||
}
|
||||
|
||||
if root.settings-open : Rectangle {
|
||||
background: #00000080;
|
||||
TouchArea { }
|
||||
SettingsWindow {
|
||||
y: (parent.height - 480px) / 2;
|
||||
x: (parent.width - 640px) / 2;
|
||||
}
|
||||
}
|
||||
if root.settings-open : SettingsWindow {
|
||||
own-avatar: root.own-avatar;
|
||||
has-avatar: root.has-avatar;
|
||||
avatar-error: root.avatar-error;
|
||||
choose-avatar => { root.choose-avatar(); }
|
||||
remove-avatar => { root.remove-avatar(); }
|
||||
theme-mode <=> root.theme-mode;
|
||||
theme-css <=> root.theme-css;
|
||||
theme-file-path <=> root.theme-file-path;
|
||||
text-size <=> root.text-size;
|
||||
theme-error: root.theme-error;
|
||||
theme-status: root.theme-status;
|
||||
theme-preview: root.theme-preview;
|
||||
theme-selected(mode) => { root.theme-selected(mode); }
|
||||
text-size-changed(size) => { root.text-size-changed(size); }
|
||||
preview-theme(css) => { root.preview-theme(css); }
|
||||
apply-theme(css) => { root.apply-theme(css); }
|
||||
reset-theme => { root.reset-theme(); }
|
||||
import-theme(path) => { root.import-theme(path); }
|
||||
export-theme(path) => { root.export-theme(path); }
|
||||
input-devices: root.input-devices;
|
||||
output-devices: root.output-devices;
|
||||
input-device-index <=> root.input-device-index;
|
||||
output-device-index <=> root.output-device-index;
|
||||
audio-changed => { root.audio-settings-changed(root.input-device-index, root.output-device-index, root.voice-bitrate, root.vad-mode, root.volume); }
|
||||
identity-pubkey: root.identity-pubkey;
|
||||
vault-enabled: root.vault-enabled;
|
||||
voice-input-device: root.voice-input-device;
|
||||
voice-output-device: root.voice-output-device;
|
||||
voice-bitrate: root.voice-bitrate;
|
||||
vad-mode: root.vad-mode;
|
||||
volume: root.volume;
|
||||
active-tab: root.active-tab;
|
||||
voice-bitrate <=> root.voice-bitrate;
|
||||
vad-mode <=> root.vad-mode;
|
||||
volume <=> root.volume;
|
||||
active-tab <=> root.active-tab;
|
||||
|
||||
passphrase-modal-open: root.passphrase-modal-open;
|
||||
passphrase-input: root.passphrase-input;
|
||||
passphrase-confirm: root.passphrase-confirm;
|
||||
passphrase-modal-open <=> root.passphrase-modal-open;
|
||||
passphrase-input <=> root.passphrase-input;
|
||||
passphrase-confirm <=> root.passphrase-confirm;
|
||||
passphrase-error: root.passphrase-error;
|
||||
|
||||
export-modal-open: root.export-modal-open;
|
||||
export-pass-input: root.export-pass-input;
|
||||
export-pass-confirm: root.export-pass-confirm;
|
||||
export-modal-open <=> root.export-modal-open;
|
||||
export-pass-input <=> root.export-pass-input;
|
||||
export-pass-confirm <=> root.export-pass-confirm;
|
||||
export-output: root.export-output;
|
||||
export-error: root.export-error;
|
||||
|
||||
import-modal-open: root.import-modal-open;
|
||||
import-keyfile-input: root.import-keyfile-input;
|
||||
import-pass-input: root.import-pass-input;
|
||||
import-modal-open <=> root.import-modal-open;
|
||||
import-keyfile-input <=> root.import-keyfile-input;
|
||||
import-pass-input <=> root.import-pass-input;
|
||||
import-error: root.import-error;
|
||||
|
||||
close => { root.close-settings(); }
|
||||
|
|
@ -218,6 +328,36 @@ export component MainWindow inherits Window {
|
|||
export-keyfile(pass, confirm) => { root.export-keyfile(pass, confirm); }
|
||||
import-keyfile(input, pass) => { root.import-keyfile(input, pass); }
|
||||
}
|
||||
|
||||
if root.pending-delete-id != "" : Rectangle {
|
||||
background: Theme.overlay;
|
||||
TouchArea { }
|
||||
Rectangle {
|
||||
width: 420px; height: 170px;
|
||||
x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2;
|
||||
background: Theme.bg-surface; border-radius: 10px;
|
||||
VerticalLayout {
|
||||
padding: 22px; spacing: 12px;
|
||||
Text { text: "Удалить сообщение?"; font-size: Math.max(11px, Theme.font-size * 1.1875); color: Theme.text-primary; }
|
||||
Text { text: "Это действие нельзя отменить."; font-size: Math.max(11px, Theme.font-size * 0.8125); color: Theme.text-muted; }
|
||||
HorizontalLayout {
|
||||
ActionButton { text: "Отмена"; clicked => { root.pending-delete-id = ""; } }
|
||||
ActionButton { text: "Удалить"; danger: true; clicked => { root.delete-msg(root.pending-delete-id); root.pending-delete-id = ""; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if root.avatar-crop-open : AvatarCropper {
|
||||
avatar-source: root.avatar-source;
|
||||
source-width: root.avatar-source-width;
|
||||
source-height: root.avatar-source-height;
|
||||
zoom <=> root.avatar-zoom;
|
||||
offset-x: root.avatar-offset-x;
|
||||
offset-y: root.avatar-offset-y;
|
||||
error: root.avatar-error;
|
||||
crop-moved(x,y) => { root.avatar-crop-moved(x,y); }
|
||||
zoom-changed(value) => { root.avatar-zoom-changed(value); }
|
||||
confirm => { root.confirm-avatar(); }
|
||||
cancel => { root.cancel-avatar(); }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,44 @@
|
|||
import { Theme } from "theme.slint";
|
||||
import { Button, LineEdit } from "std-widgets.slint";
|
||||
import { Theme, ActionButton, Symbol } from "theme.slint";
|
||||
import { AudioSettings } from "settings/audio.slint";
|
||||
import { AppearanceSettings } from "settings/appearance.slint";
|
||||
import { IdentitySettings } from "settings/identity.slint";
|
||||
|
||||
export component SettingsWindow {
|
||||
width: 640px;
|
||||
height: 480px;
|
||||
component SettingsNav inherits Rectangle {
|
||||
in property <string> label;
|
||||
in property <string> detail;
|
||||
in property <string> mark;
|
||||
in property <bool> active;
|
||||
callback clicked();
|
||||
height: 58px;
|
||||
border-radius: 7px;
|
||||
background: root.active ? Theme.selected : touch.has-hover ? Theme.bg-hover : transparent;
|
||||
border-width: keyboard.has-focus ? 1px : 0px;
|
||||
border-color: Theme.accent;
|
||||
accessible-role: button;
|
||||
accessible-label: root.label;
|
||||
HorizontalLayout {
|
||||
padding-left: 12px; padding-right: 12px; spacing: 11px;
|
||||
Text { text: root.mark; color: root.active ? Theme.text-primary : Theme.text-muted; font-size: Theme.font-size + 2px; width: 23px; vertical-alignment: center; }
|
||||
VerticalLayout {
|
||||
spacing: 2px; alignment: center;
|
||||
Text { text: root.label; color: Theme.text-primary; font-size: Math.max(Theme.font-size - 2px, 11px); font-weight: root.active ? 600 : 400; overflow: elide; }
|
||||
Text { text: root.detail; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 5px, 11px); overflow: elide; }
|
||||
}
|
||||
}
|
||||
touch := TouchArea { clicked => { keyboard.focus(); root.clicked(); } }
|
||||
keyboard := FocusScope { key-pressed(event) => { if event.text == " " || event.text == "\n" { root.clicked(); return accept; } return reject; } }
|
||||
}
|
||||
|
||||
export component SettingsWindow inherits Rectangle {
|
||||
in property <image> own-avatar;
|
||||
in property <bool> has-avatar;
|
||||
in property <string> avatar-error;
|
||||
callback choose-avatar();
|
||||
callback remove-avatar();
|
||||
in property <[string]> input-devices;
|
||||
in property <[string]> output-devices;
|
||||
in-out property <int> input-device-index;
|
||||
in-out property <int> output-device-index;
|
||||
in-out property <string> identity-pubkey;
|
||||
in-out property <bool> vault-enabled;
|
||||
in-out property <string> voice-input-device;
|
||||
|
|
@ -12,180 +46,131 @@ export component SettingsWindow {
|
|||
in-out property <float> voice-bitrate;
|
||||
in-out property <int> vad-mode;
|
||||
in-out property <float> volume;
|
||||
in-out property <string> active-tab;
|
||||
|
||||
in-out property <string> active-tab: "audio";
|
||||
in-out property <bool> passphrase-modal-open;
|
||||
in-out property <string> passphrase-input;
|
||||
in-out property <string> passphrase-confirm;
|
||||
in-out property <string> passphrase-error;
|
||||
|
||||
in-out property <bool> export-modal-open;
|
||||
in-out property <string> export-pass-input;
|
||||
in-out property <string> export-pass-confirm;
|
||||
in-out property <string> export-output;
|
||||
in-out property <string> export-error;
|
||||
|
||||
in-out property <bool> import-modal-open;
|
||||
in-out property <string> import-keyfile-input;
|
||||
in-out property <string> import-pass-input;
|
||||
in-out property <string> import-error;
|
||||
|
||||
in-out property <string> theme-mode;
|
||||
in-out property <string> theme-css;
|
||||
in-out property <string> theme-file-path;
|
||||
in-out property <float> text-size;
|
||||
in property <string> theme-error;
|
||||
in property <string> theme-status;
|
||||
in property <bool> theme-preview;
|
||||
callback audio-changed();
|
||||
callback close();
|
||||
callback set-passphrase(string, string);
|
||||
callback remove-passphrase();
|
||||
callback export-keyfile(string, string);
|
||||
callback import-keyfile(string, string);
|
||||
|
||||
Rectangle {
|
||||
background: Theme.bg-base;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 12px;
|
||||
border-width: 1px;
|
||||
border-color: Theme.bg-elevated;
|
||||
|
||||
callback theme-selected(string);
|
||||
callback text-size-changed(float);
|
||||
callback preview-theme(string);
|
||||
callback apply-theme(string);
|
||||
callback reset-theme();
|
||||
callback import-theme(string);
|
||||
callback export-theme(string);
|
||||
background: Theme.bg-base;
|
||||
changed active-tab => { settings-scroll.content-y = 0px; }
|
||||
HorizontalLayout {
|
||||
spacing: 0;
|
||||
Rectangle {
|
||||
width: 236px; background: Theme.bg-surface;
|
||||
VerticalLayout {
|
||||
padding-left: 16px; padding-right: 16px; padding-top: 32px; padding-bottom: 20px; spacing: 7px;
|
||||
Text { text: "Настройки"; color: Theme.text-primary; font-size: Theme.font-size + 6px; font-weight: 700; height: 46px; }
|
||||
SettingsNav { label: "Звук и микрофон"; detail: "Устройства и передача"; mark: "◖"; active: root.active-tab == "audio"; clicked => { root.active-tab = "audio"; } }
|
||||
SettingsNav { label: "Внешний вид"; detail: "Темы, цвета и текст"; mark: "Aa"; active: root.active-tab == "appearance"; clicked => { root.active-tab = "appearance"; } }
|
||||
SettingsNav { label: "Профиль и ключи"; detail: "Защита и резервная копия"; mark: "◇"; active: root.active-tab == "identity"; clicked => { root.active-tab = "identity"; } }
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
Text { text: "VNOX"; color: Theme.text-secondary; font-size: Math.max(Theme.font-size - 3px, 11px); font-weight: 700; height: 30px; vertical-alignment: bottom; }
|
||||
Text { text: "Настройки этого устройства"; color: Theme.text-disabled; font-size: Math.max(Theme.font-size - 5px, 11px); }
|
||||
ActionButton { text: "Вернуться в приложение"; quiet: true; clicked => { root.close(); } }
|
||||
}
|
||||
}
|
||||
Rectangle { width: 1px; background: Theme.border; }
|
||||
VerticalLayout {
|
||||
padding: 0;
|
||||
spacing: 0;
|
||||
|
||||
Rectangle {
|
||||
height: 44px;
|
||||
background: Theme.bg-surface;
|
||||
border-radius: 12px;
|
||||
height: 114px;
|
||||
HorizontalLayout {
|
||||
padding: 8px;
|
||||
spacing: 4px;
|
||||
Rectangle {
|
||||
height: 28px;
|
||||
background: active-tab == "audio" ? Theme.accent : Theme.bg-interactive;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea { clicked => { active-tab = "audio"; } }
|
||||
Text { text: "Audio"; color: Theme.text-primary; font-size: 13px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
Rectangle {
|
||||
height: 28px;
|
||||
background: active-tab == "network" ? Theme.accent : Theme.bg-interactive;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea { clicked => { active-tab = "network"; } }
|
||||
Text { text: "Network"; color: Theme.text-primary; font-size: 13px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
Rectangle {
|
||||
height: 28px;
|
||||
background: active-tab == "identity" ? Theme.accent : Theme.bg-interactive;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea { clicked => { active-tab = "identity"; } }
|
||||
Text { text: "Identity"; color: Theme.text-primary; font-size: 13px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
HorizontalLayout { horizontal-stretch: 1; }
|
||||
Rectangle {
|
||||
height: 28px;
|
||||
width: 28px;
|
||||
border-radius: Theme.radius;
|
||||
background: Theme.bg-interactive;
|
||||
TouchArea { clicked => { close(); } }
|
||||
Text { text: "✕"; color: Theme.text-muted; font-size: 14px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
padding-left: 34px; padding-right: 28px; padding-top: 29px; padding-bottom: 20px; spacing: 18px;
|
||||
VerticalLayout {
|
||||
spacing: 6px;
|
||||
Text { text: root.active-tab == "appearance" ? "Внешний вид" : root.active-tab == "identity" ? "Профиль и ключи" : "Звук и микрофон"; color: Theme.text-primary; font-size: Theme.font-size + 12px; font-weight: 700; }
|
||||
Text { text: root.active-tab == "appearance" ? "Сделай Vnox своим." : root.active-tab == "identity" ? "Твой профиль и его сохранность." : "Голос должен звучать так, как тебе удобно."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); }
|
||||
}
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
ActionButton { text: "×"; width: 34px; text-size: 21px; quiet: true; clicked => { root.close(); } }
|
||||
}
|
||||
}
|
||||
|
||||
if active-tab == "audio" : VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 12px;
|
||||
Text { text: "Voice Settings"; color: Theme.text-primary; font-size: 16px; font-weight: 600; }
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Text { text: "Input Device:"; color: Theme.text-secondary; }
|
||||
Text { text: voice-input-device; color: Theme.text-primary; }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Text { text: "Output Device:"; color: Theme.text-secondary; }
|
||||
Text { text: voice-output-device; color: Theme.text-primary; }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Text { text: "Bitrate:"; color: Theme.text-secondary; }
|
||||
Text { text: voice-bitrate; color: Theme.text-primary; }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Text { text: "Mode:"; color: Theme.text-secondary; }
|
||||
Text { text: vad-mode == 0 ? "Push to Talk" : vad-mode == 1 ? "Voice Activity" : "Always On"; color: Theme.text-primary; }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Text { text: "Volume:"; color: Theme.text-secondary; }
|
||||
Text { text: volume; color: Theme.text-primary; }
|
||||
}
|
||||
}
|
||||
|
||||
if active-tab == "network" : VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 12px;
|
||||
Text { text: "Network"; color: Theme.text-primary; font-size: 16px; font-weight: 600; }
|
||||
Text { text: "Connection settings will appear here."; color: Theme.text-muted; }
|
||||
}
|
||||
|
||||
if active-tab == "identity" : VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 12px;
|
||||
Text { text: "Identity"; color: Theme.text-primary; font-size: 16px; font-weight: 600; }
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Text { text: "Public Key:"; color: Theme.text-secondary; }
|
||||
Text { text: identity-pubkey; color: Theme.text-primary; font-family: "monospace"; }
|
||||
}
|
||||
Text { text: vault-enabled ? "Vault is encrypted" : "Vault is plaintext"; color: Theme.text-secondary; }
|
||||
|
||||
if !passphrase-modal-open && !export-modal-open && !import-modal-open : VerticalLayout {
|
||||
spacing: 8px;
|
||||
Rectangle { height: 28px; background: Theme.accent; border-radius: Theme.radius; TouchArea { clicked => { passphrase-modal-open = true; } } Text { text: vault-enabled ? "Change Passphrase" : "Set Passphrase"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; } }
|
||||
if vault-enabled : Rectangle { height: 28px; background: Theme.danger; border-radius: Theme.radius; TouchArea { clicked => { remove-passphrase(); } } Text { text: "Remove Passphrase"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; } }
|
||||
Rectangle { height: 28px; background: Theme.accent; border-radius: Theme.radius; TouchArea { clicked => { export-modal-open = true; } } Text { text: "Export Keyfile"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; } }
|
||||
Rectangle { height: 28px; background: Theme.accent; border-radius: Theme.radius; TouchArea { clicked => { import-modal-open = true; } } Text { text: "Import Keyfile"; color: Theme.text-primary; horizontal-alignment: center; vertical-alignment: center; } }
|
||||
}
|
||||
|
||||
if passphrase-modal-open : VerticalLayout {
|
||||
spacing: 8px;
|
||||
Rectangle { height: 1px; background: Theme.bg-elevated; }
|
||||
Text { text: vault-enabled ? "Change Passphrase" : "Set Passphrase"; color: Theme.text-primary; font-weight: 600; }
|
||||
LineEdit { text <=> passphrase-input; placeholder-text: "New passphrase"; }
|
||||
LineEdit { text <=> passphrase-confirm; placeholder-text: "Confirm passphrase"; }
|
||||
if passphrase-error != "" : Text { text: passphrase-error; color: Theme.danger; font-size: 12px; }
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Button { text: "Cancel"; clicked => { passphrase-modal-open = false; } }
|
||||
Button { text: "Save"; clicked => { set-passphrase(passphrase-input, passphrase-confirm); } }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
settings-scroll := Flickable {
|
||||
content-width: self.width;
|
||||
VerticalLayout {
|
||||
padding-left: 34px; padding-right: 34px; padding-top: 28px; padding-bottom: 16px; spacing: 0;
|
||||
if root.active-tab == "audio" || (root.active-tab != "appearance" && root.active-tab != "identity") : AudioSettings {
|
||||
input-devices: root.input-devices;
|
||||
output-devices: root.output-devices;
|
||||
input-device-index <=> root.input-device-index;
|
||||
output-device-index <=> root.output-device-index;
|
||||
voice-bitrate <=> root.voice-bitrate;
|
||||
vad-mode <=> root.vad-mode;
|
||||
volume <=> root.volume;
|
||||
audio-changed => { root.audio-changed(); }
|
||||
}
|
||||
}
|
||||
|
||||
if export-modal-open : VerticalLayout {
|
||||
spacing: 8px;
|
||||
Rectangle { height: 1px; background: Theme.bg-elevated; }
|
||||
Text { text: "Export Keyfile"; color: Theme.text-primary; font-weight: 600; }
|
||||
LineEdit { text <=> export-pass-input; placeholder-text: "Optional passphrase"; }
|
||||
LineEdit { text <=> export-pass-confirm; placeholder-text: "Confirm passphrase"; }
|
||||
if export-error != "" : Text { text: export-error; color: Theme.danger; font-size: 12px; }
|
||||
if export-output != "" : Text { text: export-output; color: Theme.text-muted; font-size: 11px; }
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Button { text: "Cancel"; clicked => { export-modal-open = false; } }
|
||||
Button { text: "Generate"; clicked => { export-keyfile(export-pass-input, export-pass-confirm); } }
|
||||
if root.active-tab == "appearance" : AppearanceSettings {
|
||||
theme-mode <=> root.theme-mode;
|
||||
theme-css <=> root.theme-css;
|
||||
theme-file-path <=> root.theme-file-path;
|
||||
text-size <=> root.text-size;
|
||||
theme-error: root.theme-error;
|
||||
theme-status: root.theme-status;
|
||||
theme-preview: root.theme-preview;
|
||||
theme-selected(mode) => { root.theme-selected(mode); }
|
||||
text-size-changed(size) => { root.text-size-changed(size); }
|
||||
preview-theme(css) => { root.preview-theme(css); }
|
||||
apply-theme(css) => { root.apply-theme(css); }
|
||||
reset-theme => { root.reset-theme(); }
|
||||
import-theme(path) => { root.import-theme(path); }
|
||||
export-theme(path) => { root.export-theme(path); }
|
||||
}
|
||||
}
|
||||
|
||||
if import-modal-open : VerticalLayout {
|
||||
spacing: 8px;
|
||||
Rectangle { height: 1px; background: Theme.bg-elevated; }
|
||||
Text { text: "Import Keyfile"; color: Theme.text-primary; font-weight: 600; }
|
||||
Text { text: "Paste your keyfile JSON below:"; color: Theme.text-secondary; font-size: 12px; }
|
||||
TextInput { text <=> import-keyfile-input; height: 80px; }
|
||||
LineEdit { text <=> import-pass-input; placeholder-text: "Passphrase (if encrypted)"; }
|
||||
if import-error != "" : Text { text: import-error; color: Theme.danger; font-size: 12px; }
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Button { text: "Cancel"; clicked => { import-modal-open = false; } }
|
||||
Button { text: "Import & Replace"; clicked => { import-keyfile(import-keyfile-input, import-pass-input); } }
|
||||
if root.active-tab == "identity" : IdentitySettings {
|
||||
own-avatar: root.own-avatar;
|
||||
has-avatar: root.has-avatar;
|
||||
avatar-error: root.avatar-error;
|
||||
choose-avatar => { root.choose-avatar(); }
|
||||
remove-avatar => { root.remove-avatar(); }
|
||||
identity-pubkey: root.identity-pubkey;
|
||||
vault-enabled: root.vault-enabled;
|
||||
passphrase-modal-open <=> root.passphrase-modal-open;
|
||||
passphrase-input <=> root.passphrase-input;
|
||||
passphrase-confirm <=> root.passphrase-confirm;
|
||||
passphrase-error: root.passphrase-error;
|
||||
export-modal-open <=> root.export-modal-open;
|
||||
export-pass-input <=> root.export-pass-input;
|
||||
export-pass-confirm <=> root.export-pass-confirm;
|
||||
export-output: root.export-output;
|
||||
export-error: root.export-error;
|
||||
import-modal-open <=> root.import-modal-open;
|
||||
import-keyfile-input <=> root.import-keyfile-input;
|
||||
import-pass-input <=> root.import-pass-input;
|
||||
import-error: root.import-error;
|
||||
set-passphrase(pass, confirm) => { root.set-passphrase(pass, confirm); }
|
||||
remove-passphrase => { root.remove-passphrase(); }
|
||||
export-keyfile(pass, confirm) => { root.export-keyfile(pass, confirm); }
|
||||
import-keyfile(input, pass) => { root.import-keyfile(input, pass); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
110
src/ui/slint/settings/appearance.slint
Normal file
110
src/ui/slint/settings/appearance.slint
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
import { Theme, ActionButton } from "../theme.slint";
|
||||
import { AudioSlider, ThemeInput, ThemeEditor } from "../controls.slint";
|
||||
|
||||
component ThemeChoice inherits Rectangle {
|
||||
in property <string> label;
|
||||
in property <bool> selected;
|
||||
in property <color> preview-background;
|
||||
in property <color> preview-sidebar;
|
||||
in property <color> preview-ink;
|
||||
callback clicked();
|
||||
height: 142px;
|
||||
border-radius: 9px;
|
||||
border-width: keyboard.has-focus || root.selected ? 2px : 1px;
|
||||
border-color: root.selected || keyboard.has-focus ? Theme.accent : Theme.border;
|
||||
background: pointer.has-hover ? Theme.bg-hover : Theme.bg-surface;
|
||||
accessible-role: button;
|
||||
accessible-label: root.label;
|
||||
VerticalLayout {
|
||||
padding: 8px; spacing: 10px;
|
||||
Rectangle {
|
||||
height: 86px; background: root.preview-background; border-radius: 5px; clip: true;
|
||||
Rectangle { width: 23%; height: 100%; background: root.preview-sidebar; }
|
||||
Rectangle { x: parent.width * 0.29; y: 15px; width: 41%; height: 6px; background: root.preview-ink; opacity: 0.8; border-radius: 2px; }
|
||||
Rectangle { x: parent.width * 0.29; y: 29px; width: 59%; height: 4px; background: root.preview-ink; opacity: 0.28; border-radius: 2px; }
|
||||
Rectangle { x: parent.width * 0.29; y: 40px; width: 45%; height: 4px; background: root.preview-ink; opacity: 0.28; border-radius: 2px; }
|
||||
Rectangle { x: parent.width * 0.29; y: 61px; width: 60%; height: 13px; background: root.preview-sidebar; border-radius: 3px; }
|
||||
}
|
||||
HorizontalLayout {
|
||||
Text { text: root.label; color: Theme.text-primary; font-size: Math.max(Theme.font-size - 3px, 11px); font-weight: 500; overflow: elide; horizontal-stretch: 1; }
|
||||
Text { text: root.selected ? "✓" : ""; color: Theme.accent; width: 16px; font-size: Math.max(Theme.font-size - 2px, 11px); }
|
||||
}
|
||||
}
|
||||
pointer := TouchArea { clicked => { keyboard.focus(); root.clicked(); } }
|
||||
keyboard := FocusScope { key-pressed(event) => { if event.text == " " || event.text == "\n" { root.clicked(); return accept; } return reject; } }
|
||||
}
|
||||
|
||||
export component AppearanceSettings inherits Rectangle {
|
||||
in-out property <string> theme-mode;
|
||||
in-out property <string> theme-css;
|
||||
in-out property <string> theme-file-path;
|
||||
in-out property <float> text-size;
|
||||
in property <string> theme-error;
|
||||
in property <string> theme-status;
|
||||
in property <bool> theme-preview;
|
||||
callback theme-selected(string);
|
||||
callback text-size-changed(float);
|
||||
callback preview-theme(string);
|
||||
callback apply-theme(string);
|
||||
callback reset-theme();
|
||||
callback import-theme(string);
|
||||
callback export-theme(string);
|
||||
VerticalLayout {
|
||||
spacing: 0; alignment: start;
|
||||
Text { text: "Тема приложения"; color: Theme.text-primary; font-size: Theme.font-size + 2px; font-weight: 600; }
|
||||
Text { text: "Один выбор для чата, комнат и настроек. Можно изменить в любой момент."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 20px; }
|
||||
HorizontalLayout {
|
||||
spacing: 12px;
|
||||
ThemeChoice { label: "Светлая"; selected: root.theme-mode == "light"; preview-background: #f5f4f2; preview-sidebar: #e6e4e0; preview-ink: #353330; clicked => { root.theme-selected("light"); } }
|
||||
ThemeChoice { label: "Тёмная"; selected: root.theme-mode == "dark"; preview-background: #272729; preview-sidebar: #202022; preview-ink: #e9e7e4; clicked => { root.theme-selected("dark"); } }
|
||||
ThemeChoice { label: "Мега-тёмная"; selected: root.theme-mode == "black"; preview-background: #080808; preview-sidebar: #131313; preview-ink: #dedbd5; clicked => { root.theme-selected("black"); } }
|
||||
ThemeChoice { label: "Своя тема"; selected: root.theme-mode == "custom"; preview-background: Theme.bg-base; preview-sidebar: Theme.bg-surface; preview-ink: Theme.accent; clicked => { root.theme-selected("custom"); } }
|
||||
}
|
||||
Rectangle { height: 29px; }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
Rectangle { height: 24px; }
|
||||
HorizontalLayout {
|
||||
Text { text: "Размер текста"; color: Theme.text-primary; font-size: Theme.font-size - 1px; font-weight: 600; horizontal-stretch: 1; }
|
||||
Text { text: Math.round(root.text-size) + " px"; color: Theme.text-secondary; font-size: Math.max(Theme.font-size - 2px, 11px); horizontal-alignment: right; }
|
||||
}
|
||||
Rectangle { height: 9px; }
|
||||
AudioSlider { minimum: 12; maximum: 22; value <=> root.text-size; changed(value) => { root.text-size-changed(value); } }
|
||||
Text { text: "Меняет масштаб текста во всём приложении."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 29px; }
|
||||
if root.theme-mode == "custom" : VerticalLayout {
|
||||
spacing: 12px; alignment: start;
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
Rectangle { height: 8px; }
|
||||
HorizontalLayout {
|
||||
Text { text: "Редактор темы"; color: Theme.text-primary; font-size: Theme.font-size + 2px; font-weight: 600; horizontal-stretch: 1; }
|
||||
if root.theme-preview : Text { text: "Предпросмотр"; color: Theme.accent; font-size: Math.max(Theme.font-size - 3px, 11px); }
|
||||
}
|
||||
Text { text: "CSS-переменные в блоке :root меняют цвета и размер текста. Обычные CSS-селекторы, стили размещения и внешние ресурсы не поддерживаются."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
ThemeEditor { text <=> root.theme-css; height: 220px; }
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton { text: "Предпросмотр"; clicked => { root.preview-theme(root.theme-css); } }
|
||||
ActionButton { text: "Применить"; active: true; clicked => { root.apply-theme(root.theme-css); } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
ActionButton { text: "Сбросить"; quiet: true; clicked => { root.reset-theme(); } }
|
||||
}
|
||||
Text { text: "Основные переменные: --vnox-bg, --vnox-surface, --vnox-text, --vnox-accent, --vnox-font-size. Полный список описан в документации тем."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 4px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 8px; }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
Rectangle { height: 8px; }
|
||||
Text { text: "Файл темы"; color: Theme.text-primary; font-size: Theme.font-size - 1px; font-weight: 600; }
|
||||
Text { text: "Введи локальный путь к .css, чтобы импортировать тему или сохранить её в файл."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
ThemeInput { text <=> root.theme-file-path; placeholder-text: "Например: /home/user/themes/my-vnox.css"; accepted => { root.import-theme(root.theme-file-path); } }
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton { text: "Импортировать"; clicked => { root.import-theme(root.theme-file-path); } }
|
||||
ActionButton { text: "Экспортировать"; clicked => { root.export-theme(root.theme-file-path); } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
}
|
||||
if root.theme-error != "" : Text { text: root.theme-error; color: Theme.danger; font-size: Math.max(Theme.font-size - 2px, 11px); wrap: word-wrap; }
|
||||
if root.theme-status != "" : Text { text: root.theme-status; color: Theme.success; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 26px; }
|
||||
}
|
||||
}
|
||||
71
src/ui/slint/settings/audio.slint
Normal file
71
src/ui/slint/settings/audio.slint
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { Theme } from "../theme.slint";
|
||||
import { DeviceSelect, AudioSlider } from "../controls.slint";
|
||||
|
||||
export component AudioSettings inherits Rectangle {
|
||||
in property <[string]> input-devices;
|
||||
in property <[string]> output-devices;
|
||||
in-out property <int> input-device-index;
|
||||
in-out property <int> output-device-index;
|
||||
in-out property <float> voice-bitrate;
|
||||
in-out property <int> vad-mode;
|
||||
in-out property <float> volume;
|
||||
callback audio-changed();
|
||||
VerticalLayout {
|
||||
spacing: 0;
|
||||
alignment: start;
|
||||
Text { text: "Устройства"; color: Theme.text-primary; font-size: Theme.font-size + 2px; font-weight: 600; }
|
||||
Text { text: "Выбери, откуда брать голос и куда выводить звук."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 24px; }
|
||||
Text { text: "Микрофон"; color: Theme.text-primary; font-size: Math.max(Theme.font-size - 2px, 11px); }
|
||||
Rectangle { height: 9px; }
|
||||
DeviceSelect {
|
||||
model: root.input-devices;
|
||||
current-index <=> root.input-device-index;
|
||||
selected(value) => { root.audio-changed(); }
|
||||
}
|
||||
Rectangle { height: 19px; }
|
||||
Text { text: "Наушники или колонки"; color: Theme.text-primary; font-size: Math.max(Theme.font-size - 2px, 11px); }
|
||||
Rectangle { height: 9px; }
|
||||
DeviceSelect {
|
||||
model: root.output-devices;
|
||||
current-index <=> root.output-device-index;
|
||||
selected(value) => { root.audio-changed(); }
|
||||
}
|
||||
Rectangle { height: 29px; }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
Rectangle { height: 26px; }
|
||||
HorizontalLayout {
|
||||
spacing: 20px;
|
||||
Text { text: "Громкость"; color: Theme.text-primary; font-size: Theme.font-size - 1px; font-weight: 600; horizontal-stretch: 1; }
|
||||
Text { text: Math.round(root.volume) + "%"; color: Theme.text-secondary; font-size: Math.max(Theme.font-size - 2px, 11px); horizontal-alignment: right; }
|
||||
}
|
||||
Text { text: "Общий уровень воспроизведения голосовых комнат."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 10px; }
|
||||
AudioSlider { minimum: 0; maximum: 100; value <=> root.volume; changed(value) => { root.audio-changed(); } }
|
||||
Rectangle { height: 25px; }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
Rectangle { height: 26px; }
|
||||
Text { text: "Передача голоса"; color: Theme.text-primary; font-size: Theme.font-size + 2px; font-weight: 600; }
|
||||
Text { text: "Определи, когда тебя слышат остальные."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 18px; }
|
||||
DeviceSelect {
|
||||
model: ["Нажми и говори", "Активация голосом", "Открытый микрофон"];
|
||||
current-index <=> root.vad-mode;
|
||||
selected(value) => { root.audio-changed(); }
|
||||
}
|
||||
Rectangle { height: 10px; }
|
||||
Text {
|
||||
text: root.vad-mode == 0 ? "Удерживай кнопку разговора в голосовой комнате. Отпусти — микрофон перестанет передавать звук." : root.vad-mode == 1 ? "Микрофон передаёт звук, когда обнаружен голос." : "Звук передаётся постоянно, пока микрофон включён.";
|
||||
color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap;
|
||||
}
|
||||
Rectangle { height: 24px; }
|
||||
HorizontalLayout {
|
||||
Text { text: "Качество голоса"; color: Theme.text-primary; font-size: Theme.font-size - 1px; font-weight: 600; horizontal-stretch: 1; }
|
||||
Text { text: Math.round(root.voice-bitrate) + " кбит/с"; color: Theme.text-secondary; font-size: Math.max(Theme.font-size - 2px, 11px); horizontal-alignment: right; }
|
||||
}
|
||||
Rectangle { height: 9px; }
|
||||
AudioSlider { minimum: 8; maximum: 128; value <=> root.voice-bitrate; changed(value) => { root.audio-changed(); } }
|
||||
Text { text: "Меньше трафика"; color: Theme.text-disabled; font-size: Math.max(Theme.font-size - 4px, 11px); }
|
||||
Rectangle { height: 26px; }
|
||||
}
|
||||
}
|
||||
147
src/ui/slint/settings/identity.slint
Normal file
147
src/ui/slint/settings/identity.slint
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
import { AvatarView } from "../avatar-view.slint";
|
||||
import { Theme, ActionButton } from "../theme.slint";
|
||||
import { ThemeInput, ThemeEditor } from "../controls.slint";
|
||||
|
||||
export component IdentitySettings inherits Rectangle {
|
||||
in property <image> own-avatar;
|
||||
in property <bool> has-avatar;
|
||||
in property <string> avatar-error;
|
||||
callback choose-avatar();
|
||||
callback remove-avatar();
|
||||
in-out property <string> identity-pubkey;
|
||||
in-out property <bool> vault-enabled;
|
||||
in-out property <bool> passphrase-modal-open;
|
||||
in-out property <string> passphrase-input;
|
||||
in-out property <string> passphrase-confirm;
|
||||
in-out property <string> passphrase-error;
|
||||
in-out property <bool> export-modal-open;
|
||||
in-out property <string> export-pass-input;
|
||||
in-out property <string> export-pass-confirm;
|
||||
in-out property <string> export-output;
|
||||
in-out property <string> export-error;
|
||||
in-out property <bool> import-modal-open;
|
||||
in-out property <string> import-keyfile-input;
|
||||
in-out property <string> import-pass-input;
|
||||
in-out property <string> import-error;
|
||||
private property <bool> confirm-remove;
|
||||
callback set-passphrase(string, string);
|
||||
callback remove-passphrase();
|
||||
callback export-keyfile(string, string);
|
||||
callback import-keyfile(string, string);
|
||||
VerticalLayout {
|
||||
spacing: 0; alignment: start;
|
||||
Text { text: "Фото профиля"; color: Theme.text-primary; font-size: Theme.font-size + 2px; font-weight: 600; }
|
||||
Text { text: "Выбери изображение и обрежь его под аватар."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 18px; }
|
||||
HorizontalLayout {
|
||||
spacing: 20px;
|
||||
AvatarView { width: 82px; height: 82px; source: root.own-avatar; has-source: root.has-avatar; initials: "Фото"; mask: Theme.bg-base; }
|
||||
VerticalLayout {
|
||||
spacing: 9px; alignment: center;
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton { text: root.has-avatar ? "Изменить фото" : "Выбрать фото"; clicked => { root.choose-avatar(); } }
|
||||
if root.has-avatar : ActionButton { text: "Удалить"; quiet: true; danger: true; clicked => { root.remove-avatar(); } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
Text { text: "Пока хранится только на этом устройстве."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 4px, 11px); wrap: word-wrap; }
|
||||
}
|
||||
}
|
||||
Rectangle { height: 26px; }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
Rectangle { height: 24px; }
|
||||
Text { text: "Твой ключ"; color: Theme.text-primary; font-size: Theme.font-size + 2px; font-weight: 600; }
|
||||
Text { text: "Открытый ключ определяет твой профиль. Им можно поделиться; секретный ключ остаётся на устройстве."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 16px; }
|
||||
ThemeEditor { text: root.identity-pubkey; read-only: true; height: 78px; }
|
||||
if root.avatar-error != "" : Text { text: root.avatar-error; color: Theme.danger; font-size: Math.max(11px, Theme.font-size - 3px); wrap: word-wrap; }
|
||||
Rectangle { height: 28px; }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
Rectangle { height: 24px; }
|
||||
HorizontalLayout {
|
||||
Text { text: "Защита на устройстве"; color: Theme.text-primary; font-size: Theme.font-size + 2px; font-weight: 600; horizontal-stretch: 1; }
|
||||
Text { text: root.vault-enabled ? "● Защищено паролем" : "Без пароля"; color: root.vault-enabled ? Theme.success : Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); vertical-alignment: center; }
|
||||
}
|
||||
Rectangle { height: 6px; }
|
||||
Text { text: root.vault-enabled ? "При запуске Vnox потребуется пароль для доступа к ключам." : "Добавь пароль, чтобы зашифровать сохранённый секретный ключ."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 15px; }
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton {
|
||||
text: root.vault-enabled ? "Изменить пароль" : "Добавить пароль";
|
||||
clicked => { root.passphrase-modal-open = !root.passphrase-modal-open; root.export-modal-open = false; root.import-modal-open = false; }
|
||||
}
|
||||
if root.vault-enabled : ActionButton { text: "Убрать пароль"; danger: true; quiet: true; clicked => { root.confirm-remove = true; } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
if root.confirm-remove : VerticalLayout {
|
||||
spacing: 10px; alignment: start;
|
||||
Text { text: "Ключ будет сохранён без шифрования. Убрать пароль?"; color: Theme.danger; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton { text: "Отмена"; quiet: true; clicked => { root.confirm-remove = false; } }
|
||||
ActionButton { text: "Убрать пароль"; danger: true; clicked => { root.remove-passphrase(); root.confirm-remove = false; } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
}
|
||||
if root.passphrase-modal-open : VerticalLayout {
|
||||
spacing: 10px; alignment: start;
|
||||
Rectangle { height: 8px; }
|
||||
ThemeInput { input-type: InputType.password; text <=> root.passphrase-input; placeholder-text: "Новый пароль · минимум 8 символов"; }
|
||||
ThemeInput { input-type: InputType.password; text <=> root.passphrase-confirm; placeholder-text: "Повтори пароль"; accepted => { root.set-passphrase(root.passphrase-input, root.passphrase-confirm); } }
|
||||
if root.passphrase-error != "" : Text { text: root.passphrase-error; color: Theme.danger; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton { text: "Сохранить пароль"; active: true; clicked => { root.set-passphrase(root.passphrase-input, root.passphrase-confirm); } }
|
||||
ActionButton { text: "Свернуть"; quiet: true; clicked => { root.passphrase-modal-open = false; } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
}
|
||||
Rectangle { height: 28px; }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
Rectangle { height: 24px; }
|
||||
Text { text: "Резервная копия"; color: Theme.text-primary; font-size: Theme.font-size + 2px; font-weight: 600; }
|
||||
Text { text: "Сохрани ключи в безопасном месте, чтобы восстановить профиль на другом устройстве."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
Rectangle { height: 15px; }
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton { text: "Экспортировать ключи"; clicked => { root.export-modal-open = !root.export-modal-open; root.passphrase-modal-open = false; root.import-modal-open = false; } }
|
||||
ActionButton { text: "Импортировать"; quiet: true; clicked => { root.import-modal-open = !root.import-modal-open; root.passphrase-modal-open = false; root.export-modal-open = false; } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
if root.export-modal-open : VerticalLayout {
|
||||
spacing: 10px; alignment: start;
|
||||
Rectangle { height: 8px; }
|
||||
Text { text: "Пароль резервной копии можно оставить пустым. Такая копия содержит секретный ключ без защиты."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
ThemeInput { input-type: InputType.password; text <=> root.export-pass-input; placeholder-text: "Пароль копии · необязательно"; }
|
||||
ThemeInput { input-type: InputType.password; text <=> root.export-pass-confirm; placeholder-text: "Повтори пароль копии"; }
|
||||
if root.export-error != "" : Text { text: root.export-error; color: Theme.danger; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton { text: "Создать копию"; active: true; clicked => { root.export-keyfile(root.export-pass-input, root.export-pass-confirm); } }
|
||||
ActionButton { text: "Свернуть"; quiet: true; clicked => { root.export-modal-open = false; } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
if root.export-output != "" : VerticalLayout {
|
||||
spacing: 8px;
|
||||
Text { text: "Скопируй содержимое в файл и сохрани отдельно от устройства."; color: Theme.text-muted; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
ThemeEditor { text: root.export-output; read-only: true; height: 180px; }
|
||||
}
|
||||
}
|
||||
if root.import-modal-open : VerticalLayout {
|
||||
spacing: 10px; alignment: start;
|
||||
Rectangle { height: 8px; }
|
||||
Text { text: "Импорт заменит сохранённый профиль. Сначала сделай резервную копию текущих ключей."; color: Theme.danger; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
ThemeEditor { text <=> root.import-keyfile-input; height: 150px; }
|
||||
ThemeInput { input-type: InputType.password; text <=> root.import-pass-input; placeholder-text: "Пароль резервной копии, если он задан"; }
|
||||
if root.import-error != "" : Text { text: root.import-error; color: Theme.danger; font-size: Math.max(Theme.font-size - 3px, 11px); wrap: word-wrap; }
|
||||
HorizontalLayout {
|
||||
spacing: 9px;
|
||||
ActionButton { text: "Импортировать и заменить"; danger: true; clicked => { root.import-keyfile(root.import-keyfile-input, root.import-pass-input); } }
|
||||
ActionButton { text: "Свернуть"; quiet: true; clicked => { root.import-modal-open = false; } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
}
|
||||
Rectangle { height: 28px; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,243 +1,160 @@
|
|||
import { Theme } from "theme.slint";
|
||||
import { AvatarView } from "avatar-view.slint";
|
||||
import { Theme, ActionButton } from "theme.slint";
|
||||
|
||||
export struct ChannelItem {
|
||||
channel_id: string,
|
||||
name: string,
|
||||
kind: string,
|
||||
}
|
||||
export struct ChannelItem { channel_id: string, name: string, kind: string }
|
||||
export struct GuildItem { guild_id: string, name: string, short_name: string, selected: bool }
|
||||
export struct DmItem { dm_id: string, name: string, unread: int }
|
||||
|
||||
export struct GuildItem {
|
||||
guild_id: string,
|
||||
name: string,
|
||||
short_name: string,
|
||||
selected: bool,
|
||||
}
|
||||
|
||||
component GuildBar {
|
||||
in-out property <[GuildItem]> guilds;
|
||||
in-out property <int> active-guild-idx;
|
||||
|
||||
callback guild-selected(int);
|
||||
|
||||
width: 56px;
|
||||
height: 100%;
|
||||
|
||||
Rectangle {
|
||||
background: #111118;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
VerticalLayout {
|
||||
padding: 8px;
|
||||
spacing: 4px;
|
||||
alignment: start;
|
||||
|
||||
Rectangle {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: active-guild-idx == -1 ? 12px : 20px;
|
||||
background: active-guild-idx == -1 ? Theme.accent : Theme.bg-surface;
|
||||
TouchArea {
|
||||
clicked => { guild-selected(-1); }
|
||||
}
|
||||
Text {
|
||||
text: "@";
|
||||
color: Theme.text-primary;
|
||||
font-size: 18px;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
height: 2px;
|
||||
width: 32px;
|
||||
background: Theme.bg-elevated;
|
||||
border-radius: 1px;
|
||||
x: 12px;
|
||||
}
|
||||
|
||||
for g[idx] in guilds: Rectangle {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: g.selected ? 12px : 20px;
|
||||
background: g.selected ? Theme.accent : Theme.bg-elevated;
|
||||
TouchArea {
|
||||
clicked => { guild-selected(idx); }
|
||||
}
|
||||
Text {
|
||||
text: g.short_name;
|
||||
color: Theme.text-primary;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
component NavRow inherits Rectangle {
|
||||
in property <string> label;
|
||||
in property <string> symbol: "#";
|
||||
in property <bool> selected;
|
||||
in property <int> unread;
|
||||
callback clicked();
|
||||
height: root.visible ? 36px : 0px;
|
||||
border-radius: 6px;
|
||||
background: selected ? Theme.selected : touch.has-hover ? Theme.bg-hover : transparent;
|
||||
border-width: keyboard.has-focus ? 1px : 0px;
|
||||
border-color: Theme.accent;
|
||||
accessible-role: button;
|
||||
accessible-label: label;
|
||||
HorizontalLayout {
|
||||
padding-left: 10px; padding-right: 10px; spacing: 10px;
|
||||
Text { text: root.symbol; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 1.125); width: 20px; }
|
||||
Text { text: root.label; color: root.selected || root.unread > 0 ? Theme.text-primary : Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.875); horizontal-stretch: 1; overflow: elide; }
|
||||
if root.unread > 0 : Text { text: root.unread; color: Theme.accent; font-size: Math.max(11px, Theme.font-size * 0.75); }
|
||||
}
|
||||
touch := TouchArea { clicked => { keyboard.focus(); root.clicked(); } }
|
||||
keyboard := FocusScope {
|
||||
key-pressed(event) => {
|
||||
if event.text == " " || event.text == "\n" { root.clicked(); return accept; }
|
||||
return reject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component ChannelList {
|
||||
in-out property <[ChannelItem]> channels;
|
||||
in-out property <string> active-channel-id;
|
||||
in-out property <string> section-title;
|
||||
|
||||
callback channel-selected(string);
|
||||
|
||||
VerticalLayout {
|
||||
Rectangle {
|
||||
height: 48px;
|
||||
background: Theme.bg-surface;
|
||||
HorizontalLayout {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
Text { text: section-title; color: Theme.text-primary; font-size: 15px; font-weight: 600; }
|
||||
}
|
||||
}
|
||||
|
||||
Flickable {
|
||||
VerticalLayout {
|
||||
for item in channels: Rectangle {
|
||||
height: 36px;
|
||||
background: item.channel_id == active-channel-id ? Theme.bg-elevated : Theme.bg-base;
|
||||
HorizontalLayout {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
spacing: 6px;
|
||||
Text {
|
||||
text: item.kind == "voice" ? "🔊 " : "# ";
|
||||
color: Theme.text-secondary;
|
||||
font-size: 14px;
|
||||
}
|
||||
Text {
|
||||
text: item.name;
|
||||
color: item.channel_id == active-channel-id ? Theme.text-primary : Theme.text-secondary;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
TouchArea {
|
||||
clicked => { channel-selected(item.channel_id); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component DmList {
|
||||
in-out property <[string]> dm-conversations;
|
||||
|
||||
callback dm-selected(string);
|
||||
|
||||
VerticalLayout {
|
||||
Rectangle {
|
||||
height: 48px;
|
||||
background: Theme.bg-surface;
|
||||
HorizontalLayout {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
Text { text: "Direct Messages"; color: Theme.text-primary; font-size: 15px; font-weight: 600; }
|
||||
}
|
||||
}
|
||||
|
||||
Flickable {
|
||||
VerticalLayout {
|
||||
for dm in dm-conversations: Rectangle {
|
||||
height: 36px;
|
||||
HorizontalLayout {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
spacing: 6px;
|
||||
Text { text: "@"; color: Theme.text-secondary; font-size: 14px; }
|
||||
Text { text: dm; color: Theme.text-secondary; font-size: 14px; }
|
||||
}
|
||||
TouchArea {
|
||||
clicked => { dm-selected(dm); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export component Sidebar {
|
||||
export component Sidebar inherits Rectangle {
|
||||
in-out property <[GuildItem]> guilds;
|
||||
in-out property <[ChannelItem]> channels;
|
||||
in-out property <[string]> dm-conversations;
|
||||
in-out property <[DmItem]> dm-conversations;
|
||||
in property <image> own-avatar;
|
||||
in property <bool> has-avatar;
|
||||
in-out property <string> username;
|
||||
in-out property <string> user-status;
|
||||
in-out property <string> active-channel-id;
|
||||
in-out property <string> active-dm-id;
|
||||
in-out property <int> active-guild-idx;
|
||||
in-out property <bool> show-dms;
|
||||
|
||||
in-out property <bool> voice-connected;
|
||||
in-out property <string> voice-channel-name;
|
||||
in-out property <bool> mic-enabled;
|
||||
in-out property <bool> deafened;
|
||||
in-out property <string> node-name;
|
||||
callback channel-selected(string);
|
||||
callback guild-selected(int);
|
||||
callback dm-selected(string);
|
||||
callback disconnect();
|
||||
|
||||
width: 296px;
|
||||
height: 100%;
|
||||
|
||||
callback open-settings();
|
||||
callback toggle-mic();
|
||||
callback toggle-deafen();
|
||||
callback leave-voice();
|
||||
callback show-voice();
|
||||
callback show-friends();
|
||||
width: 332px;
|
||||
background: Theme.bg-surface;
|
||||
HorizontalLayout {
|
||||
spacing: 0;
|
||||
|
||||
GuildBar {
|
||||
guilds: root.guilds;
|
||||
active-guild-idx: root.active-guild-idx;
|
||||
guild-selected(idx) => { root.guild-selected(idx); }
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: 240px;
|
||||
height: 100%;
|
||||
background: Theme.bg-base;
|
||||
|
||||
width: 64px;
|
||||
background: Theme.bg-rail;
|
||||
VerticalLayout {
|
||||
padding: 9px; spacing: 11px;
|
||||
ActionButton { text: "Личные сообщения"; icon: "home"; height: 44px; text-size: 20px; active: root.show-dms; clicked => { root.show-friends(); } }
|
||||
Rectangle { height: 1px; background: Theme.border; }
|
||||
ActionButton { text: "V"; height: 44px; text-size: 19px; active: !root.show-dms && root.active-guild-idx < 0; clicked => { root.guild-selected(-1); } }
|
||||
for guild[index] in root.guilds: ActionButton {
|
||||
height: 44px;
|
||||
text: guild.short_name;
|
||||
active: guild.selected && !root.show-dms;
|
||||
clicked => { root.guild-selected(index); }
|
||||
}
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
ActionButton { text: "Настройки"; icon: "settings"; quiet: true; text-size: 19px; clicked => { root.open-settings(); } }
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
VerticalLayout {
|
||||
spacing: 0;
|
||||
|
||||
if root.show-dms : DmList {
|
||||
dm-conversations: root.dm-conversations;
|
||||
dm-selected(id) => { root.dm-selected(id); }
|
||||
}
|
||||
if !root.show-dms : ChannelList {
|
||||
channels: root.channels;
|
||||
active-channel-id: root.active-channel-id;
|
||||
section-title: root.active-guild-idx >= 0 && root.active-guild-idx < root.guilds.length ? root.guilds[root.active-guild-idx].name : "Channels";
|
||||
channel-selected(id) => { root.channel-selected(id); }
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
height: 52px;
|
||||
background: Theme.bg-surface;
|
||||
height: 56px;
|
||||
border-width: 1px; border-color: Theme.border;
|
||||
HorizontalLayout {
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
spacing: 8px;
|
||||
Rectangle {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 16px;
|
||||
background: Theme.bg-elevated;
|
||||
padding-left: 17px; padding-right: 10px; spacing: 8px;
|
||||
Text { text: root.show-dms ? "Личные сообщения" : root.active-guild-idx >= 0 && root.active-guild-idx < root.guilds.length ? root.guilds[root.active-guild-idx].name : root.node-name; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.0); font-weight: 600; overflow: elide; horizontal-stretch: 1; vertical-alignment: center; }
|
||||
ActionButton { text: "Отключиться"; icon: "power"; width: 30px; quiet: true; clicked => { root.disconnect(); } }
|
||||
}
|
||||
}
|
||||
Flickable {
|
||||
content-width: self.width;
|
||||
VerticalLayout {
|
||||
padding: 10px; spacing: 3px;
|
||||
if root.show-dms : NavRow { label: "Друзья"; symbol: "@"; clicked => { root.show-friends(); } }
|
||||
if root.show-dms : Text { text: "Личные сообщения"; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); height: 32px; vertical-alignment: bottom; }
|
||||
if root.show-dms && root.dm-conversations.length == 0 : Text { text: "Открой профиль друга, чтобы написать ему."; wrap: word-wrap; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); }
|
||||
for dm in root.dm-conversations: NavRow {
|
||||
visible: root.show-dms;
|
||||
label: dm.name; symbol: "@"; unread: dm.unread;
|
||||
selected: root.active-dm-id == dm.dm_id;
|
||||
clicked => { root.dm-selected(dm.dm_id); }
|
||||
}
|
||||
VerticalLayout {
|
||||
spacing: 2px;
|
||||
Text { text: root.username; color: Theme.text-primary; font-size: 14px; font-weight: 600; }
|
||||
Text { text: root.user-status; color: Theme.text-muted; font-size: 11px; }
|
||||
if !root.show-dms : Text { text: "Текстовые каналы"; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); height: 32px; vertical-alignment: bottom; }
|
||||
for ch in root.channels: NavRow {
|
||||
visible: !root.show-dms && ch.kind != "voice";
|
||||
label: ch.name;
|
||||
selected: root.active-channel-id == ch.channel_id;
|
||||
clicked => { root.channel-selected(ch.channel_id); }
|
||||
}
|
||||
if !root.show-dms : Text { text: "Голосовые комнаты"; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); height: 40px; vertical-alignment: bottom; }
|
||||
for ch in root.channels: NavRow {
|
||||
visible: !root.show-dms && ch.kind == "voice";
|
||||
label: ch.name; symbol: "◖";
|
||||
selected: root.voice-connected && root.voice-channel-name == ch.name;
|
||||
clicked => { root.channel-selected(ch.channel_id); }
|
||||
}
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
}
|
||||
}
|
||||
if root.voice-connected : Rectangle {
|
||||
height: 88px;
|
||||
background: Theme.voice-bg;
|
||||
border-radius: 8px;
|
||||
border-width: 1px; border-color: Theme.border;
|
||||
VerticalLayout {
|
||||
padding: 10px; spacing: 5px;
|
||||
Text { text: "● Голос подключён"; color: Theme.success; font-size: Math.max(11px, Theme.font-size * 0.8125); font-weight: 600; }
|
||||
Text { text: root.voice-channel-name; color: Theme.text-secondary; font-size: Math.max(11px, Theme.font-size * 0.6875); overflow: elide; }
|
||||
HorizontalLayout {
|
||||
horizontal-stretch: 1;
|
||||
spacing: 6px;
|
||||
ActionButton { text: "Открыть"; clicked => { root.show-voice(); } }
|
||||
ActionButton { text: "Выйти"; danger: true; clicked => { root.leave-voice(); } }
|
||||
}
|
||||
Rectangle {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: 6px;
|
||||
background: Theme.bg-interactive;
|
||||
TouchArea {
|
||||
clicked => { root.disconnect(); }
|
||||
}
|
||||
Text { text: "⏻"; color: Theme.text-muted; font-size: 14px; horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
height: 66px;
|
||||
background: Theme.bg-elevated;
|
||||
HorizontalLayout {
|
||||
padding: 9px; spacing: 5px;
|
||||
AvatarView { width: 30px; height: 30px; source: root.own-avatar; has-source: root.has-avatar; initials: "●"; mask: Theme.bg-elevated; }
|
||||
VerticalLayout {
|
||||
spacing: 1px; horizontal-stretch: 1;
|
||||
Text { text: root.username; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.8125); font-weight: 600; overflow: elide; }
|
||||
Text { text: root.user-status; color: Theme.success; font-size: Math.max(11px, Theme.font-size * 0.625); overflow: elide; }
|
||||
}
|
||||
ActionButton { text: root.mic-enabled ? "Выключить микрофон" : "Включить микрофон"; icon: "mic"; width: 30px; danger: !root.mic-enabled; quiet: true; clicked => { root.toggle-mic(); } }
|
||||
ActionButton { text: root.deafened ? "Включить звук" : "Выключить звук"; icon: "headphones"; width: 30px; danger: root.deafened; quiet: true; clicked => { root.toggle-deafen(); } }
|
||||
ActionButton { text: "Настройки"; icon: "settings"; width: 30px; quiet: true; clicked => { root.open-settings(); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,70 @@
|
|||
export global Theme {
|
||||
in-out property <color> bg-base: #181825;
|
||||
in-out property <color> bg-surface: #1e1e2e;
|
||||
in-out property <color> bg-hover: #2a2a3e;
|
||||
in-out property <color> bg-elevated: #2a2a3e;
|
||||
in-out property <color> bg-interactive: #313244;
|
||||
in-out property <color> accent: #E67E22;
|
||||
in-out property <color> text-primary: #cdd6f4;
|
||||
in-out property <color> text-secondary: #a0a4b8;
|
||||
in-out property <color> text-muted: #6c7086;
|
||||
in-out property <color> text-disabled: #45475a;
|
||||
in-out property <color> danger: #f38ba8;
|
||||
in-out property <color> success: #a6e3a1;
|
||||
in-out property <length> radius: 8px;
|
||||
in-out property <color> bg-base: #272729;
|
||||
in-out property <color> bg-surface: #202022;
|
||||
in-out property <color> bg-rail: #151516;
|
||||
in-out property <color> bg-hover: #38383c;
|
||||
in-out property <color> bg-elevated: #303033;
|
||||
in-out property <color> bg-interactive: #343336;
|
||||
in-out property <color> selected: #3a393c;
|
||||
in-out property <color> border: #ffffff12;
|
||||
in-out property <color> accent: #d5b58a;
|
||||
in-out property <color> text-primary: #e9e7e4;
|
||||
in-out property <color> text-secondary: #b8b4b1;
|
||||
in-out property <color> text-muted: #aaa29b;
|
||||
in-out property <color> text-disabled: #85817f;
|
||||
in-out property <color> danger: #e58b85;
|
||||
in-out property <color> success: #a8c1a4;
|
||||
in-out property <length> font-size: 16px;
|
||||
out property <float> scale: font-size / 16px;
|
||||
in-out property <color> on-accent: #29221b;
|
||||
in-out property <color> avatar-bg: #49433d;
|
||||
in-out property <color> voice-bg: #282c28;
|
||||
in-out property <color> overlay: #00000080;
|
||||
in-out property <length> radius: 7px;
|
||||
}
|
||||
|
||||
export component Symbol inherits Rectangle {
|
||||
in property <string> kind;
|
||||
in property <color> ink: Theme.text-secondary;
|
||||
if kind == "mic" : Path { width: parent.width; height: parent.height; viewbox-width: 24; viewbox-height: 24; fill: transparent; stroke: root.ink; stroke-width: 1.7px; commands: "M9 11V5 A3 3 0 0 1 15 5 V11 A3 3 0 0 1 9 11 M5 10V12 A7 7 0 0 0 19 12 V10 M12 19V22 M8 22H16"; }
|
||||
if kind == "headphones" : Path { width: parent.width; height: parent.height; viewbox-width: 24; viewbox-height: 24; fill: transparent; stroke: root.ink; stroke-width: 1.7px; commands: "M3 14V11 A9 9 0 0 1 21 11 V14 M3 13H7V21H3Z M17 13H21V21H17Z"; }
|
||||
if kind == "settings" : Path { width: parent.width; height: parent.height; viewbox-width: 24; viewbox-height: 24; fill: transparent; stroke: root.ink; stroke-width: 1.7px; commands: "M9 3L8 6L5 7L3 10L5 12L4 15L7 17L10 16L12 18L15 16V13L17 11L16 8L13 7L12 3Z M14 11 A3 3 0 1 1 8 11 A3 3 0 1 1 14 11"; }
|
||||
if kind == "power" : Path { width: parent.width; height: parent.height; viewbox-width: 24; viewbox-height: 24; fill: transparent; stroke: root.ink; stroke-width: 1.7px; commands: "M12 2V12 M6 5 A9 9 0 1 0 18 5"; }
|
||||
if kind == "home" : Path { width: parent.width; height: parent.height; viewbox-width: 24; viewbox-height: 24; fill: transparent; stroke: root.ink; stroke-width: 1.7px; commands: "M2 10L12 2L22 10V22H2Z M9 22V13H15V22"; }
|
||||
}
|
||||
|
||||
export component ActionButton inherits Rectangle {
|
||||
in property <string> text;
|
||||
in property <string> icon;
|
||||
in property <bool> active: false;
|
||||
in property <bool> danger: false;
|
||||
in property <bool> quiet: false;
|
||||
in property <length> text-size: 13px;
|
||||
callback clicked();
|
||||
min-width: 30px;
|
||||
preferred-width: icon == "" ? label.preferred-width + 22px : 32px;
|
||||
height: 32px;
|
||||
border-radius: 6px;
|
||||
background: active ? Theme.selected : touch.has-hover ? Theme.bg-hover : quiet ? transparent : Theme.bg-interactive;
|
||||
border-width: keyboard.has-focus ? 1px : 0px;
|
||||
border-color: Theme.accent;
|
||||
accessible-role: button;
|
||||
accessible-label: text;
|
||||
Symbol { visible: root.icon != ""; kind: root.icon; ink: root.danger ? Theme.danger : Theme.text-secondary; width: 18px; height: 18px; x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; }
|
||||
label := Text {
|
||||
visible: root.icon == "";
|
||||
text: root.text;
|
||||
color: root.danger ? Theme.danger : root.active ? Theme.text-primary : Theme.text-secondary;
|
||||
font-size: Math.max(11px, root.text-size * Theme.scale);
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
touch := TouchArea { clicked => { keyboard.focus(); root.clicked(); } }
|
||||
keyboard := FocusScope {
|
||||
key-pressed(event) => {
|
||||
if event.text == " " || event.text == "\n" { root.clicked(); return accept; }
|
||||
return reject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
25
src/ui/slint/unlock.slint
Normal file
25
src/ui/slint/unlock.slint
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { Theme, ActionButton } from "theme.slint";
|
||||
import { ThemeInput } from "controls.slint";
|
||||
|
||||
export component UnlockWindow inherits Window {
|
||||
title: "Vnox — разблокировка";
|
||||
icon: @image-url("assets/vnox-mark.svg");
|
||||
preferred-width: 480px;
|
||||
preferred-height: 300px;
|
||||
background: Theme.bg-base;
|
||||
in-out property <string> error;
|
||||
callback unlock(string);
|
||||
|
||||
VerticalLayout {
|
||||
padding: 30px; spacing: 14px; alignment: start;
|
||||
Text { text: "Разблокировать профиль"; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.375); font-weight: 600; }
|
||||
Text { text: "Ключи на этом устройстве защищены паролем."; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.8125); wrap: word-wrap; }
|
||||
password := ThemeInput {
|
||||
input-type: InputType.password;
|
||||
placeholder-text: "Пароль профиля";
|
||||
accepted => { root.unlock(self.text); }
|
||||
}
|
||||
if root.error != "" : Text { text: root.error; color: Theme.danger; font-size: Math.max(11px, Theme.font-size * 0.75); wrap: word-wrap; }
|
||||
ActionButton { text: "Разблокировать"; clicked => { root.unlock(password.text); } }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +1,83 @@
|
|||
import { Theme } from "theme.slint";
|
||||
import { Theme, ActionButton } from "theme.slint";
|
||||
|
||||
export struct VoiceMemberItem {
|
||||
user_id: string,
|
||||
nickname: string,
|
||||
speaking: bool,
|
||||
}
|
||||
export struct VoiceMemberItem { user_id: string, nickname: string, speaking: bool, avatar_text: string }
|
||||
|
||||
export component VoicePanel {
|
||||
export component VoicePanel inherits Rectangle {
|
||||
in-out property <[VoiceMemberItem]> members;
|
||||
in-out property <bool> mic-enabled;
|
||||
in-out property <bool> deafened;
|
||||
in-out property <string> channel-name;
|
||||
in-out property <string> activity-banner;
|
||||
|
||||
in-out property <bool> push-to-talk;
|
||||
callback ptt-held(bool);
|
||||
callback toggle-mic();
|
||||
callback toggle-deafen();
|
||||
callback leave-voice();
|
||||
|
||||
background: Theme.bg-base;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 8px;
|
||||
|
||||
Text {
|
||||
text: "🔊 " + channel-name;
|
||||
color: Theme.text-primary;
|
||||
spacing: 0;
|
||||
Rectangle {
|
||||
height: 56px; border-width: 1px; border-color: Theme.border;
|
||||
HorizontalLayout {
|
||||
padding-left: 22px; spacing: 12px;
|
||||
Text { text: "◖"; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 1.4375); width: 20px; vertical-alignment: center; }
|
||||
Text { text: root.channel-name; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.0); font-weight: 600; vertical-alignment: center; }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: activity-banner;
|
||||
color: Theme.text-muted;
|
||||
}
|
||||
Flickable {
|
||||
VerticalLayout {
|
||||
for m in members: Rectangle {
|
||||
height: 48px;
|
||||
HorizontalLayout {
|
||||
padding: 8px;
|
||||
spacing: 8px;
|
||||
Rectangle {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 6px;
|
||||
background: m.speaking ? Theme.success : Theme.text-muted;
|
||||
}
|
||||
Text {
|
||||
text: m.nickname;
|
||||
color: Theme.text-primary;
|
||||
VerticalLayout {
|
||||
padding: 24px; spacing: 16px;
|
||||
Text { text: root.members.length + " участников"; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.8125); }
|
||||
Flickable {
|
||||
content-width: self.width;
|
||||
VerticalLayout {
|
||||
spacing: 12px;
|
||||
for member in root.members: Rectangle {
|
||||
height: 120px; border-radius: 12px;
|
||||
background: Theme.bg-interactive;
|
||||
border-width: member.speaking ? 2px : 1px;
|
||||
border-color: member.speaking ? Theme.success : Theme.border;
|
||||
HorizontalLayout {
|
||||
padding: 24px; spacing: 18px;
|
||||
Rectangle {
|
||||
width: 58px; height: 58px; border-radius: 20px; background: Theme.avatar-bg;
|
||||
Text { text: member.avatar_text; color: Theme.accent; font-size: Math.max(11px, Theme.font-size * 1.625); horizontal-alignment: center; vertical-alignment: center; }
|
||||
}
|
||||
VerticalLayout {
|
||||
spacing: 5px;
|
||||
Text { text: member.nickname; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 1.0625); }
|
||||
Text { text: member.speaking ? "Говорит" : "В голосовой комнате"; color: member.speaking ? Theme.success : Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.75); }
|
||||
}
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
}
|
||||
if root.members.length == 0 : Text { text: "Подключение к голосовой комнате…"; color: Theme.text-muted; font-size: Math.max(11px, Theme.font-size * 0.875); }
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 8px;
|
||||
Rectangle {
|
||||
height: 32px;
|
||||
background: Theme.accent;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => { toggle-mic(); }
|
||||
if root.push-to-talk : Rectangle {
|
||||
height: 46px; background: ptt-area.pressed ? Theme.voice-bg : Theme.bg-interactive;
|
||||
border-radius: 8px; border-width: ptt-focus.has-focus ? 1px : 0px; border-color: Theme.accent;
|
||||
accessible-role: button; accessible-label: "Удерживать для разговора";
|
||||
Text { text: ptt-area.pressed ? "Микрофон передаёт звук" : "Удерживай здесь, чтобы говорить"; color: Theme.text-primary; font-size: Math.max(11px, Theme.font-size * 0.875); horizontal-alignment: center; vertical-alignment: center; }
|
||||
ptt-area := TouchArea {
|
||||
clicked => { ptt-focus.focus(); }
|
||||
changed pressed => { root.ptt-held(self.pressed); }
|
||||
}
|
||||
Text {
|
||||
text: mic-enabled ? "Mute" : "Unmute";
|
||||
color: Theme.text-primary;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
ptt-focus := FocusScope {
|
||||
key-pressed(event) => { if event.text == " " { root.ptt-held(true); return accept; } return reject; }
|
||||
key-released(event) => { if event.text == " " { root.ptt-held(false); return accept; } return reject; }
|
||||
changed has-focus => { if !self.has-focus { root.ptt-held(false); } }
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
height: 32px;
|
||||
background: Theme.accent;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => { toggle-deafen(); }
|
||||
}
|
||||
Text {
|
||||
text: deafened ? "Undeafen" : "Deafen";
|
||||
color: Theme.text-primary;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
height: 32px;
|
||||
background: Theme.danger;
|
||||
border-radius: Theme.radius;
|
||||
TouchArea {
|
||||
clicked => { leave-voice(); }
|
||||
}
|
||||
Text {
|
||||
text: "Leave";
|
||||
color: Theme.text-primary;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Text { text: root.activity-banner; color: Theme.success; font-size: Math.max(11px, Theme.font-size * 0.8125); height: 22px; }
|
||||
HorizontalLayout {
|
||||
spacing: 10px;
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
ActionButton { text: root.mic-enabled ? "Выключить микрофон" : "Включить микрофон"; danger: !root.mic-enabled; clicked => { root.toggle-mic(); } }
|
||||
ActionButton { text: root.deafened ? "Включить звук" : "Выключить звук"; danger: root.deafened; clicked => { root.toggle-deafen(); } }
|
||||
ActionButton { text: "Покинуть комнату"; danger: true; clicked => { root.leave-voice(); } }
|
||||
Rectangle { horizontal-stretch: 1; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use super::types::{ConnState, UiState, VoiceUiState};
|
|||
impl Default for UiState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
appearance: crate::ui::appearance::AppearancePreferences::default(),
|
||||
conn: ConnState::Disconnected,
|
||||
connect_input: "127.0.0.1:7600".into(),
|
||||
bookmarks: default_bookmarks(),
|
||||
|
|
@ -15,6 +16,11 @@ impl Default for UiState {
|
|||
active_channel: None,
|
||||
messages: Default::default(),
|
||||
chat_input: String::new(),
|
||||
drafts: HashMap::new(),
|
||||
browsing_dms: false,
|
||||
showing_voice: false,
|
||||
voice_target: None,
|
||||
vault_enabled: false,
|
||||
scroll_bottom: false,
|
||||
voice: VoiceUiState::Off,
|
||||
voice_joined_at: None,
|
||||
|
|
@ -24,6 +30,7 @@ impl Default for UiState {
|
|||
settings_open: false,
|
||||
|
||||
mic_enabled: true,
|
||||
ptt_held: false,
|
||||
deafen: false,
|
||||
vad_mode: 0,
|
||||
voice_bitrate: 64.0,
|
||||
|
|
@ -63,20 +70,11 @@ impl Default for UiState {
|
|||
replying_to_content: String::new(),
|
||||
editing_message_id: None,
|
||||
|
||||
settings_passphrase_open: false,
|
||||
settings_passphrase_input: String::new(),
|
||||
settings_passphrase_confirm: String::new(),
|
||||
settings_passphrase_error: None,
|
||||
|
||||
settings_export_open: false,
|
||||
settings_export_pass: String::new(),
|
||||
settings_export_confirm: String::new(),
|
||||
settings_export_output: None,
|
||||
settings_export_error: None,
|
||||
|
||||
settings_import_open: false,
|
||||
settings_import_input: String::new(),
|
||||
settings_import_pass: String::new(),
|
||||
settings_import_error: None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
mod default;
|
||||
mod models;
|
||||
mod navigation;
|
||||
mod types;
|
||||
|
||||
pub use models::{Channel, ChatMessage, DmConversation, FriendState, GuildState, NodeBookmark};
|
||||
|
|
@ -34,47 +35,4 @@ impl UiState {
|
|||
.map(|s| s.as_str())
|
||||
.unwrap_or(sender_id)
|
||||
}
|
||||
|
||||
pub fn seed_default_channels(&mut self) {
|
||||
if !self.channels.is_empty() {
|
||||
return;
|
||||
}
|
||||
self.channels = vec![
|
||||
Channel {
|
||||
id: "general".into(),
|
||||
name: "general".into(),
|
||||
kind: "text".into(),
|
||||
guild_id: None,
|
||||
members: Vec::new(),
|
||||
},
|
||||
Channel {
|
||||
id: "dev-talk".into(),
|
||||
name: "dev-talk".into(),
|
||||
kind: "text".into(),
|
||||
guild_id: None,
|
||||
members: Vec::new(),
|
||||
},
|
||||
Channel {
|
||||
id: "plugins".into(),
|
||||
name: "plugins".into(),
|
||||
kind: "text".into(),
|
||||
guild_id: None,
|
||||
members: Vec::new(),
|
||||
},
|
||||
Channel {
|
||||
id: "lobby".into(),
|
||||
name: "lobby".into(),
|
||||
kind: "voice".into(),
|
||||
guild_id: None,
|
||||
members: Vec::new(),
|
||||
},
|
||||
Channel {
|
||||
id: "gaming".into(),
|
||||
name: "gaming".into(),
|
||||
kind: "voice".into(),
|
||||
guild_id: None,
|
||||
members: Vec::new(),
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
131
src/ui/state/navigation.rs
Normal file
131
src/ui/state/navigation.rs
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
use super::UiState;
|
||||
|
||||
impl UiState {
|
||||
fn conversation_key(&self) -> Option<String> {
|
||||
self.active_dm_id
|
||||
.as_ref()
|
||||
.map(|id| format!("dm:{id}"))
|
||||
.or_else(|| {
|
||||
self.active_channel
|
||||
.as_ref()
|
||||
.map(|id| format!("channel:{id}"))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn remember_draft(&mut self, text: String) {
|
||||
self.chat_input = text;
|
||||
if let Some(key) = self.conversation_key() {
|
||||
self.drafts.insert(key, self.chat_input.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn save_draft(&mut self) {
|
||||
self.remember_draft(self.chat_input.clone());
|
||||
}
|
||||
|
||||
fn restore_draft(&mut self) {
|
||||
self.chat_input = self
|
||||
.conversation_key()
|
||||
.and_then(|key| self.drafts.get(&key).cloned())
|
||||
.unwrap_or_default();
|
||||
self.replying_to_message = None;
|
||||
self.replying_to_sender.clear();
|
||||
self.replying_to_content.clear();
|
||||
self.editing_message_id = None;
|
||||
}
|
||||
|
||||
pub fn select_text_channel(&mut self, channel_id: String) {
|
||||
self.save_draft();
|
||||
self.active_channel = Some(channel_id);
|
||||
self.active_dm_id = None;
|
||||
self.showing_voice = false;
|
||||
self.browsing_dms = false;
|
||||
self.restore_draft();
|
||||
}
|
||||
|
||||
pub fn select_dm(&mut self, dm_id: String) {
|
||||
self.save_draft();
|
||||
self.active_dm_id = Some(dm_id);
|
||||
self.active_channel = None;
|
||||
self.showing_voice = false;
|
||||
self.browsing_dms = true;
|
||||
self.restore_draft();
|
||||
}
|
||||
|
||||
pub fn clear_server_conversations(&mut self) {
|
||||
self.chat_input.clear();
|
||||
self.drafts.clear();
|
||||
self.messages.clear();
|
||||
self.dm_messages.clear();
|
||||
self.dm_conversations.clear();
|
||||
self.active_channel = None;
|
||||
self.active_dm_id = None;
|
||||
self.restore_draft();
|
||||
}
|
||||
|
||||
pub fn select_friends(&mut self) {
|
||||
self.save_draft();
|
||||
self.active_dm_id = None;
|
||||
self.active_channel = None;
|
||||
self.showing_voice = false;
|
||||
self.browsing_dms = true;
|
||||
self.restore_draft();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn channel_and_dm_drafts_are_isolated_even_when_ids_match() {
|
||||
let mut state = UiState::default();
|
||||
state.select_text_channel("same-id".into());
|
||||
state.remember_draft("channel draft".into());
|
||||
state.select_dm("same-id".into());
|
||||
assert!(state.chat_input.is_empty());
|
||||
state.remember_draft("private draft".into());
|
||||
state.select_text_channel("same-id".into());
|
||||
assert_eq!(state.chat_input, "channel draft");
|
||||
state.select_dm("same-id".into());
|
||||
assert_eq!(state.chat_input, "private draft");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn browsing_text_and_dm_preserves_voice_target() {
|
||||
let mut state = UiState {
|
||||
voice_target: Some("voice-room".into()),
|
||||
showing_voice: true,
|
||||
..UiState::default()
|
||||
};
|
||||
state.select_text_channel("general".into());
|
||||
assert_eq!(state.voice_target.as_deref(), Some("voice-room"));
|
||||
assert!(!state.showing_voice);
|
||||
state.select_dm("dm-id".into());
|
||||
assert_eq!(state.voice_target.as_deref(), Some("voice-room"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sending_clears_only_current_draft() {
|
||||
let mut state = UiState::default();
|
||||
state.select_text_channel("a".into());
|
||||
state.remember_draft("keep".into());
|
||||
state.select_text_channel("b".into());
|
||||
state.remember_draft("send".into());
|
||||
state.remember_draft(String::new());
|
||||
state.select_text_channel("a".into());
|
||||
assert_eq!(state.chat_input, "keep");
|
||||
state.select_text_channel("b".into());
|
||||
assert!(state.chat_input.is_empty());
|
||||
}
|
||||
#[test]
|
||||
fn leaving_server_does_not_expose_drafts_to_next_server() {
|
||||
let mut state = UiState::default();
|
||||
state.select_text_channel("general".into());
|
||||
state.remember_draft("private to server A".into());
|
||||
state.clear_server_conversations();
|
||||
state.select_text_channel("general".into());
|
||||
assert!(state.chat_input.is_empty());
|
||||
assert!(state.drafts.is_empty());
|
||||
}
|
||||
}
|
||||
|
|
@ -25,6 +25,7 @@ pub enum ConnState {
|
|||
}
|
||||
|
||||
pub struct UiState {
|
||||
pub appearance: crate::ui::appearance::AppearancePreferences,
|
||||
pub conn: ConnState,
|
||||
pub connect_input: String,
|
||||
pub bookmarks: Vec<super::NodeBookmark>,
|
||||
|
|
@ -35,6 +36,11 @@ pub struct UiState {
|
|||
pub active_channel: Option<String>,
|
||||
pub messages: HashMap<String, Vec<super::ChatMessage>>,
|
||||
pub chat_input: String,
|
||||
pub drafts: HashMap<String, String>,
|
||||
pub browsing_dms: bool,
|
||||
pub showing_voice: bool,
|
||||
pub voice_target: Option<String>,
|
||||
pub vault_enabled: bool,
|
||||
pub scroll_bottom: bool,
|
||||
|
||||
pub voice: VoiceUiState,
|
||||
|
|
@ -46,6 +52,7 @@ pub struct UiState {
|
|||
pub settings_open: bool,
|
||||
|
||||
pub mic_enabled: bool,
|
||||
pub ptt_held: bool,
|
||||
pub deafen: bool,
|
||||
pub vad_mode: usize,
|
||||
pub voice_bitrate: f32,
|
||||
|
|
@ -91,19 +98,10 @@ pub struct UiState {
|
|||
pub replying_to_content: String,
|
||||
pub editing_message_id: Option<String>,
|
||||
|
||||
pub settings_passphrase_open: bool,
|
||||
pub settings_passphrase_input: String,
|
||||
pub settings_passphrase_confirm: String,
|
||||
pub settings_passphrase_error: Option<String>,
|
||||
|
||||
pub settings_export_open: bool,
|
||||
pub settings_export_pass: String,
|
||||
pub settings_export_confirm: String,
|
||||
pub settings_export_output: Option<String>,
|
||||
pub settings_export_error: Option<String>,
|
||||
|
||||
pub settings_import_open: bool,
|
||||
pub settings_import_input: String,
|
||||
pub settings_import_pass: String,
|
||||
pub settings_import_error: Option<String>,
|
||||
}
|
||||
|
|
|
|||
109
src/ui/update.rs
109
src/ui/update.rs
|
|
@ -23,22 +23,25 @@ pub fn process_net_events(state: &mut AppState) {
|
|||
state.ui.private_mode = private_mode;
|
||||
if restored {
|
||||
state.ui.status_msg = Some("reconnected".into());
|
||||
if let Some(ch) = state.ui.active_channel.clone() {
|
||||
let net = state.net.clone();
|
||||
tokio::spawn(async move {
|
||||
net.send(NetCommand::JoinChannel { channel_id: ch }).await;
|
||||
});
|
||||
}
|
||||
let text_channel = state.ui.active_channel.clone();
|
||||
let voice_channel = state.ui.voice_target.clone();
|
||||
let net = state.net.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Some(channel_id) = text_channel {
|
||||
net.send(NetCommand::JoinChannel { channel_id }).await;
|
||||
}
|
||||
if let Some(channel_id) = voice_channel {
|
||||
net.send(NetCommand::JoinChannel { channel_id }).await;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
state.ui.seed_default_channels();
|
||||
state.ui.active_channel = Some("general".into());
|
||||
state.ui.status_msg = None;
|
||||
let net = state.net.clone();
|
||||
tokio::spawn(async move {
|
||||
net.send(NetCommand::JoinChannel {
|
||||
channel_id: "general".into(),
|
||||
})
|
||||
.await;
|
||||
net.send(NetCommand::ChannelList).await;
|
||||
net.send(NetCommand::GuildList).await;
|
||||
net.send(NetCommand::FriendList).await;
|
||||
net.send(NetCommand::BlockList).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -51,17 +54,22 @@ pub fn process_net_events(state: &mut AppState) {
|
|||
state.ui.status_msg = Some(format!("connection lost: {reason}"));
|
||||
} else {
|
||||
state.ui.conn = ConnState::Disconnected;
|
||||
state.ui.voice_target = None;
|
||||
state.ui.showing_voice = false;
|
||||
state.ui.clear_server_conversations();
|
||||
state.ui.channels.clear();
|
||||
state.ui.active_channel = None;
|
||||
state.ui.user_names.clear();
|
||||
state.ui.rtt_ms = None;
|
||||
state.ui.status_msg = Some(format!("disconnected: {reason}"));
|
||||
}
|
||||
state.ui.dm_conversations.clear();
|
||||
state.ui.dm_messages.clear();
|
||||
state.ui.active_dm_id = None;
|
||||
state.ui.new_dm_input = None;
|
||||
state.ui.private_mode = false;
|
||||
if !will_retry {
|
||||
state.ui.dm_conversations.clear();
|
||||
state.ui.dm_messages.clear();
|
||||
state.ui.active_dm_id = None;
|
||||
state.ui.new_dm_input = None;
|
||||
state.ui.private_mode = false;
|
||||
}
|
||||
}
|
||||
NetEvent::Reconnecting {
|
||||
attempt,
|
||||
|
|
@ -209,10 +217,27 @@ pub fn process_net_events(state: &mut AppState) {
|
|||
}
|
||||
event => process_net_event(&mut state.ui, &state.net, event),
|
||||
}
|
||||
sync_voice_audio(state);
|
||||
flush_encoded_voice(state);
|
||||
}
|
||||
// Capture/playback runs independently from incoming control packets.
|
||||
sync_voice_audio(state);
|
||||
flush_encoded_voice(state);
|
||||
if let Some(pipeline) = state.audio.as_ref() {
|
||||
pipeline.sync_controls(vnox_client::audio::AudioSync {
|
||||
mic_enabled: state.ui.mic_enabled && !state.ui.deafen,
|
||||
vad_mode: state.ui.vad_mode,
|
||||
vad_threshold: 40.0,
|
||||
input_volume: 100.0,
|
||||
ptt_held: state.ui.ptt_held,
|
||||
output_volume: if state.ui.deafen {
|
||||
0.0
|
||||
} else {
|
||||
state.ui.output_volume
|
||||
},
|
||||
jitter_size: 1,
|
||||
adaptive_buffer: true,
|
||||
voice_bitrate_kbps: state.ui.voice_bitrate,
|
||||
noise_suppress: false,
|
||||
});
|
||||
state.ui.local_speaking = pipeline.local_speaking();
|
||||
state.ui.remote_speaking = pipeline.remote_speaking(500);
|
||||
} else {
|
||||
|
|
@ -335,8 +360,14 @@ fn chat_handle(ui: &mut UiState, net: &NetHandle, event: NetEvent) {
|
|||
members: mems,
|
||||
});
|
||||
}
|
||||
if ui.active_channel.is_none() {
|
||||
ui.active_channel = Some(channel_id.clone());
|
||||
if kind == "voice" {
|
||||
ui.voice_target = Some(channel_id.clone());
|
||||
// A newly acknowledged join is also an explicit retry after an audio error.
|
||||
if matches!(ui.voice, VoiceUiState::Error(_)) {
|
||||
ui.voice = VoiceUiState::Off;
|
||||
}
|
||||
} else if ui.active_channel.is_none() && ui.active_dm_id.is_none() {
|
||||
ui.select_text_channel(channel_id.clone());
|
||||
}
|
||||
let net = net.clone();
|
||||
let ch_id = channel_id;
|
||||
|
|
@ -370,6 +401,10 @@ fn chat_handle(ui: &mut UiState, net: &NetHandle, event: NetEvent) {
|
|||
ui.active_channel = ui.channels.first().map(|c| c.id.clone());
|
||||
}
|
||||
ui.messages.remove(&channel_id);
|
||||
if ui.voice_target.as_deref() == Some(&channel_id) {
|
||||
ui.voice_target = None;
|
||||
ui.showing_voice = false;
|
||||
}
|
||||
}
|
||||
NetEvent::ChannelListEvent { channels } => {
|
||||
let old: std::collections::HashMap<String, crate::ui::state::Channel> =
|
||||
|
|
@ -393,6 +428,21 @@ fn chat_handle(ui: &mut UiState, net: &NetHandle, event: NetEvent) {
|
|||
}
|
||||
})
|
||||
.collect();
|
||||
if ui.active_channel.is_none()
|
||||
&& ui.active_dm_id.is_none()
|
||||
&& !ui.browsing_dms
|
||||
&& let Some(id) = ui
|
||||
.channels
|
||||
.iter()
|
||||
.find(|c| c.kind == "text")
|
||||
.map(|c| c.id.clone())
|
||||
{
|
||||
ui.select_text_channel(id.clone());
|
||||
let net = net.clone();
|
||||
tokio::spawn(async move {
|
||||
net.send(NetCommand::JoinChannel { channel_id: id }).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
NetEvent::UserJoin {
|
||||
channel_id,
|
||||
|
|
@ -437,7 +487,7 @@ fn chat_handle(ui: &mut UiState, net: &NetHandle, event: NetEvent) {
|
|||
}
|
||||
ui.dm_messages
|
||||
.insert(dm_id.clone(), messages.into_iter().map(into_msg).collect());
|
||||
ui.active_dm_id = Some(dm_id);
|
||||
ui.select_dm(dm_id);
|
||||
}
|
||||
NetEvent::ChatMessage {
|
||||
message_id,
|
||||
|
|
@ -729,6 +779,11 @@ pub fn pipeline_config(channel_id: &str, state: &AppState) -> PipelineConfig {
|
|||
|
||||
pub fn start_voice(state: &mut AppState, channel_id: &str) {
|
||||
let cfg = pipeline_config(channel_id, state);
|
||||
if matches!(state.ui.voice, VoiceUiState::Error(_))
|
||||
&& state.last_pipeline_config.as_ref() == Some(&cfg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if state.voice_channel.as_deref() == Some(channel_id)
|
||||
&& state.audio.is_some()
|
||||
&& state.last_pipeline_config.as_ref() == Some(&cfg)
|
||||
|
|
@ -753,7 +808,7 @@ pub fn start_voice(state: &mut AppState, channel_id: &str) {
|
|||
Err(e) => {
|
||||
tracing::warn!("audio start failed: {e}");
|
||||
state.voice_channel = None;
|
||||
state.last_pipeline_config = None;
|
||||
state.last_pipeline_config = Some(cfg);
|
||||
state.ui.voice = VoiceUiState::Error(e.to_string());
|
||||
state.ui.status_msg = Some(format!("microphone error: {e}"));
|
||||
}
|
||||
|
|
@ -773,13 +828,7 @@ pub fn sync_voice_audio(state: &mut AppState) {
|
|||
stop_voice(state);
|
||||
return;
|
||||
}
|
||||
let active_voice = state
|
||||
.ui
|
||||
.active_channel
|
||||
.as_ref()
|
||||
.and_then(|id| state.ui.channels.iter().find(|c| &c.id == id))
|
||||
.filter(|c| c.kind == "voice")
|
||||
.map(|c| c.id.clone());
|
||||
let active_voice = state.ui.voice_target.clone();
|
||||
match active_voice {
|
||||
Some(id) => start_voice(state, &id),
|
||||
None => stop_voice(state),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue