Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<string, Object> | 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', '当前身份'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { MiniAppDragOverlay } from './MiniAppDragOverlay';
import { SessionDetailsOverlay } from './SessionDetailsOverlay';
import { AdaptiveSheetContent } from './AdaptiveSheetContent';
import { RemoteCompactHomePolicy } from '../policy/RemoteCompactHomePolicy';
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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)
}
Expand All @@ -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() {
Expand All @@ -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}` : '');
}
})
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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();
Expand All @@ -37,17 +40,17 @@ 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 {
this.alive = false;
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 {
Expand Down Expand Up @@ -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');
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
})
}
}
Loading
Loading