Skip to content

Commit

Permalink
Add shortcut to disconnect fields (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Mar 16, 2023
1 parent 034bc37 commit a44a1c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 9 additions & 9 deletions source/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()',
Expand Down Expand Up @@ -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);
}
});

Expand Down
3 changes: 3 additions & 0 deletions source/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"default": "Ctrl+Shift+K",
"linux": "Ctrl+Shift+H"
}
},
"close": {
"description": "Disconnect from GhostText"
}
},
"content_scripts": [
Expand Down

0 comments on commit a44a1c8

Please sign in to comment.