1/**
2 * Copyright (c) 2021 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 BaseModel from '../model/BaseModel';
17import ConfigData from './ConfigData';
18import LogUtil from './LogUtil';
19import { GlobalContext } from './GlobalContext';
20
21export class GlobalResourceManager extends BaseModel {
22  public async getStringByResource(res: Resource): Promise<string> {
23    let json = JSON.parse(JSON.stringify(res));
24    let id = json.id;
25    return await this.getStringById(id);
26  }
27
28  public getStringById(id: number): Promise<string> {
29    let promise = new Promise<string>(resolve => {
30      let context = GlobalContext.getContext().getObject(GlobalContext.globalKeySettingsAbilityContext) as Context;
31      let resourceMgr = context.resourceManager;
32      resourceMgr.getString(id)
33        .then((resource) => {
34          resolve(resource);
35          LogUtil.info('getStringById resolve(resource) : ' + resolve(resource));
36          LogUtil.info('getStringById resource : ' + resource);
37          LogUtil.info('getStringById resource2 : ' + JSON.stringify(resource));
38        })
39        .catch((err) => {
40          LogUtil.info('getStringById err : ' + JSON.stringify(err));
41        });
42    });
43    LogUtil.info('getStringById promise: ' + JSON.stringify(promise));
44    return promise;
45  }
46}
47
48let mGlobalResourceManager = new GlobalResourceManager();
49
50export default mGlobalResourceManager as GlobalResourceManager
51;
52