• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 UIExtensionAbility from '@ohos.app.ability.UIExtensionAbility';
16import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
17import Want from '@ohos.app.ability.Want';
18import { Configuration } from '@ohos.app.ability.Configuration';
19import { logger } from '../utils/Logger';
20
21const TAG: string = '[ContinueSwitchAbility]';
22
23export default class ContinueSwitchAbility extends UIExtensionAbility {
24  onCreate() {
25    logger.info(`${TAG} UIExtAbility onCreate`);
26    AppStorage.setOrCreate('currentColorMode', this.context.config.colorMode);
27    AppStorage.setOrCreate('currentFontSizeScale', this.context.config.fontSizeScale);
28  }
29
30  onConfigurationUpdate(newConfig: Configuration) {
31    AppStorage.setOrCreate('currentColorMode', this.context.config.colorMode);
32    AppStorage.setOrCreate('currentFontSizeScale', this.context.config.fontSizeScale);
33  }
34
35  onForeground() {
36    logger.info(`${TAG} UIExtAbility onForeground`);
37  }
38
39  onBackground() {
40    logger.info(`${TAG} UIExtAbility onBackground`);
41  }
42
43  onDestroy() {
44    logger.info(`${TAG} UIExtAbility onDestroy`);
45  }
46
47  onSessionCreate(want: Want, session: UIExtensionContentSession) {
48    logger.info(`${TAG} UIExtAbility onSessionCreate.`);
49    let parameters = want.parameters;
50    let pushParams = want.parameters?.pushParams as string | undefined;
51    let startReason = '';
52    let isShowBack =
53      pushParams?.includes('isShowBack') ? (pushParams.includes('isShowBack:false') ? false : true) : true;
54    let navigationMode = NavigationMode.Auto;
55
56    if (parameters) {
57      startReason = parameters.startReason as string;
58      navigationMode = parameters.navigationMode as NavigationMode;
59    }
60
61    if (startReason === 'from_search' && navigationMode === NavigationMode.Split) {
62      logger.info(`${TAG} navigationMode: ${navigationMode}`);
63      isShowBack = false;
64    }
65
66    AppStorage.setOrCreate('continueSession', session);
67    AppStorage.setOrCreate('startReason', startReason);
68    AppStorage.setOrCreate('isShowBack', isShowBack);
69    let param: Record<string, UIExtensionContentSession> = {
70      'session': session
71    };
72    let storage: LocalStorage = new LocalStorage(param);
73    session.loadContent('pages/ContinueSwitch', storage);
74    logger.info(`${TAG} onSessionCreate end. startReason: ${startReason}, isShowBack: ${isShowBack}`);
75  }
76
77  onSessionDestroy(session: UIExtensionContentSession) {
78    logger.info(`${TAG} UIExtAbility onSessionDestroy`);
79  }
80}