Fix 3 bug standalone: save project lỗi schema, export MIDI/WAV không hỏi nơi lưu

- Bug 1: serializeTracksList bỏ section item không có sectionId (do insertSectionAtPlayhead tạo) — tránh source_data {} làm schema oneOf fail
- Bug 2: export MIDI qua save-dialog + write file, toast kèm đường dẫn
- Bug 3: export mix WAV/MP3/OGG qua save-dialog + write file, toast kèm đường dẫn
- Marker tauri_bridge_ready: xóa khi window destroy + guard SF_PARENT_PID — tránh standalone treo 120s
This commit is contained in:
2026-08-21 17:13:28 +07:00
parent 9b14c99a7a
commit 4e3f2fd08a
6 changed files with 288 additions and 28 deletions
+44
View File
@@ -648,6 +648,40 @@ pub fn run() {
waited_ms += 100;
}
}
// ── Native Save-As dialog bridge (export MIDI/WAV) ──
// Giong pick_dir: engine ghi ipc/save_file.request (chua ten
// mac dinh) → thread mo NATIVE SaveFileDialog → ghi ket qua
// vao ipc/save_file.response. Frontend lay path → POST bytes
// /api/v1/files/write → file thuc su duoc ghi vao noi chon.
let sreq = ipc_dir_for_thread.join("save_file.request");
if sreq.exists() {
let default_name = std::fs::read_to_string(&sreq).unwrap_or_default();
let _ = std::fs::remove_file(&sreq);
let sresp = ipc_dir_for_thread.join("save_file.response");
let _ = std::fs::remove_file(&sresp);
let handle = app_handle.clone();
let sresp_for_main = sresp.clone();
let handle_for_closure = handle.clone();
let _ = handle.run_on_main_thread(move || {
let saved: Option<FilePath> = handle_for_closure
.dialog()
.file()
.set_file_name(default_name.trim())
.blocking_save_file();
let val = saved
.map(|p| match p {
FilePath::Path(pb) => pb.to_string_lossy().to_string(),
FilePath::Url(u) => u.to_string(),
})
.unwrap_or_default();
let _ = std::fs::write(&sresp_for_main, val);
});
let mut s_waited_ms = 0u32;
while !sresp.exists() && s_waited_ms < 300_000 {
std::thread::sleep(std::time::Duration::from_millis(100));
s_waited_ms += 100;
}
}
std::thread::sleep(std::time::Duration::from_millis(150));
}
});
@@ -687,6 +721,16 @@ pub fn run() {
// phu/an giu event loop song, Tauri khong tu exit; exit(0)
// ket thuc dut diem (pump da dung, khong con respawn bridge).
if window.label() == "main" {
// Xoa marker bridge khi app tat han — neu de lai, lan sau
// chay engine STANDALONE se nham tuong co bridge va cho
// response khong bao gio den (treo 120s truoc fallback).
let appdata = std::env::var("APPDATA").unwrap_or_else(|_| ".".into());
let _ = std::fs::remove_file(
std::path::Path::new(&appdata)
.join("SonicForgeDAW")
.join("ipc")
.join("tauri_bridge_ready"),
);
// Orphan sweep: bat CA dau engine con song theo image name —
// engine spawn thu cong (khong co SF_PARENT_PID), engine cua
// lan chay truoc bi crash, hoac engine song sot khi app chet