1/* 2 * Copyright (c) 2025 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 */ 15 16import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 17import UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility'; 18import { HiLog } from '../common/HiLog'; 19import Constants from '../common/constant'; 20import Want from '@ohos.app.ability.Want'; 21import OpeningDialogService from '../rpc/OpeningDialog/service/OpeningDialogService'; 22import CommonEventManager from '../common/CommonEventManager'; 23 24const TAG = 'OpeningDialogUIExt'; 25 26export default class OpeningDialogUIExtAbility extends UIExtensionAbility { 27 async onSessionCreate(want: Want, session: UIExtensionContentSession): Promise<void> { 28 HiLog.info(TAG, 'OpeningDialogUIExtAbility onSessionCreate start'); 29 try { 30 session.loadContent('pages/OpeningDialog'); 31 session.setWindowBackgroundColor(Constants.TRANSPARENT_BACKGROUND_COLOR); 32 CommonEventManager.getInstance().init(); 33 } catch (error) { 34 HiLog.wrapError(TAG, error, 'loadContent failed'); 35 } 36 OpeningDialogService.getInstance().setContext(this.context); 37 OpeningDialogService.getInstance().connectViewAbility(); 38 } 39 40 onSessionDestroy(session: UIExtensionContentSession): void { 41 HiLog.info(TAG, 'OpeningDialogUIExtAbility onSessionDestroy'); 42 CommonEventManager.getInstance().unsubscribe(); 43 OpeningDialogService.getInstance().disconnectViewAbility(); 44 } 45 46 onWindowStageDestroy(): void { 47 HiLog.info(TAG, 'OpeningDialogUIExtAbility onWindowStageDestroy'); 48 } 49 50 onForeground(): void { 51 HiLog.info(TAG, 'OpeningDialogUIExtAbility onForeground'); 52 } 53 54 onBackground() { 55 HiLog.info(TAG, 'OpeningDialogUIExtAbility onBackground'); 56 } 57}; 58