FEAT: chuẩn bị thư viện để tạo file exe trên window
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// SonicForge DAW — desktop shell: spawn/terminate daw_engine.exe sidecar.
|
||||
use tauri_plugin_shell::process::CommandChild;
|
||||
use tauri_plugin_shell::ShellExt;
|
||||
use std::sync::Mutex;
|
||||
|
||||
struct EngineProcess(Mutex<Option<CommandChild>>);
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.setup(|app| {
|
||||
// 1. Spawn sidecar daw_engine.exe (PyInstaller bundle)
|
||||
let sidecar_command = app
|
||||
.shell()
|
||||
.sidecar("daw_engine")
|
||||
.expect("sidecar daw_engine not found — run build_windows.ps1 first");
|
||||
let (_rx, child) = sidecar_command
|
||||
.env("SF_PARENT_PID", std::process::id().to_string())
|
||||
.spawn()
|
||||
.expect("Failed to spawn daw_engine sidecar");
|
||||
|
||||
app.manage(EngineProcess(Mutex::new(Some(child))));
|
||||
println!("Python Background Engine started (localhost:8000, auto-fallback 8000-8010)");
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
// 2. Terminate sidecar khi DAW window dong — tranh orphan process
|
||||
if let tauri::WindowEvent::Destroyed = event {
|
||||
let state = window.state::<EngineProcess>();
|
||||
if let Ok(mut lock) = state.0.lock() {
|
||||
if let Some(child) = lock.take() {
|
||||
let _ = child.kill();
|
||||
println!("daw_engine sidecar terminated.");
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
sonicforge_daw_lib::run()
|
||||
}
|
||||
Reference in New Issue
Block a user