From 5cc74ced102af7487ee5c38b3146d423eebab72e Mon Sep 17 00:00:00 2001 From: kirjavascript Date: Tue, 14 Mar 2023 18:01:15 +0000 Subject: [PATCH] clean up some file stuff --- frontend/src/app.rs | 4 ++-- frontend/src/widgets/file.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/src/app.rs b/frontend/src/app.rs index 973aebe..3fe59fe 100644 --- a/frontend/src/app.rs +++ b/frontend/src/app.rs @@ -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); } }); diff --git a/frontend/src/widgets/file.rs b/frontend/src/widgets/file.rs index 7c2414f..62f9bb7 100644 --- a/frontend/src/widgets/file.rs +++ b/frontend/src/widgets/file.rs @@ -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> { + pub fn get(&self) -> Option> { 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 { + pub fn get(&mut self) -> Option { std::mem::replace(&mut self.file, None) }