summaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2020-01-26 11:29:30 -0800
committerAlex Yatskov <alex@foosoft.net>2020-01-26 11:29:30 -0800
commit0c5b9b1fa1599cbf769d96cdebc226310f9dd8bc (patch)
treee734e2c3005078dbc248b541d357a934baa8a116 /ext/bg/js/backend.js
parent2a12036ca305044291f1f4105d6a8d249848b210 (diff)
parent0cf1cf3aa094585bd6db8db2c1f229ba0ea37b6e (diff)
Merge branch 'master' into testing
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js50
1 files changed, 46 insertions, 4 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 28b0201e..eeab68a5 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -51,9 +51,12 @@ class Backend {
this.onOptionsUpdated('background');
- if (chrome.commands !== null && typeof chrome.commands === 'object') {
+ if (isObject(chrome.commands) && isObject(chrome.commands.onCommand)) {
chrome.commands.onCommand.addListener((command) => this._runCommand(command));
}
+ if (isObject(chrome.tabs) && isObject(chrome.tabs.onZoomChange)) {
+ chrome.tabs.onZoomChange.addListener((info) => this._onZoomChange(info));
+ }
chrome.runtime.onMessage.addListener(this.onMessage.bind(this));
const options = this.getOptionsSync(this.optionsContext);
@@ -94,6 +97,11 @@ class Backend {
}
}
+ _onZoomChange({tabId, oldZoomFactor, newZoomFactor}) {
+ const callback = () => this.checkLastError(chrome.runtime.lastError);
+ chrome.tabs.sendMessage(tabId, {action: 'zoomChanged', params: {oldZoomFactor, newZoomFactor}}, callback);
+ }
+
applyOptions() {
const options = this.getOptionsSync(this.optionsContext);
if (!options.general.enable) {
@@ -299,8 +307,8 @@ class Backend {
const [definitions, sourceLength] = await this.translator.findTermsInternal(
text.substring(0, options.scanning.length),
dictEnabledSet(options),
- options.scanning.alphanumeric,
- {}
+ {},
+ options
);
if (definitions.length > 0) {
dictTermsSort(definitions);
@@ -522,6 +530,38 @@ class Backend {
return result;
}
+ async _onApiGetDisplayTemplatesHtml() {
+ const url = chrome.runtime.getURL('/mixed/display-templates.html');
+ return await requestText(url, 'GET');
+ }
+
+ _onApiGetZoom(params, sender) {
+ if (!sender || !sender.tab) {
+ return Promise.reject(new Error('Invalid tab'));
+ }
+
+ return new Promise((resolve, reject) => {
+ const tabId = sender.tab.id;
+ if (!(
+ chrome.tabs !== null &&
+ typeof chrome.tabs === 'object' &&
+ typeof chrome.tabs.getZoom === 'function'
+ )) {
+ // Not supported
+ resolve({zoomFactor: 1.0});
+ return;
+ }
+ chrome.tabs.getZoom(tabId, (zoomFactor) => {
+ const e = chrome.runtime.lastError;
+ if (e) {
+ reject(new Error(e.message));
+ } else {
+ resolve({zoomFactor});
+ }
+ });
+ });
+ }
+
// Command handlers
async _onCommandSearch(params) {
@@ -735,7 +775,9 @@ Backend._messageHandlers = new Map([
['frameInformationGet', (self, ...args) => self._onApiFrameInformationGet(...args)],
['injectStylesheet', (self, ...args) => self._onApiInjectStylesheet(...args)],
['getEnvironmentInfo', (self, ...args) => self._onApiGetEnvironmentInfo(...args)],
- ['clipboardGet', (self, ...args) => self._onApiClipboardGet(...args)]
+ ['clipboardGet', (self, ...args) => self._onApiClipboardGet(...args)],
+ ['getDisplayTemplatesHtml', (self, ...args) => self._onApiGetDisplayTemplatesHtml(...args)],
+ ['getZoom', (self, ...args) => self._onApiGetZoom(...args)]
]);
Backend._commandHandlers = new Map([