Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/WebHID-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ navigator.hid.getDevices().then((devices) => {

3. **Scope**: Device approval is per-window. Each window can have its own allowed device list.

4. **Logging**: Chef will log when devices are auto-approved or denied, making it easier to debug configuration issues.
4. **Multiple windows sharing an origin**: If multiple windows load pages from the same URL origin (e.g. `https://example.com`), a device will be auto-approved as long as it is listed in `allowedWebHIDDevices` for _any_ of those windows — not necessarily the one actually using it.

5. **Logging**: Chef will log when devices are auto-approved or denied, making it easier to debug configuration issues.

### Troubleshooting

Expand Down
20 changes: 10 additions & 10 deletions src/ChefManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,23 @@ export class ChefManager {
defaultSession.setDevicePermissionHandler((details) => {
if (details.deviceType !== 'hid') return false

const window = this.windowsHelper.getWindowForOrigin(details.origin)
if (!window) return false

const device = details.device as Electron.HIDDevice
const allowed = window.isAllowedWebHIDDevice(device)
const windows = this.windowsHelper.getWindowsForOrigin(details.origin)
const matchingWindow = windows.find((w) => w.isAllowedWebHIDDevice(device))

if (allowed) {
if (matchingWindow) {
this.logger.info(
`Window "${window.id}": auto-approved WebHID device ${device.vendorId}:${device.productId} (${device.deviceId})`
`Origin "${details.origin}": auto-approved WebHID device ${device.vendorId}:${device.productId} (${device.deviceId}) (matched config for window "${matchingWindow.id}")`
)
} else {
return true
}

if (windows.length > 0) {
this.logger.info(
`Window "${window.id}": denied WebHID device ${device.vendorId}:${device.productId} (${device.deviceId})`
`Origin "${details.origin}": denied WebHID device ${device.vendorId}:${device.productId} (${device.deviceId})`
)
}

return allowed
return false
})

defaultSession.on('select-hid-device', (event, details, callback) => {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/AllWindowsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export class AllWindowsManager extends EventEmitter {
return Object.values<WindowHelper>(this.windowsHandlers).find((window) => window.isMainFrame(mainFrame))
}

public getWindowForOrigin(origin: string): WindowHelper | undefined {
return Object.values<WindowHelper>(this.windowsHandlers).find((window) => window.isOrigin(origin))
public getWindowsForOrigin(origin: string): WindowHelper[] {
return Object.values<WindowHelper>(this.windowsHandlers).filter((window) => window.isOrigin(origin))
}

public getStatus(): { [index: string]: StatusObject } {
Expand Down