feat: Update resource path handling for React build directory and clean up main.spec

This commit is contained in:
Miguel 2025-08-18 00:02:33 +02:00
parent 13e7a12b6d
commit bd5b70f044
2 changed files with 16 additions and 9 deletions

23
main.py
View File

@ -58,9 +58,6 @@ CORS(
)
app.secret_key = "plc_streamer_secret_key"
# React build directory (for Vite production build)
REACT_DIST_DIR = os.path.join(os.path.abspath("."), "frontend", "dist")
def resource_path(relative_path):
"""Get absolute path to resource, works for dev and for PyInstaller"""
@ -80,6 +77,18 @@ def project_path(*parts: str) -> str:
return os.path.join(base_dir, *parts)
# React build directory (for Vite production build)
# Use resource_path to handle both development and PyInstaller scenarios
REACT_DIST_DIR = resource_path(os.path.join("frontend", "dist"))
# Global instances
streamer = None
historical_cache = None
json_manager = JSONManager()
schema_manager = SchemaManager()
# Global instances
streamer = None
historical_cache = None
@ -108,8 +117,8 @@ def serve_favicon():
1) frontend/public/favicon.ico
2) frontend/public/record.png
"""
# Use absolute paths for reliability (works in dev and bundled)
public_dir = project_path("frontend", "public")
# Use resource_path for files embedded in PyInstaller bundle
public_dir = resource_path(os.path.join("frontend", "public"))
public_favicon = os.path.join(public_dir, "favicon.ico")
public_record = os.path.join(public_dir, "record.png")
@ -125,7 +134,7 @@ def serve_favicon():
@app.route("/record.png")
def serve_public_record_png():
"""Serve /record.png from the React public folder."""
public_dir = project_path("frontend", "public")
public_dir = resource_path(os.path.join("frontend", "public"))
public_record = os.path.join(public_dir, "record.png")
if os.path.exists(public_record):
@ -137,7 +146,7 @@ def serve_public_record_png():
@app.route("/SIDEL.png")
def serve_public_sidel_png():
"""Serve /SIDEL.png from the React public folder."""
public_dir = project_path("frontend", "public")
public_dir = resource_path(os.path.join("frontend", "public"))
sidel_file = os.path.join(public_dir, "SIDEL.png")
if os.path.exists(sidel_file):
return send_from_directory(public_dir, "SIDEL.png")

View File

@ -28,8 +28,6 @@ a = Analysis(
('translation.json', '.'),
('i18n.js', '.'),
# Create records directory structure
('records', 'records'),
],
hiddenimports=[
# Flask and web dependencies