Skip to content

fix(windows): 运行时权限修复被拒绝时继续启动,不再阻止在线更新 - #148

Merged
freedomkk-qfeng merged 2 commits into
ECNU:mainfrom
wf0229:pr/runtime-access-nonfatal
Oct 13, 2026
Merged

freedomkk-qfeng merged 2 commits into
ECNU:mainfrom
wf0229:pr/runtime-access-nonfatal

Conversation

@wf0229

@wf0229 wf0229 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

问题

Windows 用户把应用装在自定义目录(例:D:\Apps\TokenWorks),从不含 b73b5a2 的旧版在线更新到含该提交的版本时,两次更新都在启动自检失败并回退:

  • 第一次在启动后约 15 秒失败(推断为用户关掉了错误框,应用随即退出);
  • 第二次报 updated application startup health stopped making progress(错误框未关闭,5 分钟没有心跳)。

update-trace.jsonl 中新版本没有任何 health-starting-* 心跳。desktop-host.log:

[desktop:runtime-access] 无法准备 Windows 程序运行权限。请检查安装目录权限或联系维护者。
grant Electron runtime read access D:\Apps\TokenWorks: Access is denied.

原因

configureEduworkPaths() 在写任何启动心跳之前同步调用 ensureRuntimeAccess(EduWork-Updater.exe ensure-runtime-access)。失败时会弹出 dialog.showErrorBox,并调用 app.exit(1)。

  • 在线更新由旧版更新器执行。旧版没有 electronaccess.Ensure,apply.go 中新增的授权不会运行,只能由新版应用自己以普通用户身份补授权。
  • 安装目录如果是以管理员权限创建的(自定义目录常见),普通用户没有该目录的 WRITE_DAC,Ensure 在根目录这一步就返回 Access is denied。
  • 同一目录中,旧版在没有这项授权的情况下一直正常运行,渲染进程沙盒可以启动。也就是说,授权失败不代表无法运行,但当前实现把它当作致命错误。
  • 模态错误框出现在第一次健康心跳之前。更新器看不到任何进展,只能报「停滞」。用户看到的错误也不含 Access is denied 的原因。

修改

dsh-electron/src/product.mjs:ensureRuntimeAccess 失败时写日志 [desktop:runtime-access] continuing without repair: …,然后继续启动。

  • 不弹框、不退出。
  • 不请求提权、不关闭沙盒。
  • 授权成功的路径不变。安装器与新版更新器中的 electronaccess.Ensure 不变,仍会回滚失败的权限修改。
  • 如果渲染进程确实因权限无法启动,后续 window-create / window-load 阶段会照常报错,这条日志说明原因。

dsh-electron/tests/runtime-access.test.mjs:原「失败时弹框并退出」的源码检查,改为「失败时记录日志并继续,处理分支中没有 showErrorBox / app.exit / throw」。基于上游 main(9b9803b)运行 node --test dsh-electron/tests/*.test.mjs:188 项,183 通过,5 项按平台跳过,0 失败。

可选的进一步改进(未包含)

  • 在第一次心跳之后再做修复,或修复前先写一个 runtime-access 阶段心跳,便于更新器显示具体阶段。
  • Ensure 遇到 Access is denied 时区分「已可读,无需修改」和「确实无法读取」:可先用受限令牌试读,再决定是否需要修改。

来源

原作者:@wf0229(词元工坊 USTC TokenWorks,核心提交 57bd000),随 TokenWorks 0.2.11 发布。用户报告日期:2026-10-13。

🤖 Generated with Claude Code

wf0229 and others added 2 commits October 13, 2026 00:49
The pre-window runtime ACL repair (b73b5a2) is fatal: it shows a modal
error and exits before the first startup heartbeat. Online updates are
applied by the previous release's updater, which does not grant the
access, so the new app repairs as the current user. When the install
folder was created with administrator rights, that user has no WRITE_DAC
and the repair returns Access is denied; the update rolls back with
'startup health stopped making progress', although the previous release
runs in the same folder without the grant.

Log the failure and continue. Successful repairs, the installer and the
updater grants are unchanged; a renderer that truly cannot start still
fails in the window phases, with this log line as the cause.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
freedomkk-qfeng added a commit that referenced this pull request Oct 13, 2026
fix(windows): 按实际失败修复工作区沙箱权限,取消启动时强制改 ACL
@freedomkk-qfeng
freedomkk-qfeng merged commit 1456d36 into ECNU:main Oct 13, 2026
5 checks passed
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