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:
Loki 2026-10-24 14:23:48 +02:00
parent 44d284a568
commit 8e5ab56611
Signed by: boba
GPG key ID: 253067914055423B
276 changed files with 53546 additions and 3399 deletions

View file

@ -16,7 +16,7 @@ use vnox_client::net;
use vnox_client::net::NetCommand;
use vnox_client::net::NetHandle;
use crate::ui::state::{ConnState, UiState, VoiceUiState};
use crate::ui::state::{ConnState, UiState};
pub struct AppState {
pub(crate) identity: identity::Identity,
@ -32,7 +32,9 @@ fn main() -> Result<()> {
.unwrap_or_else(|_| EnvFilter::new("info,wgpu=warn,wgpu_hal=warn,naga=warn"));
tracing_subscriber::fmt().with_env_filter(filter).init();
let identity = identity::load_or_generate()?;
let Some(identity) = load_identity()? else {
return Ok(());
};
info!("identity: {}", identity.short_id());
let rt = tokio::runtime::Builder::new_multi_thread()
@ -51,7 +53,18 @@ fn main() -> Result<()> {
last_pipeline_config: None,
}));
{
let mut s = state.borrow_mut();
crate::ui::preferences::load(&mut s.ui);
s.ui.appearance = crate::ui::appearance::AppearancePreferences::load();
s.ui.vault_enabled = identity::is_vault_encrypted();
let user_id = s.identity.pubkey_hex.clone();
let nickname = s.identity.nickname.clone();
s.ui.user_names.insert(user_id, nickname);
}
let window = MainWindow::new()?;
window.set_address_input(state.borrow().ui.connect_input.as_str().into());
refresh_devices(&window);
wire_signals(&window, &state);
@ -66,7 +79,7 @@ fn main() -> Result<()> {
if let Some(win) = weak.upgrade() {
let mut s = state.borrow_mut();
crate::ui::update::process_net_events(&mut s);
let own_id = s.identity.short_id().to_string();
let own_id = s.identity.pubkey_hex.clone();
let own_nick = s.identity.nickname.clone();
let own_pubkey = s.identity.pubkey_hex.clone();
crate::ui::bridge::sync_ui(&win, &s.ui, &own_id, &own_nick, &own_pubkey);
@ -79,14 +92,134 @@ fn main() -> Result<()> {
Ok(())
}
fn load_identity() -> Result<Option<identity::Identity>> {
match identity::load_or_generate() {
Ok(identity) => Ok(Some(identity)),
Err(error) if error.downcast_ref::<identity::LoadError>().is_some() => {
let dialog = crate::ui::slint::UnlockWindow::new()?;
let appearance = crate::ui::appearance::AppearancePreferences::load();
if let Ok(spec) = appearance.resolve() {
crate::ui::appearance::apply_unlock(&dialog, &spec);
}
let unlocked = Rc::new(RefCell::new(None));
let result = unlocked.clone();
let weak = dialog.as_weak();
dialog.on_unlock(move |passphrase| {
if let Some(dialog) = weak.upgrade() {
match identity::load_with_passphrase(passphrase.as_str()) {
Ok(identity) => {
*result.borrow_mut() = Some(identity);
let _ = dialog.hide();
}
Err(_) => {
dialog.set_error("Не удалось открыть профиль. Проверь пароль.".into())
}
}
}
});
dialog.run()?;
let identity = unlocked.borrow_mut().take();
Ok(identity)
}
Err(error) => Err(error),
}
}
fn refresh_devices(window: &MainWindow) {
let devices = vnox_client::audio::devices::enumerate().unwrap_or_default();
let model = |mut items: Vec<String>| {
if items.is_empty() {
items.push("Default".into());
}
Rc::new(slint::VecModel::from(
items
.into_iter()
.map(slint::SharedString::from)
.collect::<Vec<_>>(),
))
.into()
};
window.set_input_devices(model(devices.input_labels));
window.set_output_devices(model(devices.output_labels));
}
fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
crate::ui::appearance::wire(window, state, !cfg!(test));
crate::ui::avatar::wire(window, state, !cfg!(test));
{
let state = state.clone();
window.on_dismiss_status(move || state.borrow_mut().ui.status_msg = None);
}
{
let state = state.clone();
window.on_input_edited(move |text| state.borrow_mut().ui.remember_draft(text.to_string()));
}
{
let state = state.clone();
window
.on_address_edited(move |text| state.borrow_mut().ui.connect_input = text.to_string());
}
{
let state = state.clone();
window.on_auto_reconnect_changed(move |value| state.borrow_mut().ui.auto_reconnect = value);
}
{
let state = state.clone();
window
.on_friends_tab_changed(move |tab| state.borrow_mut().ui.friends_tab = tab.to_string());
}
{
let state = state.clone();
let weak = window.as_weak();
window.on_open_settings(move || {
state.borrow_mut().ui.settings_open = true;
if let Some(window) = weak.upgrade() {
refresh_devices(&window);
}
});
}
{
let state = state.clone();
window.on_show_voice_view(move || state.borrow_mut().ui.showing_voice = true);
}
{
let state = state.clone();
window.on_show_friends_view(move || state.borrow_mut().ui.select_friends());
}
{
let state = state.clone();
window.on_ptt_held(move |held| state.borrow_mut().ui.ptt_held = held);
}
{
let state = state.clone();
window.on_audio_settings_changed(move |input, output, bitrate, mode, volume| {
let mut s = state.borrow_mut();
s.ui.mic_device = input.max(0) as usize;
s.ui.output_device = output.max(0) as usize;
s.ui.voice_bitrate = bitrate.clamp(8.0, 128.0);
s.ui.vad_mode = mode.clamp(0, 2) as usize;
s.ui.output_volume = volume.clamp(0.0, 100.0);
if let Err(error) = crate::ui::preferences::save(&s.ui) {
s.ui.status_msg = Some(format!("Cannot save audio settings: {error}"));
}
});
}
{
let state = state.clone();
window.on_channel_selected(move |id| {
let id = id.to_string();
let mut s = state.borrow_mut();
s.ui.active_channel = Some(id.clone());
s.ui.active_dm_id = None;
let is_voice =
s.ui.channels
.iter()
.any(|c| c.id == id && c.kind == "voice");
if is_voice {
s.ui.showing_voice = true;
s.ui.status_msg = Some("Joining voice channel…".into());
} else {
s.ui.select_text_channel(id.clone());
}
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
@ -99,26 +232,51 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
let state = state.clone();
window.on_guild_selected(move |idx| {
let mut s = state.borrow_mut();
s.ui.active_guild_id = if idx >= 0 && (idx as usize) < s.ui.guilds.len() {
Some(s.ui.guilds[idx as usize].guild_id.clone())
s.ui.active_guild_id = if idx >= 0 {
s.ui.guilds
.get(idx as usize)
.map(|guild| guild.guild_id.clone())
} else {
None
};
s.ui.browsing_dms = false;
let destination =
s.ui.channels
.iter()
.find(|channel| {
channel.kind == "text"
&& (s.ui.active_guild_id.is_none()
|| channel.guild_id == s.ui.active_guild_id)
})
.map(|channel| channel.id.clone());
if let Some(channel_id) = destination {
s.ui.select_text_channel(channel_id.clone());
let net = s.net.clone();
tokio::spawn(async move {
net.send(NetCommand::JoinChannel { channel_id }).await;
});
} else {
s.ui.active_dm_id = None;
s.ui.active_channel = None;
s.ui.showing_voice = false;
}
});
}
{
let state = state.clone();
window.on_dm_selected(move |nickname| {
let nick = nickname.to_string();
window.on_dm_selected(move |dm_id| {
let mut s = state.borrow_mut();
if let Some(conv) =
s.ui.dm_conversations
.iter()
.find(|c| c.other_nickname == nick)
{
s.ui.active_dm_id = Some(conv.dm_id.clone());
s.ui.active_channel = None;
let id = dm_id.to_string();
if s.ui.dm_conversations.iter().any(|c| c.dm_id == id) {
s.ui.select_dm(id.clone());
if let Some(dm) = s.ui.dm_conversations.iter_mut().find(|c| c.dm_id == id) {
dm.unread_count = 0;
}
let net = s.net.clone();
tokio::spawn(async move {
net.send(NetCommand::DmReadAck { dm_id: id }).await;
});
}
});
}
@ -131,12 +289,13 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
s.ui.conn = ConnState::Connecting;
s.ui.connect_input = addr.clone();
s.ui.status_msg = Some("connecting...".into());
let auto_reconnect = s.ui.auto_reconnect;
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::Connect {
address: addr,
auto_reconnect: true,
auto_reconnect,
})
.await;
});
@ -160,14 +319,24 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
window.on_send_message(move |ch_id, text| {
let ch_id = ch_id.to_string();
let text = text.to_string();
if text.is_empty() {
if text.trim().is_empty() {
return;
}
let mut s = state.borrow_mut();
if !matches!(s.ui.conn, ConnState::Connected { .. }) {
s.ui.status_msg = Some("Нет соединения с сервером. Черновик сохранён.".into());
return;
}
if let Some(dm_id) = s.ui.active_dm_id.as_ref()
&& s.ui.dm_conversations.iter().any(|c| &c.dm_id == dm_id && c.e2ee_enabled)
{
s.ui.status_msg = Some("Зашифрованные сообщения временно недоступны. Черновик сохранён; сообщение не отправлено.".into());
return;
}
if let Some(edit_id) = s.ui.editing_message_id.take() {
let net = s.net.clone();
s.ui.chat_input = String::new();
s.ui.remember_draft(String::new());
drop(s);
tokio::spawn(async move {
net.send(NetCommand::MessageEdit {
@ -183,7 +352,7 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
let reply_to = s.ui.replying_to_message.take();
s.ui.replying_to_sender.clear();
s.ui.replying_to_content.clear();
s.ui.chat_input = String::new();
s.ui.remember_draft(String::new());
let net = s.net.clone();
drop(s);
@ -304,19 +473,25 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
let state = state.clone();
window.on_leave_voice(move || {
let mut s = state.borrow_mut();
s.ui.active_channel = None;
s.voice_channel = None;
s.audio = None;
s.last_pipeline_config = None;
s.ui.voice = VoiceUiState::Off;
s.ui.voice_joined_at = None;
let voice_channel = s.ui.voice_target.take();
crate::ui::update::stop_voice(&mut s);
s.ui.showing_voice = false;
s.ui.ptt_held = false;
let net = s.net.clone();
if let Some(channel_id) = voice_channel {
tokio::spawn(async move {
net.send(NetCommand::LeaveChannel { channel_id }).await;
});
}
});
}
{
let state = state.clone();
window.on_add_bookmark(move |_addr| {
state.borrow_mut().ui.add_bookmark_from_input();
window.on_add_bookmark(move |addr| {
let mut s = state.borrow_mut();
s.ui.connect_input = addr.to_string();
s.ui.add_bookmark_from_input();
});
}
@ -333,21 +508,21 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
{
let state = state.clone();
window.on_load_more(move |ch_id| {
let _ch_id = ch_id.to_string();
let state = state.borrow();
let net = state.net.clone();
drop(state);
tokio::spawn(async move {
net.send(NetCommand::ChannelList).await;
});
window.on_load_more(move |_| {
state.borrow_mut().ui.status_msg =
Some("Earlier history is not available with this protocol version.".into());
});
}
{
let state = state.clone();
let weak = window.as_weak();
window.on_close_settings(move || {
state.borrow_mut().ui.settings_open = false;
let mut state = state.borrow_mut();
state.ui.settings_open = false;
if let Some(window) = weak.upgrade() {
crate::ui::appearance::bindings_restore(&window, &state.ui.appearance);
}
});
}
@ -356,8 +531,7 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
window.on_set_passphrase(move |pass, confirm| {
let mut s = state.borrow_mut();
if pass != confirm {
s.ui.settings_passphrase_error =
Some("Passphrases do not match".to_string());
s.ui.settings_passphrase_error = Some("Passphrases do not match".to_string());
return;
}
if pass.len() < 8 {
@ -368,9 +542,9 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
s.ui.settings_passphrase_error = None;
let identity = s.identity.clone();
drop(s);
if let Err(e) = identity::save(&identity, Some(pass.as_str())) {
let mut s = state.borrow_mut();
s.ui.settings_passphrase_error = Some(format!("{e}"));
match identity::save(&identity, Some(pass.as_str())) {
Ok(()) => state.borrow_mut().ui.vault_enabled = true,
Err(e) => state.borrow_mut().ui.settings_passphrase_error = Some(format!("{e}")),
}
});
}
@ -381,9 +555,9 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
let s = state.borrow();
let identity = s.identity.clone();
drop(s);
if let Err(e) = identity::save(&identity, None) {
let mut s = state.borrow_mut();
s.ui.settings_passphrase_error = Some(format!("{e}"));
match identity::save(&identity, None) {
Ok(()) => state.borrow_mut().ui.vault_enabled = false,
Err(e) => state.borrow_mut().ui.settings_passphrase_error = Some(format!("{e}")),
}
});
}
@ -396,7 +570,11 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
s.ui.settings_export_error = Some("Passphrases do not match".to_string());
return;
}
let passphrase = if pass.is_empty() { None } else { Some(pass.as_str()) };
let passphrase = if pass.is_empty() {
None
} else {
Some(pass.as_str())
};
let identity = s.identity.clone();
drop(s);
match identity::export_keyfile(&identity, passphrase) {
@ -417,7 +595,11 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
let state = state.clone();
window.on_import_keyfile(move |input, pass| {
let input = input.to_string();
let passphrase = if pass.is_empty() { None } else { Some(pass.as_str()) };
let passphrase = if pass.is_empty() {
None
} else {
Some(pass.as_str())
};
let mut s = state.borrow_mut();
match identity::import_keyfile(&input, passphrase) {
Ok(identity) => {
@ -425,7 +607,11 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
s.ui.settings_import_error = Some(format!("{e}"));
} else {
s.ui.settings_import_error = None;
// Will need restart to take full effect
s.ui.vault_enabled = false;
s.ui.status_msg = Some(
"Профиль импортирован. Перезапусти Vnox, чтобы войти с новыми ключами."
.into(),
);
}
}
Err(e) => {
@ -461,15 +647,14 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
let msg_id = msg_id.to_string();
let mut s = state.borrow_mut();
s.ui.replying_to_message = Some(msg_id.clone());
if let Some(ch_id) = s.ui.active_channel.clone() {
if let Some(msgs) = s.ui.messages.get(&ch_id) {
if let Some(m) = msgs.iter().find(|m| m.message_id == msg_id) {
let sender = m.sender_id.clone();
let content = m.content.clone();
s.ui.replying_to_sender = sender;
s.ui.replying_to_content = content;
}
}
if let Some(ch_id) = s.ui.active_channel.clone()
&& let Some(msgs) = s.ui.messages.get(&ch_id)
&& let Some(m) = msgs.iter().find(|m| m.message_id == msg_id)
{
let sender = m.sender_id.clone();
let content = m.content.clone();
s.ui.replying_to_sender = s.ui.nick_for(&sender).to_owned();
s.ui.replying_to_content = content;
}
});
}
@ -489,13 +674,13 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
window.on_edit_msg(move |msg_id| {
let msg_id = msg_id.to_string();
let mut s = state.borrow_mut();
if let Some(ch_id) = s.ui.active_channel.clone() {
if let Some(msgs) = s.ui.messages.get(&ch_id) {
if let Some(m) = msgs.iter().find(|m| m.message_id == msg_id) {
s.ui.chat_input = m.content.clone();
s.ui.editing_message_id = Some(msg_id);
}
}
if let Some(ch_id) = s.ui.active_channel.clone()
&& let Some(msgs) = s.ui.messages.get(&ch_id)
&& let Some(m) = msgs.iter().find(|m| m.message_id == msg_id)
{
let content = m.content.clone();
s.ui.remember_draft(content);
s.ui.editing_message_id = Some(msg_id);
}
});
}
@ -518,3 +703,6 @@ fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
});
}
}
#[cfg(test)]
mod ui_smoke;