1 |
|
2 |
|
3 |
|
4 |
|
5 | 'use strict'
|
6 |
|
7 | const { executeAppBuilderAsJson, executeAppBuilderAndWriteJson } = require("../out/util/appBuilder")
|
8 |
|
9 | const os = require('os')
|
10 | const path = require('path')
|
11 |
|
12 | const util = require('./util')
|
13 | const debuglog = util.debuglog
|
14 | const getAppContentsPath = util.getAppContentsPath
|
15 |
|
16 | let tmpFileCounter = 0
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | async function preAutoEntitlements(opts) {
|
25 |
|
26 | const appInfoPath = path.join(getAppContentsPath(opts), 'Info.plist')
|
27 |
|
28 | debuglog('Automating entitlement app group...', '\n',
|
29 | '> Info.plist:', appInfoPath, '\n',
|
30 | '> Entitlements:', opts.entitlements)
|
31 |
|
32 | const plistContent = await executeAppBuilderAsJson(["decode-plist", "-f", opts.entitlements, "-f", appInfoPath])
|
33 | let entitlements = plistContent[0]
|
34 | if (!entitlements['com.apple.security.app-sandbox']) {
|
35 |
|
36 | return
|
37 | }
|
38 |
|
39 | const appInfo = plistContent[1]
|
40 |
|
41 |
|
42 | if (appInfo.ElectronTeamID) {
|
43 | debuglog('`ElectronTeamID` found in `Info.plist`: ' + appInfo.ElectronTeamID)
|
44 | } else {
|
45 |
|
46 | if (opts['provisioning-profile']) {
|
47 | appInfo.ElectronTeamID = opts['provisioning-profile'].message.Entitlements['com.apple.developer.team-identifier']
|
48 | debuglog('`ElectronTeamID` not found in `Info.plist`, use parsed from provisioning profile: ' + appInfo.ElectronTeamID)
|
49 | } else {
|
50 | appInfo.ElectronTeamID = opts.identity.name.substring(opts.identity.name.indexOf('(') + 1, opts.identity.name.lastIndexOf(')'))
|
51 | debuglog('`ElectronTeamID` not found in `Info.plist`, use parsed from signing identity: ' + appInfo.ElectronTeamID)
|
52 | }
|
53 | await executeAppBuilderAndWriteJson(["encode-plist"], {[appInfoPath]: appInfo})
|
54 | debuglog('`Info.plist` updated:', '\n', '> Info.plist:', appInfoPath)
|
55 | }
|
56 |
|
57 | const appIdentifier = appInfo.ElectronTeamID + '.' + appInfo.CFBundleIdentifier
|
58 |
|
59 | if (entitlements['com.apple.application-identifier']) {
|
60 | debuglog('`com.apple.application-identifier` found in entitlements file: ' + entitlements['com.apple.application-identifier'])
|
61 | } else {
|
62 | debuglog('`com.apple.application-identifier` not found in entitlements file, new inserted: ' + appIdentifier)
|
63 | entitlements['com.apple.application-identifier'] = appIdentifier
|
64 | }
|
65 |
|
66 | if (entitlements['com.apple.developer.team-identifier']) {
|
67 | debuglog('`com.apple.developer.team-identifier` found in entitlements file: ' + entitlements['com.apple.developer.team-identifier'])
|
68 | } else {
|
69 | debuglog('`com.apple.developer.team-identifier` not found in entitlements file, new inserted: ' + appInfo.ElectronTeamID)
|
70 | entitlements['com.apple.developer.team-identifier'] = appInfo.ElectronTeamID
|
71 | }
|
72 |
|
73 | if (!entitlements['com.apple.security.application-groups']) {
|
74 | entitlements['com.apple.security.application-groups'] = []
|
75 | }
|
76 |
|
77 | if (Array.isArray(entitlements['com.apple.security.application-groups']) && entitlements['com.apple.security.application-groups'].indexOf(appIdentifier) === -1) {
|
78 | debuglog('`com.apple.security.application-groups` not found in entitlements file, new inserted: ' + appIdentifier)
|
79 | entitlements['com.apple.security.application-groups'].push(appIdentifier)
|
80 | } else {
|
81 | debuglog('`com.apple.security.application-groups` found in entitlements file: ' + appIdentifier)
|
82 | }
|
83 |
|
84 |
|
85 | const entitlementsPath = path.join(os.tmpdir(), `tmp-entitlements-${process.pid.toString(16)}-${(tmpFileCounter++).toString(16)}.plist`)
|
86 | opts.entitlements = entitlementsPath
|
87 | await executeAppBuilderAndWriteJson(["encode-plist"], {[entitlementsPath]: entitlements})
|
88 | debuglog('Entitlements file updated:', '\n', '> Entitlements:', entitlementsPath)
|
89 | }
|
90 |
|
91 | module.exports.preAutoEntitlements = preAutoEntitlements |
\ | No newline at end of file |