Refactor windowed mode and subprocess handling

Removed redundant windowed mode setup from main.py and simplified subprocess creation flags logic across core and GUI modules. Centralized subprocess creation flags usage, eliminated custom run_subprocess_hidden wrapper, and improved logging handler setup for better compatibility with windowed applications.
This commit is contained in:
Your Name
2025-08-27 23:00:08 +03:00
parent b23be4335e
commit f390d23f54
5 changed files with 35 additions and 169 deletions
+4 -30
View File
@@ -1,7 +1,6 @@
import os
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Optional
@@ -501,22 +500,10 @@ def check_ytdlp_binary() -> Optional[Path]:
# Use subprocess to check if yt-dlp is available
if OS_NAME == "Windows":
# On Windows, use 'where' command and hide console window
# For windowed applications, use additional flags to prevent console window flicker
creation_flags = SUBPROCESS_CREATIONFLAGS
if getattr(sys, 'frozen', False):
# Running as compiled executable - use additional flags
creation_flags |= subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS
# Extra logic moved to src\utils\ytsage_constants.py
result = subprocess.run(
["where", "yt-dlp"],
capture_output=True,
text=True,
check=False,
creationflags=creation_flags,
# Additional parameters to suppress console
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
["where", "yt-dlp"], capture_output=True, text=True, check=False, creationflags=SUBPROCESS_CREATIONFLAGS
)
if result.returncode == 0 and result.stdout.strip():
yt_dlp_path = result.stdout.strip().split("\n")[0]
@@ -547,22 +534,9 @@ def check_ytdlp_installed() -> bool:
if ytdlp_path:
# Try to run yt-dlp --version to verify it's working
try:
# For windowed applications, use additional flags to prevent console window flicker
creation_flags = SUBPROCESS_CREATIONFLAGS
if getattr(sys, 'frozen', False):
# Running as compiled executable - use additional flags
creation_flags |= subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS
# Extra logic moved to src\utils\ytsage_constants.py
result = subprocess.run(
[ytdlp_path, "--version"],
capture_output=True,
text=True,
timeout=5,
creationflags=creation_flags,
# Additional parameters to suppress console
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
[ytdlp_path, "--version"], capture_output=True, text=True, timeout=5, creationflags=SUBPROCESS_CREATIONFLAGS
)
return result.returncode == 0
except Exception: