From dd0a307ff4ea6016d70a333baa2e6ee8c623b6c2 Mon Sep 17 00:00:00 2001 From: huangzhenpc Date: Thu, 13 Feb 2025 18:19:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9B=B4=E6=96=B0:=201.=20?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=91=BD=E4=BB=A4=E8=A1=8C=E7=AA=97=E5=8F=A3?= =?UTF-8?q?=E5=BC=B9=E5=87=BA=202.=20=E4=BC=98=E5=8C=96=E6=89=93=E5=8C=85?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=E6=8C=89=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E5=88=86=E7=B1=BB=203.=20=E4=BD=BF=E7=94=A8subprocess?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3os.system?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- account_switcher.py | 80 ++++++++++++++++++++++++++++++++++-------- build.bat | 13 ++++++- cursor_auth_manager.py | 21 ++++++++--- gui/main_window.py | 13 ++++++- testbuild.bat | 7 ++-- version.txt | 2 +- 6 files changed, 110 insertions(+), 26 deletions(-) diff --git a/account_switcher.py b/account_switcher.py index e083f39..39af179 100644 --- a/account_switcher.py +++ b/account_switcher.py @@ -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目录并创建同名文件以阻止更新 diff --git a/build.bat b/build.bat index c8f3325..fc3f522 100644 --- a/build.bat +++ b/build.bat @@ -5,8 +5,19 @@ echo 开始打包流程... :: 更新版本号 python update_version.py +:: 读取版本号 +set /p VERSION=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: diff --git a/gui/main_window.py b/gui/main_window.py index 40f845f..f0fbeb8 100644 --- a/gui/main_window.py +++ b/gui/main_window.py @@ -12,6 +12,7 @@ from PyQt5.QtGui import QIcon, QPixmap import time import requests from urllib.parse import quote +import subprocess sys.path.append(str(Path(__file__).parent.parent)) @@ -1340,7 +1341,17 @@ class MainWindow(QMainWindow): 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文件 diff --git a/testbuild.bat b/testbuild.bat index aab3bd9..5df2f27 100644 --- a/testbuild.bat +++ b/testbuild.bat @@ -29,7 +29,8 @@ set FULL_VERSION=%VERSION%.!TEST_VERSION! echo 完整版本号: !FULL_VERSION! REM 创建测试版本输出目录 -if not exist "dist\test" mkdir "dist\test" +set TEST_DIR=dist\test\%VERSION% +if not exist "!TEST_DIR!" mkdir "!TEST_DIR!" REM 清理旧文件 if exist "dist\听泉cursor助手%VERSION%.exe" del "dist\听泉cursor助手%VERSION%.exe" @@ -39,12 +40,12 @@ REM 执行打包 venv\Scripts\python.exe -m PyInstaller build_nezha.spec --clean REM 移动并重命名文件 -move "dist\听泉cursor助手%VERSION%.exe" "dist\test\听泉cursor助手v!FULL_VERSION!.exe" +move "dist\听泉cursor助手%VERSION%.exe" "!TEST_DIR!\听泉cursor助手v!FULL_VERSION!.exe" echo. echo 测试版本构建完成! echo 版本号: v!FULL_VERSION! -echo 文件位置: dist\test\听泉cursor助手v!FULL_VERSION!.exe +echo 文件位置: !TEST_DIR!\听泉cursor助手v!FULL_VERSION!.exe REM 退出虚拟环境 deactivate diff --git a/version.txt b/version.txt index a423d42..5141b61 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.4.2 \ No newline at end of file +3.4.4 \ No newline at end of file