How to use the @ledgerhq/hw-transport-node-hid.setListenDevicesPollingSkip function in @ledgerhq/hw-transport-node-hid

To help you get started, weā€™ve selected a few @ledgerhq/hw-transport-node-hid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LiskHQ / lisk-desktop / app / src / ledger.js View on Github external
//   listen: () => {},
//   setListenDevicesDebounce: () => {},
//   setListenDevicesPollingSkip: () => {},
// };
// TransportNodeHid.setListenDevicesDebounce(200);
/*
TransportNodeHid.setListenDevicesDebug((msg, ...args) => {
  console.log(msg);
  console.log({
    type: 'listenDevices',
    args,
  });
});
*/
let busy = false;
TransportNodeHid.setListenDevicesPollingSkip(() => busy);
TransportNodeHid.setListenDevicesDebounce(0);
const getLedgerAccount = (index = 0) => {
  const ledgerAccount = new LedgerAccount();
  ledgerAccount.coinIndex(SupportedCoin.LISK);
  ledgerAccount.account(index);
  return ledgerAccount;
};

const createLedgerHWDevice = ({ path, model }) =>
  new HWDevice(
    Math.floor(Math.random() * 1e5) + 1,
    null,
    model,
    path,
  );
github LedgerHQ / ledger-live-desktop / src / helpers / live-common-setup-internal-hw.js View on Github external
for (const k in process.env) {
  setEnvUnsafe(k, process.env[k])
}
/* eslint-enable guard-for-in */

process.on('message', message => {
  if (message.type === 'setEnv') {
    const { name, value } = message.env

    setEnvUnsafe(name, value)
  }
})

let busy = false

TransportNodeHid.setListenDevicesPollingSkip(() => busy)
TransportNodeHid.setListenDevicesDebounce(LISTEN_DEVICES_DEBOUNCE)

const refreshBusyUIState = throttle(() => {
  if (process.env.CLI) return
  process.send({
    type: 'setDeviceBusy',
    busy,
  })
}, 100)

addAccessHook(() => {
  busy = true
  refreshBusyUIState()
  return () => {
    busy = false
    refreshBusyUIState()
github LedgerHQ / ledger-live-desktop / src / helpers / deviceAccess.js View on Github external
const mapError = e => {
  if (e && e.message && e.message.indexOf('cannot open device with path') >= 0) {
    throw new CantOpenDevice(e.message)
  }
  if (e && e.message && e.message.indexOf('HID') >= 0) {
    throw new DisconnectedDevice(e.message)
  }
  throw e
}

let queue = Promise.resolve()

let busy = false

TransportNodeHid.setListenDevicesPollingSkip(() => busy)

const refreshBusyUIState = throttle(() => {
  if (process.env.CLI) return
  process.send({
    type: 'setDeviceBusy',
    busy,
  })
}, 100)

export const withDevice: WithDevice = devicePath => job => {
  const p = queue.then(async () => {
    busy = true
    refreshBusyUIState()
    try {
      // $FlowFixMe not sure what's wrong
      const t = await retry(() => TransportNodeHid.open(devicePath), { maxRetry: 2 }).catch(