2021-09-23 11:00:11 +00:00
|
|
|
const {app, BrowserWindow} = require('electron')
|
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
function createWindow () {
|
|
|
|
const mainWindow = new BrowserWindow({
|
|
|
|
width: 800,
|
|
|
|
height: 600
|
|
|
|
})
|
|
|
|
|
|
|
|
mainWindow.webContents.session.on('select-hid-device', (event, details, callback) => {
|
2022-05-11 20:01:56 +00:00
|
|
|
//Add events to handle devices being added or removed before the callback on
|
|
|
|
//`select-hid-device` is called.
|
|
|
|
mainWindow.webContents.session.on('hid-device-added', (event, device) => {
|
|
|
|
console.log('hid-device-added FIRED WITH', device)
|
|
|
|
//Optionally update details.deviceList
|
|
|
|
})
|
|
|
|
|
|
|
|
mainWindow.webContents.session.on('hid-device-removed', (event, device) => {
|
|
|
|
console.log('hid-device-removed FIRED WITH', device)
|
|
|
|
//Optionally update details.deviceList
|
|
|
|
})
|
|
|
|
|
2021-09-23 11:00:11 +00:00
|
|
|
event.preventDefault()
|
|
|
|
if (details.deviceList && details.deviceList.length > 0) {
|
|
|
|
callback(details.deviceList[0].deviceId)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
mainWindow.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin, details) => {
|
|
|
|
if (permission === 'hid' && details.securityOrigin === 'file:///') {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
mainWindow.webContents.session.setDevicePermissionHandler((details) => {
|
|
|
|
if (details.deviceType === 'hid' && details.origin === 'file://') {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
mainWindow.loadFile('index.html')
|
|
|
|
}
|
|
|
|
|
|
|
|
app.whenReady().then(() => {
|
|
|
|
createWindow()
|
|
|
|
|
|
|
|
app.on('activate', function () {
|
|
|
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
app.on('window-all-closed', function () {
|
|
|
|
if (process.platform !== 'darwin') app.quit()
|
|
|
|
})
|