diff --git a/mathweave-studio-onefile.spec b/mathweave-studio-onefile.spec index 1658871..5f4e88f 100644 --- a/mathweave-studio-onefile.spec +++ b/mathweave-studio-onefile.spec @@ -1,5 +1,6 @@ # -*- mode: python ; coding: utf-8 -*- +import os from PyInstaller.utils.hooks import ( collect_all, collect_data_files, @@ -9,6 +10,11 @@ from PyInstaller.utils.hooks import ( block_cipher = None +# Base directory of the project, resolved from spec file location +project_dir = SPECPATH +assets_dir = os.path.join(project_dir, "assets") +icon_path = os.path.join(assets_dir, "icon.ico") + datas = [] binaries = [] hiddenimports = [] @@ -20,7 +26,7 @@ for pkg in ["nicegui", "plotly", "latex2mathml"]: # Application modules and assets hiddenimports += collect_submodules("math_app") -datas += [("assets", "assets")] +datas += [(assets_dir, "assets")] # Pywebview and webview backend datas += collect_data_files("webview") @@ -59,8 +65,8 @@ hiddenimports += [ ] a = Analysis( - ["run.py"], - pathex=["src"], + [os.path.join(project_dir, "run.py")], + pathex=[os.path.join(project_dir, "src")], binaries=binaries, datas=datas, hiddenimports=hiddenimports, @@ -96,5 +102,5 @@ exe = EXE( target_arch=None, codesign_identity=None, entitlements_file=None, - icon="assets/icon.ico", + icon=icon_path, ) diff --git a/mathweave-studio.spec b/mathweave-studio.spec index 0d25a6e..8078473 100644 --- a/mathweave-studio.spec +++ b/mathweave-studio.spec @@ -1,15 +1,20 @@ # -*- mode: python ; coding: utf-8 -*- +import os from PyInstaller.utils.hooks import ( collect_all, collect_data_files, collect_dynamic_libs, collect_submodules, ) -from pathlib import Path block_cipher = None +# Base directory of the project, resolved from spec file location +project_dir = SPECPATH +assets_dir = os.path.join(project_dir, "assets") +icon_path = os.path.join(assets_dir, "icon.ico") + datas = [] binaries = [] hiddenimports = [] @@ -19,7 +24,7 @@ for pkg in ["nicegui", "plotly", "latex2mathml"]: hiddenimports += collect_submodules(pkg) hiddenimports += collect_submodules("math_app") -datas += [("assets", "assets")] +datas += [(assets_dir, "assets")] datas += collect_data_files("webview") binaries += collect_dynamic_libs("webview") @@ -53,8 +58,8 @@ hiddenimports += [ ] a = Analysis( - ["run.py"], - pathex=["src"], + [os.path.join(project_dir, "run.py")], + pathex=[os.path.join(project_dir, "src")], binaries=binaries, datas=datas, hiddenimports=hiddenimports, @@ -81,7 +86,7 @@ exe = EXE( strip=False, upx=True, console=False, - icon="assets/icon.ico", + icon=icon_path, ) coll = COLLECT( diff --git a/src/math_app/main.py b/src/math_app/main.py index 87dc98c..efd1c61 100644 --- a/src/math_app/main.py +++ b/src/math_app/main.py @@ -207,7 +207,10 @@ def main() -> None: "MathWeave Studio yêu cầu WebView2 Runtime để chạy ở chế độ cửa sổ ứng dụng desktop.\n\n" "Vui lòng tải và cài đặt Microsoft Edge WebView2 Runtime từ:\n" "https://go.microsoft.com/fwlink/p/?LinkId=2124703\n\n" - "Hoặc khởi chạy ứng dụng từ dòng lệnh với tham số --browser để mở qua trình duyệt." + "Hoặc khởi chạy ứng dụng từ dòng lệnh với tham số --browser để mở qua trình duyệt.\n" + "--------------------------------------------------\n" + "Microsoft Edge WebView2 Runtime is not installed on this system.\n" + "Please install it from the link above or launch with --browser." ) sys.stderr.write(f"\n[ERROR] {msg}\n\n") sys.stderr.flush() @@ -222,7 +225,7 @@ def main() -> None: except Exception: pass sys.exit(1) - except ImportError: + except Exception: pass elif sys.platform.startswith("linux"): app.native.start_args["gui"] = "qt"