summaryrefslogtreecommitdiff
path: root/ext/js/display/display.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-24 23:47:57 -0500
committerGitHub <noreply@github.com>2024-02-25 04:47:57 +0000
commit73169f06dff767020718a5715eba97d3575ba7e1 (patch)
tree99d458f9d2ca74e67dbb4bccd148ef549f7ce2cf /ext/js/display/display.js
parenta21948daf6210f67955ae4f98a81e21b8cf9f1f2 (diff)
Turn on @typescript-eslint/no-unsafe-argument (#728)24.2.26.0
Diffstat (limited to 'ext/js/display/display.js')
-rw-r--r--ext/js/display/display.js31
1 files changed, 24 insertions, 7 deletions
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index 750e0d69..f6efb5ac 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -1934,20 +1934,28 @@ export class Display extends EventDispatcher {
this._hotkeyHandler.setHotkeys(this._pageType, options.inputs.hotkeys);
}
- /** */
- async _closeTab() {
- const tab = await new Promise((resolve, reject) => {
+ /**
+ * @returns {Promise<?chrome.tabs.Tab>}
+ */
+ _getCurrentTab() {
+ return new Promise((resolve, reject) => {
chrome.tabs.getCurrent((result) => {
const e = chrome.runtime.lastError;
if (e) {
reject(new Error(e.message));
} else {
- resolve(result);
+ resolve(typeof result !== 'undefined' ? result : null);
}
});
});
- const tabId = tab.id;
- await /** @type {Promise<void>} */ (new Promise((resolve, reject) => {
+ }
+
+ /**
+ * @param {number} tabId
+ * @returns {Promise<void>}
+ */
+ _removeTab(tabId) {
+ return new Promise((resolve, reject) => {
chrome.tabs.remove(tabId, () => {
const e = chrome.runtime.lastError;
if (e) {
@@ -1956,7 +1964,16 @@ export class Display extends EventDispatcher {
resolve();
}
});
- }));
+ });
+ }
+
+ /** */
+ async _closeTab() {
+ const tab = await this._getCurrentTab();
+ if (tab === null) { return; }
+ const tabId = tab.id;
+ if (typeof tabId === 'undefined') { return; }
+ await this._removeTab(tabId);
}
/** */