-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
app.plugin.js
91 lines (77 loc) · 2.55 KB
/
app.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* eslint-disable import/no-extraneous-dependencies, functional/immutable-data, no-param-reassign, @typescript-eslint/no-var-requires */
const {
withPlugins,
createRunOncePlugin,
withEntitlementsPlist,
withInfoPlist,
} = require('@expo/config-plugins')
/**
* @typedef ConfigPlugin
* @type {import('@expo/config-plugins').ConfigPlugin<T>}
* @template T = void
*/
// please note that the BackgroundConfig currently doesn't actually enable background delivery for any types, but you
// can set it to false if you don't want the entitlement
/**
* @typedef BackgroundConfig
* @type {false | Partial<Record<
* import('./src/native-types').HKSampleTypeIdentifier,
* import('./src/native-types').HKUpdateFrequency
* >>}
/**
* @typedef InfoPlistConfig
* @type {{
* NSHealthShareUsageDescription?: string | false,
* NSHealthUpdateUsageDescription?: string | false
* }}
*/
/**
* @typedef AppPluginConfig
* @type {InfoPlistConfig & { background?: BackgroundConfig }}
*/
/**
* @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 (props?.background !== false) {
config.modResults['com.apple.developer.healthkit.background-delivery'] = true
}
return config
})
/**
* @type {ConfigPlugin<InfoPlistConfig>}
*/
const withInfoPlistPlugin = (config,
/**
* @type {{NSHealthShareUsageDescription: string | boolean, NSHealthUpdateUsageDescription: string | boolean} | undefined}
* */
props) => withInfoPlist(config, (config) => {
if (props?.NSHealthShareUsageDescription !== false) {
config.modResults.NSHealthShareUsageDescription = props.NSHealthShareUsageDescription ?? `${config.name} wants to read your health data`
}
if (props?.NSHealthUpdateUsageDescription !== false) {
config.modResults.NSHealthUpdateUsageDescription = props.NSHealthUpdateUsageDescription ?? `${config.name} wants to update your health data`
}
return config
})
const pkg = require('./package.json')
/**
* @type {ConfigPlugin<AppPluginConfig>}
*/
const healthkitAppPlugin = (config, props) => withPlugins(config, [
[withEntitlementsPlugin, props],
[withInfoPlistPlugin, props],
])
/**
* @type {ConfigPlugin<AppPluginConfig>}
*/
module.exports = createRunOncePlugin(healthkitAppPlugin, pkg.name, pkg.version)