Skip to content

Commit

Permalink
Remove explicit state management as it's maintained as a part of the …
Browse files Browse the repository at this point in the history
…sidebar
  • Loading branch information
Stvad committed Jan 19, 2022
1 parent 6fcb872 commit 1bba467
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions src/background/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import {setupCommandListener} from "./command-listener"
import browser from 'webextension-polyfill'
import {Browser} from "../core/browser"

let tabStates = {};

function initTabState(tab) {
if (!tabStates[tab.id]) {
tabStates[tab.id] = {}
}
}

window.sidebarLocked = false;

function pushProposalToSidebar(proposals, tid) {
Expand All @@ -29,8 +21,6 @@ const toggleInlineSidebar = async () =>
Browser.sendMessageToActiveTab({type: "toggle-sidebar"})

async function toggleSidebar(tab) {
initTabState(tab)

if (browser.sidebarAction) {
// if a user input handler waits on a promise, then its status as a user input handler is lost
// and this call won't work
Expand All @@ -39,14 +29,9 @@ async function toggleSidebar(tab) {
await browser.sidebarAction.toggle()
} else {
// todo I actually want this one in FF too, need a setting
// also rn the shortcut only works with the iframe sidebar, so there need to call this function instead
await toggleInlineSidebar()
}

if (tabStates[tab.id].mode === 'show_entity') {
await pushEnitiyToSidebar(tabStates[tab.id].entity, tab.id)
} else if (tabStates[tab.id].mode === 'propose_match') {
await pushProposalToSidebar(tabStates[tab.id].proposals, tab.id)
}
}

browser.browserAction.onClicked.addListener(toggleSidebar)
Expand All @@ -62,8 +47,6 @@ async function addToUrlCache(id, url) {

async function handleMatchEvent(event, sender) {
if (!sidebarLocked) {
tabStates[sender.tab.id].mode = 'show_entity'
tabStates[sender.tab.id].entity = event.wdEntityId
await browser.browserAction.setIcon({
path: activeIcon,
tabId: sender.tab.id,
Expand Down Expand Up @@ -124,9 +107,6 @@ function clearPageLinks() {
}

async function handleMatchProposal(event, sender) {
tabStates[sender.tab.id].mode = 'propose_match'
tabStates[sender.tab.id].proposals = event.proposals

await browser.browserAction.setIcon({
path: "icons/halfactive.svg",
tabId: sender.tab.id,
Expand All @@ -141,8 +121,6 @@ async function handleMatchProposal(event, sender) {
}

async function resetState(sender) {
tabStates[sender.tab.id].mode = false

await browser.browserAction.setIcon({
path: "icons/inactive.svg",
tabId: sender.tab.id,
Expand Down Expand Up @@ -170,8 +148,6 @@ browser.runtime.onMessage.addListener(async (data, sender) => {

// todo is this different in the inline-sidebar world?
if (sender.tab) {
initTabState(sender.tab)

if (data.type === 'match_event') {
await handleMatchEvent(data, sender)
} else if (data.type === 'match_proposal') {
Expand Down

0 comments on commit 1bba467

Please sign in to comment.