createIcons function
Creates OHOS launcher icons based on the provided config and flavor
Implementation
Future<void> createIcons(Config config, String? flavor) async {
utils.printStatus('Creating default icons for OHOS');
final String? foregroundFilePath = config.getImagePathOhosForeground();
final String? backgroundFilePath = config.getImagePathOhosBackground();
final bool hasLayeredPaths =
foregroundFilePath != null && backgroundFilePath != null;
if (hasLayeredPaths) {
final foreground = await utils.decodeImageFile(foregroundFilePath);
final background = await utils.decodeImageFile(backgroundFilePath);
if (foreground == null || background == null) {
return;
}
final String? startWindowFilePath = config.getImagePathOhos();
if (startWindowFilePath == null) {
throw const InvalidConfigException(constants.errorMissingImagePath);
}
final startWindowImage = await utils.decodeImageFile(startWindowFilePath);
if (startWindowImage == null) {
return;
}
utils.printStatus(
'Overwriting the default OHOS launcher icon with layered icons',
);
await Future.wait(<Future<void>>[
_copyLayeredIconWithoutResize(
sourceImage: background,
fileName: layeredOhosIcons[0].fileName,
),
_copyLayeredIconWithoutResize(
sourceImage: foreground,
fileName: layeredOhosIcons[1].fileName,
),
]);
await overwriteExistingIcons(
_startWindowOhosIcon,
startWindowImage,
flavor,
targetPaths: <String>[
_entryMainStartIconPath,
],
);
await _deleteFilesIfExists(<String>[
_appScopeIconPath,
_entryMainIconPath,
]);
await _createLayeredImageJsonIfNeeded();
await _replaceStartWindowIconRef(r'$media:startIcon');
await _replaceAbilityIconOnlyRef(r'$media:layered_image');
await _replaceAppScopeIconRef(r'$media:layered_image');
return;
}
final String? filePath = config.getImagePathOhos();
if (filePath == null) {
throw const InvalidConfigException(constants.errorMissingImagePath);
}
final Image? image = await utils.decodeImageFile(filePath);
if (image == null) {
return;
}
utils.printStatus(
'Overwriting the default OHOS launcher icon with a new icon',
);
final concurrentIconUpdates = <Future<void>>[];
for (OhosIconTemplate template in singleImageOhosIcons) {
concurrentIconUpdates.add(
overwriteExistingIcons(
template,
image,
flavor,
),
);
}
await Future.wait(concurrentIconUpdates);
await _deleteFilesIfExists(<String>[
_appScopeAppIconPath,
_appScopeBackgroundPath,
_appScopeForegroundPath,
_entryMainBackgroundPath,
_entryMainForegroundPath,
_entryMainStartIconPath,
]);
await _deleteLayeredImageJsonIfExists();
await _replaceAbilityIconRefs(_singleIconMediaRef);
await _replaceAppScopeIconRef(_singleAppScopeIconMediaRef);
}