Update Tauri to v2 and execute only the node graph in native (#2362)

* Migrate tauri app to v2

* Move flake files to sub directory

* Remove unused plugins

* Backport some of the tauri code

* Implement async node graph execution

Only move node runtime to native code

* Always use gpu feature for tauri

* Fix serialization

* Add logging filters

* Enable native window rendering with vello

* Cleanup

* Remove unused editor instance

* Remove changes from vite config

* Remove warnings

* Remove unused files

* Fix most tests

* Cleanup

* Apply frontend lint

* Readd flake.nix

* Fix tests using --all-features

* Code review

* Enable all backends

* Fix monitor node downcast types

* Change debug log to a warning

* Disable shader passthrough

* Cleanup unused imports

* Remove warning

* Update project setup instructions

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert
2025-04-14 11:43:15 +00:00
committed by GitHub
co-authored by Keavon Chambers
parent 29479f6e3e
commit 9b23c7e2db
39 changed files with 10429 additions and 2831 deletions
@@ -68,6 +68,14 @@ pub struct WasmApplicationIo {
static WGPU_AVAILABLE: std::sync::atomic::AtomicI8 = std::sync::atomic::AtomicI8::new(-1);
pub fn wgpu_available() -> Option<bool> {
// Always enable wgpu when running with Tauri
#[cfg(target_arch = "wasm32")]
if let Some(window) = web_sys::window() {
if js_sys::Reflect::get(&window, &wasm_bindgen::JsValue::from_str("__TAURI__")).is_ok() {
return Some(true);
}
}
match WGPU_AVAILABLE.load(::std::sync::atomic::Ordering::SeqCst) {
-1 => None,
0 => Some(false),
@@ -92,9 +100,32 @@ impl WasmApplicationIo {
} else {
None
};
#[cfg(not(target_arch = "wasm32"))]
let executor = WgpuExecutor::new().await;
WGPU_AVAILABLE.store(executor.is_some() as i8, ::std::sync::atomic::Ordering::SeqCst);
let mut io = Self {
#[cfg(target_arch = "wasm32")]
ids: AtomicU64::new(0),
#[cfg(feature = "wgpu")]
gpu_executor: executor,
windows: Vec::new(),
resources: HashMap::new(),
};
let window = io.create_window();
io.windows.push(WindowWrapper { window });
io.resources.insert("null".to_string(), Arc::from(include_bytes!("null.png").to_vec()));
io
}
pub async fn new_offscreen() -> Self {
let executor = WgpuExecutor::new().await;
WGPU_AVAILABLE.store(executor.is_some() as i8, ::std::sync::atomic::Ordering::SeqCst);
// Always enable wgpu when running with Tauri
let mut io = Self {
#[cfg(target_arch = "wasm32")]
ids: AtomicU64::new(0),
@@ -103,12 +134,9 @@ impl WasmApplicationIo {
windows: Vec::new(),
resources: HashMap::new(),
};
if cfg!(target_arch = "wasm32") {
let window = io.create_window();
io.windows.push(WindowWrapper { window });
}
io.resources.insert("null".to_string(), Arc::from(include_bytes!("null.png").to_vec()));
io
}
}
@@ -178,19 +206,22 @@ impl ApplicationIo for WasmApplicationIo {
}
#[cfg(not(target_arch = "wasm32"))]
fn create_window(&self) -> SurfaceHandle<Self::Surface> {
#[cfg(feature = "wayland")]
log::trace!("Spawning window");
#[cfg(not(test))]
use winit::platform::wayland::EventLoopBuilderExtWayland;
#[cfg(feature = "wayland")]
#[cfg(not(test))]
let event_loop = winit::event_loop::EventLoopBuilder::new().with_any_thread(true).build().unwrap();
#[cfg(not(feature = "wayland"))]
#[cfg(test)]
let event_loop = winit::event_loop::EventLoop::new().unwrap();
let window = winit::window::WindowBuilder::new()
.with_title("Graphite")
.with_inner_size(winit::dpi::PhysicalSize::new(800, 600))
.build(&event_loop)
.unwrap();
// self.windows.lock().as_mut().unwrap().push(window.clone());
SurfaceHandle {
window_id: SurfaceId(window.id().into()),
surface: Arc::new(window),
@@ -271,7 +302,7 @@ impl ApplicationIo for WasmApplicationIo {
pub type WasmSurfaceHandle = SurfaceHandle<wgpu_executor::Window>;
pub type WasmSurfaceHandleFrame = SurfaceHandleFrame<wgpu_executor::Window>;
#[derive(Clone, Debug, Default, PartialEq, Hash, specta::Type)]
#[derive(Clone, Debug, PartialEq, Hash, specta::Type)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EditorPreferences {
// pub imaginate_hostname: String,
@@ -287,6 +318,18 @@ impl graphene_core::application_io::GetEditorPreferences for EditorPreferences {
}
}
impl Default for EditorPreferences {
fn default() -> Self {
Self {
// imaginate_hostname: "http://localhost:7860/".into(),
#[cfg(target_arch = "wasm32")]
use_vello: false,
#[cfg(not(target_arch = "wasm32"))]
use_vello: true,
}
}
}
unsafe impl dyn_any::StaticType for EditorPreferences {
type Static = EditorPreferences;
}