This commit is contained in:
Alex Yatskov 2017-03-25 15:22:28 -07:00
parent 4a232151e0
commit 90eaae1725
2 changed files with 38 additions and 0 deletions

View File

@ -35,6 +35,7 @@ window.driver = new class {
window.addEventListener('mouseup', this.onMouseUp.bind(this)); window.addEventListener('mouseup', this.onMouseUp.bind(this));
window.addEventListener('mousemove', this.onMouseMove.bind(this)); window.addEventListener('mousemove', this.onMouseMove.bind(this));
window.addEventListener('resize', e => this.searchClear()); window.addEventListener('resize', e => this.searchClear());
window.addEventListener('message', this.onFrameMessage.bind(this));
chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this)); chrome.runtime.onMessage.addListener(this.onBgMessage.bind(this));
}).catch(this.handleError.bind(this)); }).catch(this.handleError.bind(this));
} }
@ -101,6 +102,27 @@ window.driver = new class {
} }
} }
onFrameMessage(e) {
const handlers = {
popupClose: () => {
this.searchClear();
},
scanLeft: () => {
},
scanRight: () => {
}
};
const handler = handlers[e.data];
if (handler) {
handler();
}
}
onBgMessage({action, params}, sender, callback) { onBgMessage({action, params}, sender, callback) {
const handlers = new class { const handlers = new class {
api_optionsSet(options) { api_optionsSet(options) {

View File

@ -207,6 +207,10 @@ class Display {
} }
onKeyDown(e) { onKeyDown(e) {
const notifyParent = action => {
window.parent.postMessage(action, '*');
};
const handlers = { const handlers = {
36: /* home */ () => { 36: /* home */ () => {
this.entryScroll(0, true); this.entryScroll(0, true);
@ -246,6 +250,18 @@ class Display {
8: /* backspace */ () => { 8: /* backspace */ () => {
},
27: /* escape */ () => {
notifyParent('popupClose');
},
37: /* left */ () => {
notifyParent('scanLeft');
},
39: /* right */ () => {
notifyParent('scanRight');
} }
}; };