aboutsummaryrefslogtreecommitdiff
path: root/ext/js/background/backend.js
diff options
context:
space:
mode:
authorJames Maa <jmaa@berkeley.edu>2024-05-09 15:42:35 +0800
committerGitHub <noreply@github.com>2024-05-09 07:42:35 +0000
commit13278a5cf67de69678d8c4c5fb97e6eb00c94c11 (patch)
tree1d77bcf97bb9c6f08c88c9f80ea0da735d5721c2 /ext/js/background/backend.js
parent77fa1d0f64b66d6e4fe9c8795c7844206edbcaf2 (diff)
Update eslint unsafe rule (#887)
* Enable @typescript-eslint/no-unsafe-assignment * Updates * Add missing import * Updates * Fix types? * Fix tests * Address comments * Move TextProcessorVariant to types * Update types/ext/translation-internal.d.ts Co-authored-by: StefanVukovic99 <stefanvukovic44@gmail.com> Signed-off-by: James Maa <jmaa@berkeley.edu> --------- Signed-off-by: James Maa <jmaa@berkeley.edu> Co-authored-by: toasted-nutbread <toasted-nutbread@users.noreply.github.com> Co-authored-by: StefanVukovic99 <stefanvukovic44@gmail.com>
Diffstat (limited to 'ext/js/background/backend.js')
-rw-r--r--ext/js/background/backend.js29
1 files changed, 19 insertions, 10 deletions
diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js
index 294c11db..d042a253 100644
--- a/ext/js/background/backend.js
+++ b/ext/js/background/backend.js
@@ -1831,16 +1831,7 @@ export class Backend {
}
try {
- const tabWindow = await new Promise((resolve, reject) => {
- chrome.windows.get(tab.windowId, {}, (value) => {
- const e = chrome.runtime.lastError;
- if (e) {
- reject(new Error(e.message));
- } else {
- resolve(value);
- }
- });
- });
+ const tabWindow = await this._getWindow(tab.windowId);
if (!tabWindow.focused) {
await /** @type {Promise<void>} */ (new Promise((resolve, reject) => {
chrome.windows.update(tab.windowId, {focused: true}, () => {
@@ -1859,6 +1850,23 @@ export class Backend {
}
/**
+ * @param {number} windowId
+ * @returns {Promise<chrome.windows.Window>}
+ */
+ _getWindow(windowId) {
+ return new Promise((resolve, reject) => {
+ chrome.windows.get(windowId, {}, (value) => {
+ const e = chrome.runtime.lastError;
+ if (e) {
+ reject(new Error(e.message));
+ } else {
+ resolve(value);
+ }
+ });
+ });
+ }
+
+ /**
* @param {number} tabId
* @param {number} frameId
* @param {?number} [timeout=null]
@@ -2208,6 +2216,7 @@ export class Backend {
async _injectAnkiNoteDictionaryMedia(ankiConnect, timestamp, dictionaryMediaDetails) {
const targets = [];
const detailsList = [];
+ /** @type {Map<string, {dictionary: string, path: string, media: ?import('dictionary-database').MediaDataStringContent}>} */
const detailsMap = new Map();
for (const {dictionary, path} of dictionaryMediaDetails) {
const target = {dictionary, path};