1{"version":3,"file":"withAndroidNotifications.js","names":["_configPlugins","data","require","_imageUtils","_fsExtra","_interopRequireDefault","_path","_withAndroidIcons","obj","__esModule","default","Colors","AndroidConfig","addMetaDataItemToMainApplication","getMainApplicationOrThrow","removeMetaDataItemFromMainApplication","Manifest","BASELINE_PIXEL_SIZE","META_DATA_NOTIFICATION_ICON","exports","META_DATA_NOTIFICATION_ICON_COLOR","NOTIFICATION_ICON","NOTIFICATION_ICON_RESOURCE","NOTIFICATION_ICON_COLOR","NOTIFICATION_ICON_COLOR_RESOURCE","withNotificationIcons","config","withDangerousMod","setNotificationIconAsync","modRequest","projectRoot","withNotificationIconColor","withAndroidColors","modResults","setNotificationIconColor","withNotificationManifest","withAndroidManifest","setNotificationConfig","getNotificationIcon","_config$notification","notification","icon","getNotificationColor","_config$notification2","color","writeNotificationIconImageFilesAsync","removeNotificationIconImageFilesAsync","manifest","mainApplication","colors","assignColorValue","name","value","Promise","all","Object","values","dpiValues","map","folderName","scale","drawableFolderName","replace","dpiFolderPath","path","resolve","ANDROID_RES_PATH","fs","ensureDir","iconSizePx","resizedIcon","generateImageAsync","cacheType","src","width","height","resizeMode","backgroundColor","source","writeFile","e","Error","remove"],"sources":["../../../../src/plugins/unversioned/expo-notifications/withAndroidNotifications.ts"],"sourcesContent":["import {\n  AndroidConfig,\n  ConfigPlugin,\n  withAndroidColors,\n  withAndroidManifest,\n  withDangerousMod,\n} from '@expo/config-plugins';\nimport { ExpoConfig } from '@expo/config-types';\nimport { generateImageAsync } from '@expo/image-utils';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport { ANDROID_RES_PATH, dpiValues } from '../../icons/withAndroidIcons';\n\nconst { Colors } = AndroidConfig;\nconst {\n  addMetaDataItemToMainApplication,\n  getMainApplicationOrThrow,\n  removeMetaDataItemFromMainApplication,\n} = AndroidConfig.Manifest;\n\ntype AndroidManifest = AndroidConfig.Manifest.AndroidManifest;\nconst BASELINE_PIXEL_SIZE = 24;\nexport const META_DATA_NOTIFICATION_ICON = 'expo.modules.notifications.default_notification_icon';\nexport const META_DATA_NOTIFICATION_ICON_COLOR =\n  'expo.modules.notifications.default_notification_color';\nexport const NOTIFICATION_ICON = 'notification_icon';\nexport const NOTIFICATION_ICON_RESOURCE = `@drawable/${NOTIFICATION_ICON}`;\nexport const NOTIFICATION_ICON_COLOR = 'notification_icon_color';\nexport const NOTIFICATION_ICON_COLOR_RESOURCE = `@color/${NOTIFICATION_ICON_COLOR}`;\n\nexport const withNotificationIcons: ConfigPlugin = (config) => {\n  return withDangerousMod(config, [\n    'android',\n    async (config) => {\n      await setNotificationIconAsync(config, config.modRequest.projectRoot);\n      return config;\n    },\n  ]);\n};\n\nexport const withNotificationIconColor: ConfigPlugin = (config) => {\n  return withAndroidColors(config, (config) => {\n    config.modResults = setNotificationIconColor(config, config.modResults);\n    return config;\n  });\n};\n\nexport const withNotificationManifest: ConfigPlugin = (config) => {\n  return withAndroidManifest(config, (config) => {\n    config.modResults = setNotificationConfig(config, config.modResults);\n    return config;\n  });\n};\n\nexport function getNotificationIcon(config: ExpoConfig) {\n  return config.notification?.icon || null;\n}\n\nexport function getNotificationColor(config: ExpoConfig) {\n  return config.notification?.color || null;\n}\n\n/**\n * Applies configuration for expo-notifications, including\n * the notification icon and notification color.\n */\nexport async function setNotificationIconAsync(config: ExpoConfig, projectRoot: string) {\n  const icon = getNotificationIcon(config);\n  if (icon) {\n    await writeNotificationIconImageFilesAsync(icon, projectRoot);\n  } else {\n    await removeNotificationIconImageFilesAsync(projectRoot);\n  }\n}\n\nexport function setNotificationConfig(config: ExpoConfig, manifest: AndroidManifest) {\n  const icon = getNotificationIcon(config);\n  const color = getNotificationColor(config);\n  const mainApplication = getMainApplicationOrThrow(manifest);\n  if (icon) {\n    addMetaDataItemToMainApplication(\n      mainApplication,\n      META_DATA_NOTIFICATION_ICON,\n      NOTIFICATION_ICON_RESOURCE,\n      'resource'\n    );\n  } else {\n    removeMetaDataItemFromMainApplication(mainApplication, META_DATA_NOTIFICATION_ICON);\n  }\n  if (color) {\n    addMetaDataItemToMainApplication(\n      mainApplication,\n      META_DATA_NOTIFICATION_ICON_COLOR,\n      NOTIFICATION_ICON_COLOR_RESOURCE,\n      'resource'\n    );\n  } else {\n    removeMetaDataItemFromMainApplication(mainApplication, META_DATA_NOTIFICATION_ICON_COLOR);\n  }\n  return manifest;\n}\n\nexport function setNotificationIconColor(\n  config: ExpoConfig,\n  colors: AndroidConfig.Resources.ResourceXML\n) {\n  return Colors.assignColorValue(colors, {\n    name: NOTIFICATION_ICON_COLOR,\n    value: getNotificationColor(config),\n  });\n}\n\nasync function writeNotificationIconImageFilesAsync(icon: string, projectRoot: string) {\n  await Promise.all(\n    Object.values(dpiValues).map(async ({ folderName, scale }) => {\n      const drawableFolderName = folderName.replace('mipmap', 'drawable');\n      const dpiFolderPath = path.resolve(projectRoot, ANDROID_RES_PATH, drawableFolderName);\n      await fs.ensureDir(dpiFolderPath);\n      const iconSizePx = BASELINE_PIXEL_SIZE * scale;\n\n      try {\n        const resizedIcon = (\n          await generateImageAsync(\n            { projectRoot, cacheType: 'android-notification' },\n            {\n              src: icon,\n              width: iconSizePx,\n              height: iconSizePx,\n              resizeMode: 'cover',\n              backgroundColor: 'transparent',\n            }\n          )\n        ).source;\n        await fs.writeFile(path.resolve(dpiFolderPath, NOTIFICATION_ICON + '.png'), resizedIcon);\n      } catch (e) {\n        throw new Error('Encountered an issue resizing Android notification icon: ' + e);\n      }\n    })\n  );\n}\n\nasync function removeNotificationIconImageFilesAsync(projectRoot: string) {\n  await Promise.all(\n    Object.values(dpiValues).map(async ({ folderName }) => {\n      const drawableFolderName = folderName.replace('mipmap', 'drawable');\n      const dpiFolderPath = path.resolve(projectRoot, ANDROID_RES_PATH, drawableFolderName);\n      await fs.remove(path.resolve(dpiFolderPath, NOTIFICATION_ICON + '.png'));\n    })\n  );\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAAA,eAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAA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