mirror of
https://github.com/Zippland/Snap-Solver.git
synced 2026-02-27 08:01:10 +08:00
删除托盘
This commit is contained in:
64
app.py
64
app.py
@@ -5,8 +5,7 @@ import base64
|
|||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import socket
|
import socket
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import pystray
|
from PIL import Image
|
||||||
from PIL import Image, ImageDraw
|
|
||||||
import pyperclip
|
import pyperclip
|
||||||
from models import ModelFactory
|
from models import ModelFactory
|
||||||
import time
|
import time
|
||||||
@@ -15,6 +14,7 @@ import json
|
|||||||
import traceback
|
import traceback
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import sys
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
socketio = SocketIO(app, cors_allowed_origins="*", ping_timeout=30, ping_interval=5, max_http_buffer_size=50 * 1024 * 1024)
|
socketio = SocketIO(app, cors_allowed_origins="*", ping_timeout=30, ping_interval=5, max_http_buffer_size=50 * 1024 * 1024)
|
||||||
@@ -36,33 +36,6 @@ def get_local_ip():
|
|||||||
except Exception:
|
except Exception:
|
||||||
return "127.0.0.1"
|
return "127.0.0.1"
|
||||||
|
|
||||||
def create_tray_icon():
|
|
||||||
# Create a simple icon (a colored circle)
|
|
||||||
icon_size = 64
|
|
||||||
icon_image = Image.new('RGB', (icon_size, icon_size), color='white')
|
|
||||||
draw = ImageDraw.Draw(icon_image)
|
|
||||||
draw.ellipse([4, 4, icon_size-4, icon_size-4], fill='#2196F3') # Using the primary color from our CSS
|
|
||||||
|
|
||||||
# Get server URL
|
|
||||||
ip_address = get_local_ip()
|
|
||||||
server_url = f"http://{ip_address}:5000"
|
|
||||||
|
|
||||||
# Create menu
|
|
||||||
menu = pystray.Menu(
|
|
||||||
pystray.MenuItem(server_url, lambda icon, item: None, enabled=False),
|
|
||||||
pystray.MenuItem("Exit", lambda icon, item: icon.stop())
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create icon
|
|
||||||
icon = pystray.Icon(
|
|
||||||
"SnapSolver",
|
|
||||||
icon_image,
|
|
||||||
"Snap Solver",
|
|
||||||
menu
|
|
||||||
)
|
|
||||||
|
|
||||||
return icon
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
local_ip = get_local_ip()
|
local_ip = get_local_ip()
|
||||||
@@ -449,22 +422,6 @@ def handle_capture_screenshot(data):
|
|||||||
'error': error_msg
|
'error': error_msg
|
||||||
}, room=request.sid)
|
}, room=request.sid)
|
||||||
|
|
||||||
def run_tray():
|
|
||||||
icon = create_tray_icon()
|
|
||||||
icon.run()
|
|
||||||
|
|
||||||
# 添加配置文件路由
|
|
||||||
@app.route('/config/<path:filename>')
|
|
||||||
def serve_config(filename):
|
|
||||||
return send_from_directory(CONFIG_DIR, filename)
|
|
||||||
|
|
||||||
# 添加用于获取所有模型信息的API
|
|
||||||
@app.route('/api/models', methods=['GET'])
|
|
||||||
def get_models():
|
|
||||||
"""返回可用的模型列表"""
|
|
||||||
models = ModelFactory.get_available_models()
|
|
||||||
return jsonify(models)
|
|
||||||
|
|
||||||
def load_model_config():
|
def load_model_config():
|
||||||
"""加载模型配置信息"""
|
"""加载模型配置信息"""
|
||||||
try:
|
try:
|
||||||
@@ -592,6 +549,18 @@ def api_check_update():
|
|||||||
update_info = check_for_updates()
|
update_info = check_for_updates()
|
||||||
return jsonify(update_info)
|
return jsonify(update_info)
|
||||||
|
|
||||||
|
# 添加配置文件路由
|
||||||
|
@app.route('/config/<path:filename>')
|
||||||
|
def serve_config(filename):
|
||||||
|
return send_from_directory(CONFIG_DIR, filename)
|
||||||
|
|
||||||
|
# 添加用于获取所有模型信息的API
|
||||||
|
@app.route('/api/models', methods=['GET'])
|
||||||
|
def get_models():
|
||||||
|
"""返回可用的模型列表"""
|
||||||
|
models = ModelFactory.get_available_models()
|
||||||
|
return jsonify(models)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
local_ip = get_local_ip()
|
local_ip = get_local_ip()
|
||||||
print(f"Local IP Address: {local_ip}")
|
print(f"Local IP Address: {local_ip}")
|
||||||
@@ -603,10 +572,5 @@ if __name__ == '__main__':
|
|||||||
ModelFactory.update_model_capabilities(model_config)
|
ModelFactory.update_model_capabilities(model_config)
|
||||||
print("已加载模型配置信息")
|
print("已加载模型配置信息")
|
||||||
|
|
||||||
# Run system tray icon in a separate thread
|
|
||||||
tray_thread = Thread(target=run_tray)
|
|
||||||
tray_thread.daemon = True
|
|
||||||
tray_thread.start()
|
|
||||||
|
|
||||||
# Run Flask in the main thread without debug mode
|
# Run Flask in the main thread without debug mode
|
||||||
socketio.run(app, host='0.0.0.0', port=5000, allow_unsafe_werkzeug=True)
|
socketio.run(app, host='0.0.0.0', port=5000, allow_unsafe_werkzeug=True)
|
||||||
|
|||||||
@@ -5,5 +5,4 @@ flask-socketio==5.5.1
|
|||||||
python-engineio==4.11.2
|
python-engineio==4.11.2
|
||||||
python-socketio==5.12.1
|
python-socketio==5.12.1
|
||||||
requests==2.32.3
|
requests==2.32.3
|
||||||
openai==1.61.0
|
openai==1.61.0
|
||||||
pystray
|
|
||||||
Reference in New Issue
Block a user