);
}
public onKeyUp(event: any) {
switch (event.key) {
case 'Enter':
this.initLogin();
break;
default:
}
event.preventDefault();
}
public async onLogin(passPhrase: string) {
const passPhraseTrimmed = passPhrase.trim();
try {
await window.onLogin(passPhraseTrimmed);
} catch (error) {
// Increment the error counter and show the button if necessary
this.setState({
errorCount: this.state.errorCount + 1,
});
this.setState({ error });
global.setTimeout(() => {
document.getElementById('password-prompt-input')?.focus();
}, 50);
}
this.setState({
loading: false,
});
}
private initLogin() {
this.setState({
loading: true,
});
const passPhrase = String((this.inputRef as HTMLInputElement).value);
// this is to make sure a render has the time to happen before we lock the thread with all of the db work
// this might be removed once we get the db operations to a worker thread
global.setTimeout(() => this.onLogin(passPhrase), 100);
}
private initClearDataView() {
this.setState({
error: '',
errorCount: 0,
clearDataView: true,
});
}
private renderPasswordViewButtons(): JSX.Element {
const showResetElements = this.state.errorCount >= MAX_LOGIN_TRIES;
return (