Phase 2: E2EE for DM + Slint migration + dead code cleanup

- E2EE crypto (src/e2ee.rs) with X25519 key derivation from Ed25519,
  HKDF shared secret, ChaCha20-Poly1305 encrypt/decrypt
- E2EE net layer: PID 0x0071-0x0074, JSON payloads, dispatch, session handlers
- E2EE UI: lock icons in DM header and sidebar
- Slint migration: all .slint files, bridge.rs, update.rs, main.rs
- Removed egui UI (~50 files), cleaned all dead code
- Clean cargo clippy -- -D warnings
This commit is contained in:
Loki 2026-07-14 13:25:15 +02:00
parent f361b037cb
commit 03d94e0465
Signed by: boba
GPG key ID: 253067914055423B
83 changed files with 5055 additions and 9202 deletions

View file

@ -1,17 +1,36 @@
mod ui;
pub use ui::VnoxApp;
pub use ui::{chat, connect, keybind, members, settings, sidebar, state, theme, titlebar};
use std::cell::RefCell;
use std::rc::Rc;
use std::time::Duration;
use crate::ui::slint::MainWindow;
use anyhow::Result;
use slint::ComponentHandle;
use tracing::info;
use tracing_subscriber::EnvFilter;
use vnox_client::{identity, net};
use vnox_client::audio::AudioPipeline;
use vnox_client::audio::PipelineConfig;
use vnox_client::identity;
use vnox_client::net;
use vnox_client::net::NetCommand;
use vnox_client::net::NetHandle;
use crate::ui::state::{ConnState, UiState, VoiceUiState};
pub struct AppState {
pub(crate) identity: identity::Identity,
pub(crate) net: NetHandle,
pub(crate) ui: UiState,
pub(crate) audio: Option<AudioPipeline>,
pub(crate) voice_channel: Option<String>,
pub(crate) last_pipeline_config: Option<PipelineConfig>,
}
fn main() -> Result<()> {
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
EnvFilter::new("info,wgpu=warn,wgpu_hal=warn,egui_wgpu=warn,naga=warn")
});
let filter = EnvFilter::try_from_default_env()
.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()?;
@ -24,16 +43,306 @@ fn main() -> Result<()> {
let net = net::spawn(identity.clone());
eframe::run_native(
"Vnox",
eframe::NativeOptions {
viewport: eframe::egui::ViewportBuilder::default()
.with_title("Vnox")
.with_inner_size([900.0, 560.0])
.with_min_inner_size([600.0, 400.0]),
..Default::default()
},
Box::new(|cc| Ok(Box::new(ui::VnoxApp::new(cc, identity, net)))),
)
.map_err(|e| anyhow::anyhow!("eframe: {e}"))
let state = Rc::new(RefCell::new(AppState {
identity,
net,
ui: UiState::default(),
audio: None,
voice_channel: None,
last_pipeline_config: None,
}));
let window = MainWindow::new()?;
wire_signals(&window, &state);
let timer = slint::Timer::default();
{
let state = state.clone();
let weak = window.as_weak();
timer.start(
slint::TimerMode::Repeated,
Duration::from_millis(16),
move || {
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();
crate::ui::bridge::sync_ui(&win, &s.ui, &own_id);
}
},
);
}
window.run()?;
Ok(())
}
fn wire_signals(window: &MainWindow, state: &Rc<RefCell<AppState>>) {
{
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 net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::JoinChannel { channel_id: id }).await;
});
});
}
{
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())
} else {
None
};
});
}
{
let state = state.clone();
window.on_dm_selected(move |nickname| {
let nick = nickname.to_string();
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 state = state.clone();
window.on_connect(move |addr| {
let addr = addr.to_string();
let mut s = state.borrow_mut();
s.ui.conn = ConnState::Connecting;
s.ui.connect_input = addr.clone();
s.ui.status_msg = Some("connecting...".into());
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::Connect {
address: addr,
auto_reconnect: true,
})
.await;
});
});
}
{
let state = state.clone();
window.on_disconnect(move || {
let s = state.borrow();
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::Disconnect).await;
});
});
}
{
let state = state.clone();
window.on_send_message(move |ch_id, text| {
let ch_id = ch_id.to_string();
let text = text.to_string();
if text.is_empty() {
return;
}
let mut s = state.borrow_mut();
s.ui.chat_input = String::new();
let net = s.net.clone();
drop(s);
if !ch_id.is_empty() {
tokio::spawn(async move {
net.send(NetCommand::SendChat {
channel_id: ch_id,
content: text,
reply_to: None,
})
.await;
});
} else {
let s = state.borrow();
if let Some(dm_id) = s.ui.active_dm_id.clone() {
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::DmSend {
dm_id,
content: text,
})
.await;
});
}
}
});
}
{
let state = state.clone();
window.on_add_friend(move |user_id| {
let user_id = user_id.to_string();
let s = state.borrow();
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::FriendRequest {
target_user_id: user_id,
})
.await;
});
});
}
{
let state = state.clone();
window.on_accept_friend(move |user_id| {
let user_id = user_id.to_string();
let s = state.borrow();
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::FriendAccept { user_id }).await;
});
});
}
{
let state = state.clone();
window.on_decline_friend(move |user_id| {
let user_id = user_id.to_string();
let s = state.borrow();
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::FriendDecline { user_id }).await;
});
});
}
{
let state = state.clone();
window.on_remove_friend(move |user_id| {
let user_id = user_id.to_string();
let s = state.borrow();
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::FriendRemove { user_id }).await;
});
});
}
{
let state = state.clone();
window.on_start_dm(move |user_id| {
let user_id = user_id.to_string();
let s = state.borrow();
let net = s.net.clone();
drop(s);
tokio::spawn(async move {
net.send(NetCommand::DmStart {
target_user_id: user_id,
})
.await;
});
});
}
{
let state = state.clone();
window.on_toggle_mic(move || {
let mut s = state.borrow_mut();
s.ui.mic_enabled = !s.ui.mic_enabled;
});
}
{
let state = state.clone();
window.on_toggle_deafen(move || {
let mut s = state.borrow_mut();
s.ui.deafen = !s.ui.deafen;
});
}
{
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 state = state.clone();
window.on_add_bookmark(move |_addr| {
state.borrow_mut().ui.add_bookmark_from_input();
});
}
{
let state = state.clone();
window.on_remove_bookmark(move |address| {
let addr = address.to_string();
let mut s = state.borrow_mut();
if let Some(idx) = s.ui.bookmarks.iter().position(|b| b.address == addr) {
s.ui.remove_bookmark(idx);
}
});
}
{
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;
});
});
}
{
let state = state.clone();
window.on_close_settings(move || {
state.borrow_mut().ui.settings_open = false;
});
}
{
let _state = state.clone();
window.on_set_passphrase(move |_pass| {});
}
{
let _state = state.clone();
window.on_export_keyfile(move || {});
}
{
let _state = state.clone();
window.on_import_keyfile(move || {});
}
}