• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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 */
15
16import UIAbility from '@ohos.app.ability.UIAbility';
17import hilog from '@ohos.hilog';
18import window from '@ohos.window';
19import AcCtrl from '@ohos.abilityAccessCtrl';
20import {Core} from 'deccjsunit/index';
21
22let AcManager = AcCtrl.createAtManager();
23export default class MainAbility extends UIAbility {
24    onCreate(want, launchParam) {
25        console.info('AceApplication onCreate');
26        const core = Core.getInstance();
27        core.init();
28        const configService = core.getDefaultService('config');
29        configService.setConfig(this);
30
31        console.info('Calc[IndexPage] grantPermission');
32        AcManager.requestPermissionsFromUser(this.context, ['ohos.permission.DISTRIBUTED_DATASYNC'], function (result) {
33            console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser');
34        });
35    }
36
37    onDestroy() {
38        console.info("onDestroy");
39    }
40
41    onWindowStageCreate(windowStage: window.WindowStage) {
42        // Main window is created, set main page for this ability
43        hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
44
45        windowStage.loadContent('pages/Index', (err, data) => {
46          if (err.code) {
47            hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
48            return;
49          }
50            hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
51        });
52      }
53
54    onWindowStageDestroy() {
55        // Main window is destroyed, release UI related resources
56        console.info("onWindowStageDestroy");
57    }
58
59    onForeground() {
60        // Ability has brought to foreground
61        console.info("onForeground");
62    }
63
64    onBackground() {
65        // Ability has back to background
66        console.info("onBackground");
67    }
68
69};
70