summaryrefslogtreecommitdiff
path: root/ext/js/background
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-27 07:23:42 -0500
committerGitHub <noreply@github.com>2024-02-27 12:23:42 +0000
commite47a0f488f3d9bbcb76ebcf4f5afe203c1ee06c0 (patch)
tree35a4a7411dd3154b19316b330c4976f291f021d2 /ext/js/background
parente74fadc5a411e907da088729ea13e23e6f5aa58d (diff)
Object utilities (#729)
* Create utilities * Rename old isObject * Use new isObject * Remove old function * Add additional function * Simplify for now * Rename function for clarity * Rename function * Expand type * Update eslint
Diffstat (limited to 'ext/js/background')
-rw-r--r--ext/js/background/backend.js15
-rw-r--r--ext/js/background/offscreen-proxy.js4
2 files changed, 10 insertions, 9 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index dbcbdd62..d19c3b45 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -26,7 +26,8 @@ import {ExtensionError} from '../core/extension-error.js';
import {fetchJson, fetchText} from '../core/fetch-utilities.js';
import {logErrorLevelToNumber} from '../core/log-utilities.js';
import {log} from '../core/log.js';
-import {clone, deferPromise, isObject, promiseTimeout} from '../core/utilities.js';
+import {isObjectNotArray} from '../core/object-utilities.js';
+import {clone, deferPromise, promiseTimeout} from '../core/utilities.js';
import {isNoteDataValid} from '../data/anki-util.js';
import {OptionsUtil} from '../data/options-util.js';
import {getAllPermissions, hasPermissions, hasRequiredPermissionsForOptions} from '../data/permissions-util.js';
@@ -222,12 +223,12 @@ export class Backend {
* @returns {void}
*/
_prepareInternalSync() {
- if (isObject(chrome.commands) && isObject(chrome.commands.onCommand)) {
+ if (isObjectNotArray(chrome.commands) && isObjectNotArray(chrome.commands.onCommand)) {
const onCommand = this._onWebExtensionEventWrapper(this._onCommand.bind(this));
chrome.commands.onCommand.addListener(onCommand);
}
- if (isObject(chrome.tabs) && isObject(chrome.tabs.onZoomChange)) {
+ if (isObjectNotArray(chrome.tabs) && isObjectNotArray(chrome.tabs.onZoomChange)) {
const onZoomChange = this._onWebExtensionEventWrapper(this._onZoomChange.bind(this));
chrome.tabs.onZoomChange.addListener(onZoomChange);
}
@@ -1094,7 +1095,7 @@ export class Backend {
}
// chrome.windows not supported (e.g. on Firefox mobile)
- if (!isObject(chrome.windows)) {
+ if (!isObjectNotArray(chrome.windows)) {
throw new Error('Window creation not supported');
}
@@ -1561,7 +1562,7 @@ export class Backend {
*/
_getBrowserIconTitle() {
return (
- isObject(chrome.action) &&
+ isObjectNotArray(chrome.action) &&
typeof chrome.action.getTitle === 'function' ?
new Promise((resolve) => { chrome.action.getTitle({}, resolve); }) :
Promise.resolve('')
@@ -1573,7 +1574,7 @@ export class Backend {
*/
_updateBadge() {
let title = this._defaultBrowserActionTitle;
- if (title === null || !isObject(chrome.action)) {
+ if (title === null || !isObjectNotArray(chrome.action)) {
// Not ready or invalid
return;
}
@@ -2580,7 +2581,7 @@ export class Backend {
* @returns {boolean}
*/
_canObservePermissionsChanges() {
- return isObject(chrome.permissions) && isObject(chrome.permissions.onAdded) && isObject(chrome.permissions.onRemoved);
+ return isObjectNotArray(chrome.permissions) && isObjectNotArray(chrome.permissions.onAdded) && isObjectNotArray(chrome.permissions.onRemoved);
}
/**
diff --git a/ext/js/background/offscreen-proxy.js b/ext/js/background/offscreen-proxy.js
index 102a9eed..59d1291e 100644
--- a/ext/js/background/offscreen-proxy.js
+++ b/ext/js/background/offscreen-proxy.js
@@ -17,7 +17,7 @@
*/
import {ExtensionError} from '../core/extension-error.js';
-import {isObject} from '../core/utilities.js';
+import {isObjectNotArray} from '../core/object-utilities.js';
import {base64ToArrayBuffer} from '../data/sandbox/array-buffer-util.js';
/**
@@ -123,7 +123,7 @@ export class OffscreenProxy {
if (typeof runtimeError !== 'undefined') {
throw new Error(runtimeError.message);
}
- if (!isObject(response)) {
+ if (!isObjectNotArray(response)) {
throw new Error('Offscreen document did not respond');
}
const responseError = response.error;