Repository navigation
Conversation
…mbedded results panel Annotation experience upgrade per the 标注体验与内嵌面板增强 PRD: - Shapes: rectangle/ellipse gain an independent fillColor with legacy fallback to stroke color, solid/hollow toggle, and ⌘-held square/circle constraint while drawing plus ⌘-held aspect-ratio lock while resizing - Text: add wrapWidth with precise NSFont measurement so multi-line boxes never truncate; 8 control handles (corners scale font+wrap, left/right edges re-wrap, top/bottom scale font); multi-line TextEditor input - Color: preset swatches, system ColorPicker and NSColorSampler eyedropper in both the preview style bar and the in-place toolbar - Smart mosaic: SmartPrivacyRedactionService detects privacy regions via the configured VLM provider (prompt-parameterized analyze(image:prompt:)) and batch-applies mosaic layers with one-step undo; button on preview and in-place toolbars with not-configured/detecting/none/failure toasts - Embedded results drawer: right-side panel in the preview window with OCR/translation tabs, skeleton loading, per-line copy, bilingual comparison, target-language switch, rerun/copy-all/close; in-place OCR/translate now route to this panel instead of an external window - Fix menu bar raw localization keys (menu.pick.color, menu.open.image) Tests: add model coverage for fill-color fallback, multi-line wrap bounds, aspect-locked handle drag, and text handle scaling/wrapping.
…istory and pin polish - BeautifyRenderer: optional background/shadow beautification pass applied on capture confirm - ImageUploadService: optional cloud upload action in the in-place toolbar - ScrollCaptureSession: long-page scrolling capture session support - History: richer translation history persistence and list UI - Pinned windows: layout and interaction polish - Menu bar: screen color picker and open-image menu entries - Cursor extensions for annotation tool feedback
- release workflow: sign release artifacts with Developer ID - create_dmg: packaging script adjustments - App icon set refresh (all sizes)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…xt drag after commit Close the gaps found in PRD review: - In-place OCR/translation: SelectionOverlayWindow expands an embedded right-side drawer (InPlaceResultsPanel) with OCR/translation tabs, per-line copy, bilingual comparison, target-language switch and rerun/close — the capture window no longer jumps to another view - Line tool: add line drawing to the in-place toolbar with ⌘-free two-point drag (preview toolbar already had it) - ⌘ constraints in the in-place overlay: square/circle while drawing, aspect-ratio lock while dragging resize handles (preview tools already had both) - Text boxes: commit now keeps the box selected so its 8 handles show immediately; single click drags the whole box (with active tool too), double click re-edits content in place — in the preview window and the in-place overlay alike - Smart mosaic: share the VLM configuration explicitly (in-memory key + per-provider Keychain key) and reword the not-configured prompt to name the VLM settings it shares - Preview toolbar: add a translation button feeding the embedded drawer
评审反馈修复(c168d8a)针对手测发现的 PRD 未落地项,已全部修复并重新安装到本机验证启动:
验证: |
Unit layer (PRDAcceptanceTests, 12 cases): - Localization completeness: every dotted key referenced in source must resolve in BOTH languages with a non-expired value — caught 45 real missing keys (error.mtran/ocr.*, lang.*, translation.provider.recovery.*, preview.pin, translation.unknown), all now filled - Per-PRD checks: menu copy, text tool naming, line tool in both toolchains, ⌘ square/circle/aspect (GeometryConstraint, injectable constrainSquare for tool tests), dual-color fill isolation + export pixel assertion, text commit selection/8 handles/drag, mosaic intensity clamping, shared VLM config for smart mosaic, embedded drawer model E2E layer (scripts/e2e/, drives the installed app via AX + CGEvent): - eventsynth: drag/click/type/key synthesis, screencapture crops, red-stroke bbox and pixel-diff assertions - run_e2e.sh: menu localization, in-place OCR drawer (window count unchanged, drawer chrome, OCR text, close), line draw, text commit + drag, ⌘ square via bbox ratio — 18/18 passing Product fixes surfaced by the tests: - In-place toolbar buttons get accessibility labels - RectangleTool/EllipseTool expose calculatedRect(constrainSquare:) backed by shared GeometryConstraint (overlay reuses it)
测试层交付(624a4c0)— 不等手测,测试先行单元/验收层:
|
| 场景 | 断言 | 结果 |
|---|---|---|
| 菜单本地化 | 含「屏幕取色/打开图片编辑.../区域截图」,无裸键名 | PASS |
| 就地 OCR 内嵌面板 | 按 OCR 后窗口数不变(无外部窗);面板出现含关闭;结果含识别文本;关闭收起 | PASS |
| 直线工具 | 就地工具栏激活直线并绘制,像素 diff 0.0195 | PASS |
| 文本框 | 提交后画布有内容(0.010);拖动后像素位移(0.016) | PASS |
| ⌘ 正方形 | 像素 bbox 446×443(2x),|w−h|=3 ≤ 4 | PASS |
截图证据(⌘ 正方形实绘):外框正圆/正方约束实测生效。
测试驱动出的产品修复
- 就地工具栏按钮补无障碍标签(E2E/VoiceOver 定位)
- ⌘ 约束收敛为共享
GeometryConstraint,工具层参数可注入(可测)
备注
E2E 过程中系统弹出一次 Keychain 授权(重签名身份首次访问旧密钥,预期一次性行为),已顺手取消;稳定授权需你在屏幕上触控 ID 一次。
…ults drawer Address the three interaction reports: 1. Toolbar edge clicks no longer leak through to the overlay and cancel the selection. Button hit areas expand inside the label (padding + contentShape) so edge clicks activate the tool; SelectionInPlaceToolbar now swallows every click within the bar via hitTest override so the remaining dead zones are inert instead of destructive. Preview toolbar buttons get the same contentShape treatment. 2. Clicking outside the selection and toolbar is now a no-op: a plain click restores the previous selection and toolbar (only a real drag starts a new selection). Window-snap re-picking no longer hijacks a stray click. 3. The OCR/translation drawer merges with the selection into one interaction unit: flush to its edge, height follows the selection, re-anchors while moving/resizing, closes together with it. Results text (both tabs) now use SelectableTextBlock (NSTextView) — continuous cross-line selection, click-to-copy the clicked line, 原文/译文 styles preserved in one selectable block. Applies to the preview drawer too. Tests: unit coverage for line extraction and attributed builders; E2E scenarios for edge activation, outside-click inertness and cross-line clipboard copy.
交互修复交付(dce286e)— 三项报告的实现与验证
测试结果
|
… capture hotkeys Regression fixes for the 2026-10-23 interaction report: 1. hitTest coordinate contract: NSView.hitTest receives its point in the SUPERVIEW's coordinate system, but the in-place toolbar compared it to its own local `bounds`, rejecting nearly every real click and starving SwiftUI hover events. Rectangle/ellipse tooltips vanished first because they sit at the row edge where the mis-guarded check failed hardest. Check `frame.contains(point)` (superview space) instead. 2. preferredSize truncation: the hard-coded 520pt width predated the line/smart-mosaic/eyedropper additions and pushed the leftmost buttons outside the view, killing their hover areas and click targets. Derive the size from NSHostingView.fittingSize so the row never clips. 3. 截图翻译 vs 区域截图: translation mode only remapped copy→translate at final confirm, so both hotkeys presented identical flows. CaptureMode now declares its post-selection action (screenshotTranslation → .translate); the overlay runs it automatically after a fresh region commit, opening the in-place translation drawer immediately. Tests: hitTest superview-coordinate contract, preferredSize vs content fitting, CaptureMode action distinction. E2E: real-click tool activation, rectangle/ellipse tooltip screenshots, and hotkey separation scenarios.
交互回归修复(0d9569f)— 三项症状均已验证
测试
之前 E2E 全绿却漏掉这批回归的原因:测试用 AXPress 触发按钮(绕过真实 hitTest 链),且坐标在样式栏展开后失效。本轮改用真实 CGEvent 鼠标事件。 |
…ine text selection - New BilingualOverlayView renders translated strips directly below source text inside the selection (anchored, width-capped, never covering source) - SelectableTextBlock supports cross-line selection and line copy - Results drawer/panel polish; separate capture hotkeys; e2e harness updates - PRD acceptance coverage for overlay anchors, drawer actions, toolbars 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…tput, OCR queueing - New AnalysisImageEncoder caps analysis uploads at 2000px longest edge for all six provider paths (OpenAI/Claude/Gemini/Ollama/PaddleOCR cloud+local); normalized bboxes unaffected, PaddleOCR size baseline tracks the sent image - OpenAI/Claude continuation rounds replace the base64 image with a text placeholder instead of re-uploading it per retry - OpenAI chat adds response_format json_object with one-shot 400 fallback; Responses API adds text.format; Ollama native uses format:"json"; Gemini OpenAI-compatible branch adds response_format - Local-endpoint max_tokens 1024/2048 -> 4096 - Vision OCR languages follow the source-language setting (auto-detect fallback) instead of hardcoded en+zh - OCREngine drops the busy-reject mutex and runs Vision on a global queue; PaddleOCR queues callers FIFO; removes operationInProgress errors and the unused detectLanguage scan - Removes unwired GLMOCRVLMProvider (528 lines) and its tests Verified: full TransFrameTests suite green incl. new AnalysisImageEncoderTests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Per opencode.ai/docs/github: anomalyco/opencode/github action runs on pull_request events; requires the opencode-agent GitHub App and an ANTHROPIC_API_KEY Actions secret to be configured by the repo admin. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The previous commit wired up sst/opencode by mistake; the user wants alibaba/open-code-review (alibaba/open-code-review#action). Uses the official composite action v1.13.3 with DashScope Qwen (OpenAI-compatible, thinking disabled), Chinese review output. Requires a single repo secret: OCR_LLM_AUTH_TOKEN (DashScope API key). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
llm_url https://api.z.ai/api/coding/paas/v4/chat/completions, model glm-4.6, GLM-style thinking-disable extra_body. Secret renamed in docs to Z.ai key (still OCR_LLM_AUTH_TOKEN). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
pull_request_target only fires workflows already on the default branch, so the branch-hosted ocr-review.yml never ran. Same-repo PRs can read secrets with plain pull_request; switch back if fork PRs need reviews. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
🔍 OpenCodeReview found 47 issue(s) in this PR.
📄
|
| timeout-minutes: 30 | ||
| steps: | ||
| - name: Run OpenCodeReview | ||
| uses: alibaba/open-code-review@v1.13.3 |
There was a problem hiding this comment.
第三方 action alibaba/open-code-review@v1.13.3 仅锁定可变 tag,而该 step 接收 llm_auth_token secret:若 tag 被劫持,token 会泄露给第三方代码。此 action 并非 GitHub 官方(actions/*),按最小信任原则应 pin 到完整 commit SHA。
Suggestion:
| uses: alibaba/open-code-review@v1.13.3 | |
| uses: alibaba/open-code-review@<full-commit-sha> # v1.13.3 |
| # Also create an explicit arm64-named DMG for release downloads | ||
| cp "$DMG_FILE" "$ARM64_DMG_FILE" |
There was a problem hiding this comment.
release 构建改为 ARCHS=arm64 单架构后,同一产物被复制成两个 DMG($NAME-$VERSION.dmg 与 $NAME-$VERSION-arm64.dmg):无后缀的通用命名不再准确(不含 x86_64 切片),已下载过旧通用版的用户可能误判升级包架构。建议无后缀文件仅保留向后兼容或改为显式 -universal/-arm64 命名,并在 release 上传步骤中注明架构。
Suggestion:
| # Also create an explicit arm64-named DMG for release downloads | |
| cp "$DMG_FILE" "$ARM64_DMG_FILE" | |
| # arm64-only build; keep the un-suffixed name for backward compatibility, | |
| # but ensure release notes state this is an arm64-only artifact. | |
| cp "$DMG_FILE" "$ARM64_DMG_FILE" | |
| shasum -a 256 "$DMG_FILE" "$ARM64_DMG_FILE" > "${VERSION}.sha256" |
| lipo -thin "$TARGET_ARCH" "$SPARKLE_DIR/$b" -output "$SPARKLE_DIR/$b.thin" 2>/dev/null && mv "$SPARKLE_DIR/$b.thin" "$SPARKLE_DIR/$b" || true | ||
| strip -x "$SPARKLE_DIR/$b" 2>/dev/null || true |
There was a problem hiding this comment.
对 Sparkle 框架内二进制执行 lipo -thin 和 strip 后未重新签名:lipo/strip 都会使已有的代码签名失效(摘要不再匹配),若外层随后用 --deep 重签尚可掩盖,但在非 --deep 路径下会导致框架签名无效、更新安装失败。且 || true 静默吞掉失败,构建者无法得知瘦身是否生效,建议至少输出警告日志。
Suggestion:
| lipo -thin "$TARGET_ARCH" "$SPARKLE_DIR/$b" -output "$SPARKLE_DIR/$b.thin" 2>/dev/null && mv "$SPARKLE_DIR/$b.thin" "$SPARKLE_DIR/$b" || true | |
| strip -x "$SPARKLE_DIR/$b" 2>/dev/null || true | |
| if ! lipo -thin "$TARGET_ARCH" "$SPARKLE_DIR/$b" -output "$SPARKLE_DIR/$b.thin"; then | |
| echo "⚠️ lipo -thin 失败: $b" >&2 | |
| else | |
| mv "$SPARKLE_DIR/$b.thin" "$SPARKLE_DIR/$b" | |
| strip -x "$SPARKLE_DIR/$b" 2>/dev/null || true | |
| fi |
| SIGN_IDENTITY=$(security find-identity -v -p codesigning | grep -m1 "Developer ID Application" | awk -F '"' '{print $2}' || true) | ||
| if [ -n "$SIGN_IDENTITY" ]; then | ||
| echo "🔐 使用 Developer ID 签名: $SIGN_IDENTITY" | ||
| codesign --force --deep --options runtime --timestamp=none --sign "$SIGN_IDENTITY" "$DMG_TEMP_DIR/TransFrame.app" |
There was a problem hiding this comment.
对整包使用 --deep 签名并关闭时间戳(--timestamp=none)存在分发风险:--deep 不按各自 entitlements 正确签名嵌套 helper(Sparkle 的 Autoupdate/Installer.xpc 等),且无安全时间戳的 hardened runtime 签名通常无法通过 Apple 公证,可能导致 Gatekeeper 拒绝或 Sparkle 更新校验失败。建议去掉 --deep,显式逐层签名(先嵌套 helper/xpc 再外层 app),并使用 --timestamp(默认时间戳服务)而非 --timestamp=none。另外 lipo -thin + strip 后必须重新签名这些二进制,否则签名摘要与内容不一致。
Suggestion:
| codesign --force --deep --options runtime --timestamp=none --sign "$SIGN_IDENTITY" "$DMG_TEMP_DIR/TransFrame.app" | |
| codesign --force --options runtime --timestamp --sign "$SIGN_IDENTITY" "$DMG_TEMP_DIR/TransFrame.app" |
| guard let ev = CGEvent(mouseEventSource: nil, mouseType: type, | ||
| mouseCursorPosition: CGPoint(x: x, y: y), mouseButton: button) else { return } |
There was a problem hiding this comment.
CGEvent 创建失败时静默 return(仅打印到 /dev/null),合成输入实际未发出。E2E 脚本随后对截图/AX 状态做断言,会因“没有事件但环境没变化”得到看似确定的假失败,或相反在某些检查中被 vacuous 通过。建议失败时向 stderr 输出事件类型与坐标并 exit(1),让上层明确失败而非产生不可诊断的像素 diff。
Suggestion:
| guard let ev = CGEvent(mouseEventSource: nil, mouseType: type, | |
| mouseCursorPosition: CGPoint(x: x, y: y), mouseButton: button) else { return } | |
| guard let ev = CGEvent(mouseEventSource: nil, mouseType: type, | |
| mouseCursorPosition: CGPoint(x: x, y: y), mouseButton: button) else { | |
| fputs("CGEvent create failed: \(type) (\(x), \(y))\n", stderr); exit(1) | |
| } |
| // Rounded clipping path | ||
| let path = CGPath( | ||
| roundedRect: imageRect, | ||
| cornerWidth: config.cornerRadius, | ||
| cornerHeight: config.cornerRadius, | ||
| transform: nil | ||
| ) | ||
| context.addPath(path) | ||
| context.clip() |
There was a problem hiding this comment.
阴影永远不会渲染:clip() 在设置阴影之后执行,后续绘制的阴影会被裁剪路径限制在圆角矩形内部,而阴影落在路径之外,因此被完全裁掉。应先用阴影 fill 圆角路径(产生阴影),restore 后再 clip 并绘制图像。
Suggestion:
| // Rounded clipping path | |
| let path = CGPath( | |
| roundedRect: imageRect, | |
| cornerWidth: config.cornerRadius, | |
| cornerHeight: config.cornerRadius, | |
| transform: nil | |
| ) | |
| context.addPath(path) | |
| context.clip() | |
| // 先用阴影填充路径生成阴影(阴影不会被裁剪), | |
| // 再在独立的 save/restore 中 clip 并绘制图像。 | |
| let path = CGPath( | |
| roundedRect: imageRect, | |
| cornerWidth: config.cornerRadius, | |
| cornerHeight: config.cornerRadius, | |
| transform: nil | |
| ) | |
| context.addPath(path) | |
| context.setFillColor(NSColor.black.cgColor) | |
| context.fillPath() // 仅用于产生阴影 | |
| context.restoreGState() | |
| context.saveGState() | |
| context.addPath(path) | |
| context.clip() | |
| context.draw(image, in: imageRect) | |
| context.restoreGState() |
| private func setupNotificationObservers() { | ||
| NotificationCenter.default.addObserver( | ||
| forName: .colorDidPick, | ||
| object: nil, | ||
| queue: .main | ||
| ) { [weak self] notif in |
There was a problem hiding this comment.
HistoryStore 在每次打开历史窗口时都会新建实例(HistoryWindowController 中 self.store = HistoryStore()),而这里使用 block-based addObserver(forName:object:queue:) 且未保存返回的 token、也没有任何 removeObserver/deinit 清理。NotificationCenter 会长期持有这些闭包(即使 [weak self] 也不会解除注册),旧实例被释放后 observer 仍残留;多次开关历史窗口后,同一个 .colorDidPick / .imageDidUpload 通知会被多个残留观察者处理,导致同一取色/上传结果被重复写入历史(且新 store 会覆盖 UserDefaults 存储),产生数据重复与观察者泄漏。建议保存 observer token 并在 deinit 中 removeObserver,或改用单例 store / NotificationCenter 的 publisher 并用 cancellables 生命周期管理。
Suggestion:
| private func setupNotificationObservers() { | |
| NotificationCenter.default.addObserver( | |
| forName: .colorDidPick, | |
| object: nil, | |
| queue: .main | |
| ) { [weak self] notif in | |
| private var observers: [NSObjectProtocol] = [] | |
| private func setupNotificationObservers() { | |
| observers.append(NotificationCenter.default.addObserver( | |
| forName: .colorDidPick, | |
| object: nil, | |
| queue: .main | |
| ) { [weak self] notif in |
| forName: .colorDidPick, | ||
| object: nil, | ||
| queue: .main | ||
| ) { [weak self] notif in |
There was a problem hiding this comment.
AppDelegate 通过 Notification.Name("colorDidPick")(字符串字面量)发送通知,而 HistoryStore 监听 ImageUploadService.colorDidPick。二者 raw value 当前相同所以能工作,但依赖魔法字符串匹配,重命名任一处会静默断开历史记录功能。建议 AppDelegate 改用 extension 中定义的 Notification.Name.colorDidPick / imageDidUpload 常量。
Suggestion:
| forName: .colorDidPick, | |
| object: nil, | |
| queue: .main | |
| ) { [weak self] notif in | |
| forName: Notification.Name.colorDidPick, // 保持与 AppDelegate 发送处使用同一常量 | |
| object: nil, | |
| queue: .main | |
| ) { [weak self] notif in |
| entries.removeAll { $0.translatedText == entry.translatedText && $0.category == entry.category } | ||
| entries.insert(entry, at: 0) |
There was a problem hiding this comment.
addEntry 以 translatedText + category 相同即移除旧条目,这会静默丢弃旧记录(丢失原时间戳和收藏状态)。尤其对 upload 类别:同一图片重复上传会返回不同的新 URL(translatedText 不同则产生重复条目),而相同 URL(例如重复粘贴同一图床链接)则会丢掉旧记录。更关键的是去重条件不含 id,若与 isFavorite 收藏结合,用户可能已对旧条目标星,重新 add 后被无提示删除。建议至少保留被删条目的 isFavorite,或仅在完全相同内容(含 sourceText)时去重。
Suggestion:
| entries.removeAll { $0.translatedText == entry.translatedText && $0.category == entry.category } | |
| entries.insert(entry, at: 0) | |
| // 仅在内容完全一致时去重,并保留原收藏状态 | |
| if let index = entries.firstIndex(where: { | |
| $0.sourceText == entry.sourceText && | |
| $0.translatedText == entry.translatedText && | |
| $0.category == entry.category | |
| }) { | |
| var merged = entry | |
| merged.isFavorite = entries[index].isFavorite | |
| entries[index] = merged | |
| return | |
| } | |
| entries.insert(entry, at: 0) |
| /// Renders composited annotations and optional beautification to a final CGImage. | ||
| func renderFinalImage( | ||
| _ image: CGImage, | ||
| annotations: [Annotation], | ||
| beautifyConfig: BeautifyConfig? = nil | ||
| ) throws -> CGImage { |
There was a problem hiding this comment.
renderFinalImage 目前在整个代码库中没有调用方(CaptureSessionController 的 copy/save/upload 路径都是手动调用 BeautifyRenderer 后再调 save,且传 beautifyConfig: nil),与 save() 中的合成+美化逻辑完全重复。两处实现并存容易在后续改动时出现导出路径行为不一致(例如 beautify 应用时机不同)。建议要么让 save() 复用 renderFinalImage 并迁移现有调用方,要么删除该未使用方法。
Suggestion:
| /// Renders composited annotations and optional beautification to a final CGImage. | |
| func renderFinalImage( | |
| _ image: CGImage, | |
| annotations: [Annotation], | |
| beautifyConfig: BeautifyConfig? = nil | |
| ) throws -> CGImage { | |
| // 让所有导出路径统一经由该方法,或删除未使用的重复实现 |
| let frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, attributedString.length), textPath, nil) | ||
| CTFrameDraw(frame, context) |
There was a problem hiding this comment.
气泡内文字使用 CTFramesetterCreateFrame 直接排入气泡内框,且未检查 frame 的可见字符范围(CTFrameGetVisibleStringRange)。当 annotation.rect 小于实际文字测量尺寸(例如用户缩小气泡、或旧文档的 rect 按旧排版逻辑保存)时,超出的文本会被静默截断,导出图与预览显示不一致且无任何提示。建议截断时按内容重新测量并扩大气泡,或至少与预览侧 SelectableTextBlock 使用相同的排版/约束逻辑。
Suggestion:
| let frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, attributedString.length), textPath, nil) | |
| CTFrameDraw(frame, context) | |
| let frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, attributedString.length), textPath, nil) | |
| CTFrameDraw(frame, context) | |
| // 可选:校验是否完整渲染,必要时按测量结果扩大气泡后再绘制 |
| private func saveSettings() { | ||
| if let encoded = try? JSONEncoder().encode(settings) { | ||
| UserDefaults.standard.set(encoded, forKey: userDefaultsKey) | ||
| } | ||
| } |
There was a problem hiding this comment.
云存储密钥(OSS AccessKeySecret、COS SecretKey、七牛 SecretKey)以明文 JSON 存储在 UserDefaults 中,可被本机任意进程读取并随系统备份导出。建议将 secret 类字段存入 Keychain,UserDefaults 仅保存非敏感配置。
Suggestion:
| private func saveSettings() { | |
| if let encoded = try? JSONEncoder().encode(settings) { | |
| UserDefaults.standard.set(encoded, forKey: userDefaultsKey) | |
| } | |
| } | |
| private func saveSettings() { | |
| // 密钥字段持久化到 Keychain;UserDefaults 只保存非敏感配置。 | |
| KeychainSecretStore.save(settings.ossAccessKeySecret, key: "ossAccessKeySecret") | |
| KeychainSecretStore.save(settings.cosSecretKey, key: "cosSecretKey") | |
| KeychainSecretStore.save(settings.kodoSecretKey, key: "kodoSecretKey") | |
| if let encoded = try? JSONEncoder().encode(settings) { | |
| UserDefaults.standard.set(encoded, forKey: userDefaultsKey) | |
| } | |
| } |
| guard let httpResponse = response as? HTTPURLResponse, (200...299).contains(httpResponse.statusCode) else { | ||
| throw TransFrameError.exportEncodingFailed(format: .png) | ||
| } | ||
|
|
||
| if let json = try? JSONSerialization.jsonObject(with: respData) as? [String: Any], | ||
| let resultList = json["result"] as? [String], let firstURL = resultList.first { | ||
| return firstURL | ||
| } | ||
| throw TransFrameError.exportEncodingFailed(format: .png) |
There was a problem hiding this comment.
所有上传失败路径(网络错误、HTTP 非 2xx、PicGo 响应异常)统一抛 TransFrameError.exportEncodingFailed(format: .png),错误类型与实际失败原因不符,调用方和用户无法区分“编码失败”与“上传失败/配置错误”,且掩盖了根因。建议新增专门的 upload 错误 case 并携带原始错误信息。
Suggestion:
| guard let httpResponse = response as? HTTPURLResponse, (200...299).contains(httpResponse.statusCode) else { | |
| throw TransFrameError.exportEncodingFailed(format: .png) | |
| } | |
| if let json = try? JSONSerialization.jsonObject(with: respData) as? [String: Any], | |
| let resultList = json["result"] as? [String], let firstURL = resultList.first { | |
| return firstURL | |
| } | |
| throw TransFrameError.exportEncodingFailed(format: .png) | |
| guard let httpResponse = response as? HTTPURLResponse, (200...299).contains(httpResponse.statusCode) else { | |
| throw TransFrameError.imageUploadFailed(provider: .picgo, reason: "HTTP \(httpResponse.statusCode)") | |
| } | |
| if let json = try? JSONSerialization.jsonObject(with: respData) as? [String: Any], | |
| let resultList = json["result"] as? [String], let firstURL = resultList.first { | |
| return firstURL | |
| } | |
| throw TransFrameError.imageUploadFailed(provider: .picgo, reason: "unexpected response payload") |
| "temperature": 0.1, | ||
| "response_format": ["type": "json_object"] | ||
| ] |
There was a problem hiding this comment.
与 OpenAIVLMProvider 不同,这里无条件添加 "response_format": ["type": "json_object"],而部分 OpenAI-compatible 端点会因该字段返回 400(OpenAI 侧已为此实现了回退重试)。此路径一旦遇到不兼容端点会整体失败,建议对齐 OpenAI 提供方的检测与回退逻辑。
Suggestion:
| "temperature": 0.1, | |
| "response_format": ["type": "json_object"] | |
| ] | |
| "temperature": 0.1, | |
| "response_format": ["type": "json_object"] | |
| ] | |
| // 建议参照 OpenAIVLMProvider:捕获 400 后去掉 response_format 重试一次。 |
| "temperature": 0.1, | ||
| "response_format": ["type": "json_object"] | ||
| ] |
There was a problem hiding this comment.
无条件添加 "response_format": ["type": "json_object"]。部分 OpenAI 兼容端点会因该字段返回 400 导致整体失败。OpenAIVLMProvider 已为此实现了检测与回退(捕获 400/invalidConfiguration 后去掉 response_format 重试一次),建议此处对齐,或同样提供关闭该字段的降级路径。
Suggestion:
| "temperature": 0.1, | |
| "response_format": ["type": "json_object"] | |
| ] | |
| "temperature": 0.1 | |
| // 依赖 prompts 的 JSON 指令即可;如需 response_format, | |
| // 应像 OpenAIVLMProvider 一样在 400 时降级重试。 | |
| ] |
| private func processNextSlice() async { | ||
| guard isCapturing, !isProcessing else { return } | ||
| isProcessing = true | ||
| defer { isProcessing = false } | ||
|
|
||
| guard let currentSlice = await captureCurrentSlice(), let prev = previousImage else { return } |
There was a problem hiding this comment.
捕捉循环以 10 Hz 在 MainActor 上同步执行两项昂贵操作:SCShareableContent.excludingDesktopWindows(...) 每帧重新枚举全部窗口(系统调用开销大且可缓存),以及 VNImageRequestHandler.perform 同步图像配准。二者都会阻塞主线程,滚动截图期间会造成可感知的卡顿。display 列表在会话期间基本不变,可在 start() 时获取一次复用;Vision 配准属于 CPU 密集工作,建议移出主 actor 执行。
Suggestion:
| private func processNextSlice() async { | |
| guard isCapturing, !isProcessing else { return } | |
| isProcessing = true | |
| defer { isProcessing = false } | |
| guard let currentSlice = await captureCurrentSlice(), let prev = previousImage else { return } | |
| private func processNextSlice() async { | |
| guard isCapturing, !isProcessing else { return } | |
| isProcessing = true | |
| defer { isProcessing = false } | |
| guard let currentSlice = await captureCurrentSlice(), let prev = previousImage else { return } | |
| // Vision 配准应在非主线程执行,避免 10Hz 循环阻塞 MainActor |
| // In Vision coordinates, ty > 0 means current image moved downwards relative to target | ||
| let ty = observation.alignmentTransform.ty | ||
| let dy = CGFloat(ty) |
There was a problem hiding this comment.
processNextSlice 中方向注释与判定逻辑需谨慎核实:VNTranslationalImageRegistrationRequest 的 alignmentTransform 是把 target(此处为 prev)对齐到 requested image(currentSlice)的变换,ty > 0 的语义与注释"current 相对 prev 向下移动"可能相反;方向判断错误会导致滚动时静默丢弃所有帧(或拼接错方向)且无任何用户反馈,仅 debug 日志。建议以一次真实滚动场景验证 ty 的符号,并考虑对失败/无进展状态向用户暴露提示。
Suggestion:
| // In Vision coordinates, ty > 0 means current image moved downwards relative to target | |
| let ty = observation.alignmentTransform.ty | |
| let dy = CGFloat(ty) | |
| // Verify sign convention: alignmentTransform maps target -> requested. | |
| // Confirm with a real scroll test whether ty > 0 corresponds to downward scroll. |
| let width = base.width | ||
| let addedHeight = Int(round(deltaY)) | ||
| let newTotalHeight = base.height + addedHeight |
There was a problem hiding this comment.
appendSlice 每帧新建更高的 CGContext 位图且没有任何总高度上限:以 10 FPS 循环,长时间滚动时位图高度线性增长(数万像素级),内存无界增长;当 CGContext 初始化失败时仅静默 return,用户得不到任何反馈,拼接结果停在旧帧。建议设置最大拼接高度上限(如 maxStitchHeight)并在达到上限或创建失败时结束会话并提示用户。
Suggestion:
| let width = base.width | |
| let addedHeight = Int(round(deltaY)) | |
| let newTotalHeight = base.height + addedHeight | |
| let width = base.width | |
| let addedHeight = Int(round(deltaY)) | |
| let newTotalHeight = base.height + addedHeight | |
| guard newTotalHeight <= Self.maxStitchHeight else { | |
| Self.logger.error("Stitched height limit reached (\(newTotalHeight, privacy: .public)); stopping scroll capture") | |
| finish() | |
| onUpdateLimitReached?() | |
| return | |
| } |
| let scale: CGFloat = NSScreen.main?.backingScaleFactor ?? 2.0 | ||
| config.width = max(1, Int(screenRect.width * scale)) | ||
| config.height = max(1, Int(screenRect.height * scale)) |
There was a problem hiding this comment.
captureCurrentSlice 使用 NSScreen.main?.backingScaleFactor 计算输出分辨率,但捕获目标是 self.displayID 指定的显示器。在多显示器且缩放系数不同的场景下(例如 2x 主屏 + 1x 副屏上滚动截图),config.width/height 与 sourceRect 的实际像素比不匹配,切片分辨率错误,导致 Vision 配准的 dy 与实际滚动量对不上,拼接结果错位或帧被静默丢弃。应通过 displayID 找到对应 NSScreen 并使用其 backingScaleFactor。
Suggestion:
| let scale: CGFloat = NSScreen.main?.backingScaleFactor ?? 2.0 | |
| config.width = max(1, Int(screenRect.width * scale)) | |
| config.height = max(1, Int(screenRect.height * scale)) | |
| let scale = NSScreen.screens.first(where: { $0.deviceDescription[.deviceDescriptionKey(NSDeviceDescriptionKey("NSScreenNumber"))] as? CGDirectDisplayID == displayID })?.backingScaleFactor | |
| ?? NSScreen.main?.backingScaleFactor | |
| ?? 2.0 | |
| config.width = max(1, Int(screenRect.width * scale)) | |
| config.height = max(1, Int(screenRect.height * scale)) |
| let engine = ScreenCoderEngine.shared | ||
| guard let provider = try? await engine.currentProvider() else { | ||
| throw PrivacyDetectionError.providerNotConfigured | ||
| } |
There was a problem hiding this comment.
provider 获取失败的原因被 try? 静默吞掉,统一上报为 providerNotConfigured。实际失败可能是网络错误、provider 初始化异常等非配置问题,用户会看到错误的“未配置”提示,排障时也丢失了根因信息。建议让 detectPrivacyRegions 透传 engine.currentProvider() 的原始错误,或至少将底层 error 记录到 logger。
Suggestion:
| let engine = ScreenCoderEngine.shared | |
| guard let provider = try? await engine.currentProvider() else { | |
| throw PrivacyDetectionError.providerNotConfigured | |
| } | |
| let engine = ScreenCoderEngine.shared | |
| let provider: any VLMProvider | |
| do { | |
| provider = try await engine.currentProvider() | |
| } catch { | |
| logger.error("Smart privacy detection provider error: \(String(describing: error))") | |
| throw PrivacyDetectionError.providerNotConfigured | |
| } |
Four parallel fix squads (windows/lifecycle, scripts/CI/packaging, preview UI, services); 7 findings skipped with documented reasons. Windows & lifecycle: stale in-place analysis task cancelled on rerun/ESC; annotation-preserving clipboard/save fallbacks; ⌘/⌥ modifier guards for keyboard shortcuts; precise-trackpad scroll accumulation; ⌘C on pinned windows; point-size (vs pixel) pinned-window geometry on 2x screens; localized menu keys completed across 10 languages. Scripts & CI: OCR action pinned to dereferenced commit SHA; Sparkle nested signing replaces --deep with timestamp enabled; lipo/strip failures surface instead of silently corrupting; eventsynth arg guards, RGB channel offsets, and no more try! crashes; run_e2e builds its own tool, skips OCR scene offline / on small displays, and only dismisses whitelisted dialogs. Preview & annotation UI: pasteboard changeCount guard; balanced cursor push/pop; text-commit gesture invalidation; edge-clamped editor sizing; collapsible drawer keeps an expand handle; empty-text delete no longer resel ects neighbours; NSCache-backed text measurement; unified number- label size clamping; localized hardcoded strings. Services: upload keys moved to Keychain with plaintext migration; typed imageUploadFailed errors; Ollama chat 400 response_format fallback; OpenAI continuation keeps text parts and drops only the image; PaddleOCR queue is cancellable; scroll capture caches SCDisplay and detaches Vision work; history observers removed on deinit and favourites survive dedupe; CoreText bubble grows to fit measured text. Plus mainline compile fixes from squad handoff: NSValue rectValue on macOS, static-call qualification, CoreText nil frameAttributes, and PreviewContentView body decomposition to fit the type-checker budget. Verified: Debug build clean, full TransFrameTests suite green. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
| # arm64-only build; keep the un-suffixed name for backward compatibility, | ||
| # but release notes state this is an arm64-only artifact (see Create Release body). | ||
| cp "$DMG_FILE" "$ARM64_DMG_FILE" |
| body: | | ||
| > **注意**:本次构建为 **arm64-only**。`$NAME-$VERSION.dmg` 与 `$NAME-$VERSION-arm64.dmg` 为同一 arm64 产物(无后缀名为向后兼容保留),不含 x86_64 切片。 |
There was a problem hiding this comment.
body: 位于 with: 块内,由 action 解析,不会经过 shell 展开——$NAME 和 $VERSION 将以字面量出现在 Release 说明中,而非实际的 TransFrame-1.5.1.dmg 等文件名。应使用 GitHub 表达式或先在前面 run 步骤中生成 body 文件后用 body_path 引用。
Suggestion:
| body: | | |
| > **注意**:本次构建为 **arm64-only**。`$NAME-$VERSION.dmg` 与 `$NAME-$VERSION-arm64.dmg` 为同一 arm64 产物(无后缀名为向后兼容保留),不含 x86_64 切片。 | |
| body: | | |
| > **注意**:本次构建为 **arm64-only**。`${{ env.PROJECT_NAME }}-${{ steps.vars.outputs.version }}.dmg` 与同名 `-arm64.dmg` 为同一 arm64 产物(无后缀名为向后兼容保留),不含 x86_64 切片。 |
| echo "🏗️ 正在编译 Release 版本..." | ||
| xcodebuild -project "$XCODE_PROJ" -scheme TransFrame -configuration Release -derivedDataPath "$PROJECT_PATH/build_artifacts/dmg" -quiet | ||
| # 2. 编译 Release 版本 (默认 arm64,可传入参数: ./create_dmg.sh x86_64) | ||
| TARGET_ARCH="${1:-arm64}" |
There was a problem hiding this comment.
| fi | ||
|
|
||
| # 优先使用本机钥匙串中的 Developer ID Application 证书签名(与 GitHub Release 保持一致) | ||
| SIGN_IDENTITY=$(security find-identity -v -p codesigning | grep -m1 "Developer ID Application" | awk -F '"' '{print $2}' || true) |
| guard let a = NSImage(contentsOf: URL(fileURLWithPath: args[2])), | ||
| let b = NSImage(contentsOf: URL(fileURLWithPath: args[3])), | ||
| let ca = a.cgImage(forProposedRect: nil, context: nil, hints: nil), | ||
| let cb = b.cgImage(forProposedRect: nil, context: nil, hints: nil), | ||
| let da = ca.dataProvider?.data, let db = cb.dataProvider?.data else { exit(1) } |
There was a problem hiding this comment.
diff 命令对 NSImage 解码或 dataProvider 失败时直接 exit(1) 且无任何输出信息,E2E 失败时难以定位是截图未生成还是解码/像素格式不支持。建议在退出前向 stderr 输出具体原因。
Suggestion:
| guard let a = NSImage(contentsOf: URL(fileURLWithPath: args[2])), | |
| let b = NSImage(contentsOf: URL(fileURLWithPath: args[3])), | |
| let ca = a.cgImage(forProposedRect: nil, context: nil, hints: nil), | |
| let cb = b.cgImage(forProposedRect: nil, context: nil, hints: nil), | |
| let da = ca.dataProvider?.data, let db = cb.dataProvider?.data else { exit(1) } | |
| let da = ca.dataProvider?.data, let db = cb.dataProvider?.data else { | |
| fputs("diff: 图片解码或像素数据读取失败\n", stderr); exit(1) | |
| } |
| var merged = entry | ||
| merged.isFavorite = entries[index].isFavorite | ||
| entries[index] = merged |
There was a problem hiding this comment.
addEntry 去重命中时用 entries[index] = merged 原位替换,重复条目不会移动到列表顶部,且 merged 沿用调用方传入的 timestamp(默认 Date())。结果是用户再次取同一颜色/上传同一图时,列表中旧位置出现一条"新时间戳"的条目,与"最新记录在最前"的预期不符。建议命中重复时移到顶部:entries.remove(at: index); entries.insert(merged, at: 0),并考虑保留原 timestamp 还是刷新为当前时间,语义需明确。
Suggestion:
| var merged = entry | |
| merged.isFavorite = entries[index].isFavorite | |
| entries[index] = merged | |
| var merged = entry | |
| merged.isFavorite = entries[index].isFavorite | |
| merged.timestamp = Date() // 或保留 entries[index].timestamp,按产品语义二选一 | |
| entries.remove(at: index) | |
| entries.insert(merged, at: 0) |
| if status == errSecItemNotFound { | ||
| var add = query | ||
| add[kSecValueData as String] = data | ||
| SecItemAdd(add as CFDictionary, nil) | ||
| } |
There was a problem hiding this comment.
SecItemUpdate/SecItemAdd 的返回状态只对 errSecItemNotFound 做了处理,其余失败(如 errSecInteractionNotAllowed、钥匙串写入被拒)被静默吞掉。此时密钥既未写入钥匙串,UserDefaults 中又被清洗为空字符串,密钥会永久丢失且用户无任何提示,后续上传只能以空密钥失败。建议至少记录错误日志或向调用方暴露迁移失败状态。
Suggestion:
| if status == errSecItemNotFound { | |
| var add = query | |
| add[kSecValueData as String] = data | |
| SecItemAdd(add as CFDictionary, nil) | |
| } | |
| if status == errSecItemNotFound { | |
| var add = query | |
| add[kSecValueData as String] = data | |
| let addStatus = SecItemAdd(add as CFDictionary, nil) | |
| if addStatus != errSecSuccess { | |
| Logger.security.error("Keychain save failed for \(account, privacy: .public): \(addStatus)") | |
| } | |
| } else if status != errSecSuccess { | |
| Logger.security.error("Keychain update failed for \(account, privacy: .public): \(status)") | |
| } |
| // Convert CGImage to PNG Data | ||
| let rep = NSBitmapImageRep(cgImage: image) | ||
| guard let data = rep.representation(using: .png, properties: [:]) else { | ||
| throw TransFrameError.exportEncodingFailed(format: .png) | ||
| } |
There was a problem hiding this comment.
ImageUploadService 标注为 @mainactor,upload() 中 NSBitmapImageRep 生成 PNG 数据是同步 CPU 密集操作,大尺寸截图会在主线程阻塞,造成上传期间 UI 卡顿。建议把编码与网络上传放到非隔离上下文(如 detached Task 或 static 非隔离方法)执行。
Suggestion:
| // Convert CGImage to PNG Data | |
| let rep = NSBitmapImageRep(cgImage: image) | |
| guard let data = rep.representation(using: .png, properties: [:]) else { | |
| throw TransFrameError.exportEncodingFailed(format: .png) | |
| } | |
| let data = try await Task.detached(priority: .userInitiated) { | |
| let rep = NSBitmapImageRep(cgImage: image) | |
| guard let data = rep.representation(using: .png, properties: [:]) else { | |
| throw TransFrameError.exportEncodingFailed(format: .png) | |
| } | |
| return data | |
| }.value |
| } catch VLMProviderError.invalidConfiguration { | ||
| // Some OpenAI-compatible endpoints reject response_format with a | ||
| // 400; retry once without it (mirrors OpenAIVLMProvider). | ||
| let request = try buildRequest(base64Image: encoded.base64String, prompts: prompt, includeResponseFormat: false) | ||
| responseData = try await executeRequest(request) | ||
| } |
| extension VLMProvider { | ||
| func analyze(image: CGImage, prompt: VLMPromptPair) async throws -> ScreenAnalysisResult { | ||
| try await analyze(image: image) | ||
| } | ||
| } |
There was a problem hiding this comment.
协议扩展为 analyze(image:prompt:) 提供了默认实现,直接回退到 OCR 的 analyze(image:)。未重写该方法的 Provider(如 PaddleOCRVLMProvider 等仅实现基础协议的实现方)在调用方传入自定义 prompt(如 VLMPromptPair.privacy)时会静默忽略提示词,返回 OCR 文本 segment,但 text 字段语义完全不同(OCR 文本 vs 隐私类别),调用方无法感知降级,可能基于错误语义的 segment 做后续处理(如按类别做隐私打码)。建议:要么在协议中要求实现(无默认实现),要么在默认实现中以日志/断言明确提示 prompt 被忽略。
Suggestion:
| extension VLMProvider { | |
| func analyze(image: CGImage, prompt: VLMPromptPair) async throws -> ScreenAnalysisResult { | |
| try await analyze(image: image) | |
| } | |
| } | |
| extension VLMProvider { | |
| func analyze(image: CGImage, prompt: VLMPromptPair) async throws -> ScreenAnalysisResult { | |
| if prompt != .ocr { | |
| assertionFailure("Provider \(Self.self) does not support custom prompts; ignoring prompt") | |
| Logger.translation.warning("Provider does not support custom prompts, falling back to OCR prompt") | |
| } | |
| return try await analyze(image: image) | |
| } | |
| } |
- ImageHostSecretStore.exists checks attributes only, no secret data
- read() bails out before any data query when nothing is stored;
a fresh install never touches secret reads during migration
- save("") deletes the entry so clearing a key in Settings really
removes the stored secret instead of leaving the old one behind
- upload() fails fast with a clear message when the active host's
key is missing, instead of sending a request that cannot sign
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
| body: | | ||
| > **注意**:本次构建为 **arm64-only**。`$NAME-$VERSION.dmg` 与 `$NAME-$VERSION-arm64.dmg` 为同一 arm64 产物(无后缀名为向后兼容保留),不含 x86_64 切片。 |
There was a problem hiding this comment.
body: | 是传给 softprops/action-gh-release 的 YAML 字面输入,不会经过 shell 展开。$NAME 和 $VERSION 在此上下文中既不会被替换、也从未定义,用户在 Release 页面看到的是字面文本 "$NAME-$VERSION.dmg",无法起到说明产物命名的作用。建议改用运行步骤生成 body(用 heredoc + 唯一分隔符写入 GITHUB_OUTPUT,如上方 tag_message 步骤的做法),或直接写死实际项目名/在 env 中通过 GitHub Actions 表达式 ${{ env.PROJECT_NAME }} 与 ${{ steps.vars.outputs.version }} 拼进字面值。
Suggestion:
| body: | | |
| > **注意**:本次构建为 **arm64-only**。`$NAME-$VERSION.dmg` 与 `$NAME-$VERSION-arm64.dmg` 为同一 arm64 产物(无后缀名为向后兼容保留),不含 x86_64 切片。 | |
| body: >- | |
| > **注意**:本次构建为 **arm64-only**。`${{ env.PROJECT_NAME }}-${{ steps.vars.outputs.version }}.dmg` | |
| 与 `${{ env.PROJECT_NAME }}-${{ steps.vars.outputs.version }}-arm64.dmg` 为同一 arm64 产物(无后缀名为向后兼容保留),不含 x86_64 切片。 |
| echo "⚠️ 未找到 Developer ID 证书,回退为 Ad-hoc 签名" | ||
| CODESIGN_ARGS=(--force --sign -) |
| if let ev = CGEvent(keyboardEventSource: nil, virtualKey: 8, keyDown: down) { | ||
| ev.flags = .maskCommand | ||
| ev.post(tap: .cghidEventTap) | ||
| usleep(20_000) | ||
| } |
There was a problem hiding this comment.
copy 命令硬编码 virtualKey: 8(仅对应 ANSI 美式布局的 C 键)。在 Dvorak、Colemak 或非 ANSI 物理布局下该键码不是 "C",Cmd+C 会变成其他按键,导致 crossline 场景的剪贴板断言在特定环境静默失败或误报。建议改用 keyboardSetUnicodeString 发送 "c"(与 type 命令一致),仅附加 .maskCommand 标志,使断言与键盘布局解耦。
Suggestion:
| if let ev = CGEvent(keyboardEventSource: nil, virtualKey: 8, keyDown: down) { | |
| ev.flags = .maskCommand | |
| ev.post(tap: .cghidEventTap) | |
| usleep(20_000) | |
| } | |
| for down in [true, false] { | |
| if let ev = CGEvent(keyboardEventSource: nil, virtualKey: 0, keyDown: down) { | |
| ev.flags = .maskCommand | |
| let utf = Array("c".utf16) | |
| utf.withUnsafeBufferPointer { buf in | |
| ev.keyboardSetUnicodeString(stringLength: buf.count, unicodeString: buf.baseAddress!) | |
| } | |
| ev.post(tap: .cghidEventTap) | |
| usleep(20_000) | |
| } | |
| } |
| .disabled(viewModel.isDetectingPrivacy) | ||
| .customTooltip(String(localized: "preview.tooltip.smartMosaic")) |
There was a problem hiding this comment.
本地化缺失:本批新增的 key(preview.tooltip.smartMosaic、preview.color.eyedropper、preview.fill.color、preview.color.custom、preview.tooltip.editText、preview.panel.rerun/copyAll/close/expandDrawer/recognizing/copyLine/targetLanguage/noResults/translating/translate 等)目前只在 en 和 zh-Hans 的 Localizable.strings 中添加,ja/ko/de/fr/es/it/pt/ru 均未添加(已抽查确认无这些条目)。这些语言下 UI 会显示裸 key 字符串。请在其余 8 个语言资源中补齐对应翻译。
| if viewModel.selectedTool == .text { | ||
| // Swallow the rest of this gesture so the | ||
| // commit click cannot start a stray drawing | ||
| // mid-gesture (didBeginGesture is already true). | ||
| didInvalidateGesture = true | ||
| return | ||
| } |
There was a problem hiding this comment.
“吞手势”逻辑仅对 .text 生效;calloutBubble 工具下提交文字的那次点击不会 invalidate,onChanged 会继续走 handle 命中/beginDrawing。用户点击气泡本身时 beginDrawing 的 hitTest 会立刻重新进入编辑态,点击空白处则会直接开始画一个新气泡——与文字工具“提交点击后吞掉本次手势”的行为不一致,容易产生意外的连环编辑/新建。建议将 invalidate 条件扩展到 selectedTool == .text || selectedTool == .calloutBubble,或将提交后吞手势的决策收敛到 beginDrawing 单一入口。
Suggestion:
| if viewModel.selectedTool == .text { | |
| // Swallow the rest of this gesture so the | |
| // commit click cannot start a stray drawing | |
| // mid-gesture (didBeginGesture is already true). | |
| didInvalidateGesture = true | |
| return | |
| } | |
| if viewModel.selectedTool == .text || viewModel.selectedTool == .calloutBubble { | |
| didInvalidateGesture = true | |
| return | |
| } |
| let bubble = CalloutBubbleAnnotation( | ||
| rect: bubbleRect, | ||
| targetPoint: target, | ||
| text: "Note", |
There was a problem hiding this comment.
新建标注气泡的默认文本 "Note" 是硬编码的英文字符串,会直接显示给用户并被持久化到标注数据中。本 PR 其他新增用户可见字符串均使用了 String(localized:),此处应保持一致,否则非英文环境会出现中英文混杂的界面文本。
Suggestion:
| let bubble = CalloutBubbleAnnotation( | |
| rect: bubbleRect, | |
| targetPoint: target, | |
| text: "Note", | |
| let bubble = CalloutBubbleAnnotation( | |
| rect: bubbleRect, | |
| targetPoint: target, | |
| text: String(localized: "preview.callout.defaultText"), |
| let bubble = CalloutBubbleAnnotation( | ||
| rect: bubbleRect, | ||
| targetPoint: target, | ||
| text: "Note", |
There was a problem hiding this comment.
新建标注气泡的默认文本 "Note" 是硬编码英文字符串,会直接显示给用户并被持久化到标注数据中。本 PR 其他新增用户可见字符串均使用 String(localized:),此处应保持一致。
Suggestion:
| let bubble = CalloutBubbleAnnotation( | |
| rect: bubbleRect, | |
| targetPoint: target, | |
| text: "Note", | |
| let bubble = CalloutBubbleAnnotation( | |
| rect: bubbleRect, | |
| targetPoint: target, | |
| text: String(localized: "preview.callout.defaultText"), |
| if trimmedText.isEmpty { | ||
| // Removing the annotation shifts later indices down; | ||
| // re-selecting editIdx would grab an unrelated neighbor. | ||
| removeAnnotation(at: editIdx) | ||
| if selectedAnnotationIndex == editIdx { | ||
| selectedAnnotationIndex = nil | ||
| } | ||
| } else { |
There was a problem hiding this comment.
删除空文本标注后仅处理了 selectedAnnotationIndex == editIdx 的情况。removeAnnotation(at:)(PreviewViewModel.swift:278)内部并不会平移选中索引,因此当当前选中的是 editIdx 之后的标注时,selectedAnnotationIndex 会指向删除后的错误标注,随后的拖拽/控制柄/删除操作会命中错误的元素。建议在删除后对所有 > editIdx 的索引统一减一(或直接清空选中)。
Suggestion:
| if trimmedText.isEmpty { | |
| // Removing the annotation shifts later indices down; | |
| // re-selecting editIdx would grab an unrelated neighbor. | |
| removeAnnotation(at: editIdx) | |
| if selectedAnnotationIndex == editIdx { | |
| selectedAnnotationIndex = nil | |
| } | |
| } else { | |
| if trimmedText.isEmpty { | |
| removeAnnotation(at: editIdx) | |
| if selectedAnnotationIndex == editIdx { | |
| selectedAnnotationIndex = nil | |
| } else if let sel = selectedAnnotationIndex, sel > editIdx { | |
| selectedAnnotationIndex = sel - 1 | |
| } | |
| } else { |
| func beginResizingAnnotation(handle: AnnotationHandle, at point: CGPoint) { | ||
| guard let index = selectedAnnotationIndex, | ||
| index >= 0, | ||
| index < annotations.count else { return } | ||
|
|
||
| if isWaitingForTextInputInternal { | ||
| commitTextInput() | ||
| } | ||
|
|
||
| activeResizeHandle = handle | ||
| dragStartPoint = point | ||
| dragOriginalAnnotation = annotations[index] |
There was a problem hiding this comment.
beginResizingAnnotation 先取 index 并 guard,随后才调用 commitTextInput()。当正在原地编辑文本且内容为空时,commitTextInput 会走 removeAnnotation(at: editIdx) 删除该标注(即使编辑态下选中指示器被隐藏,handles 仍可通过 hitTestSelectedAnnotationHandle 命中,路径可达),此时 annotations.count 已减一,接着的 dragOriginalAnnotation = annotations[index] 和 dragInitialScreenshot 赋值会以过期索引访问数组,触发 index out of range 崩溃。另外编辑态下 handles 虽不可见但仍参与命中,本身也会造成'隐身手柄可拖'的问题。建议先提交/取消文本输入并重新校验 index 有效性,再读取 annotations[index];同时在 editingIndex == index 时跳过 handle 命中。
Suggestion:
| func beginResizingAnnotation(handle: AnnotationHandle, at point: CGPoint) { | |
| guard let index = selectedAnnotationIndex, | |
| index >= 0, | |
| index < annotations.count else { return } | |
| if isWaitingForTextInputInternal { | |
| commitTextInput() | |
| } | |
| activeResizeHandle = handle | |
| dragStartPoint = point | |
| dragOriginalAnnotation = annotations[index] | |
| func beginResizingAnnotation(handle: AnnotationHandle, at point: CGPoint) { | |
| if isWaitingForTextInputInternal { | |
| commitTextInput() | |
| } | |
| guard let index = selectedAnnotationIndex, | |
| index >= 0, | |
| index < annotations.count else { return } | |
| activeResizeHandle = handle | |
| dragStartPoint = point | |
| dragOriginalAnnotation = annotations[index] |
| guard let index = selectedAnnotationIndex, | ||
| index >= 0, | ||
| index < annotations.count else { return } | ||
|
|
||
| if isWaitingForTextInputInternal { | ||
| commitTextInput() | ||
| } | ||
|
|
||
| activeResizeHandle = handle | ||
| dragStartPoint = point | ||
| dragOriginalAnnotation = annotations[index] |
There was a problem hiding this comment.
beginResizingAnnotation 先用 index 做 guard,随后才调用 commitTextInput()。当正在原地编辑文本且编辑器内容为空时,commitTextInput 会通过 removeAnnotation(at: editIdx) 删除该标注(编辑态下选中指示器被隐藏,但 handles 仍可被 hitTestSelectedAnnotationHandle 命中,此路径可达),此时 annotations.count 已减一,接下来的 dragOriginalAnnotation = annotations[index] 会以过期索引访问数组,触发 index out of range 崩溃。建议先提交/取消文本输入,再重新校验 index 有效性后读取 annotations[index]。
Suggestion:
| guard let index = selectedAnnotationIndex, | |
| index >= 0, | |
| index < annotations.count else { return } | |
| if isWaitingForTextInputInternal { | |
| commitTextInput() | |
| } | |
| activeResizeHandle = handle | |
| dragStartPoint = point | |
| dragOriginalAnnotation = annotations[index] | |
| if isWaitingForTextInputInternal { | |
| commitTextInput() | |
| } | |
| guard let index = selectedAnnotationIndex, | |
| index >= 0, | |
| index < annotations.count else { return } | |
| activeResizeHandle = handle | |
| dragStartPoint = point | |
| dragOriginalAnnotation = annotations[index] |
| // ⌘ held: preserve the annotation's current aspect ratio | ||
| let options = HandleDragOptions( | ||
| preserveAspectRatio: NSEvent.modifierFlags.contains(.command) | ||
| ) |
There was a problem hiding this comment.
使用全局 NSEvent.modifierFlags.contains(.command) 读取修饰键:其一它读取的是全局键盘状态而非驱动本次手势的事件;其二在拖拽过程中用户的按键状态可能与拖拽开始时不一致,导致同一手势中途行为跳变。建议在 beginResizingAnnotation 时捕获一次标志并缓存,供整个拖拽会话使用。
Suggestion:
| // ⌘ held: preserve the annotation's current aspect ratio | |
| let options = HandleDragOptions( | |
| preserveAspectRatio: NSEvent.modifierFlags.contains(.command) | |
| ) | |
| // ⌘ held (captured at drag start): preserve the annotation's current aspect ratio | |
| let options = HandleDragOptions( | |
| preserveAspectRatio: dragStartedWithCommandKey | |
| ) |
| let updated = originalAnnotation.offsetBy(dx: delta.x, dy: delta.y) | ||
| screenshot.annotations[index] = updated | ||
| drawingUpdateCounter += 1 |
There was a problem hiding this comment.
拖拽/resize 提交时用 initial.annotations != screenshot.annotations 判断是否有变更,而 Annotation 的相等性包含位置信息,逻辑本身成立;但 endDraggingAnnotation 在手势被吞(didInvalidateGesture,仅对 .text 生效)之外的所有路径都会执行,包括双击进入编辑后未产生拖动的单击——此时 isDraggingAnnotation 为 false,isResizing 也为 false,均跳过,正确。确认无误,但注意 continueDraggingAnnotation 中 screenshot.annotations[index] = updated 依赖 index 在拖拽期间不被其他路径删除(当前无并发删除入口),暂无问题。此条仅作备忘,无需修改。
| case .text(let text): | ||
| selectedAnnotationIndex = index | ||
| editingAnnotationIndex = index | ||
| textInputContent = text.content | ||
| textInputPositionInternal = text.position |
There was a problem hiding this comment.
对 .text 标注,编辑器使用 text.position 定位,但 AnnotationCanvas.drawTextAnnotation 已改为在 annotation.bounds 内绘制文本(bounds.origin 等于 position,当前等价)。二者目前恰好一致,但文本隐藏/编辑器定位依赖的是两个不同字段(position vs bounds);若后续任一渲染或布局调整使 bounds.origin 偏离 position,编辑器会与实际文本错位。建议统一从 bounds.origin 取位以绑定同一几何来源。
Suggestion:
| case .text(let text): | |
| selectedAnnotationIndex = index | |
| editingAnnotationIndex = index | |
| textInputContent = text.content | |
| textInputPositionInternal = text.position | |
| case .text(let text): | |
| selectedAnnotationIndex = index | |
| editingAnnotationIndex = index | |
| textInputContent = text.content | |
| textInputPositionInternal = text.bounds.origin |
| let languages = Set( | ||
| [AppSettings.shared.translationSourceLanguage] | ||
| .compactMap { OCREngine.RecognitionLanguage(translationLanguage: $0) } | ||
| ) |
There was a problem hiding this comment.
OCR 语言从固定 [.english, .chineseSimplified] 改为仅映射单一 translationSourceLanguage。对混排截图(如源语言设为英文但图中含中文,或反之),Vision 在单语言约束下对另一语言脚本的识别率会明显下降;而旧实现是双语言集合。RecognitionLanguage(translationLanguage:) 映射为 nil 时回退自动检测,但用户显式选择了某个具体源语言时不会回退。建议至少把源语言与其互补的常用语言(如 english + 当前源语言)一起传入,或在映射结果上保留原有的双语兜底。
Suggestion:
| let languages = Set( | |
| [AppSettings.shared.translationSourceLanguage] | |
| .compactMap { OCREngine.RecognitionLanguage(translationLanguage: $0) } | |
| ) | |
| var languageSet: Set<OCREngine.RecognitionLanguage> = [.english] | |
| if let mapped = OCREngine.RecognitionLanguage(translationLanguage: AppSettings.shared.translationSourceLanguage) { | |
| languageSet.insert(mapped) | |
| } | |
| let languages = languageSet |
| resultsPanelTab = .translate | ||
| isTranslating = true | ||
| ocrTranslationError = nil |
There was a problem hiding this comment.
performTranslation 开始时没有清空旧的 bilingualSegments。若上一次翻译成功(bilingualSegments 非空),再次翻译失败时 hasTranslationResults 仍为 true:PreviewResultsPanel.translateContent 会走结果分支继续展示旧译文,BilingualOverlayView 也会在画布上持续渲染过期的译文覆盖层,错误状态被掩盖(ocrTranslationError 只被写入、全工程无读取点,用户看不到任何错误提示)。建议在 isTranslating = true 前先 bilingualSegments = [](以及为失败路径补充可见的错误展示)。
Suggestion:
| resultsPanelTab = .translate | |
| isTranslating = true | |
| ocrTranslationError = nil | |
| resultsPanelTab = .translate | |
| bilingualSegments = [] | |
| isTranslating = true | |
| ocrTranslationError = nil |
| box.width > 0, box.height > 0, | ||
| !segment.translated.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return nil } | ||
| let anchor = translationAnchor(for: box, in: displaySize) | ||
| guard anchor.maxWidth > 8, anchor.y < displaySize.height else { return nil } |
There was a problem hiding this comment.
此处仅校验条带顶部 anchor.y < displaySize.height,未校验条带底边:多行译文的测量高度(frame.height = ceil(measured.height) + 4)可能使条带超出画布底部,被 Canvas 裁剪导致译文显示不全。建议在创建 Strip 后对 frame 做 frame.intersection(CGRect(origin: .zero, size: displaySize)) 或向上偏移超出部分。
Suggestion:
| guard anchor.maxWidth > 8, anchor.y < displaySize.height else { return nil } | |
| guard anchor.maxWidth > 8, anchor.y < displaySize.height else { return nil } | |
| ... | |
| let rawFrame = CGRect(x: anchor.x, y: anchor.y, width: anchor.maxWidth, height: ceil(measured.height) + 4) | |
| return Strip( | |
| frame: rawFrame.intersection(CGRect(origin: .zero, size: displaySize)), | |
| fontSize: anchor.fontSize | |
| ) |
| return .highlight(h) | ||
| case .mosaic(var m): | ||
| m.rect = scaleRect(m.rect) | ||
| m.blockSize = max(4, min(128, Int(round(CGFloat(m.blockSize) * factor)))) |
| case .translation: return "Translation" | ||
| case .screenshot: return "Screenshot" | ||
| case .color: return "Color" | ||
| case .upload: return "Upload" |
There was a problem hiding this comment.
displayName 返回硬编码英文字符串("Translation"/"Screenshot" 等),而项目中所有用户可见文案均通过 Localizable.strings 本地化(如本次新增的 bilingualResult.pin)。这些字符串会直接展示在历史记录 UI 中,非英语环境下将出现未翻译文案。建议改用 String(localized:) 并补充各语言词条。
Suggestion:
| case .translation: return "Translation" | |
| case .screenshot: return "Screenshot" | |
| case .color: return "Color" | |
| case .upload: return "Upload" | |
| case .translation: return String(localized: "history.category.translation") | |
| case .screenshot: return String(localized: "history.category.screenshot") | |
| case .color: return String(localized: "history.category.color") | |
| case .upload: return String(localized: "history.category.upload") |
| let originalWidth = CGFloat(image.width) | ||
| let originalHeight = CGFloat(image.height) | ||
| let padding = config.padding |
| let ciContext = CIContext() | ||
| return ciContext.createCGImage(output, from: ciImage.extent) ?? cg |
There was a problem hiding this comment.
BeautifyRenderer.render 在 CaptureSessionController.dispatchAction 的 .copy/.save/.upload 等主线程路径上被同步调用;desktopWallpaper 样式会在此路径上新建 CIContext() 并执行 30px 高斯模糊,属于较昂贵的同步 GPU/CPU 工作,大图导出/复制时可能阻塞 UI。另外 fetchBlurredWallpaper 依赖 Thread.isMainThread + MainActor.assumeIsolated 的脆弱假设访问 NSWorkspace API,非主线程时静默返回 nil 回退渐变。建议将 render 移到后台队列执行,并对 CIContext 做复用(CIContext 创建成本高)。
Suggestion:
| let ciContext = CIContext() | |
| return ciContext.createCGImage(output, from: ciImage.extent) ?? cg | |
| let ciContext = Self.sharedCIContext | |
| return ciContext.createCGImage(output, from: ciImage.extent) ?? cg | |
| } | |
| private static let sharedCIContext = CIContext(options: [.cacheIntermediates: false]) |
| "content": [ | ||
| ["type": "text", "text": VLMPromptTemplate.userPrompt], | ||
| ["type": "text", "text": prompts.user], | ||
| ["type": "image_url", "image_url": ["url": "data:image/jpeg;base64,\(base64Image)"]] |
There was a problem hiding this comment.
对话分支的 image_url 硬编码 "data:image/jpeg;base64," 前缀,而 encoded 对象本身已提供与实际 MIME 一致的 dataURI(AnalysisImageEncoder.jpeg 固定产生 image/jpeg,目前一致)。建议直接使用 encoded.dataURI,消除未来切换编码格式(如 PNG)时前缀与实际格式不一致的隐患。
Suggestion:
| ["type": "image_url", "image_url": ["url": "data:image/jpeg;base64,\(base64Image)"]] | |
| + ["type": "image_url", "image_url": ["url": encoded.dataURI]] |
| "response_format": ["type": "json_object"] | ||
| ] | ||
| request.httpBody = try JSONSerialization.data(withJSONObject: body) |
There was a problem hiding this comment.
chat/completions 分支新增了 "response_format": ["type": "json_object"],但没有像 OpenAIVLMProvider / OllamaVLMProvider 那样提供 400 降级重试:Ollama 的 executeRequest 在 HTTP 400 时抛 invalidConfiguration,其他两家都据此关闭 structured output 重试一次;这里若端点不支持 response_format,请求将持续 400 失败,属于相对旧行为(不带该字段可用)的回归。建议复用同样的 catch invalidConfiguration → 去掉 response_format 重试一次的模式,或仅在确认端点支持时启用。
Suggestion:
| "response_format": ["type": "json_object"] | |
| ] | |
| request.httpBody = try JSONSerialization.data(withJSONObject: body) | |
| + "response_format": ["type": "json_object"] | |
| ] | |
| request.httpBody = try JSONSerialization.data(withJSONObject: body) | |
| // TODO: 对 400 (invalidConfiguration) 降级为不带 response_format 重试一次, | |
| // 与 OpenAIVLMProvider/OllamaVLMProvider 保持一致 |
| if let bConfig = beautifyConfig, bConfig.isEnabled { | ||
| if let beautified = BeautifyRenderer.shared.render(image: finalImage, config: bConfig) { | ||
| finalImage = beautified | ||
| } | ||
| } |
| let font = NSFont.systemFont(ofSize: fontSize, weight: .medium) | ||
| let attributes: [NSAttributedString.Key: Any] = [ | ||
| .font: font, | ||
| .foregroundColor: annotation.style.color.nsColor | ||
| ] |
There was a problem hiding this comment.
气泡注释的导出渲染与 DocumentRenderer(预览/文档渲染路径)存在双重不一致:(1) 导出使用 NSFont.systemFont(ofSize:weight: .medium),而 DocumentRenderer 及文本注释渲染路径均使用 style.fontName 解析字体,同一气泡在预览与导出中字形不同;(2) 导出会在内容过高时自动向下扩展 bubbleRect,DocumentRenderer 的同函数没有该测量/扩展逻辑,导致预览中文本被截断而导出正常(或反之),出现 WYSIWYG 偏差。建议把气泡测量+尾巴绘制抽成共享渲染代码,两侧使用同一字体与同一扩展规则。
Suggestion:
| let font = NSFont.systemFont(ofSize: fontSize, weight: .medium) | |
| let attributes: [NSAttributedString.Key: Any] = [ | |
| .font: font, | |
| .foregroundColor: annotation.style.color.nsColor | |
| ] | |
| let font = NSFont(name: annotation.style.fontName, size: fontSize) | |
| ?? NSFont.systemFont(ofSize: fontSize, weight: .medium) |
| let attachX = max(bubbleRect.minX + 10, min(bubbleRect.maxX - 10, cgTarget.x)) | ||
| let attachY = cgTarget.y < bubbleRect.minY ? bubbleRect.minY : (cgTarget.y > bubbleRect.maxY ? bubbleRect.maxY : bubbleRect.midY) | ||
| let halfBase = min(8.0, max(4.0, bubbleRect.width * 0.1)) |
There was a problem hiding this comment.
ImageExporter.drawCalloutBubble 与 DocumentRenderer.drawCalloutBubble 是两份近似复制的手绘代码,但常量已经漂移:attachX 边距(8 vs 10)、halfBase 公式(width0.1 上下限相同但入口矩形不同)、引导线/尾巴线宽与 numberLabel 引导点尺寸(size/12 vs 固定 2.0、size0.14 vs 固定 3px)均不一致。同类差异也存在于箭头 arrowLength(14 vs 12)。这会在预览与导出之间产生可见的视觉差异,且后续修 bug 需要双处同步。建议抽取共享绘制原语(尾部三角、引导点)供两个渲染器复用。
| texts = try await withCheckedThrowingContinuation { continuation in | ||
| DispatchQueue.global(qos: .userInitiated).async { | ||
| let handler = VNImageRequestHandler(cgImage: boxedImage.value, options: [:]) |
There was a problem hiding this comment.
withCheckedThrowingContinuation 未注册 onCancel:调用方 Task 被取消后,DispatchQueue.global 上的同步 handler.perform 仍会完整执行(VNRecognizeTextRequest 无法中断,但也没有提前检查 Task.isCancelled),已取消的操作继续占用 CPU/内存,取消也不会向上游及时传导。建议通过 withTaskCancellationHandler 注册取消,在派发闭包执行前检查 isCancelled,必要时以 CancellationError 恢复 continuation(注意与正常完成路径互斥,避免双重 resume)。
Suggestion:
| texts = try await withCheckedThrowingContinuation { continuation in | |
| DispatchQueue.global(qos: .userInitiated).async { | |
| let handler = VNImageRequestHandler(cgImage: boxedImage.value, options: [:]) | |
| + texts = try await withTaskCancellationHandler { | |
| + try await withCheckedThrowingContinuation { continuation in | |
| + DispatchQueue.global(qos: .userInitiated).async { | |
| + guard !Task.isCancelled else { | |
| + continuation.resume(throwing: CancellationError()) | |
| + return | |
| + } | |
| + ... | |
| + } | |
| + } | |
| + } onCancel: { | |
| + Task { await self.cancelPendingRecognition() } | |
| + } |
| if let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any], | ||
| json["object"] as? String == "response" || json["output"] is [[String: Any]] || json["output_text"] is String { |
There was a problem hiding this comment.
把 json["output_text"] is String 作为进入 Responses API 分支的条件后,若兼容端点在 Chat Completions 响应顶层返回空字符串的 output_text(早期代码会因 !outputText.isEmpty 判断失败而继续走 chat 解码路径),现在会直接落入分支底部并抛出 invalidResponse("no message text"),而不是按 OpenAI Chat 响应格式解析 choices。建议在进入分支前校验 output_text 非空,或分支内解析失败时回退到 chat 格式解码。
Suggestion:
| if let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any], | |
| json["object"] as? String == "response" || json["output"] is [[String: Any]] || json["output_text"] is String { | |
| if let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any], | |
| json["object"] as? String == "response" || json["output"] is [[String: Any]] || (json["output_text"] as? String)?.isEmpty == false { |
| let analysisImage = AnalysisImageEncoder.downsampled(image) | ||
| let analysisSize = CGSize(width: analysisImage.width, height: analysisImage.height) |
There was a problem hiding this comment.
OCRResult.imageSize 现在是降采样后的 analysisSize 而非原始捕获尺寸。坐标消费方均使用归一化 boundingBox 并以结果自带的 imageSize 换算,当前一致;但任何直接用原始图像尺寸对 PaddleOCR 结果做像素换算的调用方都会产生系统性缩放偏移。建议在 downsampled 确实缩放时记录缩放比(或在注释/结果中标注分析尺寸),便于上层排查。
Suggestion:
| let analysisImage = AnalysisImageEncoder.downsampled(image) | |
| let analysisSize = CGSize(width: analysisImage.width, height: analysisImage.height) | |
| + let analysisImage = AnalysisImageEncoder.downsampled(image) | |
| + let analysisSize = CGSize(width: analysisImage.width, height: analysisImage.height) | |
| + // 注意:归一化坐标基准是降采样后的分析图,消费方必须使用 result.imageSize 而非原始捕获尺寸 |
| } | ||
|
|
||
| logger.info("Smart privacy detection started via \(provider.name)") | ||
| let result = try await provider.analyze(image: image, prompt: .privacy) |
There was a problem hiding this comment.
以“隐私保护”为目标的智能马赛克功能,会把尚未打码的整张截图(可能包含密码、密钥、聊天记录等敏感内容)通过 provider.analyze(image:prompt: .privacy) 上传到在线 VLM 服务。isConfigured 仅校验 provider 配置,调用路径(PreviewViewModel.performSmartRedaction)中也没有任何关于数据将出站的用户告知/确认或本地降级(如使用本地 PaddleOCR 文本检测)逻辑。对于此用例,敏感数据在打码前就已离开设备,存在隐私外泄风险。建议:在触发检测前明确提示用户“内容将发送到 ”并取得确认,或优先使用本地检测通道。
Suggestion:
| let result = try await provider.analyze(image: image, prompt: .privacy) | |
| // Require explicit user consent before uploading un-redacted content | |
| guard settings.userConsentedToCloudPrivacyDetection else { | |
| throw PrivacyDetectionError.providerNotConfigured | |
| } | |
| let result = try await provider.analyze(image: image, prompt: .privacy) |
| extension VLMProvider { | ||
| func analyze(image: CGImage, prompt: VLMPromptPair) async throws -> ScreenAnalysisResult { | ||
| try await analyze(image: image) | ||
| } | ||
| } |
There was a problem hiding this comment.
协议扩展的 analyze(image:prompt:) 默认实现会静默丢弃 prompt 参数、退回普通 OCR。而 ScreenCoderEngine.currentProvider() 可能返回 PaddleOCRVLMProvider(未重写该方法),SmartPrivacyRedactionService.detectPrivacyRegions 会用它执行 .privacy 提示词:结果是 OCR 文本段落被当作隐私区域返回,导致与敏感内容无关的位置被涂黑(或真正的敏感内容未被遮挡),属于隐私功能上的静默错误行为。建议让所有 VLMProvider 都实现该重写,或在该默认实现中针对非 .ocr prompt 抛出不受支持的错误,让上层提示用户更换 provider。
Suggestion:
| extension VLMProvider { | |
| func analyze(image: CGImage, prompt: VLMPromptPair) async throws -> ScreenAnalysisResult { | |
| try await analyze(image: image) | |
| } | |
| } | |
| extension VLMProvider { | |
| func analyze(image: CGImage, prompt: VLMPromptPair) async throws -> ScreenAnalysisResult { | |
| guard prompt == .ocr else { | |
| throw VLMProviderError.invalidResponse("Provider does not support custom prompts") | |
| } | |
| return try await analyze(image: image) | |
| } | |
| } |
No description provided.