1/*
2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 UIAbility from '@ohos.app.ability.UIAbility';
17import hilog from '@ohos.hilog';
18import window from '@ohos.window';
19import Want from '@ohos.app.ability.Want';
20import AbilityConstant from '@ohos.app.ability.AbilityConstant';
21
22export default class EntryAbility extends UIAbility {
23  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
24    AppStorage.setOrCreate('cameraContext', this.context)
25    console.log('[Demo] MainAbility onCreate')
26    const that = this
27    this.context.eventHub.on("getAbilityData", (data: Record<string, Object>) => {
28      data.context = that.context
29      data.launchWant = want
30    })
31    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
32  }
33
34  onDestroy() {
35    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
36  }
37
38  onWindowStageCreate(windowStage: window.WindowStage) {
39    // Main window is created, set main page for this ability
40    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
41    windowStage.getMainWindow().then((win: window.Window) => {
42      win.setWindowKeepScreenOn(true);
43    });
44    windowStage.loadContent('pages/Index', (err, data) => {
45      if (err.code) {
46        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
47        return;
48      }
49      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
50    });
51  }
52
53  onWindowStageDestroy() {
54    // Main window is destroyed, release UI related resources
55    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
56  }
57
58  onForeground() {
59    // Ability has brought to foreground
60    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
61  }
62
63  onBackground() {
64    // Ability has back to background
65    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
66  }
67}
68