feat: 全面优化用户界面和操作流程 1.统一所有弹窗界面风格 2.优化禁用更新/突破限制/刷新授权的操作流程 3.增加复制命令按钮功能 4.改进错误提示和操作指引 5.提升整体操作流畅度

This commit is contained in:
huangzhenpc
2025-02-14 20:44:16 +08:00
parent 26e159d71c
commit ae698796e7
9 changed files with 945 additions and 509 deletions

View File

@@ -143,38 +143,101 @@ class CursorResetter:
logging.error(f"更新配置文件失败: {str(e)}")
return False
def disable_auto_update(self) -> bool:
"""禁用自动更新"""
def disable_auto_update(self) -> Tuple[bool, str]:
"""禁用自动更新
Returns:
Tuple[bool, str]: (是否成功, 消息)
"""
try:
updater_path = Path(self.localappdata) / "cursor-updater"
# 删除现有文件/目录
if updater_path.exists():
if updater_path.is_dir():
import shutil
shutil.rmtree(updater_path)
else:
updater_path.unlink()
# 1. 先尝试删除现有文件/目录
try:
if updater_path.exists():
if updater_path.is_dir():
import shutil
shutil.rmtree(str(updater_path))
logging.info("已删除updater目录")
else:
updater_path.unlink()
logging.info("已删除updater文件")
except Exception as e:
logging.warning(f"删除现有updater文件/目录失败: {str(e)}")
# 创建空文件并设置只读
updater_path.touch()
import stat
updater_path.chmod(stat.S_IREAD)
# 设置文件权限
if os.name == 'nt':
subprocess.run(
f'icacls "{updater_path}" /inheritance:r /grant:r "{os.getenv("USERNAME")}:(R)"',
shell=True,
check=True
)
# 2. 创建空文件
try:
# 如果文件已存在,先移除它
if updater_path.exists():
try:
os.remove(str(updater_path))
except:
pass
# 创建空文件
with open(updater_path, 'w') as f:
pass
logging.info("已创建updater空文件")
except Exception as e:
logging.error(f"创建updater文件失败: {str(e)}")
return False, f"创建updater文件失败: {str(e)}"
# 3. 设置文件权限
try:
import stat
# 设置文件为只读
os.chmod(str(updater_path), stat.S_IREAD)
logging.info("已设置只读属性")
if os.name == 'nt':
# 使用takeown获取文件所有权
subprocess.run(['takeown', '/f', str(updater_path)], check=True, capture_output=True)
logging.info("已获取文件所有权")
# 使用icacls设置权限
username = os.getenv("USERNAME")
subprocess.run(
['icacls', str(updater_path), '/inheritance:r', '/grant:r', f'{username}:(R)'],
check=True,
capture_output=True
)
logging.info("已设置文件权限")
except Exception as e:
logging.error(f"设置文件权限失败: {str(e)}")
return False, f"设置文件权限失败: {str(e)}"
# 4. 修改package.json
try:
if self.package_json.exists():
with open(self.package_json, "r", encoding="utf-8") as f:
data = json.load(f)
data["updateUrl"] = ""
data["disableUpdate"] = True
with open(self.package_json, "w", encoding="utf-8", newline='\n') as f:
json.dump(data, f, indent=2)
logging.info("已修改package.json配置")
except Exception as e:
logging.warning(f"修改package.json失败: {str(e)}")
# 5. 验证文件权限
try:
if not updater_path.exists():
return False, "updater文件不存在"
if os.access(str(updater_path), os.W_OK):
return False, "文件权限设置失败"
except Exception as e:
logging.error(f"验证文件权限失败: {str(e)}")
return False, f"验证文件权限失败: {str(e)}"
logging.info("已禁用自动更新")
return True
return True, "Cursor更新已禁用"
except Exception as e:
logging.error(f"禁用自动更新失败: {str(e)}")
return False
error_msg = f"禁用自动更新失败: {str(e)}"
logging.error(error_msg)
return False, error_msg
def reset_cursor(self, disable_update: bool = True) -> Tuple[bool, str]:
"""重置Cursor
@@ -201,8 +264,7 @@ class CursorResetter:
return False, "更新系统MachineGuid失败"
# 4. 禁用自动更新(如果需要)
if disable_update and not self.disable_auto_update():
logging.warning("禁用自动更新失败")
# 5. 修改package.json
if self.package_json.exists():