FileEngine: expose native file types on different platforms (#1258)

* Get native file

* Correct visibility
This commit is contained in:
wooden-worm authored and GitHub committed 2023-08-17 08:03:56 -05:00
1 parent fa39408d58
commit f652474a6e
4 files changed
+40 -1

No files matched your search

+23
View File
@@ -1,3 +1,5 @@
use std::any::Any;
use dioxus_html::FileEngine;
use futures_channel::oneshot;
use js_sys::Uint8Array;
@@ -100,4 +102,25 @@ impl FileEngine for WebFileEngine {
None
}
}
async fn get_native_file(&self, file: &str) -> Option<Box<dyn Any>> {
let file = self.find(file)?;
Some(Box::new(file))
}
}
/// Helper trait for WebFileEngine
#[async_trait::async_trait(?Send)]
pub trait WebFileEngineExt {
/// returns web_sys::File
async fn get_web_file(&self, file: &str) -> Option<web_sys::File>;
}
#[async_trait::async_trait(?Send)]
impl WebFileEngineExt for std::sync::Arc<dyn FileEngine> {
async fn get_web_file(&self, file: &str) -> Option<web_sys::File> {
let native_file = self.get_native_file(file).await?;
let ret = native_file.downcast::<web_sys::File>().ok()?;
Some(*ret)
}
}
+1
View File
@@ -54,6 +54,7 @@
// - Do DOM work in the next requestAnimationFrame callback
pub use crate::cfg::Config;
pub use crate::file_engine::WebFileEngineExt;
use dioxus_core::{Element, Scope, VirtualDom};
use futures_util::{
future::{select, Either},