优化更新: 1. 隐藏命令行窗口弹出 2. 优化打包目录结构按版本号分类 3. 使用subprocess替代os.system

This commit is contained in:
huangzhenpc
2025-02-13 18:19:06 +08:00
parent b5cbf0779b
commit dd0a307ff4
6 changed files with 110 additions and 26 deletions

View File

@@ -5,6 +5,7 @@ import time
import logging
import sqlite3
from pathlib import Path
import subprocess
class CursorAuthManager:
"""Cursor认证信息管理器"""
@@ -99,9 +100,19 @@ class CursorAuthManager:
logging.info("正在重启Cursor...")
if sys.platform == "win32":
# Windows系统
# 创建startupinfo对象来隐藏命令行窗口
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
# 关闭Cursor
os.system("taskkill /f /im Cursor.exe 2>nul")
subprocess.run(
"taskkill /f /im Cursor.exe 2>nul",
startupinfo=startupinfo,
shell=True
)
time.sleep(2)
# 获取Cursor安装路径
cursor_exe = self.cursor_path / "Cursor.exe"
if cursor_exe.exists():
@@ -114,16 +125,16 @@ class CursorAuthManager:
return False
elif sys.platform == "darwin":
# macOS系统
os.system("killall Cursor 2>/dev/null")
subprocess.run("killall Cursor 2>/dev/null", shell=True)
time.sleep(2)
os.system("open -a Cursor")
subprocess.run("open -a Cursor", shell=True)
logging.info("Cursor重启成功")
return True
elif sys.platform == "linux":
# Linux系统
os.system("pkill -f cursor")
subprocess.run("pkill -f cursor", shell=True)
time.sleep(2)
os.system("cursor &")
subprocess.run("cursor &", shell=True)
logging.info("Cursor重启成功")
return True
else: