Implement Rust and Slint native client migration and fix desktop startup
ci / linux-arm64-cross (push) Successful in 4m7s
ci / linux-x64 (push) Successful in 4m42s

This commit is contained in:
omar committed 2026-11-10 15:45:24 +03:00
1 parent 0d11f8f99d
commit eb24965076
1303 files changed
+732670 -2375

No files matched your search

+79
View File
@@ -0,0 +1,79 @@
//! Send-only presentation state. Slint Images are created exclusively by the attachment.
use std::{collections::HashSet,sync::Arc};
use crate::{app::connections::{ConnectionsSnapshot,SessionKey},ui::{shell::*,settings::{SettingsSnapshot,ViewState},chat::ChatPresentation,i18n::{Catalog,Language}}};
use super::{context::RuntimeServices,events::UiEffect};
#[derive(Clone,Debug,PartialEq,Eq)]
pub enum BootstrapState {Loading,ChooseProfile,RecoverImport,Username,Ready,Failed}
#[derive(Clone)]
pub struct Snapshot {
pub revision:u64,pub bootstrap:BootstrapState,pub root:Option<std::path::PathBuf>,pub catalog:Catalog,
pub ready:bool,pub audio_input_active:bool,pub audio_output_active:bool,
pub audio_input_starts:u64,pub audio_output_starts:u64,
pub connections:Arc<ConnectionsSnapshot>,pub tabs:Vec<Tab>,pub tree:Vec<Entry>,pub bookmarks:Vec<Entry>,pub contacts:Vec<Entry>,
pub detail:Detail,pub actions:Vec<Action>,pub voice:Option<Voice>,pub profile_form:Option<Form>,pub dialog:Option<Form>,
pub last_error:Option<crate::services::ServiceError>,pub settings_completed:u64,
pub status:String,pub error:String,pub loading:bool,pub destination:Destination,
pub settings:SettingsSnapshot,pub settings_view:ViewState,pub chat:ChatPresentation,
pub streams:Vec<super::stream_actions::StreamPresentation>,
#[cfg(feature="webrtc")]
pub frames:Vec<(String,Arc<crate::media::stream::frames::VideoFrames>)>,
pub theme:Option<crate::services::themes::ResolvedTheme>,
pub theme_revision:u64,pub theme_fonts:Vec<super::theme_actions::ThemeFont>,
pub insets:crate::platform::lifecycle::Insets,pub text_scale:f32,pub reduced_motion:bool,pub high_contrast:bool,
}
impl Default for Snapshot {
fn default()->Self{Self{revision:0,ready:false,last_error:None,settings_completed:0,audio_input_active:false,audio_output_active:false,audio_input_starts:0,audio_output_starts:0,bootstrap:BootstrapState::Loading,root:None,catalog:Catalog::default(),connections:Arc::default(),tabs:vec![],tree:vec![],bookmarks:vec![],contacts:vec![],detail:Detail::default(),actions:vec![],voice:None,profile_form:None,dialog:None,status:String::new(),error:String::new(),loading:true,destination:Destination::Servers,settings:SettingsSnapshot::default(),settings_view:ViewState::default(),chat:ChatPresentation::default(),streams:vec![],#[cfg(feature="webrtc")]frames:vec![],theme:None,theme_revision:0,theme_fonts:vec![],insets:Default::default(),text_scale:1.,reduced_motion:false,high_contrast:false}}
}
pub struct AppState {
pub snapshot:Snapshot,pub selected:Option<Target>,pub expanded:HashSet<(String,u64)>,pub folder:Option<String>,
pub detail_target:Option<Target>,pub detail_operation:Option<Operation>,pub query:crate::app::server_actions::QueryOptions,
}
impl Default for AppState{fn default()->Self{Self{snapshot:Snapshot::default(),selected:None,expanded:HashSet::new(),folder:None,detail_target:None,detail_operation:None,query:Default::default()}}}
impl AppState {
pub fn apply(&mut self,effect:&UiEffect){match effect{
UiEffect::Detail{target,detail}=>{self.detail_target=Some(target.clone());self.snapshot.detail=detail.clone();},
UiEffect::Navigate(destination)=>self.snapshot.destination=*destination,
UiEffect::BookmarkFolder(folder)=>self.folder=folder.clone(),
UiEffect::SettingsNavigate(nav)=>{self.snapshot.settings_view.navigate(nav);self.snapshot.destination=Destination::Settings;},
UiEffect::Status(value)=>self.snapshot.status=value.clone(),UiEffect::Error(error)=>{self.snapshot.error=error.message.clone();self.snapshot.last_error=Some(error.clone());},
UiEffect::SettingsComplete{serial,result}=>{self.snapshot.settings_completed=*serial;self.snapshot.last_error=result.as_ref().err().cloned();self.snapshot.error=result.as_ref().err().map(|e|e.message.clone()).unwrap_or_default();},
UiEffect::Theme(theme)=>self.snapshot.theme=Some(theme.clone()),_=>{}
}}
pub async fn project(&mut self,ctx:&RuntimeServices)->crate::services::Result<()> {
let prefs=ctx.profile()?.prefs.get();let c=Catalog::new(Language::from_code(prefs["language"].as_str().unwrap_or("en")));
self.snapshot.catalog=c;let connections=ctx.connected.connections.snapshot();
self.snapshot.tabs=connections.connections.iter().map(|connection|{
let target=Target{session:Some(connection.key.clone()),entity:Entity::Connection,name:connection.server.as_ref().and_then(|s|s["server"]["name"].as_str()).filter(|s|!s.is_empty()).unwrap_or(if connection.address.is_empty(){"TeamsPeach"}else{&connection.address}).into(),own_channel_id:connection.server.as_ref().and_then(|s|s["own_channel_id"].as_u64())};
let mut operations=if connection.is_connected(){vec![Operation::Disconnect,Operation::UseMicrophone,Operation::SetNickname,Operation::SetAway,Operation::ServerChat,Operation::RecordingOpen,Operation::CaptureChoose]}else{vec![Operation::Connect,Operation::RestartCore]};operations.push(Operation::CloseConnection);
Tab{title:target.name.clone(),selected:connections.viewed_id.as_deref()==Some(&connection.key.connection_id),microphone_owner:connections.input_id.as_deref()==Some(&connection.key.connection_id),connected:connection.is_connected(),unread:ctx.notifications.lock().ok().and_then(|n|n.unread_count(&connection.key).ok()).unwrap_or(0).min(usize::MAX as u64) as usize,actions:actions(&target,&operations,&c),target}
}).collect();
let viewed=connections.viewed_id.as_deref().and_then(|id|connections.get(id));
self.snapshot.tree.clear();
if let Some(connection)=viewed {if let Some(server)=connection.server.as_ref(){
let target=Target{session:Some(connection.key.clone()),entity:Entity::Server{uid:server["server"]["uid"].as_str().unwrap_or_default().into()},name:server["server"]["name"].as_str().unwrap_or_default().into(),own_channel_id:server["own_channel_id"].as_u64()};
let mut entry=entry(target.clone(),"server".into(),0);entry.expandable=true;entry.expanded=true;entry.actions=actions(&target,&[Operation::ServerInfo,Operation::ServerEdit,Operation::ServerChat,Operation::ServerPermissions,Operation::ServerBans,Operation::ServerKeys,Operation::ServerPasswords,Operation::ServerIcons,Operation::ServerClients,Operation::ServerLog,Operation::ChannelCreate,Operation::SubscribeAll,Operation::UnsubscribeAll,Operation::TransferList,Operation::RecordingOpen,Operation::SnapshotExport,Operation::SnapshotChoose,Operation::KeyUse,Operation::TalkQueue,Operation::CaptureChoose],&c);self.snapshot.tree.push(entry);
let mut visited=HashSet::new();self.channel_children(ctx,&connection.key,server,0,1,&mut visited,&c);
}}
self.snapshot.voice=connections.input_id.as_deref().and_then(|id|connections.get(id)).filter(|s|s.is_connected()).map(|s|Voice{target:Target{session:Some(s.key.clone()),entity:Entity::Connection,name:s.address.clone(),own_channel_id:s.server.as_ref().and_then(|v|v["own_channel_id"].as_u64())},title:s.server.as_ref().and_then(|v|v["server"]["name"].as_str()).unwrap_or(&s.address).into(),muted:s.audio.input_muted,deafened:s.audio.output_muted,transmitting:s.audio.transmitting,ptt_enabled:prefs["pttEnabled"]==true&&!s.audio.input_muted,status:format!("{:?}",s.state)});
self.snapshot.actions=actions(&Target::application(),&[Operation::NewConnection,Operation::BookmarkCreate,Operation::BookmarkFolderCreate,Operation::ContactAdd,Operation::OpenLogs],&c);
self.snapshot.bookmarks.clear();
for folder in prefs["bookmarkFolders"].as_array().into_iter().flatten(){if folder["parent"].as_str()!=self.folder.as_deref(){continue}if let Some(id)=folder["id"].as_str(){let target=Target{entity:Entity::BookmarkFolder(id.into()),name:folder["name"].as_str().unwrap_or_default().into(),..Target::application()};let mut e=entry(target.clone(),format!("folder:{id}"),0);e.actions=actions(&target,&[Operation::BookmarkFolderOpen,Operation::BookmarkFolderRename,Operation::BookmarkFolderDelete],&c);self.snapshot.bookmarks.push(e);}}
if self.folder.is_some(){self.snapshot.actions.extend(actions(&Target::application(),&[Operation::BookmarkFolderUp],&c));}
for bookmark in prefs["savedServers"].as_array().into_iter().flatten(){if bookmark["folder"].as_str()!=self.folder.as_deref(){continue}if let Some(id)=bookmark["id"].as_str(){let target=Target{entity:Entity::Bookmark(id.into()),name:bookmark["name"].as_str().unwrap_or_default().into(),..Target::application()};let mut e=entry(target.clone(),format!("bookmark:{id}"),0);e.subtitle=bookmark["address"].as_str().unwrap_or_default().into();e.actions=actions(&target,&[Operation::BookmarkConnect,Operation::BookmarkEdit,Operation::BookmarkRename,Operation::BookmarkDuplicate,Operation::BookmarkMove,Operation::BookmarkPasswordSet,Operation::BookmarkPasswordReveal,Operation::BookmarkPasswordClear,Operation::BookmarkDelete],&c);self.snapshot.bookmarks.push(e);}}
self.snapshot.contacts.clear();for contact in prefs["contacts"].as_array().into_iter().flatten(){if let Some(uid)=contact["uid"].as_str(){let target=Target{entity:Entity::Contact(uid.into()),name:contact["alias"].as_str().filter(|s|!s.is_empty()).or_else(||contact["name"].as_str()).unwrap_or(uid).into(),..Target::application()};let mut e=entry(target.clone(),format!("contact:{uid}"),0);e.subtitle=uid.into();e.actions=actions(&target,&[Operation::ContactChat,Operation::ContactRename,Operation::ContactIgnore,Operation::ContactUnignore,Operation::ContactRemove],&c);self.snapshot.contacts.push(e);}}
if self.detail_target.as_ref().is_some_and(|t|ctx.require_target(t).is_err()){self.detail_target=None;self.snapshot.detail=Detail::default();}
self.snapshot.settings=super::settings_actions::project(ctx,&self.snapshot.settings_view)?;
self.snapshot.chat=super::chat_actions::project(ctx).await?;
self.snapshot.streams=super::stream_actions::project(ctx).await?;
#[cfg(feature="webrtc")] {self.snapshot.frames=super::stream_actions::frame_sources(ctx).await;}
self.snapshot.connections=connections;self.snapshot.loading=false;self.snapshot.bootstrap=BootstrapState::Ready;Ok(())
}
fn channel_children(&mut self,ctx:&RuntimeServices,key:&SessionKey,server:&serde_json::Value,parent:u64,depth:usize,visited:&mut HashSet<u64>,c:&Catalog){
if depth>24{return}let mut channels=server["channels"].as_array().into_iter().flatten().filter(|v|v["parent_id"].as_u64()==Some(parent)).collect::<Vec<_>>();channels.sort_by_key(|v|v["order"].as_u64().unwrap_or(0));
for channel in channels{let Some(id)=channel["id"].as_u64()else{continue};if !visited.insert(id){continue}let target=Target{session:Some(key.clone()),entity:Entity::Channel{id},name:channel["name"].as_str().unwrap_or_default().into(),own_channel_id:server["own_channel_id"].as_u64()};let mut e=entry(target.clone(),format!("channel:{id}"),depth);e.selected=self.selected.as_ref()==Some(&target);e.expandable=true;e.expanded=!self.expanded.contains(&(key.connection_id.clone(),id));e.actions=actions(&target,&[Operation::JoinChannel,Operation::ChannelInfo,Operation::ChannelCreateChild,Operation::ChannelEdit,Operation::ChannelMove,Operation::ChannelDelete,Operation::ChannelSubscribe,Operation::ChannelUnsubscribe,Operation::ChannelWhisperAdd,Operation::GroupPermissions,Operation::FileBrowse],c);let expanded=e.expanded;self.snapshot.tree.push(e);
if !expanded{continue}for client in server["clients"].as_array().into_iter().flatten().filter(|v|v["channel_id"].as_u64()==Some(id)){let(Some(client_id),Some(uid))=(client["id"].as_u64().and_then(|n|u16::try_from(n).ok()),client["uid"].as_str())else{continue};let target=Target{session:Some(key.clone()),entity:Entity::Client{id:client_id,uid:uid.into(),channel_id:id},name:client["nickname"].as_str().unwrap_or_default().into(),own_channel_id:server["own_channel_id"].as_u64()};let mut e=entry(target.clone(),format!("client:{client_id}:{uid}"),depth+1);e.selected=self.selected.as_ref()==Some(&target);e.muted=client["input_muted"]==true;e.talking=ctx.connected.connections.snapshot().get(&key.connection_id).is_some_and(|s|s.talking.contains(&client_id));e.actions=actions(&target,&[Operation::ClientInfo,Operation::ClientConnectionInfo,Operation::ClientPrivateChat,Operation::ClientPoke,Operation::ClientVolume,Operation::ClientWhisperAdd,Operation::ClientMove,Operation::ClientKickChannel,Operation::ClientKickServer,Operation::ClientBan,Operation::ClientCommander,Operation::ClientServerGroupAdd,Operation::ClientServerGroupRemove,Operation::ClientChannelGroupSet,Operation::ClientPermissions,Operation::ClientChannelPermissionSet,Operation::ClientChannelPermissionRemove,Operation::ClientAvatarChoose,Operation::ClientAvatarDelete,Operation::TalkGrant,Operation::TalkRevoke,Operation::ContactAdd],c);self.snapshot.tree.push(e);}self.channel_children(ctx,key,server,id,depth+1,visited,c);
}
}
}
fn entry(target:Target,id:String,depth:usize)->Entry{Entry{id,title:target.name.clone(),target,subtitle:String::new(),depth,selected:false,expanded:false,expandable:false,talking:false,muted:false,unread:0,actions:vec![]}}
pub fn actions(target:&Target,operations:&[Operation],catalog:&Catalog)->Vec<Action>{operations.iter().map(|op|{let mut action=Action::new(format!("{op:?}"),*op,target.clone(),catalog);super::local_actions::prepare_action(&mut action);if target.session.is_some()||matches!(op,Operation::CaptureChoose|Operation::CapturePreview|Operation::CaptureStart|Operation::StreamVolume){action.form=None;}action}).collect()}