Remove redundant getUrl handlers

This commit is contained in:
toasted-nutbread 2019-12-08 22:29:23 -05:00
parent 573f83b65a
commit 4177b63726
4 changed files with 20 additions and 23 deletions

View File

@ -238,17 +238,6 @@ class DisplaySearch extends Display {
} }
} }
onRuntimeMessage({action, params}, sender, callback) {
const handlers = DisplaySearch.runtimeMessageHandlers;
if (hasOwn(handlers, action)) {
const handler = handlers[action];
const result = handler(this, params);
callback(result);
} else {
return super.onRuntimeMessage({action, params}, sender, callback);
}
}
initClipboardMonitor() { initClipboardMonitor() {
// ignore copy from search page // ignore copy from search page
window.addEventListener('copy', () => { window.addEventListener('copy', () => {
@ -380,12 +369,6 @@ class DisplaySearch extends Display {
} }
} }
DisplaySearch.runtimeMessageHandlers = {
getUrl: () => {
return {url: window.location.href};
}
};
DisplaySearch.onKeyDownIgnoreKeys = { DisplaySearch.onKeyDownIgnoreKeys = {
'ANY_MOD': [ 'ANY_MOD': [
'Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'PageDown', 'PageUp', 'Home', 'End', 'Tab', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'PageDown', 'PageUp', 'Home', 'End',

View File

@ -199,14 +199,11 @@ async function onOptionsUpdate({source}) {
await formWrite(options); await formWrite(options);
} }
function onMessage({action, params}, sender, callback) { function onMessage({action, params}) {
switch (action) { switch (action) {
case 'optionsUpdate': case 'optionsUpdate':
onOptionsUpdate(params); onOptionsUpdate(params);
break; break;
case 'getUrl':
callback({url: window.location.href});
break;
} }
} }

View File

@ -201,6 +201,5 @@ Frontend._windowMessageHandlers = new Map([
Frontend._runtimeMessageHandlers = new Map([ Frontend._runtimeMessageHandlers = new Map([
['optionsUpdate', (self) => self.updateOptions()], ['optionsUpdate', (self) => self.updateOptions()],
['popupSetVisibleOverride', (self, {visible}) => self.popup.setVisibleOverride(visible)], ['popupSetVisibleOverride', (self, {visible}) => self.popup.setVisibleOverride(visible)]
['getUrl', () => ({url: window.location.href})]
]); ]);

View File

@ -225,3 +225,21 @@ class EventDispatcher {
return false; return false;
} }
} }
/*
* Default message handlers
*/
(() => {
function onMessage({action}, sender, callback) {
switch (action) {
case 'getUrl':
callback({url: window.location.href});
break;
}
return false;
}
chrome.runtime.onMessage.addListener(onMessage);
})();