fix(desktop): resolve permission overlay assets in bundled dev - #2045
Conversation
Astro-Han
left a comment
There was a problem hiding this comment.
Approved with a non-blocking suggestion
The fix is correct and follows the established seam. The dist-walk matches the cursor overlay's defaultOverlayDistDir() and PiP's defaultDistDir(), and the parameterized moduleUrl finally makes this walk-up logic unit-testable — the two existing copies have no test coverage at all, so this is a strict improvement.
One non-blocking observation: this is now the third byte-for-byte copy of the same walk-up resolver (cursor-overlay-window.ts, pip-electron.ts, and now permission-overlay-path.ts). That's the rule-of-three point. If you'd like, extracting a shared resolveOverlayAssetDir(moduleUrl = import.meta.url) into e.g. src/main/overlay-assets.ts and switching all three call sites would make the resolver a single source of truth — and the regression test you added would then cover the cursor/PiP paths for free, since they currently have zero coverage. Purely mechanical, low risk, and independent of this fix, so it can be a follow-up.
中文对照
批准,附带一个非阻塞建议
修复正确,且遵循了仓库既有的扩展点:向上查找 dist 的逻辑与 cursor overlay 的 defaultOverlayDistDir()、PiP 的 defaultDistDir() 一致;参数化的 moduleUrl 让这段 walk-up 逻辑第一次可以被单元测试——而现有的两份旧实现完全没有测试覆盖,因此这是净改进。
一个非阻塞观察:这已经是同一段 walk-up 解析器的第三份逐字节相同的复制(cursor-overlay-window.ts、pip-electron.ts,以及现在的 permission-overlay-path.ts),恰好到了 rule-of-three 的提取时机。如果愿意,可以提取共享的 resolveOverlayAssetDir(moduleUrl = import.meta.url)(例如放到 src/main/overlay-assets.ts),三处调用点统一使用,这样你新增的回归测试也能顺带覆盖 cursor/PiP 路径——它们目前是零覆盖。这纯粹是机械替换、风险低,且与本次修复相互独立,可以作为 follow-up 单独做。
8642907 to
31f1262
Compare
Astro-Han
left a comment
There was a problem hiding this comment.
Approve. The walk-up-to-nearest-dist resolver is correct for every current launch flow (bundled dev, tsc production, macOS dev app, asar), and the cursor/PiP refactor onto the shared resolver is behavior-preserving. Three notes for the record, none blocking: the no-dist fallback returns a silent wrong path (unreachable today, worth an existsSync check if the resolver is ever hardened); the test assertions are POSIX path literals (would break on a Windows runner, moot on the current CI matrix); the resolver diverges from the packaged-assets resourcesPath pattern, which only matters if overlay assets move to extraResources.
English
Summary
In bundled desktop development, the macOS guided-permission action opens System Settings but never displays its overlay card.
dev.mjsbundles the main process intodist/main/main.js, whileoverlayAssetDir()assumed the tsc layout atdist/main/permission-overlay/permission-overlay-main.js. Its fixed../..traversal therefore resolved to the nonexistentapps/desktop/overlaydirectory instead ofdist/overlay, so Electron could not load the overlay preload or HTML.This PR:
distdirectory, matching the existing cursor/PiP overlay pattern;The
getFileIcon()native crash is already fixed onmainby #1920 and is not part of this PR.Reproduction
On macOS, with Accessibility or Screen Recording permission ungranted:
npm --workspace @maka/desktop run dev.Before this change, System Settings opens but the permission overlay card does not appear. The bundled module resolves assets as follows:
dist/main/permission-overlay/permission-overlay-main.jsdist/overlaydist/main/main.jsapps/desktop/overlay(missing)After this change, both layouts resolve to
dist/overlay.Verification
npm --workspace @maka/desktop run build:workspace-depsnpm --workspace @maka/desktop run build:mainnode --test apps/desktop/dist/main/__tests__/permission-overlay-path.test.js— 1 passedgit diff --check origin/main...HEADNot run: the post-fix macOS permission-onboarding flow or the full repository test suite.
中文
概要
在 bundled desktop 开发环境中,macOS 的“引导授权”操作会打开系统设置,但权限引导卡片不会出现。
dev.mjs将主进程代码合并到dist/main/main.js,而overlayAssetDir()假设模块位于 tsc 输出路径dist/main/permission-overlay/permission-overlay-main.js。固定的../..因此解析到不存在的apps/desktop/overlay,而不是dist/overlay,导致 Electron 无法加载 overlay 的 preload 和 HTML。本 PR:
dist目录来解析权限浮层资源,与现有 cursor/PiP overlay 的实现方式保持一致;getFileIcon()原生崩溃已由main上的 #1920 修复,不属于本 PR。复现路径
在 macOS 上,保持“辅助功能”或“屏幕录制”权限未授权:
npm --workspace @maka/desktop run dev。修改前,系统设置会打开,但权限引导卡片不会出现。bundled module 的资源解析结果如下:
dist/main/permission-overlay/permission-overlay-main.jsdist/overlaydist/main/main.jsapps/desktop/overlay(不存在)修改后,两种布局均解析到
dist/overlay。验证
npm --workspace @maka/desktop run build:workspace-depsnpm --workspace @maka/desktop run build:mainnode --test apps/desktop/dist/main/__tests__/permission-overlay-path.test.js— 1 项通过git diff --check origin/main...HEAD未运行:修复后的 macOS 权限引导手动流程及完整仓库测试套件。