summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-23 11:59:47 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-22 20:38:21 -0500
commit8ef57936d7ab25c723d4da2d655b742cdcf8c84a (patch)
tree2a71bd55d374dc7e0e3ee4da95a7a0ebc11ed521 /ext/bg
parentf6621374817908ec5936caf635bae9bcd20b3ad1 (diff)
Add functionality for getting and observing zoom factor
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/backend.js31
1 files changed, 29 insertions, 2 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 391d6243..4e6c59df 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) {
@@ -527,6 +535,24 @@ class Backend {
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;
+ 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) {
@@ -741,7 +767,8 @@ Backend._messageHandlers = new Map([
['injectStylesheet', (self, ...args) => self._onApiInjectStylesheet(...args)],
['getEnvironmentInfo', (self, ...args) => self._onApiGetEnvironmentInfo(...args)],
['clipboardGet', (self, ...args) => self._onApiClipboardGet(...args)],
- ['getDisplayTemplatesHtml', (self, ...args) => self._onApiGetDisplayTemplatesHtml(...args)]
+ ['getDisplayTemplatesHtml', (self, ...args) => self._onApiGetDisplayTemplatesHtml(...args)],
+ ['getZoom', (self, ...args) => self._onApiGetZoom(...args)]
]);
Backend._commandHandlers = new Map([