accomodate PATH being set as a dictionary of options instead

This commit is contained in:
buzz-lightsnack-2007 2024-04-26 22:55:58 +08:00
parent 891de959db
commit 9d5df38baa

View file

@ -11,16 +11,16 @@ export default class Sidebar {
*/ */
constructor (PATH) { constructor (PATH) {
// Set side panel's URL. // Set side panel's URL.
chrome.sidePanel.setOptions({ path: PATH }); chrome.sidePanel.setOptions(((typeof PATH).includes(`str`)) ? { path: PATH } : PATH);
// Grab the current tab ID. // Grab the current tab ID.
Tabs.query({ active: true, currentWindow: true }, 0).then((TAB) => { Tabs.query({ active: true, currentWindow: true }, 0).then((TAB) => {
chrome.sidePanel.open({windowId: TAB.id}); chrome.sidePanel.open({windowId: TAB.id});
this.root = PATH; this.root = ((typeof PATH).includes(`str`)) ? PATH : chrome.sidePanel.getOptions(TAB.id).path;
}); });
chrome.runtime.onConnect.addListener((CONNECTION) => { chrome.runtime.onConnect.addListener((CONNECTION) => {
if ((CONNECTION.name).includes(`view=${PATH}`)) { if ((CONNECTION.name).includes(`view=${this.root}`)) {
this.focus(TRUE); this.focus(TRUE);
CONNECTION.onDisconnect.addListener(async () => { CONNECTION.onDisconnect.addListener(async () => {
this.focus(FALSE); this.focus(FALSE);