Make objdiff-core no_std + huge WASM rework

This commit is contained in:
2025-02-07 00:10:49 -07:00
parent d938988d43
commit e8de35b78e
49 changed files with 1463 additions and 1046 deletions

View File

@@ -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
}