From 14265515aaa870dd5007bd9a865603b1576f7b3b Mon Sep 17 00:00:00 2001 From: locphamtran Date: Sat, 22 Aug 2026 18:06:26 +0700 Subject: [PATCH] =?UTF-8?q?fix(exit):=20taskkill=20rieng=20tung=20process?= =?UTF-8?q?=20=E2=80=94=20kill=20het=20plugin=5Fhost/fx=5Fvst=5Fbridge=20k?= =?UTF-8?q?hi=20thoat=20app=20(truoc=20day=20/IM=20gop=20chi=20chay=20lenh?= =?UTF-8?q?=20dau);=20CREATE=5FNO=5FWINDOW=20cho=20moi=20subprocess=20engi?= =?UTF-8?q?ne=20(het=20terminal=20ch=E1=BB=9Bp=20ch=E1=BB=9Bp)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/files.py | 1 + app/api/v1/plugins.py | 7 +++++-- app/core/native_render.py | 6 ++++-- app/core/soundfont_converter.py | 15 ++++++++++----- app/core/vst_engine.py | 1 + src-tauri/src/lib.rs | 16 +++++++++------- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/api/v1/files.py b/app/api/v1/files.py index 98b9c4b..e2a5621 100644 --- a/app/api/v1/files.py +++ b/app/api/v1/files.py @@ -74,6 +74,7 @@ def _save_file_native_engine(default_name: str, filter_name: str, filter_ext: st r = subprocess.run( ["powershell", "-NoProfile", "-STA", "-Command", ps], capture_output=True, text=True, timeout=SAVE_DIALOG_TIMEOUT, + creationflags=subprocess.CREATE_NO_WINDOW, ) return r.stdout.strip() or None except Exception: diff --git a/app/api/v1/plugins.py b/app/api/v1/plugins.py index dbd0feb..92b27ec 100644 --- a/app/api/v1/plugins.py +++ b/app/api/v1/plugins.py @@ -419,6 +419,7 @@ def _pick_dir_native_engine() -> Optional[str]: r = subprocess.run( ["powershell", "-NoProfile", "-STA", "-Command", ps], capture_output=True, text=True, timeout=PICK_DIR_TIMEOUT, + creationflags=subprocess.CREATE_NO_WINDOW, ) return r.stdout.strip() or None except Exception: @@ -798,7 +799,8 @@ async def open_in_carla(req: OpenInCarlaRequest, current_user: dict = Depends(ge cmd.append(carxs_path) try: cwd = os.path.dirname(carla) or None - proc = subprocess.Popen(cmd, cwd=cwd, close_fds=os.name != "nt") + proc = subprocess.Popen(cmd, cwd=cwd, close_fds=os.name != "nt", + creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0) _register_carla_process(proc) return { "success": True, @@ -1778,7 +1780,8 @@ def _running_sonicforge_pids() -> list: out = subprocess.run( ["powershell", "-NoProfile", "-Command", "Get-Process sonicforge-daw,daw_engine -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Id"], - capture_output=True, text=True, timeout=10).stdout + capture_output=True, text=True, timeout=10, + creationflags=subprocess.CREATE_NO_WINDOW).stdout for line in out.splitlines(): line = line.strip() if line.isdigit(): diff --git a/app/core/native_render.py b/app/core/native_render.py index cfa4a3b..4499f0e 100644 --- a/app/core/native_render.py +++ b/app/core/native_render.py @@ -176,7 +176,8 @@ def render_offline(instrument_id, notes, bpm, sample_rate, preset_id=None, with open(job_path, "w", encoding="utf-8") as fh: json.dump(job, fh) r = subprocess.run([exe, "--render", job_path, "--out", out_path], - capture_output=True, text=True, timeout=120) + capture_output=True, text=True, timeout=120, + creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0) log = ((r.stdout or "") + (r.stderr or "")).strip() if r.returncode != 0 or not os.path.isfile(out_path): if os.path.exists(out_path): @@ -259,7 +260,8 @@ def render_fx_chain(input_wav, fx_chain, sample_rate, out_path=None) -> str: with open(job_path, "w", encoding="utf-8") as fh: json.dump(job, fh) r = subprocess.run([exe, "--render-fx", job_path, "--in", input_wav, "--out", out], - capture_output=True, text=True, timeout=120) + capture_output=True, text=True, timeout=120, + creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0) log = ((r.stdout or "") + (r.stderr or "")).strip() if r.returncode != 0 or not os.path.isfile(out): if os.path.exists(out): diff --git a/app/core/soundfont_converter.py b/app/core/soundfont_converter.py index 0475a99..9db33b2 100644 --- a/app/core/soundfont_converter.py +++ b/app/core/soundfont_converter.py @@ -78,7 +78,8 @@ class SoundFontConverter: def _check_ffmpeg_ogg(self): try: - r = subprocess.run(["ffmpeg", "-encoders"], capture_output=True, text=True, timeout=5) + r = subprocess.run(["ffmpeg", "-encoders"], capture_output=True, text=True, timeout=5, + creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0) return "libvorbis" in r.stdout except Exception: return False @@ -98,7 +99,8 @@ class SoundFontConverter: "ffmpeg", "-y", "-i", tmp_wav, "-c:a", "libvorbis", "-q:a", "3", "-f", "ogg", tmp_ogg - ], capture_output=True, timeout=600, check=True) + ], capture_output=True, timeout=600, check=True, + creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0) with open(tmp_ogg, "rb") as fo: return fo.read() except Exception as e: @@ -320,7 +322,8 @@ class SoundFontConverter: def _find_sf3_converter(): for exe in ["fluidsynth", "mscore"]: try: - subprocess.run([exe, "--help"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=2.0) + subprocess.run([exe, "--help"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=2.0, + creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0) return exe except (FileNotFoundError, subprocess.TimeoutExpired): continue @@ -353,7 +356,8 @@ class SoundFontConverter: if converter == "mscore": cmd = ["mscore", "-o", sf3_path, sf2_path] - result = subprocess.run(cmd, capture_output=True, text=True, timeout=600) + result = subprocess.run(cmd, capture_output=True, text=True, timeout=600, + creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0) if result.returncode == 0 and os.path.exists(sf3_path): logger.info(f"Created SF3 via mscore: {sf3_path} ({os.path.getsize(sf3_path)/1024/1024:.1f}MB)") return sf3_path @@ -524,7 +528,8 @@ class SoundFontConverter: fo.write(ogg) r = subprocess.run( ["ffmpeg", "-y", "-v", "error", "-i", tmp_ogg, "-f", "s16le", "-ac", "1", tmp_pcm], - capture_output=True, timeout=600) + capture_output=True, timeout=600, + creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0) if r.returncode != 0: logger.warning(f"OGG decode failed: {r.stderr.decode(errors='replace')[:120]}") return b"" diff --git a/app/core/vst_engine.py b/app/core/vst_engine.py index b6f5649..8847589 100644 --- a/app/core/vst_engine.py +++ b/app/core/vst_engine.py @@ -582,6 +582,7 @@ class PluginManager: for d in dirs: try: r = subprocess.run([exe, "--scan", d], capture_output=True, + creationflags=subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0, text=True, timeout=300) except Exception: continue diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 47d274c..cedf6da 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -737,13 +737,15 @@ pub fn run() { // dot ngot (watchdog graceful shutdown treo vi LAN client). // Task Manager dong app -> Destroyed khong chay -> engine tu // thoat nho watchdog; o day dong app binh thuong -> quet het. - let _ = std::process::Command::new("taskkill") - .args(["/IM", "daw_engine.exe", "/T", "/F"]) - .status(); - let _ = std::process::Command::new("taskkill") - .args(["/IM", "daw_vst_bridge.exe", "/T", "/F", - "/IM", "fx_vst_bridge.exe", "/T", "/F"]) - .status(); + // taskkill chi nhan MOT /IM moi lan goi — goi rieng cho tung + // process, khong gop /IM ... /IM (truoc day chi cai dau chay, + // fx_vst_bridge/plugin_host song sot thanh orphan). + for im in ["daw_engine.exe", "daw_vst_bridge.exe", + "fx_vst_bridge.exe", "plugin_host.exe"] { + let _ = std::process::Command::new("taskkill") + .args(["/IM", im, "/T", "/F"]) + .status(); + } window.app_handle().exit(0); } }