Skip to content

Commit

Permalink
Attempt to fix the audio enabled error (#828)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
karaggeorge and sindresorhus authored Apr 26, 2020
1 parent dbbe7a6 commit 647459b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 38 deletions.
14 changes: 12 additions & 2 deletions main/common/aperture.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {closePrefsWindow} = require('../preferences');
const {setRecordingTray, disableTray, resetTray} = require('../tray');
const {disableCroppers, setRecordingCroppers, closeAllCroppers} = require('../cropper');
const {setCropperShortcutAction} = require('../global-accelerators');
const {getInputDevices} = require('macos-audio-devices');

// eslint-disable-next-line no-unused-vars
const {convertToH264} = require('../utils/encoding');
Expand Down Expand Up @@ -209,9 +210,18 @@ const stopRecording = async () => {
module.exports = {
startRecording,
stopRecording,
getAudioDevices: () => {
getAudioDevices: async () => {
if (hasMicrophoneAccess()) {
return audioDevices();
try {
let devices = await audioDevices();
if (!Array.isArray(devices)) {
devices = await getInputDevices();
return devices.map(({uid, name}) => ({id: uid, name}));
}
} catch (error) {
showError(error, {reportToSentry: true});
return [];
}
}

return [];
Expand Down
16 changes: 5 additions & 11 deletions main/common/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
const {homedir} = require('os');
const Store = require('electron-store');

const {audioDevices} = require('aperture');
const {getInputDevices} = require('macos-audio-devices');
const {hasMicrophoneAccess} = require('./system-permissions');
const {audioDevices} = require('aperture');

const store = new Store({
schema: {
Expand All @@ -24,10 +25,6 @@ const store = new Store({
type: 'boolean',
default: false
},
hideDesktopIcons: {
type: 'boolean',
default: false
},
record60fps: {
type: 'boolean',
default: false
Expand All @@ -40,10 +37,6 @@ const store = new Store({
type: 'boolean',
default: true
},
doNotDisturb: {
type: 'boolean',
default: false
},
recordAudio: {
type: 'boolean',
default: false
Expand Down Expand Up @@ -92,12 +85,13 @@ const audioInputDeviceId = store.get('audioInputDeviceId');

if (hasMicrophoneAccess()) {
(async () => {
const devices = await audioDevices();
let devices = await audioDevices();

if (!Array.isArray(devices)) {
const Sentry = require('../utils/sentry');
Sentry.captureException(new Error(`devices is not an array: ${JSON.stringify(devices)}`));
return;

devices = (await getInputDevices()).map(device => ({id: device.uid}));
}

if (!devices.some(device => device.id === audioInputDeviceId)) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"mac-open-with": "^1.2.3",
"mac-screen-capture-permissions": "^1.1.0",
"mac-windows": "^0.7.1",
"macos-audio-devices": "^1.3.1",
"macos-version": "^5.2.0",
"make-dir": "^3.0.0",
"moment": "^2.24.0",
Expand Down
22 changes: 0 additions & 22 deletions renderer/components/preferences/categories/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class General extends React.Component {
allowAnalytics,
showCursor,
highlightClicks,
hideDesktopIcons,
doNotDisturb,
record60fps,
recordKeyboardShortcut,
loopExports,
Expand Down Expand Up @@ -122,20 +120,6 @@ class General extends React.Component {
/>
</Item>
}
<Item
key="hideDesktopIcons"
title="Hide desktop icons"
subtitle="Temporarily hide desktop icons while recording"
>
<Switch tabIndex={tabIndex} checked={hideDesktopIcons} onClick={() => toggleSetting('hideDesktopIcons')}/>
</Item>
<Item
key="doNotDisturb"
title="Silence notifications"
subtitle="Activate “Do Not Disturb” while recording"
>
<Switch tabIndex={tabIndex} checked={doNotDisturb} onClick={() => toggleSetting('doNotDisturb')}/>
</Item>
<Item
key="loopExports"
title="Loop exports"
Expand Down Expand Up @@ -208,8 +192,6 @@ class General extends React.Component {
General.propTypes = {
showCursor: PropTypes.bool,
highlightClicks: PropTypes.bool,
hideDesktopIcons: PropTypes.bool,
doNotDisturb: PropTypes.bool,
record60fps: PropTypes.bool,
recordKeyboardShortcut: PropTypes.bool,
toggleSetting: PropTypes.elementType.isRequired,
Expand Down Expand Up @@ -241,8 +223,6 @@ export default connect(
({
showCursor,
highlightClicks,
hideDesktopIcons,
doNotDisturb,
record60fps,
recordAudio,
recordKeyboardShortcut,
Expand All @@ -257,8 +237,6 @@ export default connect(
}) => ({
showCursor,
highlightClicks,
hideDesktopIcons,
doNotDisturb,
record60fps,
recordAudio,
recordKeyboardShortcut,
Expand Down
7 changes: 6 additions & 1 deletion renderer/containers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class PreferencesContainer extends Container {
this.systemPermissions = this.remote.require('./common/system-permissions');
this.plugins = this.remote.require('./common/plugins');
this.track = this.remote.require('./common/analytics').track;
this.showError = this.remote.require('./utils/errors').showError;

const pluginsInstalled = this.plugins.getInstalled().sort((a, b) => a.prettyName.localeCompare(b.prettyName));

Expand Down Expand Up @@ -155,7 +156,11 @@ export default class PreferencesContainer extends Container {

if (!newValue || await this.systemPermissions.ensureMicrophonePermissions()) {
if (newValue) {
await this.getAudioDevices();
try {
await this.getAudioDevices();
} catch (error) {
this.showError(error, {reportToSentry: true});
}
}

this.setState({recordAudio: newValue});
Expand Down
13 changes: 11 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3550,7 +3550,7 @@ electron-util@^0.12.1:
electron-is-dev "^1.1.0"
new-github-issue-url "^0.2.1"

electron-util@^0.13.0:
electron-util@^0.13.0, electron-util@^0.13.1:
version "0.13.1"
resolved "https://registry.yarnpkg.com/electron-util/-/electron-util-0.13.1.tgz#ba3b9cb7e5fdb6a51970a01e9070877cf7855ef8"
integrity sha512-CvOuAyQPaPtnDp7SspwnT1yTb1yynw6yp4LrZCfEJ7TG/kJFiZW9RqMHlCEFWMn3QNoMkNhGVeCvWJV5NsYyuQ==
Expand Down Expand Up @@ -4143,7 +4143,7 @@ evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3:
md5.js "^1.3.4"
safe-buffer "^5.1.1"

[email protected]:
[email protected], execa@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-4.0.0.tgz#7f37d6ec17f09e6b8fc53288611695b6d12b9daf"
integrity sha512-JbDUxwV3BoT5ZVXQrSVbAiaXhXUkIwvbhPIwZ0N13kX+5yCzOhUNdocxB/UQRuYOHRYYwAxKYwJYc0T4D12pDA==
Expand Down Expand Up @@ -6077,6 +6077,15 @@ mac-windows@^0.7.1:
resolved "https://registry.yarnpkg.com/mac-windows/-/mac-windows-0.7.1.tgz#3309ef0c7c508725cc3e17a3ea1687de0680c78b"
integrity sha512-tkjT1zWS46MM7xD131Rg3RDGTamP24/QIhYh7Zd4W1dZz3/72EOebm4fm1gBUJsrGvPluQqXjoEjoBClZ5TQJg==

macos-audio-devices@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/macos-audio-devices/-/macos-audio-devices-1.3.1.tgz#35775b7daa3e33e6388bdacb240ab5a0f81f1264"
integrity sha512-I7r4nw1SpgkQRkXYhD3hKP5+AuiSlOUP/ueMaBdxurxSmyjPgq+NwK/cAcYsPb46R81QIsuPiZVSujcyPz8ryQ==
dependencies:
electron-util "^0.13.1"
execa "^4.0.0"
macos-version "^5.2.0"

macos-release@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/macos-release/-/macos-release-2.3.0.tgz#eb1930b036c0800adebccd5f17bc4c12de8bb71f"
Expand Down

0 comments on commit 647459b

Please sign in to comment.