Added `mime` field to `DroppedFiles` (#3273)
This commit is contained in:
parent
ec506c0a43
commit
2c5fc5a0a5
|
|
@ -473,6 +473,7 @@ pub fn install_canvas_events(runner_ref: &WebRunner) -> Result<(), JsValue> {
|
||||||
for i in 0..files.length() {
|
for i in 0..files.length() {
|
||||||
if let Some(file) = files.get(i) {
|
if let Some(file) = files.get(i) {
|
||||||
let name = file.name();
|
let name = file.name();
|
||||||
|
let mime = file.type_();
|
||||||
let last_modified = std::time::UNIX_EPOCH
|
let last_modified = std::time::UNIX_EPOCH
|
||||||
+ std::time::Duration::from_millis(file.last_modified() as u64);
|
+ std::time::Duration::from_millis(file.last_modified() as u64);
|
||||||
|
|
||||||
|
|
@ -491,6 +492,7 @@ pub fn install_canvas_events(runner_ref: &WebRunner) -> Result<(), JsValue> {
|
||||||
runner_lock.input.raw.dropped_files.push(
|
runner_lock.input.raw.dropped_files.push(
|
||||||
egui::DroppedFile {
|
egui::DroppedFile {
|
||||||
name,
|
name,
|
||||||
|
mime,
|
||||||
last_modified: Some(last_modified),
|
last_modified: Some(last_modified),
|
||||||
bytes: Some(bytes.into()),
|
bytes: Some(bytes.into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,9 @@ pub struct DroppedFile {
|
||||||
/// Name of the file. Set by the `eframe` web backend.
|
/// Name of the file. Set by the `eframe` web backend.
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
||||||
|
/// With the `eframe` web backend, this is set to the mime-type of the file (if available).
|
||||||
|
pub mime: String,
|
||||||
|
|
||||||
/// Set by the `eframe` web backend.
|
/// Set by the `eframe` web backend.
|
||||||
pub last_modified: Option<std::time::SystemTime>,
|
pub last_modified: Option<std::time::SystemTime>,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -460,9 +460,18 @@ impl WrapApp {
|
||||||
} else {
|
} else {
|
||||||
"???".to_owned()
|
"???".to_owned()
|
||||||
};
|
};
|
||||||
if let Some(bytes) = &file.bytes {
|
|
||||||
write!(info, " ({} bytes)", bytes.len()).ok();
|
let mut additional_info = vec![];
|
||||||
|
if !file.mime.is_empty() {
|
||||||
|
additional_info.push(format!("type: {}", file.mime));
|
||||||
}
|
}
|
||||||
|
if let Some(bytes) = &file.bytes {
|
||||||
|
additional_info.push(format!("{} bytes", bytes.len()));
|
||||||
|
}
|
||||||
|
if !additional_info.is_empty() {
|
||||||
|
info += &format!(" ({})", additional_info.join(", "));
|
||||||
|
}
|
||||||
|
|
||||||
ui.label(info);
|
ui.label(info);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,18 @@ impl eframe::App for MyApp {
|
||||||
} else {
|
} else {
|
||||||
"???".to_owned()
|
"???".to_owned()
|
||||||
};
|
};
|
||||||
if let Some(bytes) = &file.bytes {
|
|
||||||
use std::fmt::Write as _;
|
let mut additional_info = vec![];
|
||||||
write!(info, " ({} bytes)", bytes.len()).ok();
|
if !file.mime.is_empty() {
|
||||||
|
additional_info.push(format!("type: {}", file.mime));
|
||||||
}
|
}
|
||||||
|
if let Some(bytes) = &file.bytes {
|
||||||
|
additional_info.push(format!("{} bytes", bytes.len()));
|
||||||
|
}
|
||||||
|
if !additional_info.is_empty() {
|
||||||
|
info += &format!(" ({})", additional_info.join(", "));
|
||||||
|
}
|
||||||
|
|
||||||
ui.label(info);
|
ui.label(info);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue