Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

onesignal-expo-plugin

Package Overview
Dependencies
Maintainers
6
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onesignal-expo-plugin - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

80

build/onesignal/withOneSignalAndroid.js

@@ -8,7 +8,83 @@ "use strict";

exports.withOneSignalAndroid = void 0;
const config_plugins_1 = require("@expo/config-plugins");
const image_utils_1 = require("@expo/image-utils");
const OneSignalLog_1 = require("../support/OneSignalLog");
const path_1 = require("path");
const fs_1 = require("fs");
const RESOURCE_ROOT_PATH = 'android/app/src/main/res/';
// The name of each small icon folder resource, and the icon size for that folder.
const SMALL_ICON_DIRS_TO_SIZE = {
'drawable-mdpi': 24,
'drawable-hdpi': 36,
'drawable-xhdpi': 48,
'drawable-xxhdpi': 72,
'drawable-xxxhdpi': 96
};
// The name of each large icon folder resource, and the icon size for that folder.
const LARGE_ICON_DIRS_TO_SIZE = {
'drawable-xxxhdpi': 256
};
const withSmallIcons = (config, onesignalProps) => {
var _a;
if (!onesignalProps.smallIcons && !((_a = config.notification) === null || _a === void 0 ? void 0 : _a.icon)) {
return config;
}
// we are modifying the android build (adding files) without a base mod
return (0, config_plugins_1.withDangerousMod)(config, [
'android',
async (config) => {
var _a;
if ((_a = config.notification) === null || _a === void 0 ? void 0 : _a.icon) {
await saveIconAsync(config.notification.icon, config.modRequest.projectRoot, SMALL_ICON_DIRS_TO_SIZE);
}
if (onesignalProps.smallIcons) {
await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.smallIcons, SMALL_ICON_DIRS_TO_SIZE);
}
return config;
},
]);
};
const withLargeIcons = (config, onesignalProps) => {
if (!onesignalProps.largeIcons) {
return config;
}
// we are modifying the android build (adding files) without a base mod
return (0, config_plugins_1.withDangerousMod)(config, [
'android',
async (config) => {
if (onesignalProps.largeIcons) {
await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.largeIcons, LARGE_ICON_DIRS_TO_SIZE);
}
return config;
},
]);
};
async function saveIconsArrayAsync(projectRoot, icons, dirsToSize) {
for (const icon of icons) {
await saveIconAsync(icon, projectRoot, dirsToSize);
}
}
async function saveIconAsync(icon, projectRoot, dirsToSize) {
const name = (0, path_1.parse)(icon).name;
OneSignalLog_1.OneSignalLog.log("Saving icon " + icon + " as drawable resource " + name);
for (const iconResourceDir in dirsToSize) {
const path = (0, path_1.resolve)(projectRoot, RESOURCE_ROOT_PATH, iconResourceDir);
if (!(0, fs_1.existsSync)(path)) {
(0, fs_1.mkdirSync)(path, { recursive: true });
}
const resizedIcon = (await (0, image_utils_1.generateImageAsync)({ projectRoot, cacheType: 'onesignal-icon' }, {
src: icon,
width: dirsToSize[iconResourceDir],
height: dirsToSize[iconResourceDir],
resizeMode: 'cover',
backgroundColor: 'transparent',
})).source;
(0, fs_1.writeFileSync)((0, path_1.resolve)(path, name + '.png'), resizedIcon);
}
}
const withOneSignalAndroid = (config, props) => {
//commented out until https://github.com/expo/eas-cli/issues/1226 is confirmed fixed
//OneSignalLog.log("No specific actions required for OneSignal on Android...");
config = withSmallIcons(config, props);
config = withLargeIcons(config, props);
return config;
};
exports.withOneSignalAndroid = withOneSignalAndroid;

@@ -5,2 +5,8 @@ # Changelog

## October 2022
### `1.2.0` - 10/25/22
#### Changes
- Add `smallIcons` and `largeIcons` configuration options to the plugin, which allows an app to specify large and small notification icons to package within the Android build.
- Bump jpeg-js from 0.4.3 to 0.4.4
- Bump simple-plist from 1.3.0 to 1.3.1
### `1.1.2` - 10/04/22

@@ -7,0 +13,0 @@ #### Fixes

@@ -6,6 +6,106 @@ /**

import { ConfigPlugin } from '@expo/config-plugins';
import { ConfigPlugin, withDangerousMod } from '@expo/config-plugins';
import { generateImageAsync } from '@expo/image-utils';
import { OneSignalLog } from '../support/OneSignalLog';
import { OneSignalPluginProps } from '../types/types';
import { resolve, parse } from 'path';
import { existsSync, mkdirSync, writeFileSync } from 'fs';
const RESOURCE_ROOT_PATH = 'android/app/src/main/res/';
// The name of each small icon folder resource, and the icon size for that folder.
const SMALL_ICON_DIRS_TO_SIZE: { [name: string]: number } = {
'drawable-mdpi': 24,
'drawable-hdpi': 36,
'drawable-xhdpi': 48,
'drawable-xxhdpi': 72,
'drawable-xxxhdpi': 96
};
// The name of each large icon folder resource, and the icon size for that folder.
const LARGE_ICON_DIRS_TO_SIZE: { [name: string]: number } = {
'drawable-xxxhdpi': 256
};
const withSmallIcons: ConfigPlugin<OneSignalPluginProps> = (
config,
onesignalProps
) => {
if(!onesignalProps.smallIcons && !config.notification?.icon) {
return config
}
// we are modifying the android build (adding files) without a base mod
return withDangerousMod(config, [
'android',
async (config) => {
if(config.notification?.icon) {
await saveIconAsync(config.notification.icon, config.modRequest.projectRoot, SMALL_ICON_DIRS_TO_SIZE)
}
if(onesignalProps.smallIcons) {
await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.smallIcons, SMALL_ICON_DIRS_TO_SIZE);
}
return config;
},
]);
};
const withLargeIcons: ConfigPlugin<OneSignalPluginProps> = (
config,
onesignalProps
) => {
if(!onesignalProps.largeIcons) {
return config
}
// we are modifying the android build (adding files) without a base mod
return withDangerousMod(config, [
'android',
async (config) => {
if(onesignalProps.largeIcons) {
await saveIconsArrayAsync(config.modRequest.projectRoot, onesignalProps.largeIcons, LARGE_ICON_DIRS_TO_SIZE);
}
return config;
},
]);
};
async function saveIconsArrayAsync(projectRoot: string, icons: string[], dirsToSize: { [name: string]: number }) {
for(const icon of icons) {
await saveIconAsync(icon, projectRoot, dirsToSize);
}
}
async function saveIconAsync(icon: string, projectRoot: string, dirsToSize: { [name: string]: number }) {
const name = parse(icon).name;
OneSignalLog.log("Saving icon " + icon + " as drawable resource " + name);
for(const iconResourceDir in dirsToSize) {
const path = resolve(projectRoot, RESOURCE_ROOT_PATH, iconResourceDir);
if(!existsSync(path)) {
mkdirSync(path, { recursive: true });
}
const resizedIcon = (
await generateImageAsync(
{ projectRoot, cacheType: 'onesignal-icon' },
{
src: icon,
width: dirsToSize[iconResourceDir],
height: dirsToSize[iconResourceDir],
resizeMode: 'cover',
backgroundColor: 'transparent',
}
)
).source;
writeFileSync(resolve(path, name + '.png'), resizedIcon);
}
}
export const withOneSignalAndroid: ConfigPlugin<OneSignalPluginProps> = (

@@ -15,5 +115,5 @@ config,

) => {
//commented out until https://github.com/expo/eas-cli/issues/1226 is confirmed fixed
//OneSignalLog.log("No specific actions required for OneSignal on Android...");
config = withSmallIcons(config, props);
config = withLargeIcons(config, props);
return config;
};

5

package.json
{
"name": "onesignal-expo-plugin",
"version": "1.1.2",
"version": "1.2.0",
"description": "The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.",

@@ -44,4 +44,5 @@ "main": "./app.plugin.js",

"dependencies": {
"xcode": "^3.0.1"
"xcode": "^3.0.1",
"@expo/image-utils": "^0.3.22"
}
}

@@ -84,5 +84,7 @@ <h1 align="center">Welcome to onesignal-expo-plugin 👋</h1>

|--------------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `mode` | **required** | Used to configure [APNs environment](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment) entitlement. `"development"` or `"production"` |
| `mode` | **required** | Used to configure [APNs environment](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment) entitlement. `"development"` or `"production"` |
| `devTeam` | optional | Used to configure Apple Team ID. You can find your Apple Team ID by running `expo credentials:manager` e.g: `"91SW8A37CR"` |
| `iPhoneDeploymentTarget` | optional | Target `IPHONEOS_DEPLOYMENT_TARGET` value to be used when adding the iOS [NSE](https://documentation.onesignal.com/docs/service-extensions). A deployment target is nothing more than the minimum version of the operating system the application can run on. This value should match the value in your Podfile e.g: `"12.0"`. |
| `smallIcons` | optional | An array of local paths to small notification icons for Android. Image should be white, transparent, and 96x96 in size. Input images will be automatically scaled down and placed in the appropriate resource folders. e.g: `["./assets/ic_stat_onesignal_default.png"]`. See https://documentation.onesignal.com/docs/customize-notification-icons#small-notification-icons. |
| `largeIcons` | optional | An array of local paths to large notification icons for Android. Image should be white, transparent, and 256x256 in size. e.g: `["./assets/ic_onesignal_large_icon_default.png"]`. See https://documentation.onesignal.com/docs/customize-notification-icons#large-notification-icons. |

@@ -89,0 +91,0 @@ ### OneSignal App ID

@@ -6,7 +6,27 @@ /**

/**
* (iOS only) Environment name and bundle identifier
* (required) Used to configure APNs environment entitlement. "development" or "production"
*/
mode: Mode;
/**
* (optional) Used to configure Apple Team ID. You can find your Apple Team ID by running expo credentials:manager e.g: "91SW8A37CR"
*/
devTeam: string;
/**
* (optional) Target IPHONEOS_DEPLOYMENT_TARGET value to be used when adding the iOS NSE. A deployment target is nothing more than
* the minimum version of the operating system the application can run on. This value should match the value in your Podfile e.g: "12.0".
*/
iPhoneDeploymentTarget: string;
/**
* (optional) The small notification icons for Android. Images will be automatically scaled up/down, the recommended size
* is 96x96 to always scale down.
*/
smallIcons?: string[];
/**
* (optional) The large notification icons for Android. Images will be automatically scaled up/down to 256x256.
*/
largeIcons?: string[];
};

@@ -13,0 +33,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc