1/**
2 * Copyright (c) 2021-2022 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 AbilityManager from './abilitymanager/abilityManager'
16
17/**
18 * Resource util
19 */
20export class ResourceUtil {
21  private resMgr;
22
23  /**
24   * Initialize ResourceManager
25   */
26  async initResourceManager(abilityName?: string): Promise<void> {
27    if (!this.resMgr) {
28
29      let context;
30      if(abilityName === AbilityManager.ABILITY_NAME_NOTIFICATION_MANAGEMENT) {
31        context = AbilityManager.getAbilityContext(abilityName);
32      } else {
33        context = AbilityManager.getContext(abilityName);
34      }
35      this.resMgr = await context.resourceManager;
36    }
37    return this.resMgr;
38  }
39
40  /**
41   * Get string value from NormalResource instance
42   *
43   * @param resource - NormalResource instance
44   */
45  async getString(resource): Promise<string> {
46    return await this.resMgr.getString(resource.id);
47  }
48
49  /**
50   * Get direction value from NormalResource instance
51   *
52   * @param resource - NormalResource instance
53   */
54  async getConfiguration(): Promise<string> {
55    return await this.resMgr.getConfiguration();
56  }
57}
58
59let resourceUtil = new ResourceUtil();
60
61export default resourceUtil as ResourceUtil;