Skip to content

Commit

Permalink
Handle our APIs being called despite browser not supporting WebHID
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Oct 11, 2024
1 parent bb97f2e commit 65d7bb2
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions AnalogSense.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,43 +257,51 @@ window.analogsense = {
getDevices: async function()
{
const result = [];

const devices = await navigator.hid.getDevices();
for (const dev of devices)
if ("hid" in navigator)
{
const provider = analogsense.findProviderForDevice(dev);
if (provider)
const devices = await navigator.hid.getDevices();
for (const dev of devices)
{
if (!dev.opened)
const provider = analogsense.findProviderForDevice(dev);
if (provider)
{
await dev.open();
if (!dev.opened)
{
await dev.open();
}
result.push(new provider(dev));
}
result.push(new provider(dev));
}
}

return result;
},
requestDevice: async function()
{
const filters = [];
for (const provider of analogsense.providers)
{
provider.populateFilters(filters);
}
const devices = await navigator.hid.requestDevice({ filters });
for (const dev of devices)
if ("hid" in navigator)
{
const provider = analogsense.findProviderForDevice(dev);
if (provider)
const filters = [];
for (const provider of analogsense.providers)
{
provider.populateFilters(filters);
}
const devices = await navigator.hid.requestDevice({ filters });
for (const dev of devices)
{
if (!dev.opened)
const provider = analogsense.findProviderForDevice(dev);
if (provider)
{
await dev.open();
if (!dev.opened)
{
await dev.open();
}
return new provider(dev);
}
return new provider(dev);
}
}
else
{
alert("Your browser does not support the WebHID API, so analog keyboard input will not be available.");
}
return null;
},
razerScancodeToHidScancode: function(scancode)
Expand Down

0 comments on commit 65d7bb2

Please sign in to comment.