- 优化Windows打包
This commit is contained in:
parent
4c9a66f586
commit
93c473afe7
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -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
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
.idea/
|
||||
*.c
|
||||
build/
|
||||
dist/
|
||||
nginx/
|
||||
test.py
|
||||
app/helper/sites.py
|
||||
config/user.db
|
||||
|
22
app/main.py
22
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()
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user