diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index b5ef2bb..d748eba 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2873,6 +2873,7 @@ dependencies = [ name = "sonicforge-daw" version = "1.0.0" dependencies = [ + "raw-window-handle", "serde", "serde_json", "tauri", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 6244301..4249a46 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -15,6 +15,7 @@ tauri-build = { version = "2", features = [] } tauri = { version = "2", features = [] } tauri-plugin-shell = "2" tauri-plugin-dialog = "2" +raw-window-handle = "0.6" serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8dfd03a..397c3b7 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -17,6 +17,8 @@ use tauri_plugin_shell::ShellExt; use std::path::{Path, PathBuf}; use std::sync::Mutex; +mod vst_gui; + struct EngineProcess(Mutex>); /// Các vị trí có thể chứa daw_engine, theo thứ tự ưu tiên. @@ -73,6 +75,7 @@ pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_dialog::init()) + .invoke_handler(tauri::generate_handler![vst_gui::open_vst_gui]) .setup(|app| { let res_dir = app .path() diff --git a/src-tauri/src/vst_gui.rs b/src-tauri/src/vst_gui.rs new file mode 100644 index 0000000..3a0f531 --- /dev/null +++ b/src-tauri/src/vst_gui.rs @@ -0,0 +1,44 @@ +// VST GUI windows (spec vsti_gui): floating child window per (track, plugin). +// +// T8: command `open_vst_gui(plugin_id, track_id)` tao WebviewWindow noi +// label `vst_gui_{track}_{plugin}`, 800x600, always-on-top; mo lai thi focus. +// raw_window_handle() lay HWND (Windows) — T9 se attach native VST3/VST2 +// editor vao HWND cua window nay. Chua load plugin GUI (T9), chi placeholder. +use raw_window_handle::HasWindowHandle; +use tauri::{AppHandle, Manager, WebviewUrl, WebviewWindowBuilder}; + +/// Mo (hoac focus neu da mo) cua so VST GUI cho 1 (track, plugin). +/// Tra ve chuoi trang thai cho JS log — khong throw. +#[tauri::command] +pub fn open_vst_gui( + app: AppHandle, + plugin_id: String, + track_id: String, +) -> Result { + let label = format!("vst_gui_{}_{}", track_id, plugin_id); + if let Some(win) = app.get_webview_window(&label) { + win.set_focus().map_err(|e| e.to_string())?; + return Ok(format!("focused: {}", label)); + } + let win = WebviewWindowBuilder::new(&app, &label, WebviewUrl::App("vst_gui.html".into())) + .title(format!("VST GUI - {}", plugin_id)) + .inner_size(800.0, 600.0) + .always_on_top(true) + .build() + .map_err(|e| e.to_string())?; + let _ = win.set_focus(); + // HWND cho native editor attach (T9). Log de verify — chua dung. + match win.window_handle() { + Ok(raw) => { + let raw = raw.as_raw(); + #[cfg(target_os = "windows")] + if let raw_window_handle::RawWindowHandle::Win32(h) = raw { + println!("[vst_gui] {} hwnd={:?}", label, h.hwnd); + } + #[cfg(not(target_os = "windows"))] + let _ = raw; + } + Err(e) => println!("[vst_gui] {} raw_window_handle error: {}", label, e), + } + Ok(format!("opened: {}", label)) +} diff --git a/src-tauri/ui/vst_gui.html b/src-tauri/ui/vst_gui.html new file mode 100644 index 0000000..8b19af7 --- /dev/null +++ b/src-tauri/ui/vst_gui.html @@ -0,0 +1,20 @@ + + + + + VST GUI + + + +
Cửa sổ nổi VST GUI (T8).
Plugin editor sẽ được attach vào HWND cửa sổ này ở T9.
+ + +