diff --git a/apps/mobile-shell/scripts/check-config.mjs b/apps/mobile-shell/scripts/check-config.mjs index 49ce6e6c7..2c21132e7 100644 --- a/apps/mobile-shell/scripts/check-config.mjs +++ b/apps/mobile-shell/scripts/check-config.mjs @@ -1918,7 +1918,8 @@ for (const snippet of [ } if ( - !dispatchSource.includes('getMobileAppearanceColorScheme()') || + !dispatchSource.includes('getMobileHostBridgeAppearanceColorScheme(request)') || + dispatchSource.includes('ok(request, getMobileAppearanceColorScheme())') || dispatchSource.includes('Appearance.getColorScheme()') || dispatchSource.includes('normalizeHostBridgeColorScheme') ) { @@ -1928,6 +1929,9 @@ for (const snippet of [ 'Appearance.getColorScheme()', 'normalizeHostBridgeColorScheme', 'getMobileAppearanceColorScheme', + 'getMobileHostBridgeAppearanceColorScheme', + 'request: HostBridgeRequest', + 'ok(request, getMobileAppearanceColorScheme())', ]) { if (!appearanceSource.includes(snippet)) { throw new Error(`mobile shell appearance module is missing ${snippet}`); diff --git a/apps/mobile-shell/src/host-bridge/appearance.ts b/apps/mobile-shell/src/host-bridge/appearance.ts index ed7c938a8..0bf9ee8d9 100644 --- a/apps/mobile-shell/src/host-bridge/appearance.ts +++ b/apps/mobile-shell/src/host-bridge/appearance.ts @@ -1,9 +1,19 @@ import { Appearance } from 'react-native'; -import { normalizeHostBridgeColorScheme } from '../../../../packages/shared/src/contracts/hostBridge'; +import { + type HostBridgeRequest, + normalizeHostBridgeColorScheme, +} from '../../../../packages/shared/src/contracts/hostBridge'; +import { ok } from './protocol'; export function getMobileAppearanceColorScheme() { return { colorScheme: normalizeHostBridgeColorScheme(Appearance.getColorScheme()), }; } + +export function getMobileHostBridgeAppearanceColorScheme( + request: HostBridgeRequest, +) { + return ok(request, getMobileAppearanceColorScheme()); +} diff --git a/apps/mobile-shell/src/host-bridge/dispatch.ts b/apps/mobile-shell/src/host-bridge/dispatch.ts index a38df5248..3b049c85f 100644 --- a/apps/mobile-shell/src/host-bridge/dispatch.ts +++ b/apps/mobile-shell/src/host-bridge/dispatch.ts @@ -28,7 +28,7 @@ import { } from './clipboard'; import { runMobileHostBridgeHapticsImpact } from './haptics'; import { setMobileAppBadgeCount } from './badge'; -import { getMobileAppearanceColorScheme } from './appearance'; +import { getMobileHostBridgeAppearanceColorScheme } from './appearance'; import { openMobileHostBridgeExternalUrl, openMobileHostBridgeNativePage, @@ -52,7 +52,7 @@ export async function dispatchMobileHostBridgeRequest( case 'host.getRuntime': return ok(request, getMobileHostBridgeRuntime()); case 'appearance.getColorScheme': - return ok(request, getMobileAppearanceColorScheme()); + return getMobileHostBridgeAppearanceColorScheme(request); case 'app.openExternalUrl': return ok(request, await openMobileHostBridgeExternalUrl(request.payload)); case 'app.reloadWebView': diff --git a/docs/project-memory/shared-memory/decision-log.md b/docs/project-memory/shared-memory/decision-log.md index c8b112aeb..a85cc18f3 100644 --- a/docs/project-memory/shared-memory/decision-log.md +++ b/docs/project-memory/shared-memory/decision-log.md @@ -50,7 +50,7 @@ - 2026-06-18 草稿生成未读角标:平台壳层把“可见作品架里未读的草稿生成完成更新”同步到 `app.setBadgeCount`;同一草稿的 work/profile/session 等多个恢复 ID 只计 1,已读、失败、生成中和不可见草稿不计入。该角标只消费已有 HostBridge 能力,宿主不支持或设置失败不影响 H5 红点、作品架或后端状态。 - 2026-06-19 原生壳角标边界:Expo `app.setBadgeCount` 的 iOS 平台判定、共享上限校验、`PushNotificationIOS.setApplicationIconBadgeNumber(...)` 调用和 HostBridge 成功 / 失败响应映射统一收口在 `apps/mobile-shell/src/host-bridge/badge.ts`;Tauri `app.setBadgeCount` 的 payload 校验、清除语义、主窗口 `set_badge_count` 调用和 HostBridge 响应映射统一收口在 `apps/desktop-shell/src-tauri/src/host_bridge/badge.rs`。两端 `dispatch` 只负责委托对应 badge 模块,配置检查会拒绝分发层直接导入角标底层 API、重声明数量边界或包装角标成功响应。 - 2026-06-18 宿主外观只读查询:新增 `appearance.getColorScheme` HostBridge capability,Expo 壳通过 React Native `Appearance.getColorScheme()` 读取系统配色,Tauri 壳通过主窗口 `theme()` 读取窗口主题;该能力只返回 `light` / `dark` / `unknown`,不设置 H5 主题、不覆盖系统主题,也不作为强制 UI 样式入口。 -- 2026-06-19 原生壳外观查询边界:Expo `appearance.getColorScheme` 的系统配色读取和 HostBridge 配色归一统一收口在 `apps/mobile-shell/src/host-bridge/appearance.ts`;Tauri `appearance.getColorScheme` 的主窗口 `theme()` 读取和 `light / dark / unknown` 映射统一收口在 `apps/desktop-shell/src-tauri/src/host_bridge/appearance.rs`。两端 `dispatch` 只负责委托对应 appearance 模块和映射响应,配置检查会拒绝分发层直接读取系统配色或窗口主题。 +- 2026-06-19 原生壳外观查询边界:Expo `appearance.getColorScheme` 的系统配色读取、HostBridge 配色归一和成功响应包装统一收口在 `apps/mobile-shell/src/host-bridge/appearance.ts`;Tauri `appearance.getColorScheme` 的主窗口 `theme()` 读取、`light / dark / unknown` 映射和 HostBridge 响应包装统一收口在 `apps/desktop-shell/src-tauri/src/host_bridge/appearance.rs`。两端 `dispatch` 只负责委托对应 appearance 模块,配置检查会拒绝分发层直接读取系统配色、窗口主题或包装外观查询成功响应。 - 2026-06-18 原生壳生命周期事件:新增 `app.lifecycle` HostBridge capability,Expo 壳通过 React Native `AppState` 派发 `active` / `inactive` / `background`,Tauri 壳通过主窗口 focus / blur、托盘隐藏 / 恢复和页面加载重放派发统一状态;桌面隐藏到托盘或最小化都归一为 `background`,`hidden`、`minimized`、`focused`、`blurred` 只进入 `nativeState` 便于排障,不扩展共享 `state`。两端都声明 `host.events` 表示事件通过 HostBridge message 注入,但不把它作为 request method,也不开放 Tauri event 插件或 React Native 私有事件 API。H5 只通过 `subscribeHostAppLifecycle()` 订阅统一状态,后续游戏循环、音频和轮询暂停 / 恢复不得直接依赖 Expo / Tauri 平台细节。 - 2026-06-18 原生壳网络状态:新增 `network.status` 与 `network.statusChanged` HostBridge capability,Expo 壳通过 `expo-network` 查询和订阅真实系统网络状态,Tauri 壳从 `WEB_APP_ORIGIN` 解析主站 host / port 后做短超时 TCP 可达性查询,并通过 WebView `online` / `offline` 注入变化事件;H5 统一使用 `getHostNetworkStatus()` / `subscribeHostNetworkStatusChange()`,不得直接读取 Expo / Tauri 私有网络 API。 - 2026-06-19 移动壳本地通知边界:Expo `notification.showLocal` 的 payload 归一、权限确认、iOS 仅 alert 且不请求 badge/sound、Android 固定 channel、即时调度和通知 handler 统一收口在 `apps/mobile-shell/src/host-bridge/notifications.ts`;`dispatch.ts` 只负责把 HostBridge request 委托给 `showMobileHostBridgeLocalNotification(...)`,不得直接调用 `expo-notifications` 调度或权限 API,也不得重新做通知 payload 归一。移动壳配置检查会覆盖该模块结构、固定 channel 和即时调度形态,避免后续混入远程推送、后台推送或散落的本地通知实现。