1
2/*
3 * Copyright (c) 2023 Huawei Device Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import { OtaPage } from './OtaPage';
18import { NotificationHelper } from './notify/NotificationHelper';
19import type { INotify, IPage } from '@ohos/common/src/main/ets/manager/UpgradeInterface';
20
21/**
22 * 升级适配器
23 *
24 * @since 2022-12-01
25 */
26export class UpgradeAdapter {
27  private _notifyInstance: INotify;
28  private _page: IPage;
29
30  private constructor() {
31    globalThis.upgradeAdapter = this;
32  }
33
34  /**
35   * 取单例对象
36   *
37   * @return 适配器对象
38   */
39  static getInstance(): UpgradeAdapter {
40    return (globalThis.upgradeAdapter as UpgradeAdapter) ?? new UpgradeAdapter();
41  }
42
43  /**
44   * 取支持的升级类型以及UX实例
45   *
46   * @return 支持的升级类型以及UX实例
47   */
48  getPageInstance(): IPage {
49    if (!this._page) {
50      this._page = new OtaPage();
51    }
52    return this._page;
53  }
54
55  /**
56   * 取提醒对象
57   *
58   * @return 提醒对象
59   */
60  getNotifyInstance(): INotify {
61    if (!this._notifyInstance) {
62      this._notifyInstance = new NotificationHelper();
63    }
64    return this._notifyInstance;
65  }
66}