41 lines
1003 B
Python
41 lines
1003 B
Python
#!/usr/bin/env python3
|
|
"""
|
|
Launcher for macOS .app bundle: starts the Flask server bound to 127.0.0.1 and opens the default browser.
|
|
"""
|
|
import os
|
|
import time
|
|
import threading
|
|
import webbrowser
|
|
|
|
# Import the Flask app defined in app.py
|
|
from app import app
|
|
|
|
|
|
def _run_server():
|
|
port = int(os.environ.get("PORT", 5000))
|
|
# Bind to loopback only for local use
|
|
app.run(host="127.0.0.1", port=port, debug=False, use_reloader=False)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
t = threading.Thread(target=_run_server, daemon=True)
|
|
t.start()
|
|
|
|
# Give the server a moment to start
|
|
time.sleep(1.0)
|
|
|
|
port = os.environ.get("PORT", "5000")
|
|
url = f"http://127.0.0.1:{port}/"
|
|
try:
|
|
webbrowser.open(url)
|
|
except Exception:
|
|
# If opening the browser fails, just continue; user can open manually
|
|
pass
|
|
|
|
try:
|
|
# Keep the main thread alive while the server thread runs
|
|
while t.is_alive():
|
|
t.join(0.5)
|
|
except KeyboardInterrupt:
|
|
pass
|