forked from wulkano/Kap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix audio related issues (wulkano#710)
* Ensure we have microphone access before opening cropper * Only open cropper at startup if access allows it * Add custom message when requesting microphone access * Fix hover and active colors for unmute button * Handle turning record sound setting on * Ensure muting and play/pause works correctly in the editor * Add system permissions helper * Text changes Co-Authored-By: Sindre Sorhus <[email protected]> * asked -> hasAsked and early return
- Loading branch information
1 parent
ddba608
commit 3551779
Showing
10 changed files
with
135 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const {systemPreferences, shell, dialog} = require('electron'); | ||
|
||
const getMicrophoneAccess = () => systemPreferences.getMediaAccessStatus('microphone'); | ||
|
||
const promptSystemPreferences = async ({hasAsked} = {}) => { | ||
if (hasAsked) { | ||
return false; | ||
} | ||
|
||
const {response} = await dialog.showMessageBox({ | ||
type: 'warning', | ||
buttons: ['Open System Preferences', 'Cancel'], | ||
defaultId: 0, | ||
message: 'Kap cannot access the microphone.', | ||
detail: 'Kap requires microphone access to be able to record audio. You can grant this in the System Preferences. Afterwards, relaunch Kap for the changes to take effect.', | ||
cancelId: 1 | ||
}); | ||
|
||
if (response === 0) { | ||
openSystemPreferences(); | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
const ensureMicrophonePermissions = async (fallback = promptSystemPreferences) => { | ||
const access = getMicrophoneAccess(); | ||
|
||
if (access === 'granted') { | ||
return true; | ||
} | ||
|
||
if (access !== 'denied') { | ||
const granted = await systemPreferences.askForMediaAccess('microphone'); | ||
|
||
if (granted) { | ||
return true; | ||
} | ||
|
||
return fallback({hasAsked: true}); | ||
} | ||
|
||
return fallback(); | ||
}; | ||
|
||
const openSystemPreferences = () => shell.openExternal('x-apple.systempreferences:com.apple.preference.security?Privacy_Microphone'); | ||
|
||
const hasMicrophoneAccess = () => getMicrophoneAccess() === 'granted'; | ||
|
||
module.exports = { | ||
ensureMicrophonePermissions, | ||
hasMicrophoneAccess, | ||
openSystemPreferences | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters