Skip to content

feat(pcview): add host webui access - #39

Merged
qiin2333 merged 3 commits into
masterfrom
codex/host-webui
Jun 15, 2026
Merged

feat(pcview): add host webui access#39
qiin2333 merged 3 commits into
masterfrom
codex/host-webui

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 在 PCView 主机菜单里加了 host Settings 入口,直达 Sunshine Host WebUI。
  • 新增 ArkWeb 承载页,支持复制地址、刷新、外部打开和返回。
  • WebUI URL 会按主机地址推导到 HTTPS 47990,并兼容自定义 GameStream HTTP 端口的相邻端口。
  • 自动确认 Sunshine 自签名/主机名不匹配证书错误,还补了 Basic Auth 登录弹窗,空白页杂鱼状态退退退。

为啥要改

  • 用户在主机菜单里就能直接管理 Sunshine,不用手动复制 IP 再切浏览器。
  • Sunshine WebUI 常见自签名证书和 401 Basic Auth,ArkWeb 需要应用侧接住,不然就会报证书错或白屏。

验证

  • git diff --check
  • NODE_PATH=/Users/mac/Program/moonlight-harmony/node_modules JAVA_HOME=/Applications/DevEco-Studio.app/Contents/jbr/Contents/Home DEVECO_SDK_HOME=/Applications/DevEco-Studio.app/Contents/sdk node hvigorw.js assembleApp --no-daemon
  • 模拟器安装 HAP 并打开主机菜单,点击 host Settings 后进入 https://192.168.18.42:47990,出现 Sunshine WebUI 登录弹窗。

Summary by CodeRabbit

  • 新功能
    • 新增主机 WebUI 页面,可在电脑菜单中通过“访问主机设置”打开
    • 支持自动生成并加载 WebUI 地址,提供返回、重新加载
    • 支持 HTTP 基础认证登录弹窗、复制 WebUI 地址与外部浏览器打开
    • 支持处理 WebUI 证书/SSL 错误的加载流程
  • Bug修复
    • 修复开发者认证处于 PENDING 状态时返回设置页能恢复授权对话框显示
  • 文档
    • 更新隐私政策,说明 GitHub OAuth 仅用于开发者模式 Star 验证且不集成数据追踪

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 505d54c9-0cb8-4f3f-9033-11b8e5bb5602

📥 Commits

Reviewing files that changed from the base of the PR and between 43acd93 and 21a8939.

📒 Files selected for processing (1)
  • entry/src/main/ets/pages/HostWebUiPage.ets
🚧 Files skipped from review as they are similar to previous changes (1)
  • entry/src/main/ets/pages/HostWebUiPage.ets

📝 Walkthrough

Walkthrough

新增 HostWebUiPagebuildHostWebUiUrl 工具,实现从主机菜单跳转至 Sunshine WebUI 的完整流程,含 SSL 自动接受与 HTTP 基础认证弹窗。同时扩展 ComputerMenuHelper 菜单回调,在 PcListPageV2 中接入跳转,注册路由;另含 Settings PENDING 状态授权恢复与隐私政策文本更新。

Changes

Host WebUI 功能

Layer / File(s) Summary
WebUI URL 构建工具
entry/src/main/ets/utils/HostWebUiUtil.ets
新增 DEFAULT_HOST_WEBUI_PORT(47990)与 buildHostWebUiUrl,通过 selectBestAddress 选择主机地址,按"HTTP 端口 + 1"规则推导 WebUI 端口,无法确定时使用默认端口,最终返回 https:// 形式 URL。
菜单回调扩展与页面路由注册
entry/src/main/ets/viewmodel/ComputerMenuHelper.ets, entry/src/main/ets/pages/PcListPageV2.ets, entry/src/main/resources/base/profile/main_pages.json
ComputerMenuCallbacks 新增 onHostWebUi 回调,generateMenu 插入"host Settings"菜单项;PcListPageV2 实现跳转时透传 computerIdmain_pages.json 注册路由。
HostWebUiPage 状态初始化与控制方法
entry/src/main/ets/pages/HostWebUiPage.ets(许可证、导入、状态字段、生命周期、助手方法)
声明页面状态字段(URL、加载/错误标志、SSL、认证缓存),aboutToAppear 读取 computerId 并查找主机生成 URL;reloadcopyUrlopenInBrowser 等方法实现 WebView 交互、系统剪贴板、外部浏览器启动;requestHttpAuthsubmitHttpAuthcancelHttpAuth 完整实现 HTTP 基础认证流程。
HostWebUiPage 渲染逻辑与 UI 构建器
entry/src/main/ets/pages/HostWebUiPage.ets(build 方法、构建器)
build() 根据 webUiUrl 分支渲染 WebView 或错误/空状态,绑定 onPageBeginonPageEndonSslErrorEventReceiveonHttpAuthRequest 等事件;NavBar 提供导航与快捷操作;LoadingOverlayErrorPanelEmptyState 实现各状态 UI。
HostWebUiAuthDialog 认证弹窗
entry/src/main/ets/pages/HostWebUiPage.ets
独立 @Component 弹窗,渲染用户名/密码输入(密码遮罩),显示 realm/host 说明,通过回调将输入变化与确认/取消结果返回父页面。

独立小修改

Layer / File(s) Summary
Settings PENDING 状态恢复授权对话框
entry/src/main/ets/pages/SettingsPageV2.ets
applyDeveloperUnlockResultPENDING 分支中当设备码存在且开发者未激活时重新调用 showDeveloperDeviceCodeDialog,恢复用户离开后返回的授权流程。
隐私政策文本更新
entry/src/main/ets/pages/Index.ets
"网络通信"与"第三方服务"条目补充 GitHub OAuth Device Flow 仅用于可选开发者模式 Star 验证的说明。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • AlkaidLab/moonlight-harmony#15: 本 PR 的 buildHostWebUiUrl(computer: NvHttpHost)HostWebUiPage 直接依赖该 PR 引入的 NvHttpHost 接口与端口模型。
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 标题准确总结了主要变更:新增在 PCView 主机菜单中访问 Sunshine WebUI 的功能,涵盖了新页面、路由跳转和 URL 构建等核心改动。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/host-webui

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@entry/src/main/ets/pages/HostWebUiPage.ets`:
- Around line 198-205: The early return statement when acceptedSslError is true
prevents the subsequent error handling code from executing, which means
isLoading remains true and the error panel never appears for real framework
errors like connection refusal or timeout. Remove or restructure the early
return in the acceptedSslError check so that the subsequent code block that sets
isLoading to false and populates loadError with the error description continues
to execute regardless of whether an SSL error was previously accepted. This
ensures that actual errors from the main framework are properly handled and
displayed to the user.
- Around line 179-192: The WebView configuration combines two dangerous security
practices: MixedMode.All allows HTTPS pages to load unencrypted HTTP resources
(forbidden in production), and unconditionally calling
event.handler.handleConfirm() in the onSslErrorEventReceive callback bypasses
certificate validation, exposing the app to man-in-the-middle attacks. Fix this
by changing mixedMode from MixedMode.All to MixedMode.None for strict HTTPS-only
mode, and either remove the onSslErrorEventReceive callback entirely to let the
system reject unsafe connections by default, or if custom SSL handling is
required, replace event.handler.handleConfirm() with
event.handler.handleCancel() to abort insecure connections. Self-signed
certificates should be resolved by installing legitimate CA certificates to the
system trust store rather than bypassing validation in code.
- Around line 120-129: The openInBrowser method calls context.startAbility(want)
which returns a Promise, but the current code does not await it, causing Promise
rejections to not be captured by the try/catch block. Make the openInBrowser
method async and add await before context.startAbility(want) so that any errors
from the Promise rejection are properly caught by the existing try/catch error
handler.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1357d463-afb6-47ab-8e31-ef822cc4e68b

📥 Commits

Reviewing files that changed from the base of the PR and between c683fbd and 43acd93.

📒 Files selected for processing (7)
  • entry/src/main/ets/pages/HostWebUiPage.ets
  • entry/src/main/ets/pages/Index.ets
  • entry/src/main/ets/pages/PcListPageV2.ets
  • entry/src/main/ets/pages/SettingsPageV2.ets
  • entry/src/main/ets/utils/HostWebUiUtil.ets
  • entry/src/main/ets/viewmodel/ComputerMenuHelper.ets
  • entry/src/main/resources/base/profile/main_pages.json

Comment thread entry/src/main/ets/pages/HostWebUiPage.ets Outdated
Comment on lines +179 to +192
.mixedMode(MixedMode.All)
.zoomAccess(true)
.onPageBegin(() => {
this.isLoading = true;
this.loadError = '';
})
.onPageEnd(() => {
this.isLoading = false;
})
.onSslErrorEventReceive((event) => {
this.acceptedSslError = true;
this.loadError = '';
event.handler.handleConfirm();
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

HarmonyOS ArkWeb 中 mixedMode(MixedMode.All) 与 onSslErrorEventReceive 直接 handleConfirm() 的官方安全建议是什么?生产环境是否建议自动确认所有 SSL 错误?

💡 Result:

根据华为HarmonyOS官方开发者文档及安全编码规范,针对ArkWeb组件中 mixedMode 和 SSL 错误处理的官方安全建议如下: 1. 关于 mixedMode(MixedMode.All) 的建议 官方强烈建议禁止在生产环境中使用 MixedMode.All(宽松模式)[1][2][3]。 配置为 MixedMode.All 会允许 HTTPS 页面加载 HTTP 资源,从而破坏 HTTPS 通信的完整性,引入中间人攻击风险[1][2]。 官方推荐做法是将 mixedMode 配置为 MixedMode.None(严格模式),从根源上规避混合内容安全风险,并建议推动服务器将所有 HTTP 资源链接迁移至 HTTPS[1][2]。 2. 关于 onSslErrorEventReceive 中调用 handleConfirm 的建议 官方明确禁止在 onSslErrorEventReceive 或 onSslErrorEvent 回调中调用 event.handler.handleConfirm [2][3]。 直接忽略 SSL 错误并继续加载会绕过系统的证书校验机制,直接暴露于中间人攻击的风险中[3]。 3. 生产环境的官方处理建议 官方建议在处理 SSL 错误时采取以下合规方式: 不实现 onSslErrorEventReceive 或 onSslErrorEvent 回调,此时系统会默认取消资源加载,这是最安全的默认行为[1][3]。 若需要自定义处理,应在回调中主动调用 event.handler.handleCancel 来显式中止不安全的连接[1][2][3]。 如遇到自签名证书导致校验失败,生产环境的正确解决方案是使用合法 CA 签发的证书,或将所需的 CA 证书正确安装到系统的受信任证书存储中,而非通过代码手段绕过校验[4][5][6]。 综上,生产环境严禁自动确认所有 SSL 错误,这被视为严重的安全风险行为[2][3][6]。

Citations:


禁止在生产环境组合使用 MixedMode.All 和无条件 SSL 错误确认。

第 179 行的 MixedMode.All 与第 191 行的 event.handler.handleConfirm() 无条件确认构成高危配置:

  • 混合内容风险:MixedMode.All 允许 HTTPS 页面加载 HTTP 资源,HarmonyOS 官方文档明确禁止在生产环境使用,会破坏 HTTPS 通信完整性。
  • 证书绕过风险:官方明确禁止在 onSslErrorEventReceive 中调用 handleConfirm(),此做法直接绕过系统证书校验,暴露于中间人攻击。页面处理 Basic Auth 会进一步放大凭据泄露风险。

修复方案

  1. mixedMode 改为 MixedMode.None(严格模式)。
  2. 移除 onSslErrorEventReceive 回调让系统默认取消不安全连接;或若需自定义处理,改为调用 event.handler.handleCancel() 中止连接。
  3. 对自签名证书,应通过安装合法 CA 证书到系统受信存储解决,不应通过代码绕过校验。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@entry/src/main/ets/pages/HostWebUiPage.ets` around lines 179 - 192, The
WebView configuration combines two dangerous security practices: MixedMode.All
allows HTTPS pages to load unencrypted HTTP resources (forbidden in production),
and unconditionally calling event.handler.handleConfirm() in the
onSslErrorEventReceive callback bypasses certificate validation, exposing the
app to man-in-the-middle attacks. Fix this by changing mixedMode from
MixedMode.All to MixedMode.None for strict HTTPS-only mode, and either remove
the onSslErrorEventReceive callback entirely to let the system reject unsafe
connections by default, or if custom SSL handling is required, replace
event.handler.handleConfirm() with event.handler.handleCancel() to abort
insecure connections. Self-signed certificates should be resolved by installing
legitimate CA certificates to the system trust store rather than bypassing
validation in code.

Comment thread entry/src/main/ets/pages/HostWebUiPage.ets Outdated
@qiin2333
qiin2333 merged commit 175c932 into master Jun 15, 2026
2 checks passed
@qiin2333
qiin2333 deleted the codex/host-webui branch June 15, 2026 10:37
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.

1 participant