接入原生壳外观查询能力
新增 HostBridge appearance.getColorScheme 只读契约和 H5 facade Expo 壳通过 React Native Appearance 读取系统配色 Tauri 壳通过主窗口 theme 读取桌面配色 补齐外观查询测试、漂移检查和架构文档
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type {
|
||||
AppearanceColorSchemeResult,
|
||||
FileExportImagePayload,
|
||||
FileExportImageResult,
|
||||
FileExportTextPayload,
|
||||
@@ -14,6 +15,7 @@ import type {
|
||||
import {
|
||||
isHostBridgeCapability,
|
||||
normalizeHostBridgeBadgeCount,
|
||||
normalizeHostBridgeColorScheme,
|
||||
normalizeHostBridgeExternalUrl,
|
||||
} from '../../../packages/shared/src/contracts/hostBridge';
|
||||
import type {
|
||||
@@ -95,6 +97,8 @@ export type HostShareOpenRequest = ShareOpenPayload;
|
||||
|
||||
export type HostExternalUrlRequest = OpenExternalUrlPayload;
|
||||
|
||||
export type HostAppearanceColorSchemeSnapshot = AppearanceColorSchemeResult;
|
||||
|
||||
const HOST_RUNTIME_REFRESH_TIMEOUT_MS = 3000;
|
||||
|
||||
let cachedNativeHostRuntime: HostBridgeRuntimeResult | null = null;
|
||||
@@ -764,3 +768,21 @@ export async function setHostAppBadgeCount({
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getHostAppearanceColorScheme() {
|
||||
if (!canUseNativeHostCapability('appearance.getColorScheme')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const result =
|
||||
await requestNativeAppHostBridge<AppearanceColorSchemeResult>(
|
||||
'appearance.getColorScheme',
|
||||
);
|
||||
return {
|
||||
colorScheme: normalizeHostBridgeColorScheme(result?.colorScheme),
|
||||
} satisfies HostAppearanceColorSchemeSnapshot;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user