- 优化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/temp/__keep__.txt" -ItemType File -Force
|
||||||
New-Item -Path "nginx/logs" -ItemType Directory -Force
|
New-Item -Path "nginx/logs" -ItemType Directory -Force
|
||||||
New-Item -Path "nginx/logs/__keep__.txt" -ItemType File -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
|
shell: pwsh
|
||||||
|
|
||||||
- name: Pyinstaller
|
- name: Pyinstaller
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,8 @@
|
|||||||
.idea/
|
.idea/
|
||||||
*.c
|
*.c
|
||||||
build/
|
build/
|
||||||
|
dist/
|
||||||
|
nginx/
|
||||||
test.py
|
test.py
|
||||||
app/helper/sites.py
|
app/helper/sites.py
|
||||||
config/user.db
|
config/user.db
|
||||||
|
22
app/main.py
22
app/main.py
@ -1,4 +1,6 @@
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import threading
|
import threading
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -9,6 +11,13 @@ from fastapi import FastAPI
|
|||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from uvicorn import Config
|
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.command import Command
|
||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
from app.core.module import ModuleManager
|
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.display import DisplayHelper
|
||||||
from app.helper.sites import SitesHelper
|
from app.helper.sites import SitesHelper
|
||||||
from app.scheduler import Scheduler
|
from app.scheduler import Scheduler
|
||||||
from app.utils.system import SystemUtils
|
|
||||||
|
|
||||||
# App
|
# App
|
||||||
App = FastAPI(title=settings.PROJECT_NAME,
|
App = FastAPI(title=settings.PROJECT_NAME,
|
||||||
@ -56,9 +64,9 @@ def start_frontend():
|
|||||||
if not SystemUtils.is_frozen():
|
if not SystemUtils.is_frozen():
|
||||||
return
|
return
|
||||||
if SystemUtils.is_windows():
|
if SystemUtils.is_windows():
|
||||||
nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx.exe'
|
nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx_mp.exe'
|
||||||
else:
|
else:
|
||||||
nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx'
|
nginx_path = settings.ROOT_PATH / 'nginx' / 'nginx_mp'
|
||||||
if Path(nginx_path).exists():
|
if Path(nginx_path).exists():
|
||||||
import subprocess
|
import subprocess
|
||||||
subprocess.Popen(f"start {nginx_path}", shell=True)
|
subprocess.Popen(f"start {nginx_path}", shell=True)
|
||||||
@ -72,9 +80,9 @@ def stop_frontend():
|
|||||||
return
|
return
|
||||||
import subprocess
|
import subprocess
|
||||||
if SystemUtils.is_windows():
|
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:
|
else:
|
||||||
subprocess.Popen(f"killall nginx", shell=True)
|
subprocess.Popen(f"killall nginx_mp", shell=True)
|
||||||
|
|
||||||
|
|
||||||
@App.on_event("shutdown")
|
@App.on_event("shutdown")
|
||||||
@ -161,11 +169,11 @@ def start_tray():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
# 启动托盘
|
||||||
|
start_tray()
|
||||||
# 初始化数据库
|
# 初始化数据库
|
||||||
init_db()
|
init_db()
|
||||||
# 更新数据库
|
# 更新数据库
|
||||||
update_db()
|
update_db()
|
||||||
# 启动托盘
|
|
||||||
start_tray()
|
|
||||||
# 启动API服务
|
# 启动API服务
|
||||||
Server.run()
|
Server.run()
|
||||||
|
@ -75,7 +75,7 @@ exe = EXE(
|
|||||||
a.scripts,
|
a.scripts,
|
||||||
a.binaries,
|
a.binaries,
|
||||||
a.zipfiles,
|
a.zipfiles,
|
||||||
a.datas,
|
a.datas + [('./app.ico', './app.ico', 'DATA')],
|
||||||
collect_pkg_data('config'),
|
collect_pkg_data('config'),
|
||||||
collect_pkg_data('nginx'),
|
collect_pkg_data('nginx'),
|
||||||
collect_pkg_data('cf_clearance'),
|
collect_pkg_data('cf_clearance'),
|
||||||
@ -88,7 +88,7 @@ exe = EXE(
|
|||||||
upx=True,
|
upx=True,
|
||||||
upx_exclude=[],
|
upx_exclude=[],
|
||||||
runtime_tmpdir=None,
|
runtime_tmpdir=None,
|
||||||
console=True,
|
console=False,
|
||||||
disable_windowed_traceback=False,
|
disable_windowed_traceback=False,
|
||||||
argv_emulation=False,
|
argv_emulation=False,
|
||||||
target_arch=None,
|
target_arch=None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user