Skip to content

Commit 2c5fc5a

Browse files
authored
Added mime field to DroppedFiles (#3273)
1 parent ec506c0 commit 2c5fc5a

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

crates/eframe/src/web/events.rs

+2
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ pub fn install_canvas_events(runner_ref: &WebRunner) -> Result<(), JsValue> {
473473
for i in 0..files.length() {
474474
if let Some(file) = files.get(i) {
475475
let name = file.name();
476+
let mime = file.type_();
476477
let last_modified = std::time::UNIX_EPOCH
477478
+ std::time::Duration::from_millis(file.last_modified() as u64);
478479

@@ -491,6 +492,7 @@ pub fn install_canvas_events(runner_ref: &WebRunner) -> Result<(), JsValue> {
491492
runner_lock.input.raw.dropped_files.push(
492493
egui::DroppedFile {
493494
name,
495+
mime,
494496
last_modified: Some(last_modified),
495497
bytes: Some(bytes.into()),
496498
..Default::default()

crates/egui/src/data/input.rs

+3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ pub struct DroppedFile {
155155
/// Name of the file. Set by the `eframe` web backend.
156156
pub name: String,
157157

158+
/// With the `eframe` web backend, this is set to the mime-type of the file (if available).
159+
pub mime: String,
160+
158161
/// Set by the `eframe` web backend.
159162
pub last_modified: Option<std::time::SystemTime>,
160163

crates/egui_demo_app/src/wrap_app.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,18 @@ impl WrapApp {
460460
} else {
461461
"???".to_owned()
462462
};
463+
464+
let mut additional_info = vec![];
465+
if !file.mime.is_empty() {
466+
additional_info.push(format!("type: {}", file.mime));
467+
}
463468
if let Some(bytes) = &file.bytes {
464-
write!(info, " ({} bytes)", bytes.len()).ok();
469+
additional_info.push(format!("{} bytes", bytes.len()));
465470
}
471+
if !additional_info.is_empty() {
472+
info += &format!(" ({})", additional_info.join(", "));
473+
}
474+
466475
ui.label(info);
467476
}
468477
});

examples/file_dialog/src/main.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,18 @@ impl eframe::App for MyApp {
5353
} else {
5454
"???".to_owned()
5555
};
56+
57+
let mut additional_info = vec![];
58+
if !file.mime.is_empty() {
59+
additional_info.push(format!("type: {}", file.mime));
60+
}
5661
if let Some(bytes) = &file.bytes {
57-
use std::fmt::Write as _;
58-
write!(info, " ({} bytes)", bytes.len()).ok();
62+
additional_info.push(format!("{} bytes", bytes.len()));
5963
}
64+
if !additional_info.is_empty() {
65+
info += &format!(" ({})", additional_info.join(", "));
66+
}
67+
6068
ui.label(info);
6169
}
6270
});

0 commit comments

Comments
 (0)