!594 RK3568 桌面不展示应用的分层图标

Merge pull request !594 from lanpangzii/OpenHarmony-5.0.1-Release
This commit is contained in:
openharmony_ci 2024-11-22 13:14:14 +00:00 committed by Gitee
commit a394209ecd
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}`);
}