refreshing the list of yubikeys on the start screen

pull/1541/head
antelle 2020-05-29 23:24:05 +02:00
parent b90e84be42
commit 0f582e3248
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
2 changed files with 34 additions and 15 deletions

View File

@ -13,7 +13,7 @@ const Timeouts = {
LinkDownloadRevoke: 10 * 1000 * 60,
DefaultHttpRequest: 60000,
ExternalDeviceReconnect: 3000,
ExternalDeviceAfterReconnect: 500
ExternalDeviceAfterReconnect: 1000
};
export { Timeouts };

View File

@ -1,6 +1,8 @@
import { Events } from 'framework/events';
import { View } from 'framework/views/view';
import { YubiKey } from 'comp/app/yubikey';
import { Locale } from 'util/locale';
import { Timeouts } from 'const/timeouts';
import template from 'templates/open-chal-resp.hbs';
class OpenChalRespView extends View {
@ -13,7 +15,38 @@ class OpenChalRespView extends View {
constructor() {
super();
this.listenTo(Events, 'usb-devices-changed', this.usbDevicesChanged);
this.checkDevices();
}
render() {
let error = this.error;
if (this.yubiKeys && !this.yubiKeys.length) {
error = Locale.openChalRespErrorEmpty;
}
super.render({
error,
yubiKeys: this.yubiKeys,
loading: !this.yubiKeys && !this.error
});
}
usbDevicesChanged() {
setTimeout(() => {
if (!this.removed) {
this.checkDevices();
}
}, Timeouts.ExternalDeviceAfterReconnect);
}
checkDevices() {
YubiKey.list((err, yubiKeys) => {
if (this.removed) {
return;
}
this.error = err;
this.yubiKeys = [];
if (yubiKeys) {
@ -31,20 +64,6 @@ class OpenChalRespView extends View {
});
}
render() {
let error = this.error;
if (this.yubiKeys && !this.yubiKeys.length) {
error = Locale.openChalRespErrorEmpty;
}
super.render({
error,
yubiKeys: this.yubiKeys,
loading: !this.yubiKeys && !this.error
});
}
itemClick(e) {
const el = e.target.closest('[data-serial]');
const { serial, slot } = el.dataset;