Skip to content

Commit

Permalink
fix: option use nav usb
Browse files Browse the repository at this point in the history
  • Loading branch information
hz002 committed Oct 23, 2024
1 parent 6cea435 commit 326e982
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/ui/utils/imKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export const useImKeyDeviceConnected = () => {

useEffect(() => {
detectDevice();
navigator?.usb.addEventListener('connect', onConnect);
navigator?.usb.addEventListener('disconnect', onDisconnect);
navigator.usb?.addEventListener('connect', onConnect);
navigator.usb?.addEventListener('disconnect', onDisconnect);
browser.windows.onFocusChanged.addListener(detectDevice);

return () => {
navigator?.usb.removeEventListener('connect', onConnect);
navigator?.usb.removeEventListener('disconnect', onDisconnect);
navigator.usb?.removeEventListener('connect', onConnect);
navigator.usb?.removeEventListener('disconnect', onDisconnect);
browser.windows.onFocusChanged.removeListener(detectDevice);
};
}, []);
Expand All @@ -49,13 +49,13 @@ const imKeyDevices = [
];

async function requestImKeyDevice(): Promise<any> {
const device = await navigator?.usb.requestDevice({
const device = await navigator.usb?.requestDevice({
filters: imKeyDevices,
});
return device;
}
export async function getImKeyDevices(): Promise<any> {
const devices = await navigator?.usb.getDevices();
const devices = await navigator.usb?.getDevices();
return devices.filter((d) => d.vendorId === imKeyUSBVendorId);
}

Expand Down
10 changes: 5 additions & 5 deletions src/ui/utils/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import browser from 'webextension-polyfill';
const navigator = window.navigator as any;

export const hasConnectedKeystoneDevice = async () => {
const devices = await navigator?.usb.getDevices();
const devices = await navigator.usb?.getDevices();
return (
devices.filter((device) => device.vendorId === keystoneUSBVendorId).length >
0
Expand Down Expand Up @@ -40,13 +40,13 @@ export const useKeystoneDeviceConnected = () => {

useEffect(() => {
detectDevice();
navigator?.usb.addEventListener('connect', onConnect);
navigator?.usb.addEventListener('disconnect', onDisconnect);
navigator.usb?.addEventListener('connect', onConnect);
navigator.usb?.addEventListener('disconnect', onDisconnect);
browser.windows.onFocusChanged.addListener(detectDevice);

return () => {
navigator?.usb.removeEventListener('connect', onConnect);
navigator?.usb.removeEventListener('disconnect', onDisconnect);
navigator.usb?.removeEventListener('connect', onConnect);
navigator.usb?.removeEventListener('disconnect', onDisconnect);
browser.windows.onFocusChanged.removeListener(detectDevice);
};
});
Expand Down

0 comments on commit 326e982

Please sign in to comment.