mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-17 08:57:25 +00:00
Make objdiff-core no_std + huge WASM rework
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
use std::{future::Future, path::PathBuf, pin::Pin, thread::JoinHandle};
|
||||
|
||||
use objdiff_core::config::path::check_path_buf;
|
||||
use pollster::FutureExt;
|
||||
use rfd::FileHandle;
|
||||
use typed_path::Utf8PlatformPathBuf;
|
||||
|
||||
#[derive(Default)]
|
||||
pub enum FileDialogResult {
|
||||
#[default]
|
||||
None,
|
||||
ProjectDir(PathBuf),
|
||||
TargetDir(PathBuf),
|
||||
BaseDir(PathBuf),
|
||||
Object(PathBuf),
|
||||
ProjectDir(Utf8PlatformPathBuf),
|
||||
TargetDir(Utf8PlatformPathBuf),
|
||||
BaseDir(Utf8PlatformPathBuf),
|
||||
Object(Utf8PlatformPathBuf),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -22,7 +24,7 @@ impl FileDialogState {
|
||||
pub fn queue<InitCb, ResultCb>(&mut self, init: InitCb, result_cb: ResultCb)
|
||||
where
|
||||
InitCb: FnOnce() -> Pin<Box<dyn Future<Output = Option<FileHandle>> + Send>>,
|
||||
ResultCb: FnOnce(PathBuf) -> FileDialogResult + Send + 'static,
|
||||
ResultCb: FnOnce(Utf8PlatformPathBuf) -> FileDialogResult + Send + 'static,
|
||||
{
|
||||
if self.thread.is_some() {
|
||||
return;
|
||||
@@ -30,7 +32,8 @@ impl FileDialogState {
|
||||
let future = init();
|
||||
self.thread = Some(std::thread::spawn(move || {
|
||||
if let Some(handle) = future.block_on() {
|
||||
result_cb(PathBuf::from(handle))
|
||||
let path = PathBuf::from(handle);
|
||||
check_path_buf(path).map(result_cb).unwrap_or(FileDialogResult::None)
|
||||
} else {
|
||||
FileDialogResult::None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user