refactir(gui): added flutter version with flutter_rust_bridge

This commit is contained in:
Patryk Hegenberg 2024-05-16 20:25:21 +02:00
parent f1e48f6d12
commit fbb181d95b
200 changed files with 11018 additions and 84 deletions

View file

@ -22,6 +22,13 @@ use tracing::error;
const DESTINATION: u8 = 0;
const NONCE_SIZE: usize = 12;
#[cfg(target_os = "android")]
// const FILE_PATH_PREFIX: &str = "/storage/emulated/0/Documents/";
const FILE_PATH_PREFIX: &str = "/data/data/rust.executor_android/files";
#[cfg(not(target_os = "android"))]
const FILE_PATH_PREFIX: &str = ".";
struct File {
name: String,
size: u64,
@ -126,6 +133,24 @@ fn on_chunk(context: &mut Context, chunk: ChunkPacket) -> Status {
context.sequence += 1;
#[cfg(target_os = "android")]
let file_path = format!("{}/{}", FILE_PATH_PREFIX, file.name);
// Öffnen Sie die Datei mit dem generierten Pfad
#[cfg(target_os = "android")]
let mut file_handle = match fs::File::create(&file_path) {
Ok(handle) => handle,
Err(error) => {
return Status::Err(format!(
"Error: Failed to create file '{}': {}",
file_path, error
));
}
};
#[cfg(target_os = "android")]
file_handle.write(&chunk.chunk).unwrap();
#[cfg(not(target_os = "android"))]
file.handle.write(&chunk.chunk).unwrap();
file.progress = (context.length * 100) / file.size;

View file

@ -144,16 +144,7 @@ fn on_leave_room(context: &mut Context, _: usize) -> Status {
Status::Continue()
}
async fn send_progress(
progress_tx: &mpsc::Sender<String>,
progress_message: String,
) -> Result<(), mpsc::error::SendError<String>> {
progress_tx.send(progress_message).await
}
fn on_progress(context: &Context, progress: ProgressPacket) -> Status {
// let prog_sender = ProgressSender::new();
let (progress_tx, _) = mpsc::channel(100);
if context.shared_key.is_none() {
return Status::Err("Invalid progress packet: no shared key established".into());
}
@ -163,23 +154,9 @@ fn on_progress(context: &Context, progress: ProgressPacket) -> Status {
None => return Status::Err("Invalid index in progress packet.".into()),
};
let progress_message = format!("\rTransferring '{}': {}%", file.name, progress.progress);
print!("\rTransferring '{}': {}%", file.name, progress.progress);
stdout().flush().unwrap();
let send_result = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(send_progress(&progress_tx, progress_message));
if let Err(e) = send_result {
eprintln!("Fehler beim Senden der Fortschrittsnachricht: {}", e);
}
// let progress_message = format!("Transferring '{}': {}%", file.name, progress.progress);
// print!("\r{}", progress_message);
// stdout().flush().unwrap();
// prog_sender.0.send(progress_message);
//
if progress.progress == 100 {
println!();