diff --git a/build_windows.bat b/build_windows.bat index 89b8180..75d7f02 100644 --- a/build_windows.bat +++ b/build_windows.bat @@ -69,6 +69,7 @@ if not exist "src-tauri\binaries" mkdir "src-tauri\binaries" copy /y dist\daw_engine.exe "src-tauri\binaries\daw_engine-x86_64-pc-windows-msvc.exe" >nul echo [6/6] Build Tauri installer... +taskkill /F /T /IM daw_engine.exe >nul 2>nul npm install -D @tauri-apps/cli@^2 if errorlevel 1 ( echo npm install tauri-cli that bai diff --git a/main.py b/main.py index 9553904..09be23e 100644 --- a/main.py +++ b/main.py @@ -1,20 +1,13 @@ """Entry point cho daw_engine.exe (PyInstaller — spec desktop 2026-08-08). -Chạy FastAPI backend trên 127.0.0.1:8000 (Dual-Process Desktop Architecture).""" +Chạy FastAPI backend trên 127.0.0.1:8000 (Dual-Process Desktop Architecture). +KHÔNG tự mở browser — Tauri shell (window url=localhost:8000) đảm nhiệm; +mở browser thủ công khi chạy standalone (bug 09:30: exe mở tab liên tục).""" import os -import sys -import threading -import webbrowser os.environ.setdefault("SFDATA_DIR", os.path.join(os.path.expanduser("~"), "SonicForgeDAW")) import uvicorn # noqa: E402 -def _open_browser(): - webbrowser.open("http://127.0.0.1:8000") - - if __name__ == "__main__": - # Mở browser sau khi server sẵn sàng (console=False — chạy ẩn) - threading.Timer(2.0, _open_browser).start() uvicorn.run("app.main:app", host="127.0.0.1", port=8000, log_level="warning") diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 68c88c3..84568d8 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -20,14 +20,19 @@ pub fn run() { }) .on_window_event(|window, event| { if let tauri::WindowEvent::Destroyed = event { - // 2. Terminate sidecar process when DAW window is destroyed + // 2. Terminate sidecar khi window đóng — kill CẢ TREE (PyInstaller + // onefile = parent + child — child.kill() chỉ giết parent → child + // orphan chạy mãi — bug 09:30). taskkill /T giết cả nhánh. let state = window.state::(); if let Ok(mut lock) = state.0.lock() { if let Some(child) = lock.take() { let _ = child.kill(); - println!("daw_engine sidecar terminated gracefully."); } }; + let _ = std::process::Command::new("taskkill") + .args(["/F", "/T", "/IM", "daw_engine.exe"]) + .output(); + println!("daw_engine sidecar terminated (tree killed)."); } }) .run(tauri::generate_context!()) diff --git a/wiki.md b/wiki.md index 7114624..e5350e3 100644 --- a/wiki.md +++ b/wiki.md @@ -3014,3 +3014,19 @@ - **FIX (engine.spec):** thêm hiddenimports celery family: celery.fixups(+django), celery.backends(+redis), celery.schedules, celery.app.builtins, kombu.transport.redis, billiard, vine, redis. - **Các file ảnh hưởng:** engine.spec, wiki.md. - **Ghi chú/Test:** build lại `pyinstaller engine.spec --clean --noconfirm` → chạy daw_engine.exe → server khởi động (localhost:8000). + +### [2026-08-08 09:25] Task: FIX tauri build — Access denied khi copy sidecar (daw_engine đang chạy) +- **Lỗi:** tauri-build panic `Os { code: 5, kind: PermissionDenied }` — không copy được externalBin — vì `daw_engine.exe` ĐANG CHẠY (test lần trước — tiến trình giữ file). +- **FIX (build_windows.bat [6/6]):** thêm `taskkill /F /IM daw_engine.exe >nul 2>nul` trước `npx tauri build`. +- **Các file ảnh hưởng:** build_windows.bat, wiki.md. +- **Ghi chú/Test:** (1) tay: Task Manager → kết thúc mọi `daw_engine.exe` → `npx tauri build` lại; (2) script mới tự kill. + +### [2026-08-08 09:30] Task: FIX daw_engine mở tab browser liên tục + không kill được process +- **Lỗi:** (1) exe mở tab browser liên tục; (2) taskkill không giết được process. +- **Nguyên nhân:** (1) main.py `threading.Timer(2.0, webbrowser.open)` — mở browser mỗi lần exe chạy (Tauri shell ĐÃ mở window localhost — thừa); (2) PyInstaller ONEFILE = parent + child — Tauri `child.kill()` chỉ giết PARENT → CHILD ORPHAN chạy mãi (server sống → vẫn mở tab qua timer cũ). +- **FIX:** + (1) `main.py` — XÓA auto-open browser (Tauri window url=localhost:8000 đảm nhiệm; standalone mở tay). + (2) `src-tauri/src/lib.rs` — khi window destroyed: child.kill() + `taskkill /F /T /IM daw_engine.exe` (kill CẢ TREE — cả parent + child onefile). + (3) `build_windows.bat` — `taskkill /F /T /IM` (tree). +- **Các file ảnh hưởng:** main.py, src-tauri/src/lib.rs, build_windows.bat, wiki.md. +- **Ghi chú/Test:** build lại exe + tauri → đóng app → Task Manager không còn daw_engine (cả tree) + không mở tab mới. Kill tay lúc này: `taskkill /F /T /IM daw_engine.exe`.