diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 64649737..6e7a592d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -95,6 +95,7 @@ jobs: New-Item -Path "nginx/temp/__keep__.txt" -ItemType File -Force New-Item -Path "nginx/logs" -ItemType Directory -Force New-Item -Path "nginx/logs/__keep__.txt" -ItemType File -Force + Rename-Item -Path "nginx/nginx.exe" -NewName "nginx/nginx_mp.exe" -Force shell: pwsh - name: Pyinstaller diff --git a/.gitignore b/.gitignore index 7c6cc139..78ce082c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .idea/ *.c build/ +dist/ +nginx/ test.py app/helper/sites.py config/user.db diff --git a/app/main.py b/app/main.py index a190ef93..ed05a05b 100644 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,6 @@ import multiprocessing +import os +import sys import threading from pathlib import Path @@ -9,6 +11,13 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from uvicorn import Config +from app.utils.system import SystemUtils + +# 禁用输出 +if SystemUtils.is_frozen(): + sys.stdout = open(os.devnull, 'w') + sys.stderr = open(os.devnull, 'w') + from app.command import Command from app.core.config import settings from app.core.module import ModuleManager @@ -17,7 +26,6 @@ from app.db.init import init_db, update_db from app.helper.display import DisplayHelper from app.helper.sites import SitesHelper from app.scheduler import Scheduler -from app.utils.system import SystemUtils # App App = FastAPI(title=settings.PROJECT_NAME, @@ -56,9 +64,9 @@ def start_frontend(): if not SystemUtils.is_frozen(): return if SystemUtils.is_windows(): - nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx.exe' + nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx_mp.exe' else: - nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx' + nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx_mp' if Path(nginx_path).exists(): import subprocess subprocess.Popen(f"start {nginx_path}", shell=True) @@ -72,9 +80,9 @@ def stop_frontend(): return import subprocess if SystemUtils.is_windows(): - subprocess.Popen(f"taskkill /f /im nginx.exe", shell=True) + subprocess.Popen(f"taskkill /f /im nginx_mp.exe", shell=True) else: - subprocess.Popen(f"killall nginx", shell=True) + subprocess.Popen(f"killall nginx_mp", shell=True) @App.on_event("shutdown") @@ -161,11 +169,11 @@ def start_tray(): if __name__ == '__main__': + # 启动托盘 + start_tray() # 初始化数据库 init_db() # 更新数据库 update_db() - # 启动托盘 - start_tray() # 启动API服务 Server.run() diff --git a/windows.spec b/windows.spec index b44967b3..14ae1ec7 100644 --- a/windows.spec +++ b/windows.spec @@ -75,7 +75,7 @@ exe = EXE( a.scripts, a.binaries, a.zipfiles, - a.datas, + a.datas + [('./app.ico', './app.ico', 'DATA')], collect_pkg_data('config'), collect_pkg_data('nginx'), collect_pkg_data('cf_clearance'), @@ -88,7 +88,7 @@ exe = EXE( upx=True, upx_exclude=[], runtime_tmpdir=None, - console=True, + console=False, disable_windowed_traceback=False, argv_emulation=False, target_arch=None,