-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tab-related and settings-related functions into separate modules.
- Loading branch information
Showing
6 changed files
with
49 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import browser from "webextension-polyfill"; | ||
|
||
export async function getSettings() { | ||
let {defaultClient, customClientUrl} = await browser.storage.local.get(["defaultClient", "customClientUrl"]); | ||
defaultClient = defaultClient != null ? defaultClient : true; | ||
customClientUrl = customClientUrl ? customClientUrl : DEFAULT_CLIENT_URL; | ||
return {defaultClient, customClientUrl}; | ||
} | ||
|
||
export async function setSettings({defaultClient, customClientUrl}) { | ||
await browser.storage.local.set({defaultClient, customClientUrl}); | ||
} | ||
|
||
export async function getClientUrl() { | ||
const {defaultClient, customClientUrl} = await browser.storage.local.get(["defaultClient", "customClientUrl"]); | ||
return defaultClient == null || defaultClient ? DEFAULT_CLIENT_URL : customClientUrl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import browser from 'webextension-polyfill'; | ||
|
||
import { getClientUrl } from "./settings"; | ||
|
||
const activeTabs = new Map(); | ||
|
||
export async function addTab(tabId) { | ||
const clientUrl = await getClientUrl(); | ||
activeTabs.set(tabId, {clientUrl}); | ||
} | ||
|
||
export function broadcastMessage(message, clientUrl) { | ||
let closedTabs = []; | ||
activeTabs.forEach((value, tabId) => { | ||
if (value.clientUrl === clientUrl) { | ||
browser.tabs.sendMessage(tabId, message) | ||
.catch(() => closedTabs.push(tabId)); | ||
} | ||
}); | ||
closedTabs.forEach(tabId => activeTabs.delete(tabId)); | ||
} | ||
|
||
export async function getTabClientUrl(tabId) { | ||
const {clientUrl} = activeTabs.get(tabId); | ||
return clientUrl != null ? clientUrl : await getClientUrl(); | ||
} |