Skip to content

Commit

Permalink
fix: make config plugin work without specifying props
Browse files Browse the repository at this point in the history
  • Loading branch information
robertherber committed Jun 18, 2023
1 parent 5d98a38 commit f7b8bc7
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions app.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@ const {
*/

/**
* @type {ConfigPlugin<{background: BackgroundConfig}>}
*/
const withEntitlementsPlugin = (config, { background }) => withEntitlementsPlist(config, (config) => {
* @type {ConfigPlugin<{background: BackgroundConfig}>}
*/
const withEntitlementsPlugin = (
config,
/**
* @type {{background: BackgroundConfig} | undefined}
* */
props,
) => withEntitlementsPlist(config, (config) => {
config.modResults['com.apple.developer.healthkit'] = true

// background is enabled by default, but possible to opt-out from
// (haven't seen any drawbacks from having it enabled)
if (background !== false) {
if (props?.background !== false) {
config.modResults['com.apple.developer.healthkit.background-delivery'] = true
}

Expand All @@ -55,18 +61,15 @@ const withEntitlementsPlugin = (config, { background }) => withEntitlementsPlist
*/
const withInfoPlistPlugin = (config,
/**
* @type {{NSHealthShareUsageDescription: string | boolean, NSHealthUpdateUsageDescription: string | boolean}}
* @type {{NSHealthShareUsageDescription: string | boolean, NSHealthUpdateUsageDescription: string | boolean} | undefined}
* */
{
NSHealthShareUsageDescription,
NSHealthUpdateUsageDescription,
}) => withInfoPlist(config, (config) => {
if (NSHealthShareUsageDescription !== false) {
config.modResults.NSHealthShareUsageDescription = NSHealthShareUsageDescription ?? `${config.name} wants to read your health data`
props) => withInfoPlist(config, (config) => {
if (props?.NSHealthShareUsageDescription !== false) {
config.modResults.NSHealthShareUsageDescription = props.NSHealthShareUsageDescription ?? `${config.name} wants to read your health data`
}

if (NSHealthUpdateUsageDescription !== false) {
config.modResults.NSHealthUpdateUsageDescription = NSHealthUpdateUsageDescription ?? `${config.name} wants to update your health data`
if (props?.NSHealthUpdateUsageDescription !== false) {
config.modResults.NSHealthUpdateUsageDescription = props.NSHealthUpdateUsageDescription ?? `${config.name} wants to update your health data`
}

return config
Expand All @@ -77,9 +80,9 @@ const pkg = require('./package.json')
/**
* @type {ConfigPlugin<AppPluginConfig>}
*/
const healthkitAppPlugin = (config, { NSHealthShareUsageDescription, NSHealthUpdateUsageDescription, background }) => withPlugins(config, [
[withEntitlementsPlugin, { background }],
[withInfoPlistPlugin, { NSHealthShareUsageDescription, NSHealthUpdateUsageDescription }],
const healthkitAppPlugin = (config, props) => withPlugins(config, [
[withEntitlementsPlugin, props],
[withInfoPlistPlugin, props],
])

/**
Expand Down

0 comments on commit f7b8bc7

Please sign in to comment.