fix(receiver): add filepath for download on android. #105

Merged
ikeen0807 merged 1 commit from main into 101-implement-the-gui-for-native-desktop-apps-in-tauri-20-with-angular 2024-05-21 09:22:35 +02:00

View file

@ -22,6 +22,9 @@ use tracing::error;
const DESTINATION: u8 = 0; const DESTINATION: u8 = 0;
const NONCE_SIZE: usize = 12; const NONCE_SIZE: usize = 12;
#[cfg(target_os = "android")]
const FILE_PATH_PREFIX: &str = "/storage/emulated/0/Download";
struct File { struct File {
name: String, name: String,
size: u64, size: u64,
@ -73,11 +76,29 @@ fn on_list(context: &mut Context, list: ListPacket) -> Status {
for entry in list.entries { for entry in list.entries {
let path = sanitize_filename::sanitize(entry.name.clone()); let path = sanitize_filename::sanitize(entry.name.clone());
#[cfg(target_os = "android")]
let file_path = format!("{}/{}", FILE_PATH_PREFIX, path);
#[cfg(target_os = "android")]
if Path::new(&file_path).exists() {
return Status::Err(format!("The file '{}' already exists.", path));
}
#[cfg(target_os = "android")]
let 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(not(target_os = "android"))]
if Path::new(&path).exists() { if Path::new(&path).exists() {
return Status::Err(format!("The file '{}' already exists.", path)); return Status::Err(format!("The file '{}' already exists.", path));
} }
#[cfg(not(target_os = "android"))]
let handle = match fs::File::create(&path) { let handle = match fs::File::create(&path) {
Ok(handle) => handle, Ok(handle) => handle,
Err(error) => { Err(error) => {