Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// use the function as a status check... if it works, we are in the app
// otherwise no
appVersion(transport)
.then((version: number) => {
inApp = true;
console.log(`>>> Entered app (version ${version})`);
})
.catch(() => 0);
} catch (err) {
console.log("Error connecting to ledger: " + err);
}
});
};
// listen for all changed
TransportNodeHid.listen(listener);
console.log("Press any key to exit");
(process.stdin.setRawMode as any)(true);
process.stdin.resume();
process.stdin.on("data", () => process.exit(0));
// tslint:disable:no-console
import TransportNodeHid, { DescriptorEvent } from "@ledgerhq/hw-transport-node-hid";
import { Device } from "node-hid";
// tslint:disable-next-line:readonly-array
const events: Array> = [];
const listener = {
next: (e: DescriptorEvent) => events.push(e),
error: console.log,
complete: () => console.log("Listener finished"),
};
TransportNodeHid.listen(listener);
// const pprint = (e: any) => console.log(JSON.stringify(e, null, 2));
console.log("Press space to see events, any key to exit");
(process.stdin.setRawMode as any)(true);
process.stdin.resume();
process.stdin.on("data", e => {
showAll(events);
if (e[0] !== 0x20) {
process.exit(0);
}
});
const showAll = (evts: ReadonlyArray>) => console.log(evts.map(desc));
const format = (e: DescriptorEvent): string => prefix(e.type) + genericDev(e.device);
public start(): void {
// tslint:disable-next-line:no-object-mutation
this.listeningSubscription = TransportNodeHid.listen({
next: e => this.handleEvent(e),
error: e => {
throw e;
},
complete: () => {
throw new Error("TransportNodeHid.listen completed. What does that mean?");
},
});
}
constructor() {
this.connected = false;
this.listeners = [];
this.subscription = Transport.listen({
next: (e) => {
this.onMessage(e.type);
}
});
}
const syncDevices = () => {
try {
observableListen = TransportNodeHid.listen(ledgerObserver);
} catch (e) {
syncDevices();
}
};
syncDevices();
export function deviceEventListener() {
const mainWindow = remote.getGlobal('mainWindow');
const sub = LedgerTransport.listen({
next: (e) => emitEvent(mainWindow, e),
error: (e) => emitEvent(mainWindow, e),
complete: (e) => emitEvent(mainWindow, e),
});
process.on('exit', () => {
sub.unsubscribe();
});
}
export default (send: IPCSend) => {
CommNodeHid.listen({
error: noop,
complete: noop,
next: async e => {
if (!e.device) {
return
}
if (e.type === 'add') {
send('device.add', e.device, { kill: false })
}
if (e.type === 'remove') {
send('device.remove', e.device, { kill: false })
}
},
})
}