aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display/display.js
diff options
context:
space:
mode:
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);
}
/** */