Files
SolianForPython/AppMain.py
2025-09-11 11:48:02 +00:00

73 lines
1.9 KiB
Python

import os
import threading
import traceback
import signal
import time
# 初始化设置
os.chdir(os.path.dirname(os.path.abspath(__file__))) # 切换到当前目录
import core.WebApp as WebApp
import core.PyWebPageAPI as PyWebPageAPI
import core.WebViewWIndow as WebViewWIndow
import ProjectCfg
def exit_handler(signum, frame):
"""处理退出信号"""
exit(0)
def find_available_port(start_port=5000, end_port=10000):
"""查找可用端口"""
for port in range(start_port, end_port):
if PyWebPageAPI.CheckPortAvailable(port):
return port
print("No available port found.")
exit(1)
def main():
"""主程序逻辑"""
signal.signal(signal.SIGINT, exit_handler)
try:
# 环境检查
if not PyWebPageAPI.EnvironmentCheck():
print("Error: Environment check failed.")
exit(1)
# Webview检查
webview_check = PyWebPageAPI.CheckWebviewInstalled()
if not webview_check[0]:
print("Warning: Webview not installed.")
print(webview_check[1])
StartPort = find_available_port()
# 启动应用
app_thread = threading.Thread(
target=WebApp.AppStart,
args=("127.0.0.1", StartPort),
daemon=True
)
app_thread.start()
try:
WebViewWIndow.WebViewWIndow(#窗口配置
f'http://127.0.0.1:{StartPort}',
ProjectCfg.WINDOW_TITLE,
ProjectCfg.WINDOW_WIDTH,
ProjectCfg.WINDOW_HEIGHT,
)
except Exception as e:
traceback.print_exc()
pass
while app_thread.is_alive():
time.sleep(0.1)
except Exception as e:
traceback.print_exc()
exit(1)
if __name__ == '__main__':
main()