run method

Future<void> run()

Implementation

Future<void> run() async {
  if (config.enable == false) {
    // 设置为 false,则不执行
    return;
  }

  // get 1024 icons
  File? iconFile = File(appIconPath);
  if (!iconFile.existsSync()) {
    print("android icon generator,app icon file is not exist");
    return;
  }

  Image? icon = decodeImage(iconFile.readAsBytesSync());
  if (icon == null) {
    print("android icon generator,app icon can not decode");
    return;
  }
  if (icon.width != 1024) {
    print("android icon generator,app icon width != 1024");
    return;
  } else if (icon.height != 1024) {
    print("android icon generator,app icon height != 1024");
    return;
  }

  // 移除旧的
  await _removeAppIconFromManifest('android:icon');
  await _removeFirebaseNotificationIconFromManifest();

  Image? round_app_icon;
  if (config.enableCircleIcon == true) {
    round_app_icon = ImageUtil.createCircleIcon(icon);
    await _removeAppIconFromManifest('android:roundIcon');
  }

  Image? notificationIcon;
  String firebaseNotificationIconPath = config.firebaseNotificationIcon ?? '';
  if (firebaseNotificationIconPath.isNotEmpty) {
    notificationIcon = decodeImage(File(firebaseNotificationIconPath).readAsBytesSync());
    savePngImage(image: notificationIcon, path: "$androidAppSrcMainFolder/res/drawable/$icNotificationName");
  }

  for (final Map<String, dynamic> map in constAndroidLauncherIcon) {
    await _saveIcons(map, icon, round_app_icon);
  }

  await _updateAppIconInManifest('android:icon', '@mipmap/${icName.split('.').first}');
  if (round_app_icon != null) {
    await _updateAppIconInManifest('android:roundIcon', '@mipmap/${icRoundName.split('.').first}');
  }
  await _updateFirebaseNotificationIconInManifest('@drawable/${icNotificationName.split('.').first}');
  print('android icon generated');
}