Skip to content

Commit 48a688a

Browse files
feat(sltt-app): sign and notarize macos application (#28)
What issue(s) is this trying to resolve? * feat(sltt-app): Sign and notarize Mac application #9 How does it all work? * In order for a Mac application to be successfully installed, the app installer must be signed (with a certificate) and notarized (uploaded to Apple to be scanned for viruses, etc.). What particularly has changed? * Description of procedure [HERE](https://docs.google.com/document/d/1Qk-bz-uRPBThCXs2rRfNnr4QIxsC3yNlM_e7eMjGGHs/edit?usp=sharing) * Signing certificate created * .env file with notarization credentials created * package.json "build" object updated with Mac build config Steps for testing 1. yarn build:mac 2. Copy newly created .dmg file to another mac 3. Launch dmg file, drag application icon to Applications folder, launch application, smoke test. ticket: #9 commit-convention: https://www.conventionalcommits.org/en/v1.0.0/ --------- Co-authored-by: Eric Pyle <[email protected]>
1 parent adb1584 commit 48a688a

6 files changed

+50
-24
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node_modules
22
dist
33
out
44
*.log*
5+
.env
6+
.DS_Store

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,7 @@ vite v4.3.3 building for production...
152152
[====================] 100% 0.0s | sltt-app-Setup-1.0.6.exe to github
153153
Done in 55.90s.
154154
```
155+
156+
# Building Releases for Mac
157+
158+
Discussion of process [HERE](https://docs.google.com/document/d/1Qk-bz-uRPBThCXs2rRfNnr4QIxsC3yNlM_e7eMjGGHs/edit?usp=sharing)

build/entitlements.mac.plist

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
<true/>
99
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
1010
<true/>
11+
<key>com.apple.security.device.camera</key>
12+
<true/>
1113
</dict>
1214
</plist>

build/notarize.js

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
const { notarize } = require('@electron/notarize')
2-
3-
module.exports = async (context) => {
4-
if (process.platform !== 'darwin') return
1+
console.log('afterSign hook triggered')
52

6-
console.log('aftersign hook triggered, start to notarize app.')
3+
require('dotenv').config()
74

8-
if (!process.env.CI) {
9-
console.log(`skipping notarizing, not in CI.`)
10-
return
11-
}
5+
const { notarize } = require('@electron/notarize')
126

13-
if (!('APPLE_ID' in process.env && 'APPLE_ID_PASS' in process.env)) {
14-
console.warn('skipping notarizing, APPLE_ID and APPLE_ID_PASS env variables must be set.')
7+
exports.default = async function notarizing(context) {
8+
const { electronPlatformName, appOutDir } = context
9+
if (electronPlatformName !== 'darwin') {
1510
return
1611
}
1712

18-
const appId = 'net.sltt-bible.app'
19-
20-
const { appOutDir } = context
13+
console.log('notarizing...')
2114

2215
const appName = context.packager.appInfo.productFilename
2316

24-
try {
25-
await notarize({
26-
appBundleId: appId,
27-
appPath: `${appOutDir}/${appName}.app`,
28-
appleId: process.env.APPLE_ID,
29-
appleIdPassword: process.env.APPLEIDPASS
30-
})
31-
} catch (error) {
32-
console.error(error)
17+
// Get appleId and appleIdPassword from environment variables.
18+
// These values are in the .env file.
19+
// appleId: email address you use to login to App Store Connect
20+
// appleIdPassword: app-specific password generated by appleid.apple.com
21+
const { appleId, appleIdPassword, teamId } = process.env
22+
23+
if (!appleId || !appleIdPassword || !teamId) {
24+
console.error('Missing Apple ID or Apple ID password or Team ID')
25+
return
3326
}
3427

35-
console.log(`done notarizing ${appId}.`)
28+
return await notarize({
29+
appBundleId: 'net.sltt-bible.app',
30+
appPath: `${appOutDir}/${appName}.app`,
31+
appleId,
32+
appleIdPassword,
33+
tool: 'notarytool',
34+
teamId,
35+
})
3636
}

electron-builder.yml

+4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ nsis:
2020
uninstallDisplayName: ${productName}
2121
createDesktopShortcut: always
2222
mac:
23+
category: "public.app-category.business"
24+
entitlements: build/entitlements.mac.plist
2325
entitlementsInherit: build/entitlements.mac.plist
26+
hardenedRuntime: true
27+
gatekeeperAssess: false
2428
extendInfo:
2529
- NSCameraUsageDescription: Application requests access to the device's camera.
2630
- NSMicrophoneUsageDescription: Application requests access to the device's microphone.

package.json

+14
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,26 @@
3030
"build:win:prerelease": "npm run build && electron-builder --win --config --publish onTagOrDraft --prerelease",
3131
"build:win:draft": "npm run build && electron-builder --win --config --publish onTagOrDraft",
3232
"build:win:release": "npm run build && cross-env GH_TOKEN=%SLTT_APP_PAT% electron-builder --win --config --publish always",
33+
"build:mac:norelease": "electron-vite build && electron-builder --mac --config --publish never",
3334
"build:mac": "electron-vite build && electron-builder --mac --config",
35+
"build:mac:release": "electron-vite build && electron-builder --mac --config --publish always",
3436
"build:linux": "electron-vite build && electron-builder --linux --config"
3537
},
3638
"build": {
3739
"appId": "net.sltt-bible.app",
3840
"productName": "sltt-app",
41+
"forceCodeSigning": true,
42+
"afterSign": "build/notarize.js",
43+
"mac": {
44+
"target": [
45+
{
46+
"target": "dmg",
47+
"arch": [
48+
"x64"
49+
]
50+
}
51+
]
52+
},
3953
"directories": {
4054
"output": "dist"
4155
},

0 commit comments

Comments
 (0)