feat: 1.1版本更新 - 优化UI界面和激活流程

This commit is contained in:
ruisu
2025-02-17 20:41:33 +08:00
parent 139c73d9c9
commit 3d9835bd7f
6 changed files with 466 additions and 277 deletions

View File

@@ -40,42 +40,50 @@ def get_cursor_paths() -> Tuple[str, str]:
OSError: 当找不到有效路径或系统不支持时抛出
"""
system = platform.system()
logger.info(f"当前操作系统: {system}")
paths_map = {
"Darwin": {
"base": "/Applications/Cursor.app/Contents/Resources/app",
"package": "package.json",
"main": "out/main.js",
},
"Windows": {
"base": os.path.join(
os.getenv("LOCALAPPDATA", ""), "Programs", "Cursor", "resources", "app"
),
"package": "package.json",
"main": "out/main.js",
},
"Linux": {
"bases": ["/opt/Cursor/resources/app", "/usr/share/cursor/resources/app"],
"package": "package.json",
"main": "out/main.js",
},
}
if system not in paths_map:
raise OSError(f"不支持的操作系统: {system}")
if system == "Linux":
for base in paths_map["Linux"]["bases"]:
pkg_path = os.path.join(base, paths_map["Linux"]["package"])
if os.path.exists(pkg_path):
return (pkg_path, os.path.join(base, paths_map["Linux"]["main"]))
if system == "Darwin": # macOS
base_path = "/Applications/Cursor.app/Contents/Resources/app"
pkg_path = os.path.join(base_path, "package.json")
main_path = os.path.join(base_path, "out", "main.js")
if not os.path.exists(pkg_path) or not os.path.exists(main_path):
raise OSError("在 macOS 系统上未找到 Cursor 安装路径")
return pkg_path, main_path
elif system == "Windows":
base_path = os.path.join(
os.getenv("LOCALAPPDATA", ""),
"Programs",
"Cursor",
"resources",
"app"
)
pkg_path = os.path.join(base_path, "package.json")
main_path = os.path.join(base_path, "out", "main.js")
if not os.path.exists(pkg_path) or not os.path.exists(main_path):
raise OSError("在 Windows 系统上未找到 Cursor 安装路径")
return pkg_path, main_path
elif system == "Linux":
linux_paths = [
"/opt/Cursor/resources/app",
"/usr/share/cursor/resources/app"
]
for base_path in linux_paths:
pkg_path = os.path.join(base_path, "package.json")
main_path = os.path.join(base_path, "out", "main.js")
if os.path.exists(pkg_path) and os.path.exists(main_path):
return pkg_path, main_path
raise OSError("在 Linux 系统上未找到 Cursor 安装路径")
base_path = paths_map[system]["base"]
return (
os.path.join(base_path, paths_map[system]["package"]),
os.path.join(base_path, paths_map[system]["main"]),
)
else:
raise OSError(f"不支持的操作系统: {system}")
def check_system_requirements(pkg_path: str, main_path: str) -> bool:
@@ -298,5 +306,24 @@ def patch_cursor_get_machine_id(restore_mode=False) -> None:
sys.exit(1)
# 添加patch函数作为主函数的别名
def patch(restore_mode=False) -> bool:
"""
patch函数作为patch_cursor_get_machine_id的别名
Args:
restore_mode: 是否为恢复模式
Returns:
bool: 修补是否成功
"""
try:
patch_cursor_get_machine_id(restore_mode)
return True
except Exception as e:
logger.error(f"修补失败: {str(e)}")
return False
if __name__ == "__main__":
patch_cursor_get_machine_id()