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