优化更新: 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

@@ -229,7 +229,17 @@ class AccountSwitcher:
try:
# 1. 先关闭所有Cursor进程
if sys.platform == "win32":
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
# 创建startupinfo对象来隐藏命令行窗口
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
# 使用subprocess.run来执行命令并隐藏窗口
subprocess.run(
"taskkill /f /im Cursor.exe >nul 2>&1",
startupinfo=startupinfo,
shell=True
)
time.sleep(2)
# 2. 清理注册表(包括更新系统 MachineGuid
@@ -284,7 +294,17 @@ class AccountSwitcher:
try:
# 1. 先关闭所有Cursor进程
if sys.platform == "win32":
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
# 创建startupinfo对象来隐藏命令行窗口
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
# 关闭Cursor
subprocess.run(
"taskkill /f /im Cursor.exe >nul 2>&1",
startupinfo=startupinfo,
shell=True
)
time.sleep(2)
# 2. 重置机器码
@@ -406,9 +426,19 @@ class AccountSwitcher:
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():
@@ -421,16 +451,16 @@ class AccountSwitcher:
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:
@@ -447,12 +477,7 @@ class AccountSwitcher:
Tuple[bool, str]: (是否成功, 提示消息)
"""
try:
# 1. 先关闭所有Cursor进程
if sys.platform == "win32":
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
time.sleep(2)
# 2. 获取未使用的账号
# 1. 获取未使用的账号
endpoint = "https://cursorapi.nosqli.com/admin/api.account/getUnused"
data = {
"machine_id": self.hardware_id
@@ -504,11 +529,26 @@ class AccountSwitcher:
if not all([email, access_token, refresh_token]):
return False, "获取账号信息不完整"
# 2. 先关闭Cursor进程
if sys.platform == "win32":
# 创建startupinfo对象来隐藏命令行窗口
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
# 使用subprocess.run来执行命令并隐藏窗口
subprocess.run(
"taskkill /f /im Cursor.exe >nul 2>&1",
startupinfo=startupinfo,
shell=True
)
time.sleep(2)
# 3. 更新Cursor认证信息
if not self.auth_manager.update_auth(email, access_token, refresh_token):
return False, "更新Cursor认证信息失败"
# 4. 重置机器码(包含了清理注册表、文件和重启操作
# 4. 重置机器码(使用现有的reset_machine_id方法
if not self.reset_machine_id():
return False, "重置机器码失败"
@@ -546,7 +586,17 @@ class AccountSwitcher:
try:
# 1. 先关闭所有Cursor进程
if sys.platform == "win32":
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
# 创建startupinfo对象来隐藏命令行窗口
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
# 关闭Cursor
subprocess.run(
"taskkill /f /im Cursor.exe >nul 2>&1",
startupinfo=startupinfo,
shell=True
)
time.sleep(2)
# 2. 删除updater目录并创建同名文件以阻止更新