PC端
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
# -*- mode: python ; coding: utf-8 -*-
|
||||||
|
from PyInstaller.utils.hooks import collect_all
|
||||||
|
|
||||||
|
datas = [('client\\web\\templates', 'client\\web\\templates'), ('client\\web\\static', 'client\\web\\static')]
|
||||||
|
binaries = []
|
||||||
|
hiddenimports = []
|
||||||
|
tmp_ret = collect_all('uvicorn')
|
||||||
|
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
|
||||||
|
tmp_ret = collect_all('webview')
|
||||||
|
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
|
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(
|
||||||
|
['client\\desktop.py'],
|
||||||
|
pathex=[],
|
||||||
|
binaries=binaries,
|
||||||
|
datas=datas,
|
||||||
|
hiddenimports=hiddenimports,
|
||||||
|
hookspath=[],
|
||||||
|
hooksconfig={},
|
||||||
|
runtime_hooks=[],
|
||||||
|
excludes=[],
|
||||||
|
noarchive=False,
|
||||||
|
optimize=0,
|
||||||
|
)
|
||||||
|
pyz = PYZ(a.pure)
|
||||||
|
|
||||||
|
exe = EXE(
|
||||||
|
pyz,
|
||||||
|
a.scripts,
|
||||||
|
a.binaries,
|
||||||
|
a.datas,
|
||||||
|
[],
|
||||||
|
name='Boss直聘AI投递',
|
||||||
|
debug=False,
|
||||||
|
bootloader_ignore_signals=False,
|
||||||
|
strip=False,
|
||||||
|
upx=True,
|
||||||
|
upx_exclude=[],
|
||||||
|
runtime_tmpdir=None,
|
||||||
|
console=False,
|
||||||
|
disable_windowed_traceback=False,
|
||||||
|
argv_emulation=False,
|
||||||
|
target_arch=None,
|
||||||
|
codesign_identity=None,
|
||||||
|
entitlements_file=None,
|
||||||
|
)
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
@echo off
|
||||||
|
chcp 65001 >nul
|
||||||
|
REM ============================================================
|
||||||
|
REM 打包客户端桌面版为单个 exe
|
||||||
|
REM 产物:dist\Boss直聘AI投递.exe
|
||||||
|
REM 使用:把 exe 复制到项目根目录(与 client 目录同级)双击运行,
|
||||||
|
REM client\.env 等配置照常生效。
|
||||||
|
REM ============================================================
|
||||||
|
|
||||||
|
echo [1/2] 安装打包依赖...
|
||||||
|
pip install pyinstaller pywebview --quiet
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo 依赖安装失败,请检查 Python 环境
|
||||||
|
pause & exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
echo [2/2] PyInstaller 打包中(首次较慢,请耐心等待)...
|
||||||
|
pyinstaller --noconfirm --clean --onefile --windowed ^
|
||||||
|
--name "Boss直聘AI投递" ^
|
||||||
|
--collect-all uvicorn ^
|
||||||
|
--collect-all webview ^
|
||||||
|
--add-data "client\web\templates;client\web\templates" ^
|
||||||
|
--add-data "client\web\static;client\web\static" ^
|
||||||
|
client\desktop.py
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo 打包失败,请查看上方报错
|
||||||
|
pause & exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo 打包完成:dist\Boss直聘AI投递.exe
|
||||||
|
echo 请将该 exe 复制到项目根目录(与 client 文件夹同级)后双击运行。
|
||||||
|
pause
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
"""
|
||||||
|
客户端桌面版入口(pywebview)
|
||||||
|
双击运行:后台启动本地面板服务,并用独立桌面窗口展示控制面板。
|
||||||
|
- 开发调试:python -m client.desktop
|
||||||
|
- 仍想用浏览器打开面板:python -m client.desktop --browser
|
||||||
|
- 打包 exe:运行项目根目录 build_exe.bat(产物放项目根目录运行,.env 等相对路径照常生效)
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import socket
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
import webbrowser
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def _prepare_cwd() -> None:
|
||||||
|
"""定位项目根目录作为工作目录,保证 client/.env、logs 等相对路径生效。
|
||||||
|
打包后 exe 放在项目根目录即可;开发时自动切到仓库根目录。"""
|
||||||
|
if getattr(sys, "frozen", False):
|
||||||
|
root = Path(sys.executable).resolve().parent
|
||||||
|
else:
|
||||||
|
root = Path(__file__).resolve().parents[1]
|
||||||
|
os.chdir(root)
|
||||||
|
|
||||||
|
|
||||||
|
_prepare_cwd()
|
||||||
|
|
||||||
|
import uvicorn
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
from client.config import client_settings
|
||||||
|
from client.main import setup_logger
|
||||||
|
|
||||||
|
|
||||||
|
def _wait_port(port: int, timeout: float = 20) -> bool:
|
||||||
|
"""等待本地面板端口就绪"""
|
||||||
|
deadline = time.time() + timeout
|
||||||
|
while time.time() < deadline:
|
||||||
|
try:
|
||||||
|
with socket.create_connection(("127.0.0.1", port), timeout=1):
|
||||||
|
return True
|
||||||
|
except OSError:
|
||||||
|
time.sleep(0.3)
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _port_serving(url: str) -> bool:
|
||||||
|
"""端口是否已有面板服务在响应(避免重复启动)"""
|
||||||
|
import urllib.request
|
||||||
|
try:
|
||||||
|
with urllib.request.urlopen(url, timeout=2) as resp:
|
||||||
|
return resp.status == 200
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
setup_logger()
|
||||||
|
|
||||||
|
host = client_settings.WEB_HOST
|
||||||
|
port = client_settings.WEB_PORT
|
||||||
|
url = f"http://{host}:{port}"
|
||||||
|
|
||||||
|
if _port_serving(url):
|
||||||
|
logger.info("检测到面板服务已在运行,直接打开桌面窗口")
|
||||||
|
else:
|
||||||
|
# 面板服务放到后台线程,主线程留给桌面窗口(webview 要求占用主线程)
|
||||||
|
from client.web.app import app
|
||||||
|
threading.Thread(
|
||||||
|
target=uvicorn.run,
|
||||||
|
kwargs={"app": app, "host": host, "port": port, "log_level": "warning"},
|
||||||
|
daemon=True,
|
||||||
|
).start()
|
||||||
|
|
||||||
|
if "--browser" in sys.argv:
|
||||||
|
# 兼容旧习惯:浏览器打开面板,服务前台常驻
|
||||||
|
if _wait_port(port):
|
||||||
|
logger.success(f"控制面板地址:{url}")
|
||||||
|
webbrowser.open(url)
|
||||||
|
else:
|
||||||
|
logger.error("面板服务启动超时,请查看日志")
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
time.sleep(3600)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
return
|
||||||
|
|
||||||
|
if not _wait_port(port):
|
||||||
|
logger.error("面板服务启动超时,请查看 client/logs/client.log")
|
||||||
|
input("按回车退出...")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
logger.success(f"桌面窗口已就绪(服务地址:{url})")
|
||||||
|
|
||||||
|
import webview
|
||||||
|
window = webview.create_window(
|
||||||
|
"Boss直聘 AI 智能投递",
|
||||||
|
url,
|
||||||
|
width=1080,
|
||||||
|
height=800,
|
||||||
|
min_size=(960, 680),
|
||||||
|
background_color="#f0f4f8",
|
||||||
|
)
|
||||||
|
# gui 参数留空 = 自动选择系统最佳渲染(Win10/11 用 WebView2)
|
||||||
|
webview.start(debug=False)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -8,3 +8,5 @@ openai>=1.30.0
|
|||||||
pydantic>=2.7.0
|
pydantic>=2.7.0
|
||||||
pydantic-settings>=2.3.0
|
pydantic-settings>=2.3.0
|
||||||
loguru>=0.7.2
|
loguru>=0.7.2
|
||||||
|
websocket-client>=1.7.0
|
||||||
|
pywebview>=5.0
|
||||||
|
|||||||
Reference in New Issue
Block a user