From a966fe0a929c0b642c3aafe9a5dba3e2c36a2cc1 Mon Sep 17 00:00:00 2001 From: wgqqqqq Date: Thu, 19 Nov 2026 15:26:34 +0800 Subject: [PATCH] feat(harmonyos): expand GenUI presentation and drag mini apps to the home screen --- .../main/ets/entryability/EntryAbility.ets | 7 + .../entry/src/main/ets/i18n/EnUsMessages.ets | 5 + .../entry/src/main/ets/i18n/ZhCnMessages.ets | 5 + .../pages/components/AppRootPresentation.ets | 10 +- .../pages/components/LocalGenUISurface.ets | 17 +- .../pages/components/LocalGenUIWebSurface.ets | 14 +- .../pages/components/MiniAppDragOverlay.ets | 106 + .../ets/pages/components/MiniAppGallery.ets | 179 +- .../ets/pages/components/MiniAppSurface.ets | 11 +- .../ets/pages/components/SettingsSheet.ets | 21 + .../main/ets/pages/runtime/AppRootRuntime.ets | 7 +- .../main/ets/pages/state/GenUIAppearance.ets | 20 + .../main/ets/pages/state/LocalGenUIState.ets | 35 - .../main/ets/pages/state/MiniAppDragState.ets | 45 + .../src/main/ets/pages/state/MiniAppState.ets | 2 + .../pages/viewmodel/LocalGenUIViewModel.ets | 32 +- .../ets/pages/viewmodel/MiniAppViewModel.ets | 6 + .../src/main/ets/services/MiniAppShortcut.ets | 54 + .../local-genui/LocalGenUIActionHost.ets | 12 + .../local-genui/LocalGenUIImageSearch.ets | 402 ++ .../local-genui/LocalGenUIRuntimeBridge.ets | 20 +- .../local-genui/LocalGenUIRuntimeProtocol.ets | 11 + .../LocalGenUISessionController.ets | 39 +- .../main/resources/base/element/string.json | 56 + .../main/resources/en_US/element/string.json | 56 + .../main/resources/rawfile/genui/catalog.json | 12 + .../rawfile/genui/harmony-prompt.txt | 69 +- .../rawfile/genui/runtime-manifest.json | 6 +- .../main/resources/zh_CN/element/string.json | 56 + .../genui-runtime/src/GenUIApplication.tsx | 16 +- .../genui-runtime/src/adapters/index.ts | 4 +- .../src/components/harmonyLooks.ts | 76 + .../src/components/harmonyPageKit.tsx | 88 +- .../src/components/harmonyScoreboard.tsx | 3 +- .../src/components/harmonyShowcase.tsx | 462 ++ .../src/components/harmonyShowcaseStyles.ts | 934 +++ .../genui-runtime/src/harmonyPresentation.ts | 6 +- .../src/local-runtime/LocalRuntimeApp.tsx | 34 +- .../src/local-runtime/en-US.json | 15 + .../src/local-runtime/localRuntimeProtocol.ts | 11 +- .../src/local-runtime/zh-CN.json | 15 + .../tests/local-genui-desktop-cards.test.cjs | 8 +- .../tests/local-genui-image-search.test.cjs | 74 + .../tools/tests/miniapp-gallery.test.cjs | 30 +- src/shared/generative-ui/catalog.json | 6266 ++++++++++------- src/shared/generative-ui/harmony-local.mjs | 2 +- src/shared/generative-ui/library.json | 768 +- .../harmony-local-genui-browser.test.mjs | 14 +- 48 files changed, 7513 insertions(+), 2628 deletions(-) create mode 100644 src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppDragOverlay.ets create mode 100644 src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/GenUIAppearance.ets create mode 100644 src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/MiniAppDragState.ets create mode 100644 src/apps/mobile/harmonyos/entry/src/main/ets/services/MiniAppShortcut.ets create mode 100644 src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIImageSearch.ets create mode 100644 src/apps/mobile/harmonyos/genui-runtime/src/components/harmonyLooks.ts create mode 100644 src/apps/mobile/harmonyos/genui-runtime/src/components/harmonyShowcase.tsx create mode 100644 src/apps/mobile/harmonyos/genui-runtime/src/components/harmonyShowcaseStyles.ts create mode 100644 src/apps/mobile/harmonyos/tools/tests/local-genui-image-search.test.cjs diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/entryability/EntryAbility.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/entryability/EntryAbility.ets index d120a85..d2027a2 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/entryability/EntryAbility.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,3 +1,5 @@ +import { BUILTIN_LAUNCH_PARAM } from '../services/MiniAppShortcut'; +import { BUILTIN_MINIAPP_IDS } from '../services/BuiltinMiniAppHost'; import { AbilityConstant, Configuration, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; import { display, window } from '@kit.ArkUI'; @@ -80,6 +82,11 @@ export default class EntryAbility extends UIAbility { /** A tap on a generated app's home-screen card opens that app. */ private deliverCardLaunch(want: Want): void { const appId = LocalGenUIDesktopCards.launchAppId(want.parameters as Record | undefined); + const builtin = want.parameters?.[BUILTIN_LAUNCH_PARAM]; + if (typeof builtin === 'string' && BUILTIN_MINIAPP_IDS.includes(builtin)) { + LocalGenUILaunchInbox.deliver(builtin); + return; + } if (appId.length > 0) { hilog.info(DOMAIN, TAG, '%{public}s', 'Opening a generated app from its desktop card'); LocalGenUILaunchInbox.deliver(appId); diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/EnUsMessages.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/EnUsMessages.ets index aa7baf9..156bb49 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/EnUsMessages.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/EnUsMessages.ets @@ -156,6 +156,11 @@ export const EN_US_MESSAGES: [string, string][] = [ ['generalChat.emptyResponse', 'The model returned no text.'], ['generalChat.requestFailed', 'Model request failed (HTTP {0}).'], + ['settings.genui.look', 'Mini app style'], + ['settings.genui.classic', 'Classic'], + ['settings.genui.aurora', 'Aurora'], + ['settings.genui.blueprint', 'Blueprint'], + ['settings.genui.celadon', 'Celadon'], ['settings.general.section', 'General'], ['settings.account.section', 'Account'], ['settings.account.currentIdentity', 'Current identity'], diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/ZhCnMessages.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/ZhCnMessages.ets index 3c92358..1e7747f 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/ZhCnMessages.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/i18n/ZhCnMessages.ets @@ -156,6 +156,11 @@ export const ZH_CN_MESSAGES: [string, string][] = [ ['generalChat.emptyResponse', '模型没有返回文字内容。'], ['generalChat.requestFailed', '模型请求失败(HTTP {0})。'], + ['settings.genui.look', '小应用风格'], + ['settings.genui.classic', '原生'], + ['settings.genui.aurora', '极光'], + ['settings.genui.blueprint', '蓝图'], + ['settings.genui.celadon', '青瓷'], ['settings.general.section', '通用'], ['settings.account.section', '账号'], ['settings.account.currentIdentity', '当前身份'], diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootPresentation.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootPresentation.ets index e83ace7..9049a4c 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootPresentation.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/AppRootPresentation.ets @@ -1,3 +1,4 @@ +import { MiniAppDragOverlay } from './MiniAppDragOverlay'; import { SessionDetailsOverlay } from './SessionDetailsOverlay'; import { AdaptiveSheetContent } from './AdaptiveSheetContent'; import { RemoteCompactHomePolicy } from '../policy/RemoteCompactHomePolicy'; @@ -164,6 +165,9 @@ export struct AppRootPresentation { connect: () => { this.ConnectContent(); }, onCloseSidebar: this.actions.onCloseSidebar }) + if (this.miniAppState.visible) { + MiniAppDragOverlay({ drag: this.miniAppState.drag }) + } SessionDetailsOverlay({ state: this.remoteSurfaceState.sessionDetails, placement: this.sessionDetailsPlacement }) if (this.filePreviewPlacement() === FilePreviewPlacement.CompactFullPage) { this.FilePreviewPane() @@ -218,11 +222,7 @@ export struct AppRootPresentation { actions: this.miniAppActions, generatedApps: this.localGenUIState.gallery, onOpenGenerated: (appId: string) => this.localGenUIActions.openGalleryApp(appId), - onRemoveGenerated: (appId: string) => this.localGenUIActions.removeFromGallery(appId), - generatedState: this.localGenUIState, - onPrepareDesktopCard: (appId: string) => this.localGenUIActions.prepareDesktopCard(appId), - onDesktopCardAdded: (appId: string, formId: string, error: string) => - this.localGenUIActions.desktopCardAdded(appId, formId, error) + onRemoveGenerated: (appId: string) => this.localGenUIActions.removeFromGallery(appId) }) } if (this.localGenUIState.visible) { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUISurface.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUISurface.ets index b9abeee..cdff352 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUISurface.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUISurface.ets @@ -1,5 +1,4 @@ -import { AddFormMenuItem, KeyboardAvoidMode } from '@kit.ArkUI'; -import { BusinessError } from '@kit.BasicServicesKit'; +import { KeyboardAvoidMode } from '@kit.ArkUI'; import { resourceManager } from '@kit.LocalizationKit'; import { MobileDesignTypography } from '../../generated/MobileDesignTokens'; import { RemoteI18n } from '../../i18n/RemoteI18n'; @@ -308,9 +307,7 @@ export struct LocalGenUISurface { .backgroundColor(FLOATING_PANEL_BG).backgroundBlurStyle(BlurStyle.Thin) .shadow({ radius: 12, color: SHADOW_SUBTLE, offsetY: 2 }) .accessibilityText(RemoteI18n.t('localGenui.appActions')) - .bindMenu(this.AppActionsMenu(), { - onAppear: () => this.actions.prepareDesktopCard(this.state.appId) - }) + .bindMenu(this.AppActionsMenu()) } else { Blank().width(LocalGenUISurface.CONTROL_SIZE) } @@ -323,7 +320,6 @@ export struct LocalGenUISurface { .hitTestBehavior(HitTestMode.Transparent) } - /** "Add to desktop" places a home-screen card that opens this app. */ @Builder AppActionsMenu() { Menu() { @@ -338,15 +334,6 @@ export struct LocalGenUISurface { MenuItem({ content: RemoteI18n.t('localGenui.addToGallery') }) .onClick(() => this.actions.addToGallery(this.state.appId)) } - if (this.state.canAddToDesktop(this.state.appId)) { - AddFormMenuItem(this.state.desktopCardWant(this.state.appId), APP_BODY_ID, { - formBindingData: this.state.desktopCardInitialData(this.state.appId, this.state.appTitle), - style: { options: { content: RemoteI18n.t('localGenui.addToDesktop') } }, - callback: (error: BusinessError, formId: string) => { - this.actions.desktopCardAdded(this.state.appId, formId ?? '', error && error.code ? `${error.code}` : ''); - } - }) - } } } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIWebSurface.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIWebSurface.ets index 6387ffd..6b11f33 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIWebSurface.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/LocalGenUIWebSurface.ets @@ -1,8 +1,10 @@ import { webview } from '@kit.ArkWeb'; import { image } from '@kit.ImageKit'; +import { GenUIAppearance } from '../state/GenUIAppearance'; import BuildProfile from 'BuildProfile'; import { LocalGenUIRuntimeBridge } from '../../services/local-genui/LocalGenUIRuntimeBridge'; import { LOCAL_GENUI_ICON3D_ROOT } from '../../services/local-genui/LocalGenUIIcon3DStore'; +import { LOCAL_GENUI_PHOTO_ROOT } from '../../services/local-genui/LocalGenUIImageSearch'; import { LOCAL_GENUI_COLLABORATION_ROOT } from '../../services/local-genui/LocalGenUICollaborationAssets'; import { RemoteLogger } from '../../services/RemoteLogger'; @@ -22,6 +24,7 @@ class LocalGenUINativeChannel { @ComponentV2 export struct LocalGenUIWebSurface { @Param @Require bridge: LocalGenUIRuntimeBridge; + @Local appearance: GenUIAppearance = GenUIAppearance.connect(); @Param scheme: string = 'light'; @Param locale: string = 'zh-CN'; private controller: webview.WebviewController = new webview.WebviewController(); @@ -37,7 +40,7 @@ export struct LocalGenUIWebSurface { // Debug builds only: lets native acceptance evidence inspect the real DOM. webview.WebviewController.setWebDebuggingAccess(true); } - this.bridge.setAppearance(this.scheme, this.locale); + this.bridge.setAppearance(this.scheme, this.locale, this.appearance.current()); } aboutToDisappear(): void { @@ -45,9 +48,9 @@ export struct LocalGenUIWebSurface { this.bridge.detach(); } - @Monitor('scheme', 'locale') + @Monitor('scheme', 'locale', 'appearance.look') onAppearanceChange(): void { - this.bridge.setAppearance(this.scheme, this.locale); + this.bridge.setAppearance(this.scheme, this.locale, this.appearance.current()); } private send(json: string): void { @@ -107,7 +110,8 @@ export struct LocalGenUIWebSurface { // asynchronous: the picture may need one download before the cache has it. const url = event.request.getRequestUrl(); const collaborationImage = url.startsWith(LOCAL_GENUI_COLLABORATION_ROOT); - if (!url.startsWith(LOCAL_GENUI_ICON3D_ROOT) && !collaborationImage) { + const photo = url.startsWith(LOCAL_GENUI_PHOTO_ROOT); + if (!url.startsWith(LOCAL_GENUI_ICON3D_ROOT) && !collaborationImage && !photo) { return null; } RemoteLogger.info('local genui host image request'); @@ -121,7 +125,7 @@ export struct LocalGenUIWebSurface { RemoteLogger.info(`local genui host image ${bytes ? `served ${bytes.byteLength} bytes` : 'not found'}`); if (bytes) { response.setResponseData(bytes); - response.setResponseMimeType(collaborationImage ? 'image/jpeg' : 'image/png'); + response.setResponseMimeType(collaborationImage || photo ? 'image/jpeg' : 'image/png'); response.setResponseCode(200); response.setReasonMessage('OK'); } else { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppDragOverlay.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppDragOverlay.ets new file mode 100644 index 0000000..a23ec62 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppDragOverlay.ets @@ -0,0 +1,106 @@ +import { MiniAppDragState } from '../state/MiniAppDragState'; +import { RemoteI18n } from '../../i18n/RemoteI18n'; +import { MobileDesignGeometry, MobileDesignTypography } from '../../generated/MobileDesignTokens'; +import { CARD, INK, MUTED, MEDIA_BACKGROUND, CONTENT_ON_ACTION, SHADOW_STRONG, + MEDIA_SCRIM, TRANSPARENT, CONNECT_HERO_ACCENT, CONNECT_HERO_SECONDARY } from './Theme'; + +@ComponentV2 +export struct MiniAppDragOverlay { + @Require @Param drag: MiniAppDragState; + + @Builder + private GridTile() { + Row().width(8).height(8).borderRadius(2.5).backgroundColor(CONTENT_ON_ACTION) + .opacity(this.drag.overEdge ? 0.85 : 0.55) + } + + @Builder + private DesktopGlyph() { + Column({ space: 2 }) { + Row({ space: 2 }) { + this.GridTile() + Image(this.drag.image).width(8).height(8).objectFit(ImageFit.Cover).borderRadius(2.5) + .border({ width: 0.5, color: CONTENT_ON_ACTION, radius: 2.5 }).clip(true) + .rotate({ angle: this.drag.overEdge ? 0 : 12 }) + .translate({ x: this.drag.overEdge ? 0 : 3, y: this.drag.overEdge ? 0 : -5 }) + .animation({ duration: this.drag.reduceMotion ? 0 : 220, curve: Curve.EaseOut }) + } + Row({ space: 2 }) { + this.GridTile() + this.GridTile() + } + } + } + + @Builder + private DropTarget() { + Stack({ alignContent: Alignment.Bottom }) { + Column().width('100%').height('100%') + .linearGradient({ angle: 180, colors: [[TRANSPARENT, 0], [MEDIA_SCRIM, 0.76], [MEDIA_BACKGROUND, 1]] }) + Column().width('100%').height(MiniAppDragState.GLOW_HEIGHT + this.drag.bottomInset) + .linearGradient({ angle: 180, colors: [[TRANSPARENT, 0], [CONNECT_HERO_SECONDARY, 0.72], [CONNECT_HERO_ACCENT, 1]] }) + .opacity(this.drag.overEdge ? 0.23 : 0.10) + .animation({ duration: this.drag.reduceMotion ? 0 : 200, curve: Curve.EaseOut }) + Column().width(236).height(236) + .radialGradient({ center: ['50%', '50%'], radius: 118, + colors: [[CONNECT_HERO_ACCENT, 0], [CONNECT_HERO_SECONDARY, 0.22], [TRANSPARENT, 1]] }) + .scale({ x: 1.35, y: 0.32, centerY: '100%' }) + .opacity(this.drag.overEdge ? 0.68 : 0.3) + .animation({ duration: this.drag.reduceMotion ? 0 : 200, curve: Curve.EaseOut }) + .translate({ x: this.drag.reduceMotion ? 0 : + (this.drag.fingerX - this.drag.windowX - this.drag.windowWidth / 2) * 0.34, y: 39 }) + Column() { + Column({ space: 13 }) { + Row({ space: 12 }) { + this.DesktopGlyph() + Text(RemoteI18n.t(this.drag.overEdge ? 'miniapp.releaseShortcut' : 'miniapp.dropShortcut')) + .fontSize(MobileDesignTypography.bodyMedium.size).fontWeight(FontWeight.Medium) + .fontColor(CONTENT_ON_ACTION).maxLines(2).textAlign(TextAlign.Center) + }.padding({ left: 12, right: 12 }) + Row().width(this.drag.overEdge ? '84%' : '56%').height(1) + .linearGradient({ angle: 90, colors: [[TRANSPARENT, 0], [CONNECT_HERO_SECONDARY, 0.36], + [CONTENT_ON_ACTION, 0.5], [CONNECT_HERO_ACCENT, 0.64], [TRANSPARENT, 1]] }) + .animation({ duration: this.drag.reduceMotion ? 0 : 240, curve: Curve.EaseOut }) + }.width('100%').constraintSize({ maxWidth: 420 }) + }.width('100%') + .padding({ top: 10, bottom: MiniAppDragState.GLOW_HEIGHT + this.drag.bottomInset }) + .onAreaChange((_old: Area, area: Area) => { + this.drag.setTargetTop(Number(area.globalPosition.y)); + }) + }.width('100%').height(MiniAppDragState.GLOW_HEIGHT + this.drag.bottomInset + 86) + .opacity(this.drag.hintVisible ? 1 : 0) + } + + build() { + Stack({ alignContent: Alignment.Bottom }) { + if (this.drag.active) { + Column().width('100%').height('100%').backgroundColor(MEDIA_BACKGROUND) + .opacity(this.drag.contracted ? 0.64 : 0) + this.DropTarget() + + Column() { + Image(this.drag.image).width('100%').height(this.drag.coverHeight) + .objectFit(ImageFit.Cover).draggable(false).flexShrink(0) + Column({ space: 8 }) { + Text(this.drag.name).width('100%').fontSize(MobileDesignTypography.titleSmall.size) + .fontWeight(FontWeight.Bold).fontColor(INK).maxLines(1) + Text(this.drag.description).width('100%').fontSize(MobileDesignTypography.bodyMedium.size) + .fontColor(MUTED).maxLines(3) + }.width(this.drag.initialWidth).padding(20).layoutWeight(1) + .justifyContent(FlexAlign.Center).opacity(this.drag.contracted ? 0 : 1) + }.width(this.drag.width).height(this.drag.height).backgroundColor(CARD) + .borderRadius(this.drag.contracted ? 14 : MobileDesignGeometry.miniappCardRadius).clip(true) + .shadow({ radius: this.drag.contracted ? 6 : 16, color: SHADOW_STRONG, offsetY: 4 }) + .position({ x: this.drag.fingerX + this.drag.offsetX - this.drag.windowX, + y: this.drag.fingerY + this.drag.offsetY - this.drag.windowY }) + } + }.width('100%').height('100%').clip(true).hitTestBehavior(HitTestMode.None) + .accessibilityLevel('no-hide-descendants') + .onAreaChange((_old: Area, area: Area) => { + this.drag.windowX = Number(area.globalPosition.x); + this.drag.windowY = Number(area.globalPosition.y); + this.drag.windowWidth = Number(area.width); + this.drag.windowHeight = Number(area.height); + }) + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppGallery.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppGallery.ets index 4fa9474..9013655 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppGallery.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppGallery.ets @@ -1,6 +1,7 @@ -import { AddFormMenuItem } from '@kit.ArkUI'; +import { MotionPreference } from '../../services/MotionPreference'; +import { MiniAppShortcut } from '../../services/MiniAppShortcut'; +import { RemoteLogger } from '../../services/RemoteLogger'; import { BusinessError } from '@kit.BasicServicesKit'; -import { LocalGenUIState } from '../state/LocalGenUIState'; import { LocalGenUIGalleryEntry } from '../../services/local-genui/LocalGenUIModels'; import { MobileDesignGeometry, MobileDesignTypography } from '../../generated/MobileDesignTokens'; import { MiniAppSummary } from '../../model/MiniAppModels'; @@ -20,17 +21,34 @@ export struct MiniAppGallery { @Param bottomInset: number = 0; @Event onSelect: (id: string) => void = (_id: string) => {}; @Param generatedApps: LocalGenUIGalleryEntry[] = []; - @Param generatedState: LocalGenUIState = new LocalGenUIState(); @Event onOpenGenerated: (id: string) => void = (_id: string) => {}; @Event onRemoveGenerated: (id: string) => void = (_id: string) => {}; - @Event onPrepareDesktopCard: (id: string) => void = (_id: string) => {}; - @Event onDesktopCardAdded: (id: string, formId: string, error: string) => void = - (_id: string, _formId: string, _error: string) => {}; @Local failedThumbnails: string[] = []; @Local viewportWidth: number = 360; @Local stackHeight: number = 480; + @Local lifted: MiniAppGalleryItem | null = null; + private hintTimer: number = -1; + private originX: number = 0; + private originY: number = 0; + + private pinning: boolean = false; + build() { + Stack({ alignContent: Alignment.TopStart }) { + this.GalleryContent() + + }.width('100%').height('100%').clip(true) + .onAreaChange((_old: Area, area: Area) => { + this.originX = Number(area.globalPosition.x); + this.originY = Number(area.globalPosition.y); + + this.viewportWidth = Number(area.width); + }) + } + + @Builder + private GalleryContent() { Column() { if (this.state.galleryMode === 'list') { this.ListView() @@ -45,7 +63,7 @@ export struct MiniAppGallery { .gesture(PanGesture({ direction: PanDirection.Horizontal, distance: 12 }) .onActionEnd((event: GestureEvent) => { const index = MiniAppGalleryPolicy.nextIndex(this.currentIndex(), event.offsetX, this.items().length); - this.focus(index); + if (!this.lifted) this.focus(index); })) Row({ space: 8 }) { ForEach(this.items(), (app: MiniAppGalleryItem, index: number) => { @@ -54,12 +72,12 @@ export struct MiniAppGallery { .opacity(index === this.currentIndex() ? 1 : 0.4) }, (app: MiniAppGalleryItem): string => app.id) }.justifyContent(FlexAlign.Center).padding({ top: 20, bottom: 12 }) - .accessibilityLevel('no') - Text(RemoteI18n.t('miniapp.swipeHint')).fontSize(MobileDesignTypography.labelSmall.size) - .fontColor(SUBTLE).margin({ bottom: this.bottomInset + 16 }) + .opacity(this.state.drag.active ? 0 : 1).accessibilityLevel('no') + Text(RemoteI18n.t('miniapp.shortcutHint')).fontSize(MobileDesignTypography.labelSmall.size) + .fontColor(SUBTLE).margin({ bottom: this.bottomInset + 16 }).opacity(this.state.drag.active ? 0 : 1) } }.width('100%').height('100%') - .onAreaChange((_old: Area, area: Area) => { this.viewportWidth = Number(area.width); }) + } @Builder @@ -81,20 +99,117 @@ export struct MiniAppGallery { .height(MiniAppGalleryPolicy.cardHeight(this.viewportWidth, this.stackHeight)) .padding(0).backgroundColor(CARD).borderRadius(MobileDesignGeometry.miniappCardRadius).clip(true) .shadow({ radius: 16, color: SHADOW_SUBTLE, offsetY: 6 }) - .scale({ x: index === this.currentIndex() ? 1 : 0.85, y: index === this.currentIndex() ? 1 : 0.85 }) - .rotate({ angle: index === this.currentIndex() ? 0 : index < this.currentIndex() ? -5 : 5 }) - .translate({ x: (index - this.currentIndex()) * (this.viewportWidth >= 600 ? 60 : 70) }) - .opacity(index === this.currentIndex() ? 1 : Math.abs(index - this.currentIndex()) === 1 ? 0.6 : 0) - .zIndex(index === this.currentIndex() ? 3 : 1) + .scale({ x: index === this.deckIndex() ? 1 : 0.85, y: index === this.deckIndex() ? 1 : 0.85 }) + .rotate({ angle: index === this.deckIndex() ? 0 : index < this.deckIndex() ? -5 : 5 }) + .translate({ x: (index - this.deckIndex()) * (this.viewportWidth >= 600 ? 60 : 70) }) + .opacity(this.lifted?.id === app.id ? 0 : index === this.deckIndex() ? 1 : Math.abs(index - this.deckIndex()) === 1 ? 0.6 : 0) + .zIndex(index === this.deckIndex() ? 3 : 1) .hitTestBehavior(index === this.currentIndex() ? HitTestMode.Default : HitTestMode.None) .accessibilityLevel(index === this.currentIndex() ? 'yes' : 'no-hide-descendants') .accessibilityText(`${app.name}, ${app.description}`) .onClick(() => { if (index === this.currentIndex()) this.select(app); }) - .bindContextMenu(this.GeneratedActions(app, true), ResponseType.LongPress, { - onAppear: () => { - if (app.generatedId.length > 0) this.onPrepareDesktopCard(app.generatedId); - } - }) + .gesture(GestureGroup(GestureMode.Sequence, + LongPressGesture({ duration: 380, repeat: false }) + .onAction((event: GestureEvent) => { + if (this.pinning || index !== this.currentIndex()) return; + this.beginLift(app, event); + }), + PanGesture({ direction: PanDirection.All, distance: 2 }) + .onActionUpdate((event: GestureEvent) => this.track(event)) + .onActionEnd((event: GestureEvent) => { + this.track(event); + this.drop(); + }) + ).onCancel(() => this.endLift())) + } + + private track(event: GestureEvent): void { + const finger = event.fingerList[0]; + if (finger) { + this.state.drag.move(finger.globalX, finger.globalY); + } + } + + private beginLift(app: MiniAppGalleryItem, event: GestureEvent): void { + const drag = this.state.drag; + drag.setTargetTop(undefined); + drag.bottomInset = this.bottomInset; + drag.reduceMotion = MotionPreference.reduceMotion(); + this.track(event); + drag.name = app.name; + drag.description = app.description; + drag.image = app.thumbnailPath && !this.failedThumbnails.includes(app.thumbnailPath) ? + 'file://' + app.thumbnailPath : this.iconResource(app); + drag.width = MiniAppGalleryPolicy.cardWidth(this.viewportWidth); + drag.initialWidth = drag.width; + drag.height = MiniAppGalleryPolicy.cardHeight(this.viewportWidth, this.stackHeight); + drag.coverHeight = drag.height * 0.65; + drag.offsetX = this.originX + (this.viewportWidth - drag.width) / 2 - drag.fingerX; + drag.offsetY = this.originY + (this.stackHeight - drag.height) / 2 - drag.fingerY; + drag.contracted = false; + drag.hintVisible = drag.reduceMotion; + drag.active = true; + this.lifted = app; + this.getUIContext().animateToImmediately({ duration: drag.reduceMotion ? 0 : 300, curve: Curve.EaseOut }, () => { + drag.width = 56; + drag.height = 56; + drag.coverHeight = 56; + drag.offsetX = -28; + drag.offsetY = -28; + drag.contracted = true; + }); + if (drag.reduceMotion) return; + this.hintTimer = setTimeout(() => { + this.getUIContext().animateTo({ duration: 150, curve: Curve.EaseOut }, () => { drag.hintVisible = true; }); + }, 200); + } + + private endLift(): void { + clearTimeout(this.hintTimer); + this.lifted = null; + this.state.drag.active = false; + } + + aboutToDisappear(): void { + this.endLift(); + } + + private drop(): void { + const app = this.lifted; + const accepted = this.state.drag.overEdge; + this.endLift(); + if (app && accepted) void this.pin(app, true); + } + + private deckIndex(): number { + const current = this.currentIndex(); + if (!this.state.drag.contracted || !this.state.drag.active || this.items().length < 2) return current; + return current + 1 < this.items().length ? current + 1 : current - 1; + } + + private iconResource(app: MiniAppGalleryItem): Resource { + return app.generatedId ? $r('app.media.openbitfun_app_icon') : this.preview(app.id); + } + + private async pin(app: MiniAppGalleryItem, revealDesktop: boolean = false): Promise { + if (this.pinning) return; + this.pinning = true; + let code: number = -1; + try { + code = await MiniAppShortcut.pin(this.getUIContext().getHostContext()!, + app.generatedId || app.id, app.name, !!app.generatedId, + this.failedThumbnails.includes(app.thumbnailPath) ? '' : app.thumbnailPath, this.iconResource(app), revealDesktop); + } catch (error) { + code = (error as BusinessError).code || -1; + RemoteLogger.warn('Mini app shortcut request failed: ' + code); + } finally { + this.pinning = false; + } + if (code === 1006620007 || (code === 0 && revealDesktop)) return; + const key = code === 0 ? 'miniapp.pinned' : code === 1006620003 ? 'miniapp.alreadyPinned' : + code === 1006620004 ? 'miniapp.pinLimit' : 'miniapp.pinFailed'; + this.getUIContext().getPromptAction().showToast({ message: code !== 0 && key === 'miniapp.pinFailed' ? + RemoteI18n.f(key, String(code)) : RemoteI18n.t(key) }); } @Builder @@ -117,11 +232,7 @@ export struct MiniAppGallery { .border({ width: 1, color: LINE, radius: MobileDesignGeometry.miniappListRadius }).clip(true) .accessibilityText(`${app.name}, ${app.description}`) .onClick(() => this.select(app)) - .bindContextMenu(this.GeneratedActions(app, false), ResponseType.LongPress, { - onAppear: () => { - if (app.generatedId.length > 0) this.onPrepareDesktopCard(app.generatedId); - } - }) + .bindContextMenu(this.GeneratedActions(app), ResponseType.LongPress) } }, (app: MiniAppGalleryItem): string => app.id) GridItem() { Row().height(this.bottomInset + 24).hitTestBehavior(HitTestMode.None) } @@ -152,18 +263,10 @@ export struct MiniAppGallery { } @Builder - private GeneratedActions(app: MiniAppGalleryItem, card: boolean) { - if (app.generatedId.length > 0) { - Menu() { - if (this.generatedState.canAddToDesktop(app.generatedId)) { - AddFormMenuItem(this.generatedState.desktopCardWant(app.generatedId), this.elementId(app, card), { - formBindingData: this.generatedState.desktopCardInitialData(app.generatedId, app.name), - style: { options: { content: RemoteI18n.t('localGenui.addToDesktop') } }, - callback: (error: BusinessError, formId: string) => { - this.onDesktopCardAdded(app.generatedId, formId ?? '', error && error.code ? `${error.code}` : ''); - } - }) - } + private GeneratedActions(app: MiniAppGalleryItem) { + Menu() { + MenuItem({ content: RemoteI18n.t('miniapp.pinIcon') }).onClick(() => { void this.pin(app); }) + if (app.generatedId.length > 0) { MenuItem({ content: RemoteI18n.t('localGenui.removeFromGallery') }) .onClick(() => this.onRemoveGenerated(app.generatedId)) } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppSurface.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppSurface.ets index 44d2ee0..1ae826d 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppSurface.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/MiniAppSurface.ets @@ -2,7 +2,6 @@ import { MobileDesignGeometry, MobileDesignTypography } from '../../generated/Mo import { MiniAppActions, emptyMiniAppActions } from '../../model/MiniAppModels'; import { RemoteI18n } from '../../i18n/RemoteI18n'; import { MiniAppState } from '../state/MiniAppState'; -import { LocalGenUIState } from '../state/LocalGenUIState'; import { LocalGenUIGalleryEntry } from '../../services/local-genui/LocalGenUIModels'; import { MiniAppGallery } from './MiniAppGallery'; import { TemplateIcon } from './TemplateIcon'; @@ -19,11 +18,6 @@ export struct MiniAppSurface { @Param generatedApps: LocalGenUIGalleryEntry[] = []; @Event onOpenGenerated: (appId: string) => void = (_appId: string) => {}; @Event onRemoveGenerated: (appId: string) => void = (_appId: string) => {}; - /** Local GenUI projection; supplies the add-to-desktop want. */ - @Param generatedState: LocalGenUIState = new LocalGenUIState(); - @Event onPrepareDesktopCard: (appId: string) => void = (_appId: string) => {}; - @Event onDesktopCardAdded: (appId: string, formId: string, error: string) => void = - (_appId: string, _formId: string, _error: string) => {}; @Local insets: WindowInsetsBinding = new WindowInsetsBinding(); aboutToAppear(): void { @@ -67,11 +61,8 @@ export struct MiniAppSurface { bottomInset: this.insets.bottom, onSelect: this.actions.select, generatedApps: this.generatedApps, - generatedState: this.generatedState, onOpenGenerated: this.onOpenGenerated, - onRemoveGenerated: this.onRemoveGenerated, - onPrepareDesktopCard: this.onPrepareDesktopCard, - onDesktopCardAdded: this.onDesktopCardAdded + onRemoveGenerated: this.onRemoveGenerated }) .layoutWeight(1) } diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/SettingsSheet.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/SettingsSheet.ets index 79da9e1..ff9ccff 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/SettingsSheet.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/components/SettingsSheet.ets @@ -17,8 +17,11 @@ import { WindowInsetsBinding } from '../../services/WindowSystemBarService'; import { RemoteDefaultModels, RemoteModelCatalog, RemotePermissionMode } from '../../model/RemoteModels'; import { RemotePermissionSection } from './RemotePermissionSection'; +import { GenUIAppearance, GENUI_LOOKS } from '../state/GenUIAppearance'; + @ComponentV2 export struct SettingsSheet { + @Local appearance: GenUIAppearance = GenUIAppearance.connect(); @Param directoryState: DeviceDirectoryState = new DeviceDirectoryState(); @Param sheetState: SettingsSheetState = new SettingsSheetState(); @Param accountUsername: string = ''; @@ -269,6 +272,24 @@ export struct SettingsSheet { }, $r('sys.symbol.textformat') ) + Divider().strokeWidth(0.5).color(LINE).margin({ left: 16, right: 16 }) + Row({ space: 12 }) { + Text(RemoteI18n.t('settings.genui.look')) + .fontSize(MobileDesignTypography.bodyMedium.size).fontColor(INK).layoutWeight(1) + Select(GENUI_LOOKS.map((look: string): SelectOption => { + return { value: RemoteI18n.t('settings.genui.' + look) }; + })) + .selected(GENUI_LOOKS.indexOf(this.appearance.current())) + .value(RemoteI18n.t('settings.genui.' + this.appearance.current())) + .accessibilityText(RemoteI18n.t('settings.genui.look') + ' ' + + RemoteI18n.t('settings.genui.' + this.appearance.current())) + .onSelect((index: number) => { + if (index >= 0 && index < GENUI_LOOKS.length) this.appearance.look = GENUI_LOOKS[index]; + }) + } + .width('100%') + .constraintSize({ minHeight: MobileDesignGeometry.settingsRowHeight }) + .padding({ left: MobileDesignGeometry.settingsRowPadding, right: MobileDesignGeometry.settingsRowPadding }) } .width('100%') .backgroundColor(CARD) diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets index ff54033..edd1567 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/runtime/AppRootRuntime.ets @@ -1,3 +1,4 @@ +import { BUILTIN_MINIAPP_IDS } from '../../services/BuiltinMiniAppHost'; import { RecentWorkspaceEntry, RemoteSession, @@ -45,7 +46,11 @@ export class AppRootRuntime extends AppRootRuntimeComposition { // A generated app opened from its home-screen card is local: it does not // wait for account, device, or remote restoration below. LocalGenUILaunchInbox.subscribe((appId: string): void => { - void this.localGenUIViewModel.openGalleryApp(appId); + if (BUILTIN_MINIAPP_IDS.includes(appId)) { + void this.miniAppViewModel.openShortcut(appId); + } else { + void this.localGenUIViewModel.openGalleryApp(appId); + } }); // Account login can be tapped while the rest of the cold-start work is // still running. Initialize its secure store first so the login path never diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/GenUIAppearance.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/GenUIAppearance.ets new file mode 100644 index 0000000..6da93ce --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/GenUIAppearance.ets @@ -0,0 +1,20 @@ +import { PersistenceV2 } from '@kit.ArkUI'; + +export const GENUI_LOOKS: string[] = ['classic', 'aurora', 'blueprint', 'celadon']; + +@ObservedV2 +export class GenUIAppearance { + @Trace look: string = 'aurora'; + + static connect(): GenUIAppearance { + return PersistenceV2.globalConnect({ + type: GenUIAppearance, + key: 'localGenUIAppearance', + defaultCreator: (): GenUIAppearance => new GenUIAppearance() + })!; + } + + current(): string { + return GENUI_LOOKS.includes(this.look) ? this.look : 'aurora'; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/LocalGenUIState.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/LocalGenUIState.ets index aa6feae..75dd082 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/LocalGenUIState.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/LocalGenUIState.ets @@ -1,9 +1,6 @@ import { LocalCollaborationRequest } from '../../services/local-genui/LocalGenUICollaborationHost'; import { LocalCollaborationSnapshot } from '../../services/local-genui/LocalCollaborationSession'; import { LocalGenUIGalleryEntry, LocalGenUISession } from '../../services/local-genui/LocalGenUIModels'; -import { Want } from '@kit.AbilityKit'; -import { formBindingData } from '@kit.FormKit'; -import { LocalGenUIDesktopCards } from '../../services/local-genui/LocalGenUIDesktopCards'; import { LocalGenUIModelProfile } from '../../services/local-genui/LocalGenUIModelCatalog'; import { ConversationCoreState } from './ConversationCoreState'; import { ConversationIntent } from '../actions/ConversationIntent'; @@ -47,8 +44,6 @@ export class LocalGenUIState { @Trace cameraWanted: boolean = false; // Gallery @Trace gallery: LocalGenUIGalleryEntry[] = []; - /** Bundle of this app; empty until the context is known, which hides "Add to desktop". */ - @Trace bundleName: string = ''; currentModelName(): string { const model = this.models.find((item: LocalGenUIModelProfile) => item.id === this.currentModelId); @@ -56,29 +51,6 @@ export class LocalGenUIState { return model.name.trim().length > 0 ? model.name.trim() : model.modelName; } - canAddToDesktop(appId: string): boolean { - return this.bundleName.length > 0 && LocalGenUIDesktopCards.isAppId(appId); - } - - /** Want of `AddFormMenuItem` for the app's home-screen card. */ - desktopCardWant(appId: string): Want { - return LocalGenUIDesktopCards.addWant(this.bundleName, appId); - } - - /** - * First content of the new card. It carries the app id itself, so the card - * opens its app even before the card host or the add callback binds it. - */ - desktopCardInitialData(appId: string, title: string): formBindingData.FormBindingData { - const data: Record = {}; - data['appId'] = appId; - data['state'] = title.length > 0 ? 'ready' : 'pending'; - data['title'] = title; - data['initial'] = LocalGenUIDesktopCards.initial(title); - data['imageName'] = ''; - return formBindingData.createFormBindingData(data); - } - inGallery(appId: string): boolean { return this.gallery.some((entry: LocalGenUIGalleryEntry) => entry.appId === appId); } @@ -115,11 +87,6 @@ export interface LocalGenUIActions { addToGallery: (appId: string) => void; removeFromGallery: (appId: string) => void; openGalleryApp: (appId: string) => void; - // Desktop cards - /** The add menu is about to show: make sure the card has content to show. */ - prepareDesktopCard: (appId: string) => void; - /** Result of `AddFormMenuItem`; `error` is empty on success. */ - desktopCardAdded: (appId: string, formId: string, error: string) => void; // Device capabilities (presentation facts from the surface) appOnScreen: (onScreen: boolean) => void; cameraSurface: (surfaceId: string) => void; @@ -151,8 +118,6 @@ export function emptyLocalGenUIActions(): LocalGenUIActions { addToGallery: (_appId: string) => {}, removeFromGallery: (_appId: string) => {}, openGalleryApp: (_appId: string) => {}, - prepareDesktopCard: (_appId: string) => {}, - desktopCardAdded: (_appId: string, _formId: string, _error: string) => {}, appOnScreen: (_onScreen: boolean) => {}, cameraSurface: (_surfaceId: string) => {}, collaborationClose: (_token: number) => {}, diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/MiniAppDragState.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/MiniAppDragState.ets new file mode 100644 index 0000000..4ed5f0b --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/MiniAppDragState.ets @@ -0,0 +1,45 @@ +/** Geometry is in window vp, so a drag can leave the gallery pane on a foldable. */ +@ObservedV2 +export class MiniAppDragState { + static readonly GLOW_HEIGHT: number = 72; + reduceMotion: boolean = false; + @Trace active: boolean = false; + @Trace contracted: boolean = false; + @Trace hintVisible: boolean = false; + @Trace overEdge: boolean = false; + @Trace image: ResourceStr = ''; + @Trace name: string = ''; + @Trace description: string = ''; + @Trace fingerX: number = 0; + @Trace fingerY: number = 0; + @Trace offsetX: number = 0; + @Trace offsetY: number = 0; + @Trace width: number = 0; + @Trace height: number = 0; + @Trace coverHeight: number = 0; + initialWidth: number = 0; + bottomInset: number = 0; + windowX: number = 0; + windowY: number = 0; + windowWidth: number = 0; + windowHeight: number = 0; + + private targetTop: number | undefined = undefined; + + setTargetTop(top: number | undefined): void { + this.targetTop = top; + this.updateOverEdge(); + } + + move(x: number, y: number): void { + this.fingerX = x; + this.fingerY = y; + this.updateOverEdge(); + } + + private updateOverEdge(): void { + this.overEdge = this.targetTop !== undefined && + this.fingerX >= this.windowX && this.fingerX <= this.windowX + this.windowWidth && + this.fingerY >= this.targetTop && this.fingerY <= this.windowY + this.windowHeight; + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/MiniAppState.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/MiniAppState.ets index 9b6f356..2457259 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/MiniAppState.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/state/MiniAppState.ets @@ -1,7 +1,9 @@ +import { MiniAppDragState } from './MiniAppDragState'; import { MiniAppSummary } from '../../model/MiniAppModels'; @ObservedV2 export class MiniAppState { + readonly drag: MiniAppDragState = new MiniAppDragState(); @Trace galleryMode: string = 'cards'; @Trace galleryAppId: string = ''; @Trace visible: boolean = false; diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets index f4e4d10..830b6f2 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/LocalGenUIViewModel.ets @@ -24,6 +24,7 @@ import { LocalGenUIThumbnailStore } from '../../services/local-genui/LocalGenUIT import { LocalGenUIDesktopCardStore } from '../../services/local-genui/LocalGenUIDesktopCardStore'; import { LocalGenUIOrientation } from '../../services/local-genui/LocalGenUIOrientation'; import { LocalGenUIIcon3DStore } from '../../services/local-genui/LocalGenUIIcon3DStore'; +import { LOCAL_GENUI_PHOTO_ROOT, LocalGenUIImageSearch } from '../../services/local-genui/LocalGenUIImageSearch'; import { LocalGenUIDeviceCapabilityHost } from '../../services/local-genui/LocalGenUIDeviceCapabilityHost'; import { LocalGenUIRuntimeBridge } from '../../services/local-genui/LocalGenUIRuntimeBridge'; import { HarmonyCalendarService } from '../../services/local-genui/HarmonyCalendarService'; @@ -112,21 +113,6 @@ export class LocalGenUIViewModel implements LocalGenUIControllerListener, LocalG }, removeFromGallery: (appId: string): void => { void this.withController((c) => c.removeFromGallery(appId)); }, openGalleryApp: (appId: string): void => { void this.openGalleryApp(appId); }, - prepareDesktopCard: (appId: string): void => { - void this.withController((c) => c.prepareDesktopCard(appId)); - }, - desktopCardAdded: (appId: string, formId: string, error: string): void => { - if (error.length > 0 || formId.length === 0) { - RemoteLogger.warn(`local genui desktop card not added: ${error}`); - this.notice(RemoteI18n.t('localGenui.addToDesktopFailed')); - return; - } - RemoteLogger.info('local genui desktop card add callback received'); - void this.withController(async (c) => { - await c.desktopCardAdded(appId, formId); - this.notice(RemoteI18n.t('localGenui.addedToDesktop')); - }); - }, appOnScreen: (onScreen: boolean): void => this.setAppOnScreen(onScreen), cameraSurface: (surfaceId: string): void => this.attachCameraSurface(surfaceId), cameraSurfaceGone: (): void => this.detachCameraSurface(), @@ -149,19 +135,8 @@ export class LocalGenUIViewModel implements LocalGenUIControllerListener, LocalG this.orientation = new LocalGenUIOrientation(context); } - /** The add-to-desktop want names this app's card host. */ - private syncBundleName(): void { - if (this.state.bundleName.length > 0) return; - try { - this.state.bundleName = this.context().applicationInfo.name; - } catch (err) { - RemoteLogger.warn(`local genui bundle name unavailable: ${err instanceof Error ? err.message : String(err)}`); - } - } - /** Read-only local data for the sidebar section and the gallery. */ async load(): Promise { - this.syncBundleName(); await this.withController(async (c) => { await c.refreshSessions(); await c.refreshGallery(); @@ -169,7 +144,6 @@ export class LocalGenUIViewModel implements LocalGenUIControllerListener, LocalG } async open(): Promise { - this.syncBundleName(); this.state.visible = true; this.state.standalone = false; this.state.error = ''; @@ -530,8 +504,10 @@ export class LocalGenUIViewModel implements LocalGenUIControllerListener, LocalG const thumbnails = new LocalGenUIThumbnailStore(context.filesDir); const desktopCards = new LocalGenUIDesktopCardStore(context.filesDir); const icons = new LocalGenUIIcon3DStore(context.filesDir); + const photos = new LocalGenUIImageSearch(context.filesDir); const assets = new LocalGenUICollaborationAssets(context.filesDir); this.bridge.setPictureSource(async (url: string): Promise => { + if (url.startsWith(LOCAL_GENUI_PHOTO_ROOT)) return photos.picture(url); if (!url.startsWith(LOCAL_GENUI_COLLABORATION_ROOT)) return icons.picture(url); const mount = this.bridge.currentMount(); if (!mount) return undefined; @@ -562,7 +538,7 @@ export class LocalGenUIViewModel implements LocalGenUIControllerListener, LocalG const calendar = new HarmonyCalendarService((): Context => context); this.devices = devices; this.syncDeviceVisibility(); - this.controller = new LocalGenUISessionController(repository, provider, contract, this.bridge, this, this, models, thumbnails, devices, desktopCards, calendar, collaboration); + this.controller = new LocalGenUISessionController(repository, provider, contract, this.bridge, this, this, models, thumbnails, devices, desktopCards, calendar, collaboration, photos); await this.controller.refreshModels(); RemoteLogger.info(`local genui ready renderer=${contract.manifest.rendererRevision} models=${models.list().length}`); } finally { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/MiniAppViewModel.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/MiniAppViewModel.ets index e994c26..8921eec 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/MiniAppViewModel.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/pages/viewmodel/MiniAppViewModel.ets @@ -46,6 +46,12 @@ export class MiniAppViewModel { } } + async openShortcut(id: string): Promise { + const next = this.generation + 1; + await this.open(); + if (next === this.generation) await this.select(id); + } + async select(id: string): Promise { const app = this.state.apps.find((entry) => entry.id === id); if (!this.state.visible || !app) return; diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/MiniAppShortcut.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/MiniAppShortcut.ets new file mode 100644 index 0000000..c8c4312 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/MiniAppShortcut.ets @@ -0,0 +1,54 @@ +import { RemoteLogger } from './RemoteLogger'; +import { common, Want } from '@kit.AbilityKit'; +import { productViewManager } from '@kit.AppGalleryKit'; +import { fileIo as fs } from '@kit.CoreFileKit'; +import { image } from '@kit.ImageKit'; +import { DESKTOP_CARD_LAUNCH_PARAM } from './local-genui/LocalGenUIDesktopCards'; + +export const BUILTIN_LAUNCH_PARAM: string = 'openbitfunBuiltinMiniApp'; + +/** AppGallery verifies the user-visible label, destination and square picture before it offers to pin. */ +export class MiniAppShortcut { + static async pin(host: Context, id: string, title: string, generated: boolean, + thumbnail: string, fallback: Resource, revealDesktop: boolean): Promise { + const context = host as common.UIAbilityContext; + const path = context.cacheDir + '/miniapp-shortcut-' + Date.now() + '.webp'; + try { + const source = thumbnail ? image.createImageSource(thumbnail) : + image.createImageSource((await context.resourceManager.getMediaContent(fallback.id)).buffer as ArrayBuffer); + if (!source) throw new Error('Shortcut image unavailable'); + try { + const pixels = await source.createPixelMap({ editable: true }); + try { + const size = (await pixels.getImageInfo()).size; + const side = Math.min(size.width, size.height); + await pixels.crop({ x: Math.floor((size.width - side) / 2), y: Math.floor((size.height - side) / 2), + size: { width: side, height: side } }); + await pixels.scale(144 / side, 144 / side); + const packer = image.createImagePacker(); + try { + const bytes = await packer.packToData(pixels, { format: 'image/webp', quality: 90 }); + if (bytes.byteLength > 102400) throw new Error('Shortcut image exceeds size limit'); + const file = fs.openSync(path, fs.OpenMode.CREATE | fs.OpenMode.WRITE_ONLY | fs.OpenMode.TRUNC); + try { fs.writeSync(file.fd, bytes); } finally { fs.closeSync(file); } + } finally { await packer.release(); } + } finally { await pixels.release(); } + } finally { await source.release(); } + const parameters: Record = {}; + parameters[generated ? DESKTOP_CARD_LAUNCH_PARAM : BUILTIN_LAUNCH_PARAM] = id; + const want: Want = { bundleName: context.abilityInfo.bundleName, moduleName: 'entry', abilityName: 'EntryAbility', parameters }; + const result = await productViewManager.checkPinShortcutPermitted(context, id, want, + title.slice(0, 255), path, ''); + if (result.code !== 0 || !result.tid) return result.code || -1; + await productViewManager.requestNewPinShortcut(context, result.tid); + if (revealDesktop) { + // Pinning has already succeeded if returning to the launcher is interrupted. + try { await context.moveAbilityToBackground(); } + catch (error) { RemoteLogger.warn('Unable to background mini app after pin: ' + String(error)); } + } + return 0; + } finally { + if (fs.accessSync(path)) fs.unlinkSync(path); + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIActionHost.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIActionHost.ets index 05b178b..7a4e82d 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIActionHost.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIActionHost.ets @@ -18,6 +18,8 @@ export interface LocalGenUICapabilityHandlers { /** Calendar actions; return '' when accepted or a refusal reason. */ calendar: (appId: string, action: string, params: Object) => Promise; collaboration?: (message: LocalRuntimeInbound) => string; + /** Photo search for SearchImage and photo fields; return '' when accepted or a refusal reason. */ + imageSearch?: (appId: string, requestId: string, query: string) => string; } interface LocalCapabilityPolicy { @@ -36,6 +38,7 @@ const CALENDAR_ACTIONS: string[] = [ 'ListCalendarEvents' ]; const CALENDAR: string = 'calendar.event'; +const IMAGE_SEARCH: string = 'image.search'; export class LocalGenUIActionHost { private readonly handlers: LocalGenUICapabilityHandlers; @@ -52,6 +55,7 @@ export class LocalGenUIActionHost { this.policies.set(DEVICE_HAPTIC, { maxPayloadChars: 16, perMinute: 120 }); this.policies.set(CALENDAR, { maxPayloadChars: 16000, perMinute: 30 }); this.policies.set('device.collaboration', { maxPayloadChars: 1024, perMinute: 30 }); + this.policies.set(IMAGE_SEARCH, { maxPayloadChars: 800, perMinute: 60 }); } /** Returns a short diagnostic when the message was refused. */ @@ -72,6 +76,14 @@ export class LocalGenUIActionHost { await this.handlers.saveState(appId, mountedSourceRevision, message.baseStateRevision, stateJson); return ''; } + if (message.type === 'image_search') { + const requestId = message.requestId || ''; + const query = message.query || ''; + if (requestId.length === 0 || requestId.length > 64) return 'invalid image search request'; + if (!this.handlers.imageSearch) return 'image search is unavailable'; + const refused = this.admit(appId, IMAGE_SEARCH, query.length); + return refused || this.handlers.imageSearch(appId, requestId, query); + } if (message.type === 'collaboration') { if (message.sourceRevision !== mountedSourceRevision) return 'collaboration for another source revision'; if (!this.handlers.collaboration) return 'collaboration is unavailable'; diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIImageSearch.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIImageSearch.ets new file mode 100644 index 0000000..04c0a25 --- /dev/null +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIImageSearch.ets @@ -0,0 +1,402 @@ +import { http } from '@kit.NetworkKit'; +import { fileIo as fs } from '@kit.CoreFileKit'; +import { RemoteLogger } from '../RemoteLogger'; + +/** + * Photo search for Local GenUI apps, the phone counterpart of the desktop + * `image.search` provider (src/apps/desktop/src/api/generative_ui_api.rs): + * 360 and Baidu image search together, then Wikipedia and Wikimedia Commons + * when neither returns anything, at most four photos, within 16 seconds. + * + * The page has no network access of its own. Search results are handed to it + * as `` addresses that LocalGenUIWebSurface answers, and the host + * only fetches photos it found itself in this process (or already cached), so + * a generated app cannot use the address to reach anything else. + * + * Phone differences from the desktop provider: a record contributes one photo + * (its first image field, thumbnails first), `link` is not read because 360 + * uses it for the result page, and Commons answers use the sized thumbnail + * instead of the original upload. Answers are remembered per query on the + * phone: the domestic endpoints are unofficial and rate-limit repeated searches. + */ +export const LOCAL_GENUI_PHOTO_ROOT: string = 'https://genui-assets.openbitfun.invalid/photo/'; + +const SO_IMAGE_API: string = 'https://image.so.com/j'; +const BAIDU_IMAGE_API: string = 'https://image.baidu.com/search/acjson'; +const WIKIPEDIA_SUMMARY: string = 'https://en.wikipedia.org/api/rest_v1/page/summary/'; +const WIKIMEDIA_API: string = 'https://commons.wikimedia.org/w/api.php'; +const USER_AGENT: string = 'OpenBitFun/1.0 (GenUI host provider)'; +const IMAGE_KEYS: string[] = ['thumb', 'thumburl', 'thumbURL', 'middleURL', 'src', 'img', 'url', 'objURL', 'hoverURL']; +const MAX_RESULTS: number = 4; +const MAX_COLLECTED: number = 8; +const MAX_ISSUED: number = 500; +const MAX_PHOTO_BYTES: number = 4 * 1024 * 1024; +const DOMESTIC_TIMEOUT_MS: number = 6000; +const OPEN_TIMEOUT_MS: number = 8000; +const SEARCH_TIMEOUT_MS: number = 16000; +const PHOTO_ID: RegExp = /^[0-9a-f]{16}$/; +/** Answered queries kept on the phone, so reopening an app does not search again. */ +const MAX_CACHED_QUERIES: number = 300; + +/** Stable 64-bit FNV-1a style id of an upstream URL, as 16 hex characters. */ +function photoId(url: string): string { + let a = 0x811c9dc5; + let b = 0x01000193 ^ 0x5bd1e995; + for (let i = 0; i < url.length; i++) { + const c = url.charCodeAt(i); + a = Math.imul(a ^ c, 0x01000193) >>> 0; + b = Math.imul(b ^ c, 0x5bd1e995) >>> 0; + } + return a.toString(16).padStart(8, '0') + b.toString(16).padStart(8, '0'); +} + +function acceptable(url: string): boolean { + const lower = url.toLowerCase(); + return (lower.startsWith('https://') || lower.startsWith('http://')) && + lower.indexOf('.svg') < 0 && lower.indexOf('logo') < 0 && lower.indexOf('icon') < 0 && url.length <= 2048; +} + +/** One photo per record, searched depth-first like the desktop collector. */ +function collect(value: Object | null | undefined, images: string[]): void { + if (value === null || value === undefined || images.length >= MAX_COLLECTED) { + return; + } + if (Array.isArray(value)) { + for (const item of value as Object[]) { + collect(item, images); + } + return; + } + if (typeof value !== 'object') { + return; + } + const record = value as Record; + for (const key of IMAGE_KEYS) { + const candidate = record[key]; + if (typeof candidate === 'string') { + const url = (candidate as string).trim(); + if (acceptable(url)) { + if (images.indexOf(url) < 0) { + images.push(url); + } + break; + } + } + } + for (const key of Object.keys(record)) { + if (images.length >= MAX_COLLECTED) { + return; + } + const child = record[key]; + if (child !== null && typeof child === 'object') { + collect(child, images); + } + } +} + +function withTimeout(work: Promise, ms: number, fallback: T): Promise { + return new Promise((resolve: (value: T) => void) => { + const timer = setTimeout(() => resolve(fallback), ms); + work.then((value: T) => { + clearTimeout(timer); + resolve(value); + }).catch(() => { + clearTimeout(timer); + resolve(fallback); + }); + }); +} + +export class LocalGenUIImageSearch { + private readonly directory: string; + /** Photo id -> upstream URL for photos this process found. */ + private readonly issued: Map = new Map(); + private readonly inflight: Map> = new Map>(); + private readonly searches: Map> = new Map>(); + private answers?: Map; + + constructor(filesDir: string) { + this.directory = `${filesDir}/local-genui/photos`; + } + + /** The query the desktop provider accepts: 2 to 200 characters, trimmed. */ + static queryOf(raw: string): string { + const query = (raw || '').trim(); + const length = Array.from(query).length; + return length >= 2 && length <= 200 ? query : ''; + } + + /** The photo id an address names, or '' when it is not a served photo. */ + static photoIdOf(url: string): string { + if (!url.startsWith(LOCAL_GENUI_PHOTO_ROOT)) { + return ''; + } + const id = url.substring(LOCAL_GENUI_PHOTO_ROOT.length); + return PHOTO_ID.test(id) ? id : ''; + } + + /** Host addresses of up to four photos for the query. */ + async search(raw: string): Promise { + const query = LocalGenUIImageSearch.queryOf(raw); + if (query.length === 0) { + return []; + } + const remembered = this.remembered().get(query); + if (remembered && remembered.length > 0) { + return remembered.map((url: string): string => this.issue(url)); + } + let running = this.searches.get(query); + if (!running) { + running = withTimeout(this.searchSources(query), SEARCH_TIMEOUT_MS, [] as string[]); + this.searches.set(query, running); + } + const found = await running; + this.searches.delete(query); + RemoteLogger.info(`local genui image search found ${found.length}`); + if (found.length > 0) { + this.remember(query, found); + } + return found.map((url: string): string => this.issue(url)); + } + + private answersFile(): string { + return `${this.directory}/queries.json`; + } + + private remembered(): Map { + if (this.answers) { + return this.answers; + } + const answers = new Map(); + try { + const file = this.answersFile(); + if (fs.accessSync(file)) { + const rows = JSON.parse(fs.readTextSync(file)) as Object; + if (Array.isArray(rows)) { + for (const row of rows as Object[]) { + const entry = row as Record; + const query = entry['q']; + const urls = entry['u']; + if (typeof query === 'string' && Array.isArray(urls)) { + answers.set(query as string, (urls as Object[]).filter((url: Object): boolean => typeof url === 'string' && + acceptable(url as string)) as string[]); + } + } + } + } + } catch (_err) { + // A damaged answer cache only costs new searches. + } + this.answers = answers; + return answers; + } + + private remember(query: string, urls: string[]): void { + const answers = this.remembered(); + answers.delete(query); + answers.set(query, urls); + while (answers.size > MAX_CACHED_QUERIES) { + const oldest = answers.keys().next(); + if (oldest.done) break; + answers.delete(oldest.value); + } + const rows: Record[] = []; + answers.forEach((value: string[], key: string) => { + const row: Record = { 'q': key, 'u': value }; + rows.push(row); + }); + const file = this.answersFile(); + const temporary = `${file}.${Date.now()}.tmp`; + try { + if (!fs.accessSync(this.directory)) { + fs.mkdirSync(this.directory, true); + } + const handle = fs.openSync(temporary, fs.OpenMode.CREATE | fs.OpenMode.WRITE_ONLY | fs.OpenMode.TRUNC); + try { + fs.writeSync(handle.fd, JSON.stringify(rows)); + } finally { + fs.closeSync(handle); + } + fs.renameSync(temporary, file); + } catch (_err) { + try { fs.unlinkSync(temporary); } catch (_ignored) { /* derived data */ } + } + } + + private async searchSources(query: string): Promise { + const domestic = await Promise.all([this.so(query), this.baidu(query)]); + const images: string[] = []; + for (const url of domestic[0].concat(domestic[1])) { + if (images.indexOf(url) < 0) { + images.push(url); + } + } + if (images.length > 0) { + return images.slice(0, MAX_RESULTS); + } + return this.open(query); + } + + private issue(url: string): string { + const id = photoId(url); + if (!this.issued.has(id) && this.issued.size >= MAX_ISSUED) { + const oldest = this.issued.keys().next(); + if (!oldest.done) { + this.issued.delete(oldest.value); + } + } + this.issued.set(id, url); + return LOCAL_GENUI_PHOTO_ROOT + id; + } + + private async so(query: string): Promise { + const q = encodeURIComponent(query); + const value = await this.json(`${SO_IMAGE_API}?q=${q}&pn=0&sn=0&pd=1&correct=${q}`, DOMESTIC_TIMEOUT_MS); + const images: string[] = []; + collect(value, images); + return images.slice(0, MAX_RESULTS); + } + + private async baidu(query: string): Promise { + const value = await this.json(`${BAIDU_IMAGE_API}?tn=resultjson_com&word=${encodeURIComponent(query)}&ie=utf-8&pn=0&rn=10`, + DOMESTIC_TIMEOUT_MS); + const images: string[] = []; + collect(value, images); + return images.slice(0, MAX_RESULTS); + } + + /** Wikipedia summary and Commons search, together, as the desktop open fallback. */ + private async open(query: string): Promise { + const commonsQuery = `action=query&format=json&formatversion=2&generator=search&gsrsearch=${encodeURIComponent(query)}` + + '&gsrnamespace=6&gsrlimit=8&prop=imageinfo&iiprop=url%7Cmime&iiurlwidth=960'; + const results = await Promise.all([ + this.json(WIKIPEDIA_SUMMARY + encodeURIComponent(query), OPEN_TIMEOUT_MS), + this.json(`${WIKIMEDIA_API}?${commonsQuery}`, OPEN_TIMEOUT_MS) + ]); + const images: string[] = []; + const summary = results[0]; + if (summary !== undefined && typeof summary === 'object') { + const thumbnail = (summary as Record)['thumbnail']; + if (thumbnail !== undefined && typeof thumbnail === 'object') { + const source = (thumbnail as Record)['source']; + if (typeof source === 'string' && acceptable(source as string)) { + images.push(source as string); + } + } + } + collect(results[1], images); + return images.slice(0, MAX_RESULTS); + } + + private async json(url: string, timeoutMs: number): Promise { + const request = http.createHttp(); + try { + const response = await request.request(url, { + method: http.RequestMethod.GET, + header: { 'User-Agent': USER_AGENT }, + expectDataType: http.HttpDataType.STRING, + connectTimeout: timeoutMs, + readTimeout: timeoutMs + }); + if (response.responseCode !== 200 || typeof response.result !== 'string') { + return undefined; + } + return JSON.parse(response.result as string) as Object; + } catch (_err) { + return undefined; + } finally { + request.destroy(); + } + } + + /** Image bytes for a served photo, from the cache or its upstream address. */ + async picture(url: string): Promise { + const id = LocalGenUIImageSearch.photoIdOf(url); + if (id.length === 0) { + return undefined; + } + const running = this.inflight.get(id); + if (running) { + return running; + } + const work = this.load(id).finally(() => { this.inflight.delete(id); }); + this.inflight.set(id, work); + return work; + } + + private async load(id: string): Promise { + const file = `${this.directory}/${id}.img`; + try { + if (fs.accessSync(file)) { + const handle = fs.openSync(file, fs.OpenMode.READ_ONLY); + try { + const buffer = new ArrayBuffer(fs.statSync(file).size); + fs.readSync(handle.fd, buffer); + return buffer; + } finally { + fs.closeSync(handle); + } + } + } catch (_err) { + // A damaged cache entry is fetched again. + } + const upstream = this.issued.get(id); + if (!upstream) { + return undefined; + } + const bytes = await this.download(upstream); + if (bytes) { + this.store(file, bytes); + } + return bytes; + } + + private async download(url: string): Promise { + const request = http.createHttp(); + try { + const header: Record = { 'User-Agent': USER_AGENT }; + if (url.indexOf('baidu.com') >= 0 || url.indexOf('bdimg.com') >= 0) { + header['Referer'] = 'https://image.baidu.com/'; + } + const response = await request.request(url, { + method: http.RequestMethod.GET, + header, + expectDataType: http.HttpDataType.ARRAY_BUFFER, + connectTimeout: 8000, + readTimeout: 15000 + }); + const body = response.result; + const type = String((response.header as Record)?.['content-type'] ?? + (response.header as Record)?.['Content-Type'] ?? ''); + if (response.responseCode !== 200 || !(body instanceof ArrayBuffer) || body.byteLength === 0 || + body.byteLength > MAX_PHOTO_BYTES || (type.length > 0 && !type.toLowerCase().startsWith('image/'))) { + RemoteLogger.warn(`local genui photo unavailable status=${response.responseCode}`); + return undefined; + } + return body; + } catch (err) { + RemoteLogger.warn(`local genui photo fetch failed: ${err instanceof Error ? err.message : String(err)}`); + return undefined; + } finally { + request.destroy(); + } + } + + private store(file: string, bytes: ArrayBuffer): void { + const temporary = `${file}.${Date.now()}.tmp`; + try { + if (!fs.accessSync(this.directory)) { + fs.mkdirSync(this.directory, true); + } + const handle = fs.openSync(temporary, fs.OpenMode.CREATE | fs.OpenMode.WRITE_ONLY | fs.OpenMode.TRUNC); + try { + fs.writeSync(handle.fd, bytes); + } finally { + fs.closeSync(handle); + } + fs.renameSync(temporary, file); + } catch (_err) { + try { fs.unlinkSync(temporary); } catch (_ignored) { /* derived data */ } + } + } +} diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeBridge.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeBridge.ets index 26f7e12..9c289e7 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeBridge.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeBridge.ets @@ -16,8 +16,7 @@ import { LocalRuntimeInsetsMessage, LocalRuntimeMergeMessage, LocalRuntimeThemeMessage, - runtimeIdentity -} from './LocalGenUIRuntimeProtocol'; + runtimeIdentity, LocalRuntimeImageSearchResultMessage } from './LocalGenUIRuntimeProtocol'; export interface LocalRuntimeMount { identity: LocalGenUIIdentity; @@ -69,6 +68,7 @@ export class LocalGenUIRuntimeBridge { private ready: boolean = false; private mount?: LocalRuntimeMount; private manifest?: LocalGenUIManifest; + private look: string = 'aurora'; private scheme: string = 'light'; private locale: string = 'zh-CN'; private seq: number = 0; @@ -199,12 +199,13 @@ export class LocalGenUIRuntimeBridge { this.post(json); } - setAppearance(scheme: string, locale: string): void { - const changed = scheme !== this.scheme; + setAppearance(scheme: string, locale: string, look: string = 'aurora'): void { + const changed = scheme !== this.scheme || look !== this.look; + this.look = look; this.scheme = scheme; this.locale = locale; if (changed && this.booted) { - const theme: LocalRuntimeThemeMessage = { type: 'theme', scheme }; + const theme: LocalRuntimeThemeMessage = { type: 'theme', scheme, look }; this.post(JSON.stringify(theme)); } } @@ -275,6 +276,14 @@ export class LocalGenUIRuntimeBridge { this.post(JSON.stringify(message)); } + /** Photos found for a runtime image search; dropped once another app is mounted. */ + sendImageSearchResult(appId: string, requestId: string, images: string[]): void { + const mount = this.mount; + if (!mount || mount.mode !== 'live' || mount.identity.appId !== appId) return; + const message: LocalRuntimeImageSearchResultMessage = { type: 'image_search_result', appId, requestId, images }; + this.post(JSON.stringify(message)); + } + sendCalendarReceipts(appId: string, sourceRevision: number, params: Object[]): void { const message: LocalRuntimeCalendarReceiptsMessage = { type: 'calendar_receipts', appId, sourceRevision, params }; this.post(JSON.stringify(message)); @@ -361,6 +370,7 @@ export class LocalGenUIRuntimeBridge { stateRevision: mount.stateRevision, state: JSON.parse(mount.stateJson.length > 0 ? mount.stateJson : '{}') as Object, scheme: this.scheme, + look: this.look, locale: this.locale }; if (mount.base !== undefined && mount.base.length > 0) { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeProtocol.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeProtocol.ets index bcb2a01..6632a48 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeProtocol.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUIRuntimeProtocol.ets @@ -42,6 +42,7 @@ export interface LocalRuntimeInitMessage { stateRevision: number; state: Object; scheme: string; + look?: string; locale: string; } @@ -72,6 +73,7 @@ export interface LocalRuntimeStateMessage { export interface LocalRuntimeThemeMessage { type: string; scheme: string; + look?: string; } /** Owner request: apply an OpenUI edit patch to its base program. */ @@ -156,6 +158,15 @@ export interface LocalRuntimeInbound { gesture?: string; kind?: string; orientation?: string; + /** image_search */ + query?: string; +} + +export interface LocalRuntimeImageSearchResultMessage { + type: string; + appId: string; + requestId: string; + images: string[]; } export interface LocalRuntimeCapabilityEventMessage { diff --git a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets index cd393a3..86ddfe2 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets +++ b/src/apps/mobile/harmonyos/entry/src/main/ets/services/local-genui/LocalGenUISessionController.ets @@ -36,6 +36,7 @@ import { LocalGenUIDeviceCapabilityHost } from './LocalGenUIDeviceCapabilityHost import { HarmonyCalendarAction, HarmonyCalendarService } from './HarmonyCalendarService'; import { LocalProviderFrame } from './LocalProviderSseParser'; import { LocalGenUIModelStore, LocalGenUIModelUpdate } from './LocalGenUIModelStore'; +import { LocalGenUIImageSearch } from './LocalGenUIImageSearch'; import { LocalGenUIModelCatalog, LocalGenUIModelChoice, LocalGenUIModelProfile } from './LocalGenUIModelCatalog'; /** Projection of one app for the presentation layer. */ @@ -139,6 +140,7 @@ export class LocalGenUISessionController { private mountedAppId: string = ''; /** Automatic repair queued by the finished turn; runs after it releases the slot. */ private pendingRepair?: LocalGenUIPendingRepair; + private readonly imageSearch?: LocalGenUIImageSearch; constructor( repository: LocalGenUIRepository, @@ -152,8 +154,10 @@ export class LocalGenUISessionController { devices: LocalGenUIDeviceCapabilityHost, desktopCards: LocalGenUIDesktopCardStore, calendar: HarmonyCalendarService, - collaboration: LocalGenUICollaborationHost + collaboration: LocalGenUICollaborationHost, + imageSearch?: LocalGenUIImageSearch ) { + this.imageSearch = imageSearch; this.devices = devices; this.calendar = calendar; this.collaboration = collaboration; @@ -184,6 +188,12 @@ export class LocalGenUISessionController { unsubscribeGesture: (subscriptionId: string): void => this.devices.unsubscribeGesture(subscriptionId), haptic: (kind: string): void => this.devices.haptic(kind), collaboration: (message: LocalRuntimeInbound): string => this.collaboration.handle(message), + imageSearch: (appId: string, requestId: string, query: string): string => { + const search = this.imageSearch; + if (!search) return 'image search is unavailable'; + void search.search(query).then((images: string[]): void => this.bridge.sendImageSearchResult(appId, requestId, images)); + return ''; + }, calendar: async (appId: string, action: string, params: Object): Promise => action === 'CreateCalendarEvent' ? this.calendarActions.create(appId, params, () => this.runCalendar(action, params)) : this.runCalendar(action, params) @@ -478,23 +488,6 @@ export class LocalGenUISessionController { }; } - /** Called before the add menu is shown, so a new card has content at once. */ - async prepareDesktopCard(appId: string): Promise { - // First, before any await: the launcher may add the card right away. - this.desktopCards.stagePendingAdd(appId); - if (this.thumbnails.existing(appId).length === 0) { - await this.captureThumbnail(appId); - } - this.desktopCards.saveApp(await this.desktopCardApp(appId)); - } - - /** The launcher placed a card; bind it even if `onAddForm` lost the app id. */ - async desktopCardAdded(appId: string, formId: string): Promise { - this.desktopCards.bind(formId, appId); - this.desktopCards.saveApp(await this.desktopCardApp(appId)); - await this.desktopCards.refresh(formId); - } - private async syncDesktopCards(appId: string): Promise { try { await this.desktopCards.publish(await this.desktopCardApp(appId)); @@ -812,6 +805,16 @@ export class LocalGenUISessionController { } return; } + // Photo search is read-only, so a page may ask while its source still streams. + if (message.type === 'image_search') { + if (!mount || mount.mode !== 'live') return; + const refusedSearch = await this.actions.handle(message, this.mountedAppId, mount.sourceRevision); + if (refusedSearch.length > 0) { + this.bridge.sendImageSearchResult(message.appId || '', message.requestId || '', []); + RemoteLogger.warn(`local genui refused image search: ${refusedSearch}`); + } + return; + } // Only capability-bearing messages reach the action host. if (message.type === 'capability' && message.op === 'unsubscribe') { // Releases are always honored, even while a turn streams or after a remount. diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/base/element/string.json b/src/apps/mobile/harmonyos/entry/src/main/resources/base/element/string.json index 963a9ac..2111aeb 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/resources/base/element/string.json +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/base/element/string.json @@ -1,5 +1,61 @@ { "string": [ + { + "name": "miniapp_shortcutHint", + "value": "滑动浏览 · 长按封面拖到桌面" + }, + { + "name": "miniapp_dropShortcut", + "value": "拖到这里添加桌面图标" + }, + { + "name": "miniapp_releaseShortcut", + "value": "松开以添加桌面图标" + }, + { + "name": "miniapp_pinned", + "value": "已添加桌面图标" + }, + { + "name": "miniapp_alreadyPinned", + "value": "该图标已在桌面" + }, + { + "name": "miniapp_pinLimit", + "value": "桌面快捷方式数量已达上限" + }, + { + "name": "miniapp_pinFailed", + "value": "系统未能添加桌面图标(%1$s)" + }, + { + "name": "miniapp_actions", + "value": "小应用操作" + }, + { + "name": "miniapp_pinIcon", + "value": "添加桌面图标" + }, + { + "name": "settings_genui_look", + "value": "小应用风格" + }, + { + "name": "settings_genui_classic", + "value": "原生" + }, + { + "name": "settings_genui_aurora", + "value": "极光" + }, + { + "name": "settings_genui_blueprint", + "value": "蓝图" + }, + { + "name": "settings_genui_celadon", + "value": "青瓷" + }, { "name": "session_newTitle", "value": "新会话" diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/en_US/element/string.json b/src/apps/mobile/harmonyos/entry/src/main/resources/en_US/element/string.json index f295483..11372f5 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/resources/en_US/element/string.json +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/en_US/element/string.json @@ -1,5 +1,61 @@ { "string": [ + { + "name": "miniapp_shortcutHint", + "value": "Swipe to browse · Hold a cover to pin" + }, + { + "name": "miniapp_dropShortcut", + "value": "Drag here to add a home screen icon" + }, + { + "name": "miniapp_releaseShortcut", + "value": "Release to add a home screen icon" + }, + { + "name": "miniapp_pinned", + "value": "Home screen icon added" + }, + { + "name": "miniapp_alreadyPinned", + "value": "Icon already on the home screen" + }, + { + "name": "miniapp_pinLimit", + "value": "Home screen shortcut limit reached" + }, + { + "name": "miniapp_pinFailed", + "value": "Could not add home screen icon (%1$s)" + }, + { + "name": "miniapp_actions", + "value": "Mini app actions" + }, + { + "name": "miniapp_pinIcon", + "value": "Add home screen icon" + }, + { + "name": "settings_genui_look", + "value": "Mini app style" + }, + { + "name": "settings_genui_classic", + "value": "Classic" + }, + { + "name": "settings_genui_aurora", + "value": "Aurora" + }, + { + "name": "settings_genui_blueprint", + "value": "Blueprint" + }, + { + "name": "settings_genui_celadon", + "value": "Celadon" + }, { "name": "session_newTitle", "value": "New Session" diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/catalog.json b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/catalog.json index 39f8fc9..904903b 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/catalog.json +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/catalog.json @@ -17,6 +17,8 @@ "rootComponent": "Page", "components": [ "Badge", + "BarList", + "Bento", "Box", "Button", "Caption", @@ -31,6 +33,7 @@ "Code", "Col", "CompareTable", + "Countdown", "Cover", "CrossDeviceImage", "DatePicker", @@ -45,6 +48,7 @@ "G", "GestureTrigger", "Grid", + "Heatmap", "HeroStat", "HtmlView", "Icon", @@ -64,6 +68,7 @@ "Markdown", "Math", "Metric", + "MonthCalendar", "Note", "Page", "Path", @@ -78,8 +83,10 @@ "Prose", "Quote", "RadioGroup", + "Ranking", "RecordList", "Rect", + "Ring", "Row", "Scoreboard", "SearchImage", @@ -87,9 +94,12 @@ "Segmented", "SegmentedControl", "Select", + "Shelf", "Slider", "Spacer", + "Spotlight", "StatGrid", + "Statement", "Steps", "Svg", "SvgText", @@ -98,6 +108,8 @@ "Tabs", "Text", "TextArea", + "Ticket", + "Tile", "Timeline", "Timer", "Title", diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/harmony-prompt.txt b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/harmony-prompt.txt index 5f7a158..a8f5695 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/harmony-prompt.txt +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/harmony-prompt.txt @@ -2,7 +2,7 @@ You are the Local GenUI assistant in the OpenBitFun HarmonyOS phone app. You run without a workspace, shell, files, browsing or external tools. Never claim to use them. When an interactive mini app helps the user, call the GenerativeUI tool exactly once with an OpenUI Lang program; otherwise answer in plain text. Keep any surrounding text short. Answer in the user's language. -This phone provides local component state, new chat turns, the declared native calendar actions, gesture input, haptics and page orientation. Use the capability guidance below. Calendar controls are a default part of time-based planning apps; system writes run only when the user clicks them. Generic network queries, maps and video are unsupported; prefer inline data and the declared host-served picture components. +This phone provides local component state, new chat turns, the declared native calendar actions, gesture input, haptics and page orientation. Use the capability guidance below. Calendar controls are a default part of time-based planning apps; system writes run only when the user clicks them. Photo search is available: SearchImage and the photo fields of Shelf and Spotlight show real photos the phone finds for an exact subject query. Other network queries, maps and video are unsupported; prefer inline data, photo queries and the declared host-served picture components. You are an AI assistant that responds using openui-lang, a declarative UI language. Your ENTIRE response must be valid openui-lang code — no markdown, no explanations, just openui-lang. @@ -32,11 +32,11 @@ Arguments marked with ? are optional. Sub-components can be inline or referenced Props typed `ActionExpression` accept one @step, or Action([@steps...]) for several. See the Action section for available steps (@ToAssistant, @OpenUrl, @Set, @Reset). Props marked `$binding` accept a `$variable` reference for two-way binding. -Col(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Section | Layout | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], gap?: number, align?: "start" | "center" | "end" | "stretch") — Vertical layout. Without gap it spaces blocks like an article. +Col(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Section | Layout | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage | Ring | Spotlight | Shelf | Ticket | Countdown | Ranking | BarList | Heatmap | Statement | MonthCalendar[], gap?: number, align?: "start" | "center" | "end" | "stretch") — Vertical layout. Without gap it spaces blocks like an article. Row(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger[], gap?: number, align?: "start" | "center" | "end" | "stretch", justify?: "start" | "center" | "end" | "between", wrap?: boolean) — Horizontal layout; items are vertically centered. Box(children?: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView[], direction?: "row" | "col", gap?: number, padding?: number, background?: string, radius?: string | number, border?: boolean, width?: number | string, height?: number | string, flex?: number, align?: "start" | "center" | "end" | "stretch", justify?: "start" | "center" | "end" | "between", wrap?: boolean) — Flex container, a column by default. radius also clips the content. Grid(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog[], columns?: number, minChildWidth?: number, gap?: number) — Equal columns (default 2). With minChildWidth (px), columns drop on narrow screens. -Card(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], variant?: "outline" | "soft", padding?: number, gap?: number) — Panel with a border; soft is a filled panel for summaries. +Card(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage | Ring | Spotlight | Shelf | Ticket | Countdown | Ranking | BarList | Heatmap | Statement | MonthCalendar[], variant?: "outline" | "soft", padding?: number, gap?: number) — Panel with a border; soft is a filled panel for summaries. Carousel(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView[], itemWidth?: number, gap?: number) — Horizontal row that scrolls and snaps, each child an item itemWidth px wide (default 240): photos, cards, options, days. Popover(trigger: string | any[], content: string | any[]) — Shows content in a small panel when the trigger is clicked: a definition, a source, details behind an Icon("info", "sm"). Divider() @@ -95,12 +95,12 @@ RecordList(items: {id: string, title: string, subtitle?: string, value?: string Plan(items: {id: string, title: string, detail?: string, done?: boolean}[], action?: ActionExpression, label?: string, emptyText?: string) — Native checklist or day plan. Selecting an item emits its id so local state actions can update it. Catalog(items: {id: string, title: string, subtitle?: string, value?: string | number, selected?: boolean}[], action?: ActionExpression, label?: string, emptyText?: string) — Native selectable catalog of supplied alternatives with an explicit empty state. GestureTrigger(gesture: "raise_left_hand" | "raise_right_hand" | "raise_both_hands", action?: ActionExpression, label?: string, haptic?: "none" | "light" | "medium" | "heavy") — Phone-only body gesture input. Runs the action each time the person in front of the front camera performs the gesture (raise_left_hand = their left hand above their shoulder; raise_right_hand likewise; raise_both_hands = both). Use it when the user asks to control the app with hand or body gestures, e.g. raise left hand to add a point to the left team. Recognition stays on the phone; the host asks for camera permission, shows a small camera preview and stops when the app is hidden. Put one GestureTrigger per gesture near the top of the page; label explains the gesture to the user. haptic adds vibration feedback when it fires. On devices without the capability it shows that gestures are unavailable, so keep normal buttons for the same actions. -Page(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Section | Layout | Tabs | Cover | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], title?: string, theme?: "blue" | "indigo" | "purple" | "rose" | "orange" | "brown" | "green" | "teal" | "ink", font?: "default" | "serif" | "tech" | "handwritten", opts?: {orientation?: "auto" | "portrait" | "landscape"}) — Harmony page: the root of an application. theme sets the accent and the page cast from the topic (blue tools/finance/tech, indigo study/planning, purple creative/music, rose beauty/celebrations, orange food, brown coffee/history, green health/fitness/nature, teal medicine/water/travel, ink minimal/serious). A Cover child, when first, opens the page; the other children are the page blocks, top to bottom. Every block spans the full width on narrow and wide screens alike; a wide screen turns the cover into a header row. -Section(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Layout | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], title?: string, aside?: string) — A titled group of blocks. aside is a short count, date or amount at the right of the title (6 项). -Layout(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], mode: "stack" | "grid" | "split", columns?: 2 | 3) — Peers read together in one row: grid sets 2-3 comparable blocks side by side when the screen is wide (unfolded or landscape), split sets main content then supporting content, stack is one column. Narrow screens always stack in source order. -TabPanel(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Section | Layout | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage[], label: string) — One view of Tabs. label is 2-4 characters. +Page(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Section | Layout | Tabs | Cover | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage | Bento | Ring | Spotlight | Shelf | Ticket | Countdown | Ranking | BarList | Heatmap | Statement | MonthCalendar[], title?: string, theme?: "blue" | "indigo" | "purple" | "rose" | "orange" | "brown" | "green" | "teal" | "ink", font?: "default" | "serif" | "tech" | "handwritten", opts?: {orientation?: "auto" | "portrait" | "landscape", mood?: "calm" | "vivid" | "night"}) — Harmony page: the root of an application. theme sets the accent and the page cast from the topic (blue tools/finance/tech, indigo study/planning, purple creative/music, rose beauty/celebrations, orange food, brown coffee/history, green health/fitness/nature, teal medicine/water/travel, ink minimal/serious). A Cover child, when first, opens the page; the other children are the page blocks, top to bottom. Every block spans the full width on narrow and wide screens alike; a wide screen turns the cover into a header row. mood sets the stage of the whole page so every block matches: calm is light and quiet (study, health, tools, planning, reading), vivid is saturated gradients and glow (celebrations, launches, music, shopping, travel highlights), night is a dark page with lit stages (live sports, games, cinema, concerts, astronomy, night events). Leave mood out to follow the person's chosen look. +Section(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Layout | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage | Bento | Ring | Spotlight | Shelf | Ticket | Countdown | Ranking | BarList | Heatmap | Statement | MonthCalendar[], title?: string, aside?: string) — A titled group of blocks. aside is a short count, date or amount at the right of the title (6 项). +Layout(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage | Tile | Ring | Spotlight | Shelf | Ticket | Countdown | Ranking | BarList | Heatmap | Statement | MonthCalendar[], mode: "stack" | "grid" | "split", columns?: 2 | 3) — Peers read together in one row: grid sets 2-3 comparable blocks side by side when the screen is wide (unfolded or landscape), split sets main content then supporting content, stack is one column. Narrow screens always stack in source order. +TabPanel(children: Col | Row | Box | Grid | Card | Carousel | Popover | Divider | Spacer | Title | Text | Caption | Label | Badge | Link | List | ListItem | Markdown | Quote | Code | Math | Button | IconButton | Pressable | Input | TextArea | Select | SegmentedControl | Slider | Checkbox | RadioGroup | DatePicker | Timer | Form | SearchImage | Image | Icon | Table | Chart | Map | MapMarker | YouTube | Flashcard | Celebration | HtmlView | Icon3D | Plot | Metric | Steps | RecordList | Plan | Catalog | GestureTrigger | Section | Layout | Scoreboard | HeroStat | StatGrid | ItemList | Timeline | Checklist | Note | Prose | ProCon | CompareTable | Faq | Segmented | FormCard | Progress | TrendChart | EmptyState | CrossDeviceImage | Bento | Ring | Spotlight | Shelf | Ticket | Countdown | Ranking | BarList | Heatmap | Statement | MonthCalendar[], label: string) — One view of Tabs. label is 2-4 characters. Tabs(children: TabPanel[]) — 2-8 independent views at the top level when the task needs switching; each child is a TabPanel. Keep a short task in one reading flow instead. -Cover(title: string, eyebrow?: string, meta?: string, picture?: string, opts?: {tags?: string | number | {text: string, tone?: "success" | "warning" | "danger", role?: "context" | "configuration"}[], variant?: "feature" | "compact", align?: "start" | "center", purpose?: "content" | "tool", layout?: "auto" | "stacked", tagsDisplay?: "auto" | "show" | "hide", presentation?: {cover: {mode: "gradient" | "none", colorSource: "theme" | "picture", intensity?: number, height?: number}}}) — Opening of the page, first child of Page only. picture is one emoji naming the subject, drawn as a large 3D picture. eyebrow is the real English name or title. tags are optional short facts, only when they add useful context; immediate-use tools omit tags and duplicate rule summaries: the native controls/settings already own that information. A title, one concise subtitle (meta) and optional subject picture are enough. purpose content|tool defaults to tool when the page holds a Scoreboard; layout auto|stacked defaults to auto (picture beside grouped text on wide screens, above it on narrow screens); tagsDisplay auto|show|hide defaults to auto: tool headers hide only tags marked role configuration. Mutable rules belong to their owning control settings; if supplied as tags mark them configuration. compact is a short introduction. presentation {cover:{mode:"gradient"|"none", colorSource:"theme"|"picture", intensity?:0-0.3, height?:160-400}} is the optional controlled atmosphere of a plain cover: for a cover with a concrete 3D subject picture choose mode gradient and colorSource picture so the wash matches it; when color has a semantic meaning (weather, status) choose theme; choose none when the scene calls for no wash or the user asks for none. Never infer semantic color from an icon. +Cover(title: string, eyebrow?: string, meta?: string, picture?: string, opts?: {tags?: string | number | {text: string, tone?: "success" | "warning" | "danger", role?: "context" | "configuration"}[], variant?: "feature" | "compact" | "immersive", align?: "start" | "center", purpose?: "content" | "tool", layout?: "auto" | "stacked", tagsDisplay?: "auto" | "show" | "hide", presentation?: {cover: {mode: "gradient" | "none", colorSource: "theme" | "picture", intensity?: number, height?: number}}}) — Opening of the page, first child of Page only. picture is one emoji naming the subject, drawn as a large 3D picture. eyebrow is the real English name or title. tags are optional short facts, only when they add useful context; immediate-use tools omit tags and duplicate rule summaries: the native controls/settings already own that information. A title, one concise subtitle (meta) and optional subject picture are enough. purpose content|tool defaults to tool when the page holds a Scoreboard; layout auto|stacked defaults to auto (picture beside grouped text on wide screens, above it on narrow screens); tagsDisplay auto|show|hide defaults to auto: tool headers hide only tags marked role configuration. Mutable rules belong to their owning control settings; if supplied as tags mark them configuration. compact is a short introduction. immersive is a full-bleed night-sky hero in the theme colours with the picture large and centred and the title in white: use it for events, trips, launches, celebrations, games and other pages that should open with drama. presentation {cover:{mode:"gradient"|"none", colorSource:"theme"|"picture", intensity?:0-0.3, height?:160-400}} is the optional controlled atmosphere of a plain cover: for a cover with a concrete 3D subject picture choose mode gradient and colorSource picture so the wash matches it; when color has a semantic meaning (weather, status) choose theme; choose none when the scene calls for no wash or the user asks for none. Never infer semantic color from an icon. Scoreboard(teams: string[], value?: object, opts?: {targetScore?: number, winBy?: number, scoreCap?: number, bestOf?: number, setupRequired?: boolean, input?: {plugin: "camera.open-palm", version: 1, activation: "manual" | "on-open", bindings: {left: {action: "increment", participantId: "A" | "B", points?: number}, right: {action: "increment", participantId: "A" | "B", points?: number}}, haptic?: "none" | "light" | "medium" | "heavy"}, scoring?: "rally" | "open", increments?: number[]}) — The scoreboard for any two-side contest: both scores side by side, large, with point buttons under each side, undo, side swap and a More dialog for names and rules; the host owns markup, rules and the screen fit. scoring "open" simply accumulates points (basketball, football, quizzes, card games); "rally" (the default) adds targetScore (default 21), winBy (2), optional scoreCap and odd bestOf (3) with game and match ends (badminton, table tennis, volleyball). increments are the point buttons per side, 1-3 positive integers such as [1, 2, 3] for basketball; default [1]. Bind value to an object state such as $match to keep the match across reopen. On Harmony phones, include the camera.open-palm input by default with manual activation, distinct left/right participant bindings and light haptic feedback, unless the user explicitly disables gesture scoring or vibration. Keep the point buttons as the ordinary fallback. Optional input {plugin:"camera.open-palm", version:1, activation:"manual"|"on-open", haptic?:"none"|"light"|"medium"|"heavy", bindings:{left:{action:"increment", participantId:"A"|"B", points?:n}, right:{...}}} maps raised hands to distinct immutable participants; points defaults to the first increment; use on-open only when the user requests automatic camera start; haptic gives vibration on a scored gesture. HeroStat(label: string, value: string | number, unit?: string, opts?: {tone?: "success" | "warning" | "danger", tags?: string | {text: string, tone?: "success" | "warning" | "danger"}[]}) — The one number the page is about, large in its own card. value may be a number or a short word. StatGrid(items: {label: string, value: string | number, unit?: string, tone?: "success" | "warning" | "danger"}[]) — 2-8 small numbers in an even grid of cards. @@ -119,6 +119,18 @@ Progress(label: string, done: number, total: number, unit?: string) — A label, TrendChart(label: string, x: string | number[], series: {name: string, values: number[]}[], opts?: {unit?: string, band?: {from: number, to: number, label?: string}}) — A trend line in one card with a hover readout and a data table. 1-2 series; band marks a normal range. EmptyState(text: string) — An empty state in a card. CrossDeviceImage(value: string, kind?: "photo" | "scan" | "gallery", label?: string) — User-initiated cross-device image input for Harmony Local GenUI. CrossDeviceImage($photo, "photo"|"scan"|"gallery", label?) opens a native device picker after a click. photo takes a photo on another device; scan scans a document; gallery selects one image. Bind value to a string state initialized to "". A successful transfer stores one JPEG locally for this generated app and writes its opaque host image reference into value; the component displays it and restores it after reopen. Do not fabricate references. Requires supported API 23+ devices, system collaboration support, the same HUAWEI ID, Wi-Fi and Bluetooth. Availability does not prove a peer is connected. Unavailable hosts show an explicit disabled state. This does not send the image to the model, perform OCR, remote-control apps, synchronize apps, or transfer arbitrary files. Use for receipt collection, illustrated notes, field photos or document collection; do not claim image understanding unless another capability provides it. +Bento(children: HeroStat | Progress | TrendChart | Note | Tile | Ring | Countdown | BarList[]) — A widget board in the style of phone home-screen widgets: two columns on a phone, four when wide. Children are Tile blocks, plus Ring, HeroStat, Progress or TrendChart, which span the full row. Size each Tile by importance: one "l" or "w" tile for the headline number, "s" tiles for the rest. 3-7 children. +Tile(label: string, value?: string | number, unit?: string, opts?: {sub?: string, picture?: string, size?: "s" | "w" | "t" | "l", style?: "glass" | "tint" | "vivid", tone?: "success" | "warning" | "danger", progress?: number, trend?: "up" | "down" | "flat", delta?: string}) — One widget in a Bento board: a label, a big value and unit, optionally one emoji picture drawn in 3D, a short sub line, a 0-1 progress bar and a trend with delta such as "+12%". size s (1x1, default), w (wide 2x1), t (tall 1x2), l (large 2x2). style glass (default card), tint (theme-tinted card) or vivid (full theme gradient with white text: use for at most one or two tiles that matter most). +Ring(label: string, items: {label: string, value: string | number, max?: number, unit?: string}[], opts?: {variant?: "rings" | "gauge", center?: string, sub?: string}) — Progress toward goals as glowing concentric activity rings (1-3 items, each value out of max, default 100) with a legend, or variant "gauge": a semicircle dial with a needle for the first item (a score, a rate, a level). center replaces the default percentage in the middle; sub is a short caption. +Spotlight(title: string, sub?: string, picture?: string, opts?: {eyebrow?: string, value?: string | number, unit?: string, tags?: string[], photo?: string}) — An immersive featured card on the theme gradient with a large floating 3D picture: today's pick, the recommended option, the headline result. title, sub, picture (one emoji), optional eyebrow, a value with unit and 1-3 short tags. photo is an exact subject query for a full-bleed real photo behind the text (a place, a dish, a product); picture is the emoji fallback. Use one per page, near the top. +Shelf(items: {id?: string, title: string, sub?: string, picture?: string, value?: string | number, tag?: string, photo?: string}[], action?: ActionExpression, label?: string, opts?: {size?: "s" | "m" | "l"}) — A horizontally scrolling shelf of cards, each with a large 3D picture on a tinted stage, a title, a sub line, an optional value (price, rating, time) and a tag: dishes, places, products, outfits, books, options to browse. photo is an exact subject query (浅草寺, 阳光玫瑰葡萄, Sony WH-1000XM6) for a real photo the host finds; picture stays the emoji shown until the photo arrives or when none is found. Use photo for places, dishes, products and anything with a recognisable look. 3-8 items; size s, m (default) or l. With an action, selecting a card emits its id. +Ticket(title: string, from: string, to: string, opts?: {fromLabel?: string, toLabel?: string, kind?: "flight" | "train" | "bus" | "event" | "movie", fields?: {label: string, value: string | number}[], code?: string, picture?: string}) — A boarding-pass style ticket with notches, a dashed tear line and a barcode: from and to as short codes or names (PEK, 上海虹桥), their labels, kind flight, train, bus, event or movie, up to 6 fields such as date, time, gate, seat, and a booking code. Use for trips, events, shows and reservations. +Countdown(label: string, target: string, opts?: {sub?: string, done?: string}) — A live countdown in large day, hour, minute and second cells on a dramatic theme backdrop. target is an ISO date or date-time in the future; done is the text shown once it is reached. Use for launches, trips, exams, birthdays and deadlines. +Ranking(items: {name: string, value?: string | number, sub?: string, picture?: string}[], label?: string, opts?: {unit?: string}) — A leaderboard: the first three on a gold, silver and bronze podium, the rest as numbered rows. Items are in rank order with name, value, an optional sub line and an optional emoji picture; unit follows each value. +BarList(items: {label: string, value: number, picture?: string, tone?: "success" | "warning" | "danger", note?: string}[], label?: string, opts?: {unit?: string, max?: number, highlight?: string}) — Horizontal bars that grow in to compare amounts across 2-10 named items (spending by category, votes, scores, calories). Each item has label, numeric value, optional emoji picture, tone and a short note; highlight names the item to emphasise; max sets the full bar (defaults to the largest value). +Heatmap(label: string, values: number[], opts?: {unit?: string, max?: number}) — A habit or activity calendar like a contribution graph: values are daily amounts, oldest first, filled into weekly columns of 7 days (use 28-112 values; 0 is a rest day). Shows the total and the current streak. Bind values to state to let the page add today. +Statement(text: string, cite?: string, opts?: {picture?: string}) — One sentence set large like a poster quote with a gradient quotation mark: a motto, the key takeaway, a quote with its source in cite. Use at most once per page. +MonthCalendar(value?: string, marks?: {date: string, label?: string, tone?: "accent" | "success" | "warning" | "danger"}[], opts?: {month?: string, weekStart?: "monday" | "sunday", label?: string}) — A month calendar: month title with previous, next and today controls, weekday header aligned to the day columns, today ringed, the selected day filled, and up to three dots under days that have marks. Tapping a day selects it and lists that day's marks below the grid. value is the selected day as YYYY-MM-DD: bind it to a string state such as $day to drive other blocks. marks are {date: YYYY-MM-DD, label, tone} entries for plans, deadlines or events; tone success, warning or danger colours the dot. month (YYYY-MM) sets the first month shown; weekStart monday (default) or sunday. Use it for every month or date-picking view; never build a calendar from Grid, Pressable, Box or Text. ## Built-in Functions @@ -321,6 +333,47 @@ Page structure: - Compose for a phone that may be unfolded or turned sideways. Never set widths, columns or pixel sizes. On a narrow screen the blocks stack; on a wide screen (an unfolded foldable or landscape) the same page is turned wide: the cover becomes a header row and every block spans the full width across the fold, never page columns. Put peers the reader compares at a glance (two teams' scores, before and after, budget and spent) in one Layout grid so they sit in one row when wide; keep the main block near the top so a wide screen shows it without scrolling. Do not use Col, Row, Card, Title or Text for page structure; keep them for small custom pieces inside a block that no page block covers. - Write all copy in the user's language; Chinese requests get Chinese copy, the eyebrow stays the English name. Label sample or assumed numbers as such. Do not invent extra panels, slogans or duplicate summaries; add only the blocks the task needs. +Showcase blocks and page recipes (make the page look designed, not like a form): +- Prefer the showcase blocks whenever they fit the content: Bento with Tile widgets for 3-7 key numbers; Ring for goals and completion (rings) or a score, level or rate (gauge); Spotlight for the one featured recommendation or result; Shelf for options, places, dishes or products to browse; Ticket for any trip, booking, show or event pass; Countdown for anything with a future date; Ranking for ordered winners; BarList to compare amounts; Heatmap for habits and streaks; Statement for one memorable line. Mix shapes: a page should not be a stack of identical cards. +- Pick one mood for the whole page and let every block follow it: Page(..., {mood: "night"}) for live scoreboards, games, cinema, concerts and night events; "vivid" for celebrations, launches and highlights; "calm" for study, health, tools and planning. Omit mood when nothing calls for one, so the person's chosen look decides. Never mix a dark stage block into a calm page by hand. +- Give every page one focal point near the top (Spotlight, a vivid "l" Tile, a Ring, a Countdown or a Ticket), then supporting blocks, then details (Timeline, Checklist, ItemList, CompareTable, Faq). +- Calendars and schedules: use MonthCalendar($day, marks) for any month view or date picking, with $day = "" (empty starts on today), and show the selected day's details with Timeline or ItemList computed from $day. Never assemble a calendar from Grid, Pressable, Box or Text. For a calendar or schedule cover use the 🗓️ picture, never 📅 or 📆, whose artwork shows a fixed date. +- Real photos: SearchImage(query), Shelf item photo and Spotlight photo show a real photo the phone finds for an exact subject query (the landmark, the dish, the product model). Give every place, dish and product a photo query with its emoji as the picture fallback; keep emoji-only pictures for abstract things and widgets. +- Tiles: use emoji pictures for concrete subjects, at most two vivid tiles per Bento, and real deltas only when the data supports them. +- Cover variant "immersive" opens event, trip, launch, celebration, game and night-themed pages; feature covers suit guides and knowledge; compact covers suit tools and trackers. +- Recipes (adapt, never pad with blocks the task does not need): + - Dashboard or tracker: compact Cover, Bento of Tiles (one "l" or vivid tile for the headline), Ring, TrendChart or Heatmap, then ItemList. + - Trip or itinerary: immersive Cover, Countdown to departure, Ticket, Timeline per day, Shelf of places, Checklist to pack. + - Event or celebration: immersive Cover, Countdown, Ticket or Spotlight, Timeline, Checklist. + - Health or habit: feature Cover, Ring of daily goals, Bento of Tiles, Heatmap bound to state, FormCard to log. + - Recommendation or shopping: feature Cover, Spotlight for the best pick, Shelf of alternatives, CompareTable or BarList, ProCon. + - Learning: feature Cover, Ring or Progress, Shelf of topics, Timeline plan, Faq or Flashcards, Statement for the key idea. + - Ranking or comparison: compact Cover, Ranking, BarList, CompareTable, Note. + +Example — a trip with showcase blocks: +``` +root = Page([cover, count, ticket, sights, plan], "东京五日游", "teal") +cover = Cover("东京五日游", "Tokyo Trip", "3 月 28 日出发 · 樱花季", "🗼", {variant: "immersive", tags: ["5 天 4 晚", "2 人", "预算 ¥18,000"]}) +count = Countdown("距离出发", "2027-03-28T08:30:00", {sub: "记得提前一天办理值机"}) +ticket = Ticket("国航 CA925", "PEK", "NRT", {fromLabel: "北京首都 T3", toLabel: "东京成田 T1", kind: "flight", fields: [{label: "日期", value: "3月28日"}, {label: "起飞", value: "08:30"}, {label: "座位", value: "32A"}], code: "CA925-0328"}) +sights = Shelf([{title: "浅草寺", sub: "雷门与仲见世通", picture: "⛩️", photo: "东京浅草寺雷门", tag: "必去"}, {title: "上野公园", sub: "赏樱胜地", picture: "🌸", photo: "上野公园樱花", value: "免费"}, {title: "筑地场外市场", sub: "早餐吃海鲜", picture: "🍣", photo: "筑地场外市场"}], null, "精选景点") +plan = Timeline([{time: "D1", title: "抵达 · 浅草"}, {time: "D2", title: "上野 · 秋叶原"}, {time: "D3", title: "镰仓一日游"}]) +``` + +Example — a fitness dashboard: +``` +root = Page([cover, board, week], "今日运动", "green") +cover = Cover("今日运动", null, "周三 · 目标完成 72%", null, {variant: "compact"}) +board = Bento([rings, steps, kcal, water, sleep]) +rings = Ring("今日目标", [{label: "活动", value: 420, max: 600, unit: "千卡"}, {label: "锻炼", value: 28, max: 30, unit: "分钟"}, {label: "站立", value: 9, max: 12, unit: "小时"}]) +steps = Tile("步数", 8432, "步", {size: "w", style: "vivid", picture: "👟", progress: 0.84, trend: "up", delta: "+1,200"}) +kcal = Tile("消耗", 420, "千卡", {picture: "🔥"}) +water = Tile("饮水", 1.6, "升", {picture: "💧", progress: 0.8}) +sleep = Tile("睡眠", "7h 20m", null, {picture: "🌙", style: "tint"}) +$days = [3, 5, 0, 6, 4, 7, 2, 5, 6, 0, 4, 8, 6, 5, 7, 3, 0, 6, 5, 4, 7, 8, 6, 0, 5, 7, 6, 4] +week = Heatmap("近四周运动", $days, {unit: " 次"}) +``` + Interactive tools (from the reference agent's tool guidance): - Before composing an interactive tool, decide the user's task phase and urgency. Immediate casual use should start with usable editable defaults and the primary action; put infrequent rules, naming and configuration in a discoverable More/settings dialog. - Use a compact task title on immediate-action tools; omit decorative covers, repeated rule badges and instructional filler unless the user requests them. Give the active controls and primary result the useful screen space. diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/runtime-manifest.json b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/runtime-manifest.json index f9a2649..9e72c16 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/runtime-manifest.json +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/rawfile/genui/runtime-manifest.json @@ -19,8 +19,8 @@ "designSpec" ], "toolName": "GenerativeUI", - "catalogHash": "6eb64054194ee299c9ee011e9e0c5011be2aee7fd60ff43ed9dca283279aa208", - "promptHash": "dc709398f3ad05f6749ba1ce5f21f8c79cce4fd1c7b9543e636a03d6603c1eb7", + "catalogHash": "42b37acc6e678dbf9e8769a68f925a1eb3e1ae5fc2d218302ec7aa9c0d1c84b9", + "promptHash": "078844a51f0194853d186e34bf62e203aaff6aa2ffc1278a6a0baa08659ff0a2", "toolSchemaHash": "adde0eec7669746b2d9afe9b39a45a18af0b2e8a109fde5219de0a4ed66716e3", - "rendererRevision": "openbitfun.harmony.v1@4+6eb64054194e" + "rendererRevision": "openbitfun.harmony.v1@4+42b37acc6e67" } diff --git a/src/apps/mobile/harmonyos/entry/src/main/resources/zh_CN/element/string.json b/src/apps/mobile/harmonyos/entry/src/main/resources/zh_CN/element/string.json index 1a941b9..37cc196 100644 --- a/src/apps/mobile/harmonyos/entry/src/main/resources/zh_CN/element/string.json +++ b/src/apps/mobile/harmonyos/entry/src/main/resources/zh_CN/element/string.json @@ -1,5 +1,61 @@ { "string": [ + { + "name": "miniapp_shortcutHint", + "value": "滑动浏览 · 长按封面拖到桌面" + }, + { + "name": "miniapp_dropShortcut", + "value": "拖到这里添加桌面图标" + }, + { + "name": "miniapp_releaseShortcut", + "value": "松开以添加桌面图标" + }, + { + "name": "miniapp_pinned", + "value": "已添加桌面图标" + }, + { + "name": "miniapp_alreadyPinned", + "value": "该图标已在桌面" + }, + { + "name": "miniapp_pinLimit", + "value": "桌面快捷方式数量已达上限" + }, + { + "name": "miniapp_pinFailed", + "value": "系统未能添加桌面图标(%1$s)" + }, + { + "name": "miniapp_actions", + "value": "小应用操作" + }, + { + "name": "miniapp_pinIcon", + "value": "添加桌面图标" + }, + { + "name": "settings_genui_look", + "value": "小应用风格" + }, + { + "name": "settings_genui_classic", + "value": "原生" + }, + { + "name": "settings_genui_aurora", + "value": "极光" + }, + { + "name": "settings_genui_blueprint", + "value": "蓝图" + }, + { + "name": "settings_genui_celadon", + "value": "青瓷" + }, { "name": "session_newTitle", "value": "新会话" diff --git a/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.tsx b/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.tsx index a75e213..0fd50b8 100644 --- a/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.tsx +++ b/src/apps/mobile/harmonyos/genui-runtime/src/GenUIApplication.tsx @@ -15,13 +15,15 @@ import type { GenUIAsyncRuntime, GenUIProviderInput, GenUITargetEvent } from './ import { createGenUIAsyncRuntime } from './genUIAsyncCapabilities'; import { HARMONY_STYLE_RESOURCE_CSS } from './components/vendor/harmonyStyles'; import { HARMONY_GENUI_SCOPED_CSS } from './components/vendor/harmony-genui/harmonyGenuiStyles.generated'; -import { HARMONY_AURORA_CSS } from './components/harmonyAuroraStyles'; +import { appearanceFor, AnimatedCoverContext } from './components/harmonyLooks'; +import { HARMONY_SHOWCASE_CSS } from './components/harmonyShowcaseStyles'; import { harmonyPresentation } from './harmonyPresentation'; import type { GenUIRenderDiagnostic } from './genUIRenderDiagnostics'; import { installGenUIGenerationPresentation, type GenUIGenerationPresentation } from './genUIGenerationPresentation'; export interface GenUIApplicationProps { product?: GenUIProduct; + look?: string; definition: GenUIAppEnvelope; initialState?: GenUIAppState; readOnly?: boolean; @@ -49,7 +51,7 @@ export default function GenUIApplication(props: GenUIApplicationProps) { return ; } -function Application({ product = genUIProduct, definition, initialState, readOnly = false, preview = false, streaming = false, restoredFromStorage = false, onStateChange, persistState = true, onAction, toolProvider, asyncProvider, asyncPermissions, asyncTarget = 'local', asyncTargetId, onTargetEvent, htmlBridge, onVerification, hostShell = 'emulated', onParseResult }: GenUIApplicationProps) { +function Application({ look, product = genUIProduct, definition, initialState, readOnly = false, preview = false, streaming = false, restoredFromStorage = false, onStateChange, persistState = true, onAction, toolProvider, asyncProvider, asyncPermissions, asyncTarget = 'local', asyncTargetId, onTargetEvent, htmlBridge, onVerification, hostShell = 'emulated', onParseResult }: GenUIApplicationProps) { const stream = useRef(new GenUIStream()); const sourceKey = genUIContentKey(definition); const app = useMemo(() => (streaming ? stream.current.project(definition, product.catalog) : definition as GenUIAppDefinition), [definition, streaming, product]); @@ -59,7 +61,10 @@ function Application({ product = genUIProduct, definition, initialState, readOnl const library = libraryFor(app, product.catalog); const source = app.source; const harmony = app.libraryId.startsWith('openbitfun.harmony'); + const appearance = appearanceFor(look); const harmonyStyle = harmonyPresentation(app); + // The page mood: the program's choice, else the look's natural one. + const harmonyMood = harmonyStyle.mood ?? (appearance.id === 'aurora' ? 'vivid' : 'calm'); // Keep one async controller for the mounted FlowChat application. The // source key still changes for admission and late-result isolation, but it // must not remount every map/image component as OpenUI receives fragments. @@ -161,11 +166,13 @@ function Application({ product = genUIProduct, definition, initialState, readOnl return
Semantic graph GenUI documents are no longer supported. Generate a complete OpenUI or HTML source document.
; } return -
+
{harmony ?