Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

fix(svg-editor): reuse running preview server on relaunch

hugohe39fa2f2c1b05c
diff --git a/skills/ppt-master/scripts/svg_editor/server.py b/skills/ppt-master/scripts/svg_editor/server.py
index e960265f..9ddfc4d8 100644
--- a/skills/ppt-master/scripts/svg_editor/server.py
+++ b/skills/ppt-master/scripts/svg_editor/server.py
@@ -1094,6 +1094,35 @@ def _open_browser(url: str) -> bool:
return False
+def _reuse_running_server(existing: dict, *, open_browser: bool) -> int:
+ """Idempotent relaunch: point at the already-running preview instead of failing.
+
+ A relaunch while the server is alive is the normal second-preview flow
+ (the first server keeps serving after the browser tab is closed), so it
+ must re-open the browser and exit 0 — not error out.
+ """
+ pid = existing.get('pid', '?')
+ try:
+ port = int(existing.get('port', 0) or 0)
+ except (TypeError, ValueError):
+ port = 0
+ if not port:
+ logger.error(
+ 'live preview is already running for this project (pid=%s) but its '
+ 'lock records no usable port; run --shutdown, then start again',
+ pid,
+ )
+ return 1
+ url = _server_url(port)
+ logger.info(
+ 'live preview already running for this project (pid=%s), reusing: %s',
+ pid, url,
+ )
+ if open_browser and not _open_browser(url):
+ logger.info('browser did not auto-open; open %s manually', url)
+ return 0
+
+
def _open_browser_async(url: str, delay: float = 0.4) -> None:
"""Open the browser shortly after Flask starts binding its socket."""
def _open() -> None:
@@ -1167,15 +1196,7 @@ def main(argv: Optional[list[str]] = None) -> int:
legacy_existing = _legacy_live_lock(project_path)
if legacy_existing:
- existing_pid = legacy_existing.get('pid', '?')
- existing_port = legacy_existing.get('port', '?')
- logger.error(
- 'live preview is already running for this project via legacy lock '
- '(pid=%s, port=%s). Open http://%s:%s, click '
- 'Exit preview in the browser, or stop pid %s',
- existing_pid, existing_port, PUBLIC_HOST, existing_port, existing_pid,
- )
- return 1
+ return _reuse_running_server(legacy_existing, open_browser=not args.no_browser)
runtime_dir = _runtime_dir(project_path)
lock_file = _lock_file(project_path)
@@ -1183,14 +1204,7 @@ def main(argv: Optional[list[str]] = None) -> int:
if args.daemon:
existing = _read_lock(lock_file)
if existing and _process_alive(_lock_pid(existing)):
- existing_pid = existing.get('pid', '?')
- existing_port = existing.get('port', '?')
- logger.error(
- 'live preview is already running for this project '
- '(pid=%s, port=%s). Open http://%s:%s',
- existing_pid, existing_port, PUBLIC_HOST, existing_port,
- )
- return 1
+ return _reuse_running_server(existing, open_browser=not args.no_browser)
try:
runtime_dir.mkdir(parents=True, exist_ok=True)
@@ -1243,8 +1257,9 @@ def main(argv: Optional[list[str]] = None) -> int:
# Per-project mutual exclusion. The major driver of orphaned servers is
# --live mode (which used to disable idle timeout entirely) combined with
- # silent restarts; refusing duplicate launches catches the accumulation
- # at its source. Stale locks (dead pid) are overwritten by _claim_lock.
+ # silent restarts; reusing the running server on duplicate launches catches
+ # the accumulation at its source. Stale locks (dead pid) are overwritten
+ # by _claim_lock.
try:
runtime_dir.mkdir(parents=True, exist_ok=True)
except OSError as exc:
@@ -1252,15 +1267,7 @@ def main(argv: Optional[list[str]] = None) -> int:
return 1
existing = _claim_lock(lock_file, port)
if existing:
- existing_pid = existing.get('pid', '?')
- existing_port = existing.get('port', '?')
- logger.error(
- 'live preview is already running for this project '
- '(pid=%s, port=%s). Open http://%s:%s, click '
- 'Exit preview in the browser, or run: kill %s',
- existing_pid, existing_port, PUBLIC_HOST, existing_port, existing_pid,
- )
- return 1
+ return _reuse_running_server(existing, open_browser=not args.no_browser)
# atexit covers normal interpreter shutdown (Ctrl+C / SystemExit);
# /api/shutdown and idle timeout call _release_lock directly before
# os._exit since atexit handlers do not run on os._exit.