mirror of
https://github.com/yuaotian/go-cursor-help.git
synced 2025-06-08 12:32:06 +08:00
refactor: Enhance Cursor app modification with improved file handling and signing
- Replaced `cp` with `rsync` for more robust file copying - Added detailed logging for file modification steps - Improved file permission management during modification - Enhanced codesign process with better metadata preservation - Added LaunchServices database rebuild after modification - Improved error handling and user guidance for signing issues - Temporarily disabled restore feature for future refinement
This commit is contained in:
parent
11cda5b82d
commit
11275296b4
@ -308,7 +308,8 @@ modify_cursor_app_files() {
|
|||||||
log_error "无法创建临时目录"
|
log_error "无法创建临时目录"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
cp -R "$CURSOR_APP_PATH" "$temp_dir" || {
|
log_debug "正在复制应用文件: $CURSOR_APP_PATH -> $temp_dir"
|
||||||
|
rsync -a --progress "$CURSOR_APP_PATH/" "$temp_app/" || {
|
||||||
log_error "复制应用失败"
|
log_error "复制应用失败"
|
||||||
rm -rf "$temp_dir"
|
rm -rf "$temp_dir"
|
||||||
return 1
|
return 1
|
||||||
@ -316,10 +317,13 @@ modify_cursor_app_files() {
|
|||||||
|
|
||||||
# 移除签名(增强兼容性)
|
# 移除签名(增强兼容性)
|
||||||
log_info "移除应用签名..."
|
log_info "移除应用签名..."
|
||||||
|
find "$temp_app" -type f -exec chmod 644 {} \;
|
||||||
|
find "$temp_app" -type d -exec chmod 755 {} \;
|
||||||
codesign --remove-signature "$temp_app" >/dev/null 2>&1 || log_warn "签名移除失败(可能已无签名)"
|
codesign --remove-signature "$temp_app" >/dev/null 2>&1 || log_warn "签名移除失败(可能已无签名)"
|
||||||
|
|
||||||
# 处理所有Helper进程
|
# 处理所有Helper进程
|
||||||
find "${temp_app}/Contents/Frameworks" -name "*Helper*.app" | while read helper; do
|
find "${temp_app}/Contents/Frameworks" -name "*Helper*.app" | while read helper; do
|
||||||
|
log_debug "处理Helper进程: $helper"
|
||||||
codesign --remove-signature "$helper" >/dev/null 2>&1
|
codesign --remove-signature "$helper" >/dev/null 2>&1
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -350,17 +354,23 @@ modify_cursor_app_files() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 精确修改内容
|
# 精确修改内容
|
||||||
printf "%sreturn crypto.randomUUID();\n%s" \
|
new_content="${content:0:$switch_pos}return crypto.randomUUID();\n${content:$switch_pos}"
|
||||||
"${content:0:$switch_pos}" \
|
if ! printf "%b" "$new_content" > "$file"; then
|
||||||
"${content:$switch_pos}" > "$file" || {
|
|
||||||
log_error "文件写入失败"
|
log_error "文件写入失败"
|
||||||
return 1
|
return 1
|
||||||
}
|
fi
|
||||||
|
log_info "文件修改成功: ${file/$temp_dir\//}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# 重新签名应用
|
# 重新签名应用
|
||||||
log_info "重新签名应用..."
|
log_info "重新签名应用..."
|
||||||
codesign --sign - --force --deep "$temp_app" >/dev/null 2>&1 || log_warn "重新签名失败(可能影响启动)"
|
xattr -cr "$temp_app" # 清除扩展属性
|
||||||
|
codesign --force --deep --sign - --preserve-metadata=entitlements,identifier,flags "$temp_app" >/dev/null 2>&1 || {
|
||||||
|
log_warn "重新签名失败,尝试以下方法:"
|
||||||
|
log_warn "1. 前往 系统设置 -> 隐私与安全性"
|
||||||
|
log_warn "2. 在『安全性』中找到 Cursor 相关提示"
|
||||||
|
log_warn "3. 点击『仍要打开』"
|
||||||
|
}
|
||||||
|
|
||||||
# 创建应用备份
|
# 创建应用备份
|
||||||
local backup_app="/Applications/Cursor.backup.${timestamp}.app"
|
local backup_app="/Applications/Cursor.backup.${timestamp}.app"
|
||||||
@ -373,7 +383,7 @@ modify_cursor_app_files() {
|
|||||||
|
|
||||||
# 替换原应用
|
# 替换原应用
|
||||||
log_info "安装修改版应用..."
|
log_info "安装修改版应用..."
|
||||||
mv "$temp_app" "$CURSOR_APP_PATH" || {
|
ditto "$temp_app" "$CURSOR_APP_PATH" || {
|
||||||
log_error "应用替换失败,正在恢复..."
|
log_error "应用替换失败,正在恢复..."
|
||||||
mv "$backup_app" "$CURSOR_APP_PATH"
|
mv "$backup_app" "$CURSOR_APP_PATH"
|
||||||
rm -rf "$temp_dir"
|
rm -rf "$temp_dir"
|
||||||
@ -388,6 +398,9 @@ modify_cursor_app_files() {
|
|||||||
find "$CURSOR_APP_PATH" -type d -exec chmod 755 {} \;
|
find "$CURSOR_APP_PATH" -type d -exec chmod 755 {} \;
|
||||||
find "$CURSOR_APP_PATH" -type f -exec chmod 644 {} \;
|
find "$CURSOR_APP_PATH" -type f -exec chmod 644 {} \;
|
||||||
|
|
||||||
|
log_info "正在重建LaunchServices数据库..."
|
||||||
|
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f "$CURSOR_APP_PATH"
|
||||||
|
|
||||||
log_info "Cursor 主程序文件修改完成!原版备份在: ${backup_app/$HOME/\~}"
|
log_info "Cursor 主程序文件修改完成!原版备份在: ${backup_app/$HOME/\~}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -680,7 +693,7 @@ main() {
|
|||||||
log_info "请重启 Cursor 以应用新的配置"
|
log_info "请重启 Cursor 以应用新的配置"
|
||||||
|
|
||||||
# 新增恢复功能选项
|
# 新增恢复功能选项
|
||||||
restore_feature
|
#restore_feature
|
||||||
|
|
||||||
# 显示最后的提示信息
|
# 显示最后的提示信息
|
||||||
show_follow_info
|
show_follow_info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user