fix: tray restart uses python -m for reliable process respawn
The previous os.execv approach and console_script detection both failed on Windows. Now restart always spawns `python -m media_server.main` via subprocess.Popen with start_new_session, which works regardless of how the server was originally started.
This commit is contained in:
@@ -277,6 +277,20 @@ def main():
|
||||
|
||||
# Tray exited — wait for server to finish graceful shutdown
|
||||
server_thread.join(timeout=10)
|
||||
|
||||
if tray.restart_requested:
|
||||
import subprocess
|
||||
|
||||
# Always restart via `python -m media_server.main` — this works
|
||||
# regardless of how we were originally started (console_script,
|
||||
# python -m, or direct script invocation).
|
||||
cmd = [sys.executable, "-m", "media_server.main"]
|
||||
|
||||
subprocess.Popen(
|
||||
cmd,
|
||||
cwd=Path.cwd(),
|
||||
start_new_session=True,
|
||||
)
|
||||
else:
|
||||
uvicorn.run(
|
||||
"media_server.main:app",
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
import ctypes
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import webbrowser
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
@@ -125,10 +123,13 @@ class TrayManager:
|
||||
if not _confirm("Media Server", "Restart the server?"):
|
||||
return
|
||||
logger.info("Restart requested from tray")
|
||||
self._icon.stop()
|
||||
self._restart_requested = True
|
||||
self._on_exit()
|
||||
os.environ["MEDIA_SERVER_RESTART"] = "1"
|
||||
os.execv(sys.executable, [sys.executable] + sys.argv)
|
||||
self._icon.stop()
|
||||
|
||||
@property
|
||||
def restart_requested(self) -> bool:
|
||||
return getattr(self, "_restart_requested", False)
|
||||
|
||||
def _shutdown(self, icon: "pystray.Icon", item: "pystray.MenuItem") -> None:
|
||||
if not _confirm("Media Server", "Shut down the server?"):
|
||||
|
||||
Reference in New Issue
Block a user