diff --git a/source/background.js b/source/background.js index d7978de..f0ab711 100644 --- a/source/background.js +++ b/source/background.js @@ -2,13 +2,6 @@ import browser from 'webextension-polyfill'; import oneEvent from 'one-event'; import optionsStorage from './options-storage.js'; -function inCurrentTab(callback) { - chrome.tabs.query({ - active: true, - currentWindow: true, - }, tabs => callback(tabs[0])); -} - function handleClose(info, tab) { chrome.tabs.executeScript(tab.id, { code: 'stopGT()', @@ -140,9 +133,16 @@ function init() { contexts: ['browser_action'], onclick: handleClose, }); - chrome.commands.onCommand.addListener(command => { + chrome.commands.onCommand.addListener((command, tab) => { + if (!tab?.id) { + console.warn('No tab information was received for command', {command, tab}); + return; + } + if (command === 'open') { - inCurrentTab(handleAction); + handleAction(tab); + } else if (command === 'close') { + handleClose({}, tab); } }); diff --git a/source/manifest.json b/source/manifest.json index f09917a..4a83e0f 100644 --- a/source/manifest.json +++ b/source/manifest.json @@ -47,6 +47,9 @@ "default": "Ctrl+Shift+K", "linux": "Ctrl+Shift+H" } + }, + "close": { + "description": "Disconnect from GhostText" } }, "content_scripts": [