I have a MIDI device (launchpad) that I want to use with an Electron application. I was able to read events on the MIDI device using Microsoft Edge Chromium using Web MIDI API (https://github.com/djipco/webmidi). However, in order to start reading the MIDI device, permissions needed to be set, and displayed like so:
When I run npm start
to start the electron project, I cannot find a way to enable permissions for MIDI devices. I cannot see any of my MIDI devices, and I am assuming that is because I am missing permissions.
I have researched the Electron documentation, and was not able to find anything. systemPreferences
provides a way to request permissions, but for camera and microphone, not MIDI devices (https://electronjs.org/docs/api/system-preferences).
Thank you very much, and any help is appreciated :)
we can handle this using ses.setPermissionRequestHandler.
You have to implement two handlers in your main process for the window where you're enabling WebMidi:
mainWindow.webContents.session.setPermissionRequestHandler((webContents, permission, callback, details) => {
console.log('Permission request:', permission);
if (permission === 'midi' || permission === 'midiSysex') {
callback(true);
} else {
callback(false);
}
})
mainWindow.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin) => {
console.log('Permission check:', permission);
if (permission === 'midi' || permission === 'midiSysex') {
return true;
}
return false;
});
Then you can enable WebMidi like:
WebMidi.enable({ sysex: true });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With