更新: 1. 优化程序关闭逻辑,解决临时文件清理问题 2. 更新程序版本到 3.0.4
This commit is contained in:
@@ -257,25 +257,80 @@ class AccountSwitcher:
|
||||
def reset_machine_id(self) -> bool:
|
||||
"""重置机器码"""
|
||||
try:
|
||||
# 读取package.json
|
||||
with open(self.package_json, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
# 1. 先关闭所有Cursor进程
|
||||
if sys.platform == "win32":
|
||||
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
|
||||
time.sleep(2)
|
||||
|
||||
# 删除machineId
|
||||
if "machineId" in data:
|
||||
del data["machineId"]
|
||||
|
||||
# 保存文件
|
||||
with open(self.package_json, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
# 2. 删除 package.json 中的 machineId
|
||||
if self.package_json.exists():
|
||||
with open(self.package_json, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if "machineId" in data:
|
||||
del data["machineId"]
|
||||
|
||||
with open(self.package_json, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, indent=2)
|
||||
|
||||
# 3. 清理特定的配置文件
|
||||
local_app_data = Path(os.getenv('LOCALAPPDATA'))
|
||||
cursor_path = local_app_data / "Cursor"
|
||||
|
||||
config_files = [
|
||||
cursor_path / "User" / "globalStorage" / "storage.json",
|
||||
cursor_path / "User" / "globalStorage" / "state.json",
|
||||
self.app_path / "config.json",
|
||||
self.app_path / "state.json",
|
||||
self.app_path / "settings.json"
|
||||
]
|
||||
|
||||
for file_path in config_files:
|
||||
if file_path.exists():
|
||||
try:
|
||||
os.remove(file_path)
|
||||
logging.info(f"删除配置文件成功: {file_path}")
|
||||
except Exception as e:
|
||||
logging.warning(f"删除配置文件失败: {file_path}, 错误: {str(e)}")
|
||||
|
||||
# 4. 刷新注册表
|
||||
if not self.registry.refresh_registry():
|
||||
logging.warning("注册表刷新失败")
|
||||
|
||||
# 5. 重启Cursor
|
||||
cursor_exe = self.cursor_path / "Cursor.exe"
|
||||
if cursor_exe.exists():
|
||||
os.startfile(str(cursor_exe))
|
||||
logging.info("Cursor重启成功")
|
||||
|
||||
logging.info("机器码重置完成")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"重置机器码失败: {str(e)}")
|
||||
return False
|
||||
|
||||
def bypass_version_limit(self) -> Tuple[bool, str]:
|
||||
"""突破Cursor版本限制"""
|
||||
try:
|
||||
# 1. 先关闭所有Cursor进程
|
||||
if sys.platform == "win32":
|
||||
os.system("taskkill /f /im Cursor.exe >nul 2>&1")
|
||||
time.sleep(2)
|
||||
|
||||
# 2. 重置机器码
|
||||
if not self.reset_machine_id():
|
||||
return False, "重置机器码失败"
|
||||
|
||||
# 3. 等待Cursor启动
|
||||
time.sleep(3)
|
||||
|
||||
return True, "突破版本限制成功,Cursor已重启"
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"突破版本限制失败: {str(e)}")
|
||||
return False, f"突破失败: {str(e)}"
|
||||
|
||||
def activate_and_switch(self, activation_code: str) -> Tuple[bool, str]:
|
||||
"""激活并切换账号
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from pathlib import Path
|
||||
import logging
|
||||
import os
|
||||
from PIL import Image, ImageTk
|
||||
import time
|
||||
sys.path.append(str(Path(__file__).parent.parent))
|
||||
|
||||
from utils.config import Config
|
||||
@@ -276,22 +277,44 @@ class MainWindow:
|
||||
"""窗口关闭处理"""
|
||||
try:
|
||||
logging.info("正在关闭程序...")
|
||||
# 先退出主循环
|
||||
self.root.quit()
|
||||
# 等待一小段时间确保资源释放
|
||||
time.sleep(0.5)
|
||||
except Exception as e:
|
||||
logging.error(f"关闭程序时出错: {str(e)}")
|
||||
finally:
|
||||
self.root.destroy()
|
||||
try:
|
||||
# 销毁窗口
|
||||
self.root.destroy()
|
||||
# 再等待一小段时间
|
||||
time.sleep(0.5)
|
||||
# 强制结束进程
|
||||
if sys.platform == "win32":
|
||||
import os
|
||||
os._exit(0)
|
||||
except:
|
||||
# 如果还是无法正常关闭,直接强制退出
|
||||
os._exit(0)
|
||||
|
||||
def run(self):
|
||||
"""运行程序"""
|
||||
self.root.mainloop()
|
||||
|
||||
def dummy_function(self):
|
||||
"""占位函数"""
|
||||
"""突破版本限制"""
|
||||
# 先检查状态
|
||||
if not self.check_status():
|
||||
return
|
||||
messagebox.showinfo("提示", "此功能暂未实现")
|
||||
|
||||
try:
|
||||
success, message = self.switcher.bypass_version_limit()
|
||||
if success:
|
||||
messagebox.showinfo("成功", message)
|
||||
else:
|
||||
messagebox.showerror("错误", message)
|
||||
except Exception as e:
|
||||
messagebox.showerror("错误", f"操作失败: {str(e)}")
|
||||
|
||||
def reset_machine_id(self):
|
||||
"""刷新Cursor编辑器授权"""
|
||||
|
||||
@@ -1 +1 @@
|
||||
3.0.2
|
||||
3.0.4
|
||||
Reference in New Issue
Block a user