Skip to content

webview (macOS): App Nap exemption so background/occluded UIs stay live - #4

Open
turinglambdaai wants to merge 1 commit into
mainfrom
fix/app-nap-exemption
Open

turinglambdaai wants to merge 1 commit into
mainfrom
fix/app-nap-exemption

Conversation

@turinglambdaai

Copy link
Copy Markdown
Owner

Fixes #2

改动

ensure-app!(每个进程一次)里通过 [NSProcessInfo beginActivityWithOptions:] 声明 NSActivityUserInitiated(0x00FFFFFF),token 永不释放——开着窗口的 Glaze 应用按定义就是用户发起的工作。获取失败为非致命(best effort)。

动机

macOS 会对窗口被完全遮挡的"空闲"应用做节流/挂起。监测类 UI(实时曲线、日志尾随、数据流视图)在窗口被盖住的一刻页面定时器与渲染冻结——后端仍在服务(curl 可见事件流),前端却停止刷新,用户感知为"应用坏了"。进程级 App Nap 豁免是 Electron 等框架对监测类应用的同款反制。

边界说明

本 PR 消除的是进程级挂起分量。WebKit 自身基于页面可见性的节流在不同 macOS 版本上的表现需要实测观察;若仍能观察到,那属于 WebKit 页面可见性行为,应作为平台限制文档化,而不是 App Nap 效应。

验证

  • raco test glaze-test/:216 通过(含 macOS WebView e2e:open/load/capture/navigate/close/on-close)
  • 真实监测类应用(gPTP Studio)窗口遮挡场景下事件消费恢复正常

macOS throttles/suspends 'idle' apps whose windows are fully occluded.
For monitoring-style Glaze UIs (live charts, streaming logs, dashboards)
that means the page's timers and rendering freeze as soon as another
window covers the app — the backend keeps serving, the UI goes stale.

ensure-app! now declares NSActivityUserInitiated via
[NSProcessInfo beginActivityWithOptions:] once per process. A Glaze app
with an open window is by definition user-initiated work, so the token
is intentionally never ended. Failure to acquire the activity is
non-fatal (best effort).

Note: this removes the process-level suspension component. WebKit may
still apply its own page-visibility throttling in some macOS versions;
that behavior, if observed, is a documented platform limitation rather
than an App Nap effect.

glaze-test: 216 passed (includes the macOS WebView e2e suite).

Fixes #2
@turinglambdaai

Copy link
Copy Markdown
Owner Author

CI 说明:test (windows-latest) 失败与 PR #3 相同,为 main 上已有的 appapi-test.rkt WebView2 用例问题,与本 PR(仅 webview-macos.rkt)无关。

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.

macOS: WKWebView 页面 JS 定时器在窗口遮挡时疑似被暂停(AppNap)——常驻监测类应用需要反制

1 participant