mirror of https://github.com/keeweb/keeweb.git
events
This commit is contained in:
parent
f2fe249560
commit
87eb0468a6
|
@ -1,10 +1,10 @@
|
|||
import EventEmitter from 'events';
|
||||
import { Events } from 'framework/events';
|
||||
import { IdleTracker } from 'comp/browser/idle-tracker';
|
||||
import { Keys } from 'const/keys';
|
||||
|
||||
const shortcutKeyProp = navigator.platform.indexOf('Mac') >= 0 ? 'metaKey' : 'ctrlKey';
|
||||
|
||||
class KeyHandler extends EventEmitter {
|
||||
class KeyHandler {
|
||||
SHORTCUT_ACTION = 1;
|
||||
SHORTCUT_OPT = 2;
|
||||
SHORTCUT_SHIFT = 4;
|
||||
|
@ -12,11 +12,6 @@ class KeyHandler extends EventEmitter {
|
|||
shortcuts = {};
|
||||
modal = false;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.setMaxListeners(100);
|
||||
}
|
||||
|
||||
init() {
|
||||
$(document).bind('keypress', this.keypress.bind(this));
|
||||
$(document).bind('keydown', this.keydown.bind(this));
|
||||
|
@ -121,9 +116,9 @@ class KeyHandler extends EventEmitter {
|
|||
!e.ctrlKey &&
|
||||
!e.metaKey
|
||||
) {
|
||||
this.emit('keypress', e);
|
||||
Events.emit('keypress', e);
|
||||
} else if (this.modal) {
|
||||
this.emit('keypress:' + this.modal, e);
|
||||
Events.emit('keypress:' + this.modal, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import EventEmitter from 'events';
|
||||
import QrCode from 'jsqrcode';
|
||||
import { Events } from 'framework/events';
|
||||
import { Shortcuts } from 'comp/app/shortcuts';
|
||||
import { Alerts } from 'comp/ui/alerts';
|
||||
import { Otp } from 'util/data/otp';
|
||||
|
@ -9,13 +9,12 @@ import { Logger } from 'util/logger';
|
|||
|
||||
const logger = new Logger('otp-qr-reader');
|
||||
|
||||
class OtpQrReader extends EventEmitter {
|
||||
class OtpQrReader {
|
||||
alert = null;
|
||||
|
||||
fileInput = null;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.pasteEvent = this.pasteEvent.bind(this);
|
||||
}
|
||||
|
||||
|
@ -137,7 +136,7 @@ class OtpQrReader extends EventEmitter {
|
|||
this.removeAlert();
|
||||
try {
|
||||
const otp = Otp.parseUrl(url);
|
||||
this.emit('qr-read', otp);
|
||||
Events.emit('qr-read', otp);
|
||||
} catch (err) {
|
||||
logger.error('Error parsing QR code', err);
|
||||
Alerts.error({
|
||||
|
@ -170,7 +169,7 @@ class OtpQrReader extends EventEmitter {
|
|||
}
|
||||
|
||||
enterManually() {
|
||||
this.emit('enter-manually');
|
||||
Events.emit('qe-enter-manually');
|
||||
}
|
||||
|
||||
removeAlert() {
|
||||
|
|
|
@ -3,7 +3,7 @@ import EventEmitter from 'events';
|
|||
class Events extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this.setMaxListeners(100);
|
||||
this.setMaxListeners(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ class AutoTypeSelectView extends View {
|
|||
this.initScroll();
|
||||
this.listenTo(Events, 'main-window-blur', this.mainWindowBlur);
|
||||
this.listenTo(Events, 'main-window-will-close', this.mainWindowWillClose);
|
||||
this.listenTo(Events, 'keypress:auto-type', this.keyPressed);
|
||||
this.setupKeys();
|
||||
}
|
||||
|
||||
|
@ -56,10 +57,8 @@ class AutoTypeSelectView extends View {
|
|||
this.onKey(Keys.DOM_VK_DOWN, this.downPressed, false, 'auto-type');
|
||||
this.onKey(Keys.DOM_VK_BACK_SPACE, this.backSpacePressed, false, 'auto-type');
|
||||
this.onKey(Keys.DOM_VK_O, this.openKeyPressed, KeyHandler.SHORTCUT_ACTION, 'auto-type');
|
||||
KeyHandler.on('keypress:auto-type', this.keyPressed.bind(this));
|
||||
KeyHandler.setModal('auto-type');
|
||||
this.once('remove', () => {
|
||||
KeyHandler.off('keypress:auto-type');
|
||||
KeyHandler.setModal(null);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -73,8 +73,8 @@ class DetailsView extends View {
|
|||
this.listenTo(Events, 'toggle-settings', this.settingsToggled);
|
||||
this.listenTo(Events, 'context-menu-select', this.contextMenuSelect);
|
||||
this.listenTo(Events, 'set-locale', this.render);
|
||||
this.listenTo(OtpQrReader, 'qr-read', this.otpCodeRead);
|
||||
this.listenTo(OtpQrReader, 'enter-manually', this.otpEnterManually);
|
||||
this.listenTo(Events, 'qr-read', this.otpCodeRead);
|
||||
this.listenTo(Events, 'qr-enter-manually', this.otpEnterManually);
|
||||
this.onKey(
|
||||
Keys.DOM_VK_C,
|
||||
this.copyPasswordFromShortcut,
|
||||
|
|
|
@ -161,8 +161,8 @@ class ListSearchView extends View {
|
|||
|
||||
viewShown() {
|
||||
const keypressHandler = e => this.documentKeyPress(e);
|
||||
KeyHandler.on('keypress', keypressHandler);
|
||||
this.removeKeypressHandler = () => KeyHandler.off('keypress', keypressHandler);
|
||||
Events.on('keypress', keypressHandler);
|
||||
this.removeKeypressHandler = () => Events.off('keypress', keypressHandler);
|
||||
}
|
||||
|
||||
viewHidden() {
|
||||
|
|
Loading…
Reference in New Issue