Skip to content

Commit af73790

Browse files
author
Christopher Willis-Ford
committed
macOS: request camera and microphone access
Note `audio-input` and `camera` were already in `entitlements.plist` Supporting changes: - Add `allow-jit` entitlement since documentation says it's needed. - Only use sandbox for MAS build, not for non-MAS macOS build. NOTE: both still use the hardened runtime, as required on Catalina. - Remove `entitlements.inherit.plist` since it matches default settings. - Add to `electron-builder.yaml` English descriptions for why the app requests access to the microphone and camera. I'm not yet sure if there's a way to localize these. - Minor tweaks in `electron-builder.yaml`.
1 parent 8222b71 commit af73790

File tree

6 files changed

+51
-17
lines changed

6 files changed

+51
-17
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ To generate a signed NSIS installer:
7979
4. Build the NSIS installer only: building the APPX installer will fail if these environment variables are set.
8080
- `npm run dist -- -w nsis`
8181

82+
#### Workaround for code signing issue in macOS
83+
84+
Sometimes the macOS build process will result in a build which crashes on startup. If this happens, check in `Console`
85+
for an entry similar to this:
86+
87+
```text
88+
failed to parse entitlements for Scratch Desktop[12345]: OSUnserializeXML: syntax error near line 1
89+
```
90+
91+
This appears to be an issue with `codesign` itself. Rebooting your computer and trying to build again might help. Yes,
92+
really.
93+
94+
See this issue for more detail: <https://github.com/electron/electron-osx-sign/issues/218>
95+
8296
### Make a semi-packaged build
8397

8498
This will simulate a packaged build without actually packaging it: instead the files will be copied to a subdirectory

buildResources/entitlements.inherit.plist

Lines changed: 0 additions & 12 deletions
This file was deleted.

buildResources/entitlements.plist renamed to buildResources/entitlements.mac.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>com.apple.security.app-sandbox</key>
5+
<key>com.apple.security.cs.allow-jit</key>
66
<true/>
77
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
88
<true/>

buildResources/entitlements.mas.plist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.cs.allow-jit</key>
8+
<true/>
9+
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
10+
<true/>
11+
<key>com.apple.security.device.audio-input</key>
12+
<true/>
13+
<key>com.apple.security.device.camera</key>
14+
<true/>
15+
<key>com.apple.security.files.user-selected.read-only</key>
16+
<true/>
17+
<key>com.apple.security.files.user-selected.read-write</key>
18+
<true/>
19+
<key>com.apple.security.network.client</key>
20+
<true/>
21+
</dict>
22+
</plist>

electron-builder.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ productName: "Scratch Desktop"
66
afterSign: "scripts/afterSign.js"
77
mac:
88
category: public.app-category.education
9+
entitlements: buildResources/entitlements.mac.plist
10+
extendInfo:
11+
NSCameraUsageDescription: >-
12+
This app requires camera access when taking a photo in the paint editor or using the video sensing blocks.
13+
NSMicrophoneUsageDescription: >-
14+
This app requires microphone access when recording sounds or detecting loudness.
15+
gatekeeperAssess: true
916
hardenedRuntime: true
1017
icon: buildResources/ScratchDesktop.icns
1118
provisioningProfile: embedded.provisionprofile
1219
target:
1320
- dmg
1421
- mas
15-
mas:
1622
type: distribution
23+
mas:
1724
category: public.app-category.education
18-
entitlements: buildResources/entitlements.plist
19-
entitlementsInherit: buildResources/entitlements.inherit.plist
25+
entitlements: buildResources/entitlements.mas.plist
2026
icon: buildResources/ScratchDesktop.icns
2127
win:
2228
icon: buildResources/ScratchDesktop.ico

src/main/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {BrowserWindow, Menu, app, dialog, ipcMain} from 'electron';
1+
import {BrowserWindow, Menu, app, dialog, ipcMain, systemPreferences} from 'electron';
22
import fs from 'fs';
33
import path from 'path';
44
import {format as formatUrl} from 'url';
@@ -140,6 +140,10 @@ const createMainWindow = () => {
140140
if (process.platform === 'darwin') {
141141
const osxMenu = Menu.buildFromTemplate(MacOSMenu(app));
142142
Menu.setApplicationMenu(osxMenu);
143+
(async () => {
144+
await systemPreferences.askForMediaAccess('microphone');
145+
await systemPreferences.askForMediaAccess('camera');
146+
})();
143147
} else {
144148
// disable menu for other platforms
145149
Menu.setApplicationMenu(null);

0 commit comments

Comments
 (0)