1/* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import { hilog } from '@kit.PerformanceAnalysisKit'; 16import { BusinessError, commonEventManager } from '@kit.BasicServicesKit'; 17 18@Entry 19@Component 20struct Default { 21 aboutToAppear() { 22 hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility default aboutToAppear'); 23 24 } 25 26 @State message: string = 'ni' 27 private want: Want = { 28 bundleName: 'com.example.assistappa', 29 abilityName: 'EntryEmbeddedUIExtAbilityBundle', 30 parameters: {} 31 } 32 33 build() { 34 Row() { 35 Column() { 36 Text(this.message).fontSize(30) 37 EmbeddedComponent(this.want, EmbeddedType.EMBEDDED_UI_EXTENSION) 38 .width('100%') 39 .height('90%') 40 .onTerminated((info: TerminationInfo) => { 41 this.message = 'Terminarion: code = ' + info.code + ', want = ' + JSON.stringify(info.want); 42 console.log('shuzi', JSON.stringify(EmbeddedType.EMBEDDED_UI_EXTENSION)) 43 }) 44 .onError((error: BusinessError) => { 45 this.message = 'Error: code = ' + error.code; 46 console.log('default ', JSON.stringify(error)) 47 let commonEventPublishData: commonEventManager.CommonEventPublishData = { 48 parameters: { 49 data: error.code 50 } 51 } 52 commonEventManager.publish('ExtensionDefault', commonEventPublishData, async (error) => { 53 hilog.info(0x0000, 'testTag1', '%{public}s', `Embeddedextension publish: ${JSON.stringify(error)}`); 54 }) 55 }) 56 EmbeddedComponent(this.want, EmbeddedType.EMBEDDED_UI_EXTENSION) 57 .width('100%') 58 .height('90%') 59 .onTerminated((info: TerminationInfo) => { 60 this.message = 'Terminarion: code = ' + info.code + ', want = ' + JSON.stringify(info.want); 61 console.log('shuzi', JSON.stringify(EmbeddedType.EMBEDDED_UI_EXTENSION)) 62 }) 63 .onError((error: BusinessError) => { 64 this.message = 'Error: code = ' + error.code; 65 console.log('default ', JSON.stringify(error)) 66 let commonEventPublishData: commonEventManager.CommonEventPublishData = { 67 parameters: { 68 data: error.code 69 } 70 } 71 commonEventManager.publish('ExtensionDefault', commonEventPublishData, async (error) => { 72 hilog.info(0x0000, 'testTag1', '%{public}s', `Embeddedextension publish: ${JSON.stringify(error)}`); 73 }) 74 }) 75 } 76 .width('100%') 77 } 78 .height('100%') 79 } 80}