# coding:utf-8 """ 启动入口 — Flet UI """ import sys import os import subprocess import ssl import traceback # 修复 Windows 上 flet_desktop 子进程弹出控制台窗口的问题 _original_popen = subprocess.Popen class Popen(_original_popen): def __init__(self, *args, **kwargs): if sys.platform == "win32" and "creationflags" not in kwargs: kwargs["creationflags"] = subprocess.CREATE_NO_WINDOW super().__init__(*args, **kwargs) subprocess.Popen = Popen # PyInstaller 打包后,设置 FLET_VIEW_PATH 指向打包内的 Flet 客户端 if getattr(sys, 'frozen', False): base_path = sys._MEIPASS flet_client_path = os.path.join(base_path, '.flet', 'client', 'flet-desktop-full-0.85.3') flet_exe = os.path.join(flet_client_path, 'flet', 'flet.exe') log_file = os.path.join(os.path.dirname(sys.executable), 'startup_log.txt') with open(log_file, 'w') as f: f.write(f'base_path: {base_path}\n') f.write(f'flet_client_path: {flet_client_path}\n') f.write(f'flet_exe: {flet_exe}\n') f.write(f'exists: {os.path.exists(flet_exe)}\n') if os.path.exists(flet_exe): f.write('Setting FLET_VIEW_PATH\n') os.environ['FLET_VIEW_PATH'] = flet_client_path f.write(f'FLET_VIEW_PATH: {os.environ.get("FLET_VIEW_PATH")}\n') if hasattr(ssl, '_create_unverified_context'): ssl._create_default_https_context = ssl._create_unverified_context def excepthook(type, value, tb): log_file = os.path.join(os.path.dirname(sys.executable), 'error_log.txt') with open(log_file, 'w') as f: f.write(''.join(traceback.format_exception(type, value, tb))) sys.__excepthook__(type, value, tb) sys.excepthook = excepthook if __name__ == '__main__': from core.ui.flet.app_v2 import run run()