!595 桌面展示分层图标

Merge pull request !595 from lanpangzii/master
This commit is contained in:
openharmony_ci 2024-11-22 11:03:19 +00:00 committed by Gitee
commit 72924ac251
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -17,6 +17,8 @@ import resourceManager from '@ohos.resourceManager';
import { Log } from '../utils/Log';
import { CheckEmptyUtils } from '../utils/CheckEmptyUtils';
import AppResourceCacheManager from '../cache/AppResourceCacheManager';
import { DrawableDescriptor, LayeredDrawableDescriptor } from '@ohos.arkui.drawableDescriptor';
import image from '@ohos.multimedia.image';
const KEY_ICON = 'icon';
const KEY_NAME = 'name';
@ -66,27 +68,36 @@ export class ResourceManager {
}
async updateIconCache(iconId, bundleName: string, moduleName: string): Promise<void> {
let cacheKey = `${iconId}${bundleName}${moduleName}`;
const iconBase64 = this.getAppResourceCache(cacheKey, KEY_ICON);
if (!CheckEmptyUtils.isEmpty(iconBase64)) {
return;
}
Log.showDebug(TAG, `updateIconCache bundleName:${bundleName}, moduleName:${moduleName}, iconId: ${iconId}`);
try {
let cacheKey = `${iconId}${bundleName}${moduleName}`;
const iconBase64 = this.getAppResourceCache(cacheKey, KEY_ICON);
if (!CheckEmptyUtils.isEmpty(iconBase64)) {
return;
// 先拿分层图标,拿不到再取普通图标
let resMgr: resourceManager.ResourceManager = globalThis.desktopContext.createModuleResourceManager(bundleName, moduleName);
let imageDescriptor: DrawableDescriptor = (resMgr.getDrawableDescriptor(Number(iconId), undefined));
let value: image.PixelMap = imageDescriptor.getPixelMap();
if (imageDescriptor instanceof LayeredDrawableDescriptor) {
Log.showDebug(TAG, 'updateIconCache layered icon');
this.setAppResourceCache(cacheKey, KEY_ICON, value);
} else {
let moduleContext = globalThis.desktopContext.createModuleContext(bundleName, moduleName);
if (moduleContext == null) {
return;
}
await moduleContext.resourceManager
.getMediaBase64(iconId)
.then((value) => {
Log.showDebug(TAG, 'updateIconCache normal icon');
if (value != null) {
this.setAppResourceCache(cacheKey, KEY_ICON, value);
}
}).finally(() => {
moduleContext = null;
});
}
Log.showDebug(TAG, `updateIconCache bundleName:${bundleName}, moduleName:${moduleName}, iconId: ${iconId}`);
let moduleContext = globalThis.desktopContext.createModuleContext(bundleName, moduleName);
if (moduleContext == null) {
return;
}
await moduleContext.resourceManager
.getMediaBase64(iconId)
.then((value)=> {
if (value != null) {
this.setAppResourceCache(cacheKey, KEY_ICON, value);
}
})
.finally(() => {
moduleContext = null;
});
} catch (error) {
Log.showError(TAG, `updateIconCache error ${error}`);
}