Skip to content

Commit 0c6db20

Browse files
Hieriferhutengclaude
authored
feat(harmony): add getAppBaseInfo, filter cache result (#237)
* feat: add tabbar on harmony * feat(fe): add h5 tabbar * fix(fe): tabbar height * fix: code review issue and compile tabbar icon * fix: code review issue * feat: remove useless comment * fix(fe): modal 样式问题 * fix(fe): modal 样式问题 * feat: merge conflicts * feat: change style logic * feat: add tabbar function and style * feat(fe): adapt relative icon path issue * feat: 修复展示tabbar 展开缓慢的问题 * feat(fe): border color issue * feat(jssdk): provide promiselike * fix(harmony): resolve QuickJS VERSION file conflict with C++ <version> header on macOS On case-insensitive filesystems (macOS), QuickJS's plain-text VERSION file shadows the C++17/20 standard <version> header when quickjs_SOURCE_DIR is in the include path, causing "expected unqualified-id" compilation errors. Delete the VERSION file at both configure time and after git updates in the build-time update_quickjs_latest target. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(harmony,fe): implement getAppBaseInfo with hostEnv snapshot and field filtering - Add getAppBaseInfo bridge method on Harmony with filtered fields (SDKVersion, enableDebug, host, language, version, theme, fontSizeScaleFactor, fontSizeSetting) - Add missing systemInfo fields on Harmony: enableDebug, language, theme, host, fontSizeScaleFactor, fontSizeSetting - Add DMPHostEnvBuilder to build and cache hostEnv snapshot for loadResource message - Add pick() function in service layer to filter hostEnv-resolved API responses - Add missing fields to H5 getSystemInfoSync (theme, fontSizeScaleFactor, fontSizeSetting, language) - Regenerate JSSDK to v1.0.15 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test(service): update system-info tests for field filtering Use toEqual instead of toBe for APIs that now return filtered subsets via pick(), and expand test data to cover all API field groups. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat(JSSDK): update version --------- Co-authored-by: huteng <huteng@echo.tech> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b2325d1 commit 0c6db20

9 files changed

Lines changed: 310 additions & 68 deletions

File tree

fe/packages/container/src/pages/miniApp/miniApp.js

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,25 +1544,25 @@ export class MiniApp {
15441544
const onComplete = this.createCallbackFunction(complete)
15451545

15461546
onSuccess?.({
1547-
statusBarHeight: bar.height,
1548-
brand: 'devtools',
1549-
mode: 'default',
1550-
model: 'web',
1551-
platform: 'devtools',
1552-
system: 'web',
1553-
deviceOrientation: 'portrait',
1554-
SDKVersion: '3.0.0',
1555-
language: 'zh_CN',
1556-
wifiEnabled: true,
1557-
safeArea: {
1558-
width: wb.width,
1559-
height: wb.height,
1560-
top: wb.top,
1561-
bottom: wb.bottom,
1562-
left: wb.left,
1563-
right: wb.right,
1564-
},
1565-
})
1547+
statusBarHeight: bar.height,
1548+
brand: "devtools",
1549+
mode: "default",
1550+
model: "web",
1551+
platform: "devtools",
1552+
system: "web",
1553+
deviceOrientation: "portrait",
1554+
SDKVersion: "3.0.0",
1555+
language: "zh_CN",
1556+
wifiEnabled: true,
1557+
safeArea: {
1558+
width: wb.width,
1559+
height: wb.height,
1560+
top: wb.top,
1561+
bottom: wb.bottom,
1562+
left: wb.left,
1563+
right: wb.right,
1564+
},
1565+
});
15661566
onComplete?.()
15671567
}
15681568

@@ -1602,26 +1602,33 @@ export class MiniApp {
16021602
const statusBarHeight = statusBar?.getBoundingClientRect().height || 20
16031603

16041604
return {
1605-
brand: 'devtools',
1606-
model: 'web',
1607-
platform: 'devtools',
1608-
system: 'web',
1609-
SDKVersion: '3.0.0', // vant组件库 判断 canIUseModel version 需要大于 2.9.3
1610-
pixelRatio: globalThis.devicePixelRatio || 1,
1611-
screenWidth: width,
1612-
screenHeight: height,
1613-
windowWidth: width,
1614-
windowHeight: height,
1615-
statusBarHeight,
1616-
safeArea: {
1617-
left: 0,
1618-
right: width,
1619-
top: statusBarHeight,
1620-
bottom: height,
1621-
width,
1622-
height: Math.max(height - statusBarHeight, 0),
1623-
},
1624-
}
1605+
brand: "devtools",
1606+
model: "web",
1607+
platform: "devtools",
1608+
system: "web",
1609+
SDKVersion: "3.0.0", // vant组件库 判断 canIUseModel version 需要大于 2.9.3
1610+
pixelRatio: globalThis.devicePixelRatio || 1,
1611+
screenWidth: width,
1612+
screenHeight: height,
1613+
windowWidth: width,
1614+
windowHeight: height,
1615+
statusBarHeight,
1616+
safeArea: {
1617+
left: 0,
1618+
right: width,
1619+
top: statusBarHeight,
1620+
bottom: height,
1621+
width,
1622+
height: Math.max(height - statusBarHeight, 0),
1623+
},
1624+
enableDebug: false,
1625+
host: { appId: "" },
1626+
language: navigator.language || "zh_CN",
1627+
version: "",
1628+
theme: globalThis.matchMedia?.('(prefers-color-scheme: dark)')?.matches ? "dark" : "light",
1629+
fontSizeScaleFactor: 1,
1630+
fontSizeSetting: 16,
1631+
};
16251632
}
16261633

16271634
showToast(opts = {}) {

fe/packages/service/__tests__/system-info.spec.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,57 @@ describe('system info api', () => {
1414

1515
it('should prefer host env sync info for system-related apis', () => {
1616
const systemInfo = {
17+
// window info fields
1718
statusBarHeight: 20,
1819
windowWidth: 375,
1920
windowHeight: 667,
2021
screenWidth: 375,
2122
screenHeight: 667,
2223
pixelRatio: 2,
24+
safeArea: { top: 20, bottom: 667, left: 0, right: 375, width: 375, height: 647 },
25+
// app base info fields
26+
SDKVersion: '3.0.0',
27+
enableDebug: false,
28+
host: { appId: 'test' },
29+
language: 'zh_CN',
30+
version: '1.0.0',
31+
theme: 'light',
32+
fontSizeScaleFactor: 1,
33+
fontSizeSetting: 16,
34+
// device info fields
35+
brand: 'test',
36+
model: 'test',
37+
platform: 'devtools',
38+
system: 'web',
2339
}
2440

2541
hostEnv.init({ systemInfo })
2642

27-
expect(getWindowInfo()).toBe(systemInfo)
43+
expect(getWindowInfo()).toEqual({
44+
pixelRatio: 2,
45+
screenWidth: 375,
46+
screenHeight: 667,
47+
windowWidth: 375,
48+
windowHeight: 667,
49+
statusBarHeight: 20,
50+
safeArea: { top: 20, bottom: 667, left: 0, right: 375, width: 375, height: 647 },
51+
})
2852
expect(getSystemInfoSync()).toBe(systemInfo)
29-
expect(getAppBaseInfo()).toBe(systemInfo)
30-
expect(getDeviceInfo()).toBe(systemInfo)
53+
expect(getAppBaseInfo()).toEqual({
54+
SDKVersion: '3.0.0',
55+
enableDebug: false,
56+
host: { appId: 'test' },
57+
language: 'zh_CN',
58+
version: '1.0.0',
59+
theme: 'light',
60+
fontSizeScaleFactor: 1,
61+
fontSizeSetting: 16,
62+
})
63+
expect(getDeviceInfo()).toEqual({
64+
brand: 'test',
65+
model: 'test',
66+
platform: 'devtools',
67+
system: 'web',
68+
})
3169
})
3270
})

fe/packages/service/src/api/common/index.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,51 @@ import hostEnv from '../../core/host-env'
33
import message from '../../core/message'
44
import router from '../../core/router'
55

6-
const hostEnvResolvers = {
7-
getWindowInfo: () => hostEnv.getSystemInfo(),
8-
getSystemInfoSync: () => hostEnv.getSystemInfo(),
9-
getAppBaseInfo: () => hostEnv.getSystemInfo(),
10-
getDeviceInfo: () => hostEnv.getSystemInfo(),
11-
getMenuButtonBoundingClientRect: () => hostEnv.getMenuRect(),
6+
function pick(obj, keys) {
7+
if (!obj) return obj;
8+
const result = {};
9+
for (const key of keys) {
10+
if (key in obj) result[key] = obj[key];
11+
}
12+
return result;
1213
}
1314

15+
const hostEnvResolvers = {
16+
getWindowInfo: () =>
17+
pick(hostEnv.getSystemInfo(), [
18+
"pixelRatio",
19+
"screenWidth",
20+
"screenHeight",
21+
"windowWidth",
22+
"windowHeight",
23+
"statusBarHeight",
24+
"safeArea",
25+
"screenTop",
26+
]),
27+
getSystemInfoSync: () => hostEnv.getSystemInfo(),
28+
getAppBaseInfo: () =>
29+
pick(hostEnv.getSystemInfo(), [
30+
"SDKVersion",
31+
"enableDebug",
32+
"host",
33+
"language",
34+
"version",
35+
"theme",
36+
"fontSizeScaleFactor",
37+
"fontSizeSetting",
38+
]),
39+
getDeviceInfo: () =>
40+
pick(hostEnv.getSystemInfo(), [
41+
"abi",
42+
"benchmarkLevel",
43+
"brand",
44+
"model",
45+
"platform",
46+
"system",
47+
]),
48+
getMenuButtonBoundingClientRect: () => hostEnv.getMenuRect(),
49+
};
50+
1451
const promiseUnsupportedApis = new Set([
1552
'connectSocket',
1653
'downloadFile',

harmony/dimina/src/main/cpp/CMakeLists.txt

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,18 @@ FetchContent_Declare(
2121
)
2222
FetchContent_MakeAvailable(quickjs)
2323

24-
# Handle the version file to prevent compilation errors
25-
set(VERSION_FILE "${quickjs_SOURCE_DIR}/version")
24+
# Handle the VERSION file to prevent conflicts with C++ standard <version> header
25+
# on case-insensitive filesystems (macOS). QuickJS ships a plain-text VERSION file
26+
# which shadows the C++17/20 <version> header when quickjs_SOURCE_DIR is in the
27+
# include path, causing "expected unqualified-id" errors in C++ compilations.
28+
set(VERSION_FILE "${quickjs_SOURCE_DIR}/VERSION")
2629
set(VERSION_H_FILE "${quickjs_SOURCE_DIR}/version.h")
27-
set(VERSION_TXT_FILE "${quickjs_SOURCE_DIR}/version.txt")
2830

29-
# 只在首次配置时处理 version 文件
30-
if(EXISTS "${VERSION_FILE}" AND NOT EXISTS "${VERSION_H_FILE}")
31-
# Read the version content
31+
if(EXISTS "${VERSION_FILE}")
3232
file(READ "${VERSION_FILE}" QJS_VERSION)
3333
string(STRIP "${QJS_VERSION}" QJS_VERSION)
34-
35-
# Create a version.h file
36-
file(WRITE "${VERSION_H_FILE}" "#define QJS_VERSION \"${QJS_VERSION}\"\n")
37-
38-
# Rename the original version file to prevent it from being compiled
39-
file(RENAME "${VERSION_FILE}" "${VERSION_TXT_FILE}")
40-
elseif(NOT EXISTS "${VERSION_FILE}" AND NOT EXISTS "${VERSION_H_FILE}" AND EXISTS "${VERSION_TXT_FILE}")
41-
# 如果 version.txt 已存在,从它创建 version.h
42-
file(READ "${VERSION_TXT_FILE}" QJS_VERSION)
43-
string(STRIP "${QJS_VERSION}" QJS_VERSION)
4434
file(WRITE "${VERSION_H_FILE}" "#define QJS_VERSION \"${QJS_VERSION}\"\n")
35+
file(REMOVE "${VERSION_FILE}")
4536
endif()
4637

4738
# Set build type to Release for optimization
@@ -88,6 +79,9 @@ if(DIMINA_UPDATE_QUICKJS_ON_BUILD)
8879
add_custom_target(update_quickjs_latest
8980
COMMAND ${GIT_EXECUTABLE} fetch --depth=1 origin master
9081
COMMAND ${GIT_EXECUTABLE} reset --hard FETCH_HEAD
82+
# Remove the VERSION file to prevent conflicts with the C++ standard <version> header
83+
# on case-insensitive filesystems (macOS). The version value is already in version.h.
84+
COMMAND ${CMAKE_COMMAND} -E rm -f "${quickjs_SOURCE_DIR}/VERSION"
9185
WORKING_DIRECTORY ${quickjs_SOURCE_DIR}
9286
COMMENT "Updating QuickJS to latest origin/master"
9387
)

harmony/dimina/src/main/ets/Bridges/DMPContainerBridgesModule+System.ets

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { DMPLogger } from '../EventTrack/DMPLogger';
44
import batteryInfo from '@ohos.batteryInfo';
55
import deviceInfo from '@ohos.deviceInfo';
66
import { DMPDeviceUtil } from '../Utils/DMPDeviceUtils';
7-
import { bundleManager } from '@kit.AbilityKit';
7+
import { bundleManager, ConfigurationConstant, common } from '@kit.AbilityKit';
88
import { BusinessError } from '@kit.BasicServicesKit';
99
import { DMPMap } from '../Utils/DMPMap';
1010
import BuildProfile from '../../../../BuildProfile';
1111
import { access } from '@kit.ConnectivityKit';
12+
import { i18n } from '@kit.LocalizationKit';
1213

1314
export class DMPContainerBridgesModuleSystem extends DMPContainerBridgesModule {
1415
private bundleInfo?: bundleManager.BundleInfo
@@ -17,7 +18,7 @@ export class DMPContainerBridgesModuleSystem extends DMPContainerBridgesModule {
1718

1819
getExportMethods(): string[] {
1920
return ['getSystemInfoSync', 'getEnv', 'getSystemInfoAsync', 'getAccountInfoSync', 'getSystemInfo',
20-
'getDiminaCurStackPages', 'getSystemSetting', 'getWindowInfo'];
21+
'getDiminaCurStackPages', 'getSystemSetting', 'getWindowInfo', 'getAppBaseInfo'];
2122
}
2223

2324
getWindowInfo(data: DMPMap, callback: DMPBridgeCallback) {
@@ -63,6 +64,20 @@ export class DMPContainerBridgesModuleSystem extends DMPContainerBridgesModule {
6364
}
6465
}
6566

67+
getAppBaseInfo(data: DMPMap, callback: DMPBridgeCallback) {
68+
const info = this.systemInfo()
69+
const keys = ['SDKVersion', 'enableDebug', 'host', 'language', 'version',
70+
'theme', 'fontSizeScaleFactor', 'fontSizeSetting']
71+
const result = new DMPMap()
72+
for (const key of keys) {
73+
const value: string | number | boolean | object | undefined = info.get(key)
74+
if (value !== undefined) {
75+
result.set(key, value)
76+
}
77+
}
78+
return result
79+
}
80+
6681
getSystemInfoSync(data: DMPMap, callback: DMPBridgeCallback) {
6782
const currentTime = Date.now();
6883
// 检查缓存是否有效(10秒)
@@ -135,7 +150,35 @@ export class DMPContainerBridgesModuleSystem extends DMPContainerBridgesModule {
135150

136151
//星河sdk版本
137152
result.set('SDKVersion', BuildProfile.HAR_VERSION);
153+
result.set('enableDebug', this.app.appConfig.isDebugMode);
138154
result.set('debugEnv', this.app.appConfig.isDebugMode ? 1 : 0)
155+
156+
// language: 微信客户端设置的语言
157+
const locale = i18n.System.getSystemLocale()
158+
result.set('language', locale)
159+
160+
// theme: 系统当前主题
161+
try {
162+
const uiContext = getContext(this) as common.UIAbilityContext
163+
const colorMode = uiContext.config.colorMode
164+
result.set('theme', colorMode === ConfigurationConstant.ColorMode.COLOR_MODE_DARK ? 'dark' : 'light')
165+
} catch (e) {
166+
result.set('theme', 'light')
167+
}
168+
169+
// host: 宿主信息
170+
result.set('host', { appId: this.app.appConfig.appId })
171+
172+
// font settings
173+
try {
174+
const uiCtx = getContext(this) as common.UIAbilityContext
175+
const fontSizeScale: number = uiCtx.config.fontSizeScale ?? 1.0
176+
result.set('fontSizeScaleFactor', fontSizeScale)
177+
result.set('fontSizeSetting', Math.round(16 * fontSizeScale))
178+
} catch (e) {
179+
result.set('fontSizeScaleFactor', 1.0)
180+
result.set('fontSizeSetting', 16)
181+
}
139182
try {
140183

141184
result.set('appid', this.app.bundleManager.getBundleInfo().appId)

harmony/dimina/src/main/ets/Container/DMPContainer.ets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { DMPBridges } from '../Bridges/DMPBridges';
22
import { DMPApp } from '../DApp/DMPApp';
33
import { DMPChannelProxyNext } from '../Service/DMPChannelProxyNext';
44
import { DMPMap } from '../Utils/DMPMap';
5+
import { DMPHostEnvBuilder } from '../Utils/DMPHostEnvBuilder';
56

67
export enum ResourceLoadType {
78
Init = 0 << 0,
@@ -43,6 +44,7 @@ export class DMPContainer {
4344
appId: this.app.appConfig.appId,
4445
pagePath: pagePath,
4546
root: root,
47+
hostEnv: DMPHostEnvBuilder.buildSnapshot(this.app),
4648
}
4749
})
4850

0 commit comments

Comments
 (0)