mirror of
https://github.com/kirjavascript/trueLMAO.git
synced 2024-05-20 05:10:21 -04:00
clean up some file stuff
This commit is contained in:
parent
5cb116c40d
commit
5cc74ced10
|
@ -112,11 +112,11 @@ impl eframe::App for App {
|
|||
}
|
||||
|
||||
if ui.button("Open file…").clicked() {
|
||||
self.file.open_file();
|
||||
self.file.open();
|
||||
}
|
||||
|
||||
|
||||
if let Some(file) = self.file.opened() {
|
||||
if let Some(file) = self.file.get() {
|
||||
println!("{:#?}", file);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -53,7 +53,7 @@ impl Drop for FileDialog {
|
|||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
impl FileDialog {
|
||||
pub fn open_file(&mut self) {
|
||||
pub fn open(&mut self) {
|
||||
if let Some(closure) = &self.closure {
|
||||
self.input.remove_event_listener_with_callback("change", closure.as_ref().unchecked_ref()).unwrap();
|
||||
std::mem::replace(&mut self.closure, None).unwrap().forget();
|
||||
|
@ -83,7 +83,7 @@ impl FileDialog {
|
|||
self.input.click();
|
||||
}
|
||||
|
||||
pub fn opened(&self) -> Option<Vec<u8>> {
|
||||
pub fn get(&self) -> Option<Vec<u8>> {
|
||||
if let Ok(file) = self.rx.try_recv() {
|
||||
Some(file)
|
||||
} else {
|
||||
|
@ -114,14 +114,14 @@ impl Default for FileDialog {
|
|||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl FileDialog {
|
||||
pub fn open_file(&mut self) {
|
||||
pub fn open(&mut self) {
|
||||
let path = rfd::FileDialog::new().pick_file();
|
||||
if let Some(path) = path {
|
||||
self.file = std::fs::read(path).ok();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn opened(&mut self) -> Option<File> {
|
||||
pub fn get(&mut self) -> Option<File> {
|
||||
std::mem::replace(&mut self.file, None)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue