fix trayicon

This commit is contained in:
jxxghp 2023-10-10 14:44:27 +08:00
parent 375e16e0dc
commit 4c9a66f586
2 changed files with 36 additions and 26 deletions

View File

@ -92,7 +92,9 @@ jobs:
Remove-Item -Path "dist" -Recurse -Force Remove-Item -Path "dist" -Recurse -Force
Move-Item -Path "nginx/html/nginx.conf" -Destination "nginx/conf/nginx.conf" -Force Move-Item -Path "nginx/html/nginx.conf" -Destination "nginx/conf/nginx.conf" -Force
New-Item -Path "nginx/temp" -ItemType Directory -Force New-Item -Path "nginx/temp" -ItemType Directory -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
shell: pwsh shell: pwsh
- name: Pyinstaller - name: Pyinstaller

View File

@ -32,7 +32,6 @@ App.add_middleware(
allow_headers=["*"], allow_headers=["*"],
) )
# uvicorn服务 # uvicorn服务
Server = uvicorn.Server(Config(App, host=settings.HOST, port=settings.PORT, Server = uvicorn.Server(Config(App, host=settings.HOST, port=settings.PORT,
reload=settings.DEV, workers=multiprocessing.cpu_count())) reload=settings.DEV, workers=multiprocessing.cpu_count()))
@ -120,24 +119,30 @@ def start_module():
start_frontend() start_frontend()
def open_web(): def start_tray():
"""
启动托盘图标
"""
if not SystemUtils.is_frozen():
return
def open_web():
""" """
调用浏览器打开前端页面 调用浏览器打开前端页面
""" """
import webbrowser import webbrowser
webbrowser.open(f"http://localhost:{settings.NGINX_PORT}") webbrowser.open(f"http://localhost:{settings.NGINX_PORT}")
def quit_app():
def quit_app():
""" """
退出程序 退出程序
""" """
TrayIcon.stop() TrayIcon.stop()
Server.should_exit = True Server.should_exit = True
# 托盘图标
# 托盘图标 TrayIcon = pystray.Icon(
TrayIcon = pystray.Icon(
settings.PROJECT_NAME, settings.PROJECT_NAME,
icon=Image.open(settings.ROOT_PATH / 'app.ico'), icon=Image.open(settings.ROOT_PATH / 'app.ico'),
menu=pystray.Menu( menu=pystray.Menu(
@ -150,7 +155,10 @@ TrayIcon = pystray.Icon(
quit_app, quit_app,
) )
) )
) )
# 启动托盘图标
threading.Thread(target=TrayIcon.run, daemon=True).start()
if __name__ == '__main__': if __name__ == '__main__':
# 初始化数据库 # 初始化数据库
@ -158,6 +166,6 @@ if __name__ == '__main__':
# 更新数据库 # 更新数据库
update_db() update_db()
# 启动托盘 # 启动托盘
threading.Thread(target=TrayIcon.run, daemon=True).start() start_tray()
# 启动API服务 # 启动API服务
Server.run() Server.run()