mirror of https://github.com/keeweb/keeweb.git
focus managing refactoring
This commit is contained in:
parent
5b118667ef
commit
eb2de6f3f2
|
@ -1,7 +1,10 @@
|
|||
import { Logger } from 'util/logger';
|
||||
|
||||
const logger = new Logger('auto-type-obfuscator');
|
||||
logger.setLevel(localStorage.autoTypeDebug ? Logger.Level.All : Logger.Level.Warn);
|
||||
const logger = new Logger(
|
||||
'auto-type-obfuscator',
|
||||
undefined,
|
||||
localStorage.debugAutoType ? Logger.Level.All : Logger.Level.Warn
|
||||
);
|
||||
|
||||
const MaxFakeOps = 30;
|
||||
const MaxSteps = 1000;
|
||||
|
|
|
@ -3,8 +3,11 @@ import { AutoTypeObfuscator } from 'auto-type/auto-type-obfuscator';
|
|||
import { StringFormat } from 'util/formatting/string-format';
|
||||
import { Logger } from 'util/logger';
|
||||
|
||||
const emitterLogger = new Logger('auto-type-emitter');
|
||||
emitterLogger.setLevel(localStorage.autoTypeDebug ? Logger.Level.All : Logger.Level.Warn);
|
||||
const emitterLogger = new Logger(
|
||||
'auto-type-emitter',
|
||||
undefined,
|
||||
localStorage.debugAutoType ? Logger.Level.All : Logger.Level.Warn
|
||||
);
|
||||
|
||||
const AutoTypeRunner = function(ops) {
|
||||
this.ops = ops;
|
||||
|
|
|
@ -11,7 +11,7 @@ import { Logger } from 'util/logger';
|
|||
import { AutoTypeSelectView } from 'views/auto-type/auto-type-select-view';
|
||||
|
||||
const logger = new Logger('auto-type');
|
||||
const clearTextAutoTypeLog = localStorage.autoTypeDebug;
|
||||
const clearTextAutoTypeLog = !!localStorage.debugAutoType;
|
||||
|
||||
const AutoType = {
|
||||
helper: AutoTypeHelperFactory.create(),
|
||||
|
@ -28,7 +28,7 @@ const AutoType = {
|
|||
Events.on('auto-type', e => this.handleEvent(e));
|
||||
Events.on('main-window-blur', e => this.resetPendingEvent(e));
|
||||
Events.on('main-window-will-close', e => this.resetPendingEvent(e));
|
||||
appModel.files.on('change', () => this.processPendingEvent());
|
||||
Events.on('closed-open-view', e => this.processPendingEvent(e));
|
||||
},
|
||||
|
||||
handleEvent(e) {
|
||||
|
@ -252,9 +252,6 @@ const AutoType = {
|
|||
this.selectEntryView.on('show-open-files', () => {
|
||||
this.selectEntryView.hide();
|
||||
Events.emit('open-file');
|
||||
Events.once('closed-open-view', () => {
|
||||
this.selectEntryView.show();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -266,6 +263,9 @@ const AutoType = {
|
|||
},
|
||||
|
||||
processPendingEvent() {
|
||||
if (this.selectEntryView) {
|
||||
this.selectEntryView.show();
|
||||
}
|
||||
if (!this.pendingEvent) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
import { Events } from 'framework/events';
|
||||
import { IdleTracker } from 'comp/browser/idle-tracker';
|
||||
import { Keys } from 'const/keys';
|
||||
import { Logger } from 'util/logger';
|
||||
|
||||
const shortcutKeyProp = navigator.platform.indexOf('Mac') >= 0 ? 'metaKey' : 'ctrlKey';
|
||||
const logger = new Logger(
|
||||
'key-handler',
|
||||
undefined,
|
||||
localStorage.debugKeyHandler ? Logger.Level.Debug : Logger.Level.Info
|
||||
);
|
||||
|
||||
class KeyHandler {
|
||||
SHORTCUT_ACTION = 1;
|
||||
|
@ -51,6 +57,7 @@ class KeyHandler {
|
|||
|
||||
setModal(modal) {
|
||||
this.modal = modal;
|
||||
logger.debug('Set modal', modal);
|
||||
}
|
||||
|
||||
isActionKey(e) {
|
||||
|
|
|
@ -20,9 +20,10 @@ class View extends EventEmitter {
|
|||
views = {};
|
||||
hidden = false;
|
||||
removed = false;
|
||||
modal = undefined;
|
||||
eventListeners = {};
|
||||
elementEventListeners = [];
|
||||
debugLogger = localStorage.debugViews ? new Logger('view', this.constructor.name) : undefined;
|
||||
debugLogger = localStorage.debugView ? new Logger('view', this.constructor.name) : undefined;
|
||||
|
||||
constructor(model = undefined, options = {}) {
|
||||
super();
|
||||
|
@ -88,6 +89,9 @@ class View extends EventEmitter {
|
|||
this.el = root;
|
||||
parent.appendChild(this.el);
|
||||
}
|
||||
if (this.modal) {
|
||||
KeyHandler.setModal(this.modal);
|
||||
}
|
||||
this.bindEvents();
|
||||
} else {
|
||||
throw new Error(
|
||||
|
@ -182,6 +186,9 @@ class View extends EventEmitter {
|
|||
}
|
||||
|
||||
remove() {
|
||||
if (this.modal && KeyHandler.modal === this.modal) {
|
||||
KeyHandler.setModal(null);
|
||||
}
|
||||
this.emit('remove');
|
||||
|
||||
this.removeInnerViews();
|
||||
|
@ -228,6 +235,13 @@ class View extends EventEmitter {
|
|||
visible = this.hidden;
|
||||
}
|
||||
this.hidden = !visible;
|
||||
if (this.modal) {
|
||||
if (visible) {
|
||||
KeyHandler.setModal(this.modal);
|
||||
} else if (KeyHandler.modal === this.modal) {
|
||||
KeyHandler.setModal(null);
|
||||
}
|
||||
}
|
||||
this.emit(visible ? 'show' : 'hide');
|
||||
if (this.el) {
|
||||
this.el.classList.toggle('show', !!visible);
|
||||
|
|
|
@ -11,9 +11,9 @@ const MaxLogsToSave = 100;
|
|||
|
||||
const lastLogs = [];
|
||||
|
||||
const Logger = function(name, id) {
|
||||
const Logger = function(name, id, level = Level.All) {
|
||||
this.prefix = name ? name + (id ? ':' + id : '') : 'default';
|
||||
this.level = Level.All;
|
||||
this.level = level;
|
||||
};
|
||||
|
||||
Logger.prototype.ts = function(ts) {
|
||||
|
|
|
@ -170,9 +170,11 @@ class AppView extends View {
|
|||
this.views.open = new OpenView(this.model);
|
||||
this.views.open.render();
|
||||
this.views.open.on('close', () => {
|
||||
this.showEntries();
|
||||
});
|
||||
this.views.open.on('remove', () => {
|
||||
Events.emit('closed-open-view');
|
||||
});
|
||||
this.views.open.on('close', () => this.showEntries());
|
||||
}
|
||||
|
||||
showLastOpenFile() {
|
||||
|
|
|
@ -14,6 +14,7 @@ import itemTemplate from 'templates/auto-type/auto-type-select-item.hbs';
|
|||
|
||||
class AutoTypeSelectView extends View {
|
||||
parent = 'body';
|
||||
modal = 'auto-type';
|
||||
|
||||
template = template;
|
||||
|
||||
|
@ -57,16 +58,6 @@ 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.setModal('auto-type');
|
||||
this.once('remove', () => {
|
||||
KeyHandler.setModal(null);
|
||||
});
|
||||
this.on('show', () => {
|
||||
KeyHandler.setModal('auto-type');
|
||||
});
|
||||
this.on('hide', () => {
|
||||
KeyHandler.setModal(null);
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { Events } from 'framework/events';
|
||||
import { View } from 'framework/views/view';
|
||||
import { KeyHandler } from 'comp/browser/key-handler';
|
||||
import { Keys } from 'const/keys';
|
||||
import template from 'templates/dropdown.hbs';
|
||||
|
||||
class DropdownView extends View {
|
||||
parent = 'body';
|
||||
modal = 'dropdown';
|
||||
|
||||
template = template;
|
||||
|
||||
|
@ -28,14 +28,8 @@ class DropdownView extends View {
|
|||
this.onKey(Keys.DOM_VK_RETURN, this.enterPressed, false, 'dropdown');
|
||||
this.onKey(Keys.DOM_VK_ESCAPE, this.escPressed, false, 'dropdown');
|
||||
|
||||
this.prevModal = KeyHandler.modal === 'dropdown' ? undefined : KeyHandler.modal;
|
||||
KeyHandler.setModal('dropdown');
|
||||
|
||||
this.once('remove', () => {
|
||||
$('body').off('click contextmenu keydown', this.bodyClick);
|
||||
if (KeyHandler.modal === 'dropdown') {
|
||||
KeyHandler.setModal(this.prevModal);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { View } from 'framework/views/view';
|
||||
import { KeyHandler } from 'comp/browser/key-handler';
|
||||
import { Keys } from 'const/keys';
|
||||
import template from 'templates/modal.hbs';
|
||||
|
||||
class ModalView extends View {
|
||||
parent = 'body';
|
||||
modal = 'alert';
|
||||
|
||||
template = template;
|
||||
|
||||
|
@ -21,10 +21,7 @@ class ModalView extends View {
|
|||
if (typeof this.model.enter === 'string') {
|
||||
this.onKey(Keys.DOM_VK_RETURN, this.enterPressed, false, 'alert');
|
||||
}
|
||||
const prevModal = KeyHandler.modal;
|
||||
KeyHandler.setModal('alert');
|
||||
this.once('remove', () => {
|
||||
KeyHandler.setModal(prevModal);
|
||||
if (this.model.view) {
|
||||
this.model.view.remove();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ const logger = new Logger('open-view');
|
|||
|
||||
class OpenView extends View {
|
||||
parent = '.app__body';
|
||||
modal = 'open';
|
||||
|
||||
template = template;
|
||||
|
||||
|
@ -67,13 +68,8 @@ class OpenView extends View {
|
|||
this.onKey(Keys.DOM_VK_DOWN, this.moveOpenFileSelectionDown, null, 'open');
|
||||
this.onKey(Keys.DOM_VK_UP, this.moveOpenFileSelectionUp, null, 'open');
|
||||
this.listenTo(Events, 'main-window-focus', this.windowFocused.bind(this));
|
||||
KeyHandler.setModal('open');
|
||||
this.once('remove', () => {
|
||||
this.passwordInput.reset();
|
||||
if (KeyHandler.modal !== 'auto-type') {
|
||||
// TODO: refactor this
|
||||
KeyHandler.setModal(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue