Skip to content

Commit

Permalink
Restore keyboard shortcuts in Firefox (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Mar 24, 2023
1 parent 3722bde commit e8c0968
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions source/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import browser from 'webextension-polyfill';
import oneEvent from 'one-event';
import optionsStorage from './options-storage.js';

function handleClose(info, tab) {
function stopGT(tab) {
chrome.tabs.executeScript(tab.id, {
code: 'stopGT()',
});
Expand Down Expand Up @@ -124,25 +124,25 @@ async function saveShortcut() {
}
}

async function getActiveTab() {
const [activeTab] = await browser.tabs.query({active: true, currentWindow: true});
return activeTab;
}

function init() {
chrome.browserAction.onClicked.addListener(handleAction);
chrome.runtime.onMessage.addListener(handleMessages);
chrome.contextMenus.create({
id: 'stop-gt',
title: 'Disconnect GhostText on this page',
contexts: ['browser_action'],
onclick: handleClose,
onclick: (_, tab) => stopGT(tab.id),
});
chrome.commands.onCommand.addListener((command, tab) => {
if (!tab?.id) {
console.warn('No tab information was received for command', {command, tab});
return;
}

chrome.commands.onCommand.addListener(async (command, tab = getActiveTab()) => {
if (command === 'open') {
handleAction(tab);
handleAction(await tab);
} else if (command === 'close') {
handleClose({}, tab);
stopGT(await tab);
}
});

Expand Down

0 comments on commit e8c0968

Please sign in to comment.