Skip to content

perf: faster Finder menu, app presets, per-app visibility and permission fixes - #166

Closed
SonneFish wants to merge 19 commits into
wflixu:devfrom
SonneFish:pr-to-upstream
Closed

SonneFish wants to merge 19 commits into
wflixu:devfrom
SonneFish:pr-to-upstream

Conversation

@SonneFish

@SonneFish SonneFish commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

已拆分提交

按维护者建议,本 PR 的内容已拆分为四个直接面向 dev 的独立 PR:

四个分支均已独立构建和测试;按上述顺序组合无冲突,组合后的构建和 68 项测试通过。新 PR 暂为 Draft,GitHub Actions 等待维护者 Approve and run;签名 App 的手工验证项列于各 PR。

本 PR 由上述四个 PR 替代,关闭并保留原评审历史。


摘要

优化 Finder 菜单图标缓存与心跳通信,新增应用预设、按应用控制工具栏/右键菜单可见性、图标样式及终端应用打开所在目录选项;同时修正权限页和主程序启动/重开行为。

已同步上游 dev,沿用 #163 合入的永久删除确认流程(默认开启)。此 PR 不改变签名、Sandbox 或 CI 配置。

验收标准

  • 心跳逐次发送轻量 running 回复,扩展持续在线;仅重连与配置变更发送完整菜单,移除会反复重置在线状态的 15s 监控。
  • 保留图标缓存;后台仅查询工作区图标与应用元数据,缩放绘制和预热 SF Symbols 在主线程执行;符号图按名称、尺寸和明暗外观分别缓存。
  • 修正静默启动标记的 App Group ID,与主程序共享同一常量;删除不存在的 applicationShouldRestoreWindowState 回调,窗口恢复由 SwiftUI scene 配置控制。
  • 本地化以 sentinel 区分缺 key 与合法的英文同值翻译;补齐 Installed、26 个预设名及新增设置的各语言条目,保留原目录已有条目的字节格式(仅为既有 RClick 品牌名补日语)。
  • 修正 WebStorm bundle ID;编辑应用时保留“跟随预设 / 开启 / 关闭”三态;可见性开关同时用于默认菜单和自定义布局。
  • 兼容旧 MenuConfigPayload 与 AppMenuItem;字段默认值不会破坏旧载荷解码。
  • 沿用上游默认开启的永久删除确认及其设置开关。
  • 编辑应用表单保留原生 SwiftUI Form,移除遍历 NSScrollView 的 AppKit 滚动条包装。
  • 修正沙盒、静默启动及应用打开调用链的注释,保持与当前上游配置一致。
  • 补充 CHANGELOG。

验证计划

  • Xcode 27:xcodebuild build-for-testing 编译应用、Finder 扩展和全部测试目标成功(arm64,关闭签名)。
  • 通过临时 SwiftPM library 测试宿主直接编译同一份生产代码(排除 App 入口)并运行仓库原测试:68 tests / 11 suites 全部通过。覆盖目标解析(文件/目录/不存在路径/编码路径、终端默认与显式覆盖)、预设 bundle ID 唯一及 SF Symbol 可解析、外观缓存、SwiftData/IPC 字段与三态保存、可见性、心跳超时重连,以及原先失败的旧载荷解码。
  • 持久化回读用例覆盖三态 × 两组可见性组合(6 个参数场景):通过 ConfigService.save 保存,再在新 ModelContext 中通过 ConfigService.load 重新加载,最后验证 IPC 载荷;在临时副本移除三处回读映射时,该用例按预期失败,恢复真实实现后完整 68 个测试通过。
  • python3 scripts/check-localization.py --languages es fr ja zh-Hans:两个 catalog 全部通过。
  • git diff --check 通过。
  • GitHub Actions 在最新提交 e8f75dc 上完成构建与测试:run 41401393859 为 action_required,等待上游维护者 Approve and run,尚未执行测试。
  • 签名后的 App 手工验证:Finder 菜单明暗切换、离线后点击提示重启、手动启动/再次打开与登录启动、删除确认。
  • macOS 15 / 26 / 27 的权限页跳转与状态刷新。

风险

本机 Xcode 的测试宿主在执行测试前退出(early unexpected exit),所以本地测试通过证据来自临时 library 宿主,不能替代签名 App 的端到端验证。登录启动仍使用“已启用登录项且系统 uptime < 180 秒”的启发式;启动窗口与 TCC/Finder 的实际行为需要上述手工检查。原 PR 的性能测量未在本次修复后重测。

致谢

应用预设目录、none/simple/original 图标样式和终端打开所在目录行为参考 OpenInTerminal。感谢维护者的逐项评审。

@SonneFish
SonneFish marked this pull request as draft October 28, 2026 13:29
…w appearance

- compute new-file workspace icons in the background when the menu config
  arrives and merge them into FileTypeIconProvider on the main thread
- pre-warm app symbol-name lookups (Info.plist reads) and the SF Symbol
  rendering pipeline via AppPresets.prewarm
- unify menu symbol icon construction in MenuSymbolIcon: a fresh image per
  build with theme-explicit colors, so icons track the system appearance
  instead of going stale after dark/light switches
- measured first menu build after extension start: ~55ms down to ~12ms;
  steady state unchanged (~0.5ms)
- add opensContainingDir per-app toggle on AppMenuItem (nil = follow the
  preset terminal classification)
- mark the nine preset terminal apps with isTerminal and expose
  terminalBundleIDs plus shared resolveOpenTargets in AppPresets
- host ActionService.openApp resolves targets via the shared helper so
  terminal apps receive the file's containing directory, while editors
  and Git clients keep opening the file itself
- restore offline graying for app items: a sandboxed extension calling
  NSWorkspace.open with a file URL triggers a TCC prompt, so launching the
  host from the fast path stays reserved for the bare no-document case
- make the offline hint two-liner clickable to relaunch the host app
  quietly via OpenConfiguration.environment RC_QUIET_LAUNCH=1
- suppress the SwiftUI Window scene auto-open at launch
  (.defaultLaunchBehavior(.suppressed), restorationBehavior disabled,
  applicationShouldRestoreWindowState=false)
- open the settings window on manual opens (no RC_QUIET_LAUNCH and not a
  login-item boot launch, i.e. LaunchAtLogin.isEnabled && uptime < 180s)
  and on re-opens of an already running app via
  applicationShouldHandleReopen; the request rides a notification handled
  by a MenuBarExtra label relay view, which exists from launch unlike the
  lazily built menu content
…ing app

The offline hint can stay visible while the host app is already running
(quit teardown takes ~1s; menu refresh lags startup by 1-2s). In that
window LaunchServices ignores OpenConfiguration.environment and only
dispatches a reopen event, so the app opened the settings page.

- FinderSyncExt touches a marker file in the shared App Group container
  before launching the host (HintClickLaunch.mark)
- the host checks marker recency on both launch paths: fresh launch
  treats it like RC_QUIET_LAUNCH, and applicationShouldHandleReopen
  skips posting openSettingsRequested
- use a container file rather than a UserDefaults suite: the suite maps
  to different files for the sandboxed extension and the unsandboxed
  host, while the group container is the one space both sides share
@SonneFish
SonneFish marked this pull request as ready for review October 29, 2026 06:47
…label color

hudWindow rendered light in light mode while the label was fixed white,
making the hint unreadable. Switch to the appearance-following popover
material with dynamic labelColor so background and text track the same
effective appearance in both modes.
… names

Long app names (e.g. Visual Studio Code) squeezed the trailing
checkboxes, wrapping "Open Containing Folder" onto a second line.
Give the toggles .fixedSize() so they keep their ideal width, and let
the name/summary texts truncate with an ellipsis instead.
…dit sheet

The app row no longer carries the third toggle, keeping the "Show In"
section purely about visibility; the behavior option lives in the edit
sheet where all config is one screen. The sheet keeps its fixed height,
with a persistent scrollbar added so users can tell more options exist
below the fold.
@wflixu

wflixu commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Unit tests failed ,please update unit tests

@wflixu

wflixu commented Nov 1, 2026

Copy link
Copy Markdown
Owner

结论:Request changes

感谢这个 PR。根因分析(心跳 → removeAll() → Finder 主线程同步 NSWorkspace 查询)是准确的,
「不清缓存 + 后台预热」的方向也对,注释和 PR 描述的质量都很好。

但有几处必须先修;另外 CI 目前是 action_required(首次贡献者需要维护者批准才会运行),
所以 PR 里的测试清单还没有任何自动化背书。

阻塞

  1. HintClickLaunch 的 App Group ID 写错 → 静默启动标记完全失效
  2. 心跳优化被 15s 监控抵消;而且一旦生效,扩展会把在线的主程序误判为离线
  3. applicationShouldRestoreWindowState 不是 AppKit API(死代码)
  4. AppLocalization 的缺 key 检测会把 207/211 个 key 误判为缺失

应修

  • 本地化:scripts/check-localization.py 失败(11 项);Installed 与 26 个预设名缺失
  • Localizable.xcstrings 被重新序列化(违反 CLAUDE.md 的约定)
  • 后台线程执行 AppKit 绘图(lockFocus)
  • 默认 simple 样式下 SF Symbol 完全不走缓存
  • WebStorm 的 bundleID 疑似写成了 PhpStorm
  • opensContainingDir 的三态在保存后被固化
  • 删除守卫可被多选时的 ⌘ 绕过,且是永久删除(removeItem)
  • Toast 淡出 completion 会误关新 toast

流程

  • 没有新增/修改测试(AppPresets.resolveOpenTargets 是纯函数,很好测)
  • 没有 CHANGELOG 条目
  • 按 CONTRIBUTING,feature PR 的目标分支应为 dev
  • 建议拆成 4 个 PR:性能 / 应用预设与可见性 / 权限页 / 启动策略
  • 请先点 "Approve and run" 让 CI 跑一次

我做的验证

  • swiftc -typecheck -swift-version 6 过 FinderSyncExt/* + Shared/*:通过,1 个 weak-capture 警告
  • python3 scripts/check-localization.py:base 0 问题,head 11 问题
  • 解析了两个 catalog:新增 20 个 host key、1 个 ext key;11 个新 key 缺 es/fr/ja
  • 完整 xcodebuild 被本机沙盒下的宏插件问题挡住(环境原因,不是代码问题)

@wflixu

wflixu commented Nov 1, 2026

Copy link
Copy Markdown
Owner

流程建议

  • 没有新增/修改测试:AppPresets.resolveOpenTargets 是纯函数,OpenWithApp → AppMenuItem
    字段透传、可见性过滤、MenuConfigPayload 解码也都可以单测;建议至少补
    resolveOpenTargets 和「预设表 bundleID 唯一 + symbol 可解析」两个用例。
  • 没有 CHANGELOG 条目(仓库的 changelog 维护得很细)。
  • 按 CONTRIBUTING,feature PR 的目标分支应为 dev。
  • 建议拆成 4 个 PR:性能 / 预设与可见性 / 权限页 / 启动策略。
  • 请先点 "Approve and run" 让 CI 跑一次(目前是 action_required)。

@SonneFish
SonneFish changed the base branch from main to dev November 2, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants