• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 { DlpAlertDialog } from '../common/components/dlp_alert_dialog';
17import GlobalContext from '../common/GlobalContext';
18import { getAlertMessage } from '../common/utils';
19import common from '@ohos.app.ability.common';
20import Want from '@ohos.app.ability.Want';
21import { BusinessError } from '@ohos.base'
22
23const TAG = '[DLPManager_Alert]';
24
25@Entry
26@Component
27struct Index {
28  dlpAlertDialog?: CustomDialogController;
29
30  showErrorDialogAndExit(title: Resource, message: Resource) {
31    this.dlpAlertDialog = new CustomDialogController({
32      builder: DlpAlertDialog({
33        title: title,
34        message: message,
35      }),
36      autoCancel: false,
37      cancel: () => {
38        (GlobalContext.load('context') as common.UIAbilityContext).terminateSelf();
39      },
40      alignment: DialogAlignment.Center,
41      customStyle: true,
42    })
43    this.dlpAlertDialog.open();
44  }
45
46  async aboutToAppear() {
47    try {
48      let errInfo = getAlertMessage((GlobalContext.load('abilityWant') as Want).parameters?.error as BusinessError);
49      this.showErrorDialogAndExit(errInfo.title as Resource, errInfo.msg as Resource);
50    } catch (err) {
51      console.error(TAG, 'showErrorDialog failed ' + JSON.stringify(err as BusinessError));
52    }
53  }
54
55  build() { }
56}
57