FIX: lỗi màn hình đen trên docker

This commit is contained in:
2026-08-08 10:51:58 +07:00
parent 3fc2087ee1
commit 24051a2794
7 changed files with 101 additions and 30 deletions
+25 -3
View File
@@ -1,13 +1,35 @@
"""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).
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)."""
KHÔNG tự mở browser — Tauri shell (window url=localhost:8000) đảm nhiệm.
SINGLE-INSTANCE: nếu port 8000 đã có server → EXIT ngay (bug 09:55 — mỗi lần mở
app spawn thêm daw_engine → nhiều instance + port chiếm → màn đen)."""
import os
import socket
import sys
os.environ.setdefault("SFDATA_DIR", os.path.join(os.path.expanduser("~"), "SonicForgeDAW"))
import uvicorn # noqa: E402
PORT = 8000
def _port_in_use(port: int) -> bool:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind(("127.0.0.1", port))
return False
except OSError:
return True
finally:
s.close()
except Exception:
return False
if __name__ == "__main__":
uvicorn.run("app.main:app", host="127.0.0.1", port=8000, log_level="warning")
if _port_in_use(PORT):
# Server đang chạy (instance khác — window sẽ dùng nó). KHÔNG spawn thêm.
sys.exit(0)
uvicorn.run("app.main:app", host="127.0.0.1", port=PORT, log_level="warning")