Make the background script/service worker Chromium compatible.
This commit is contained in:
parent
ded38c7bf7
commit
dcf395f01d
|
@ -3,27 +3,21 @@ import browser from 'webextension-polyfill';
|
|||
import {Settings} from '../settings/settings.js';
|
||||
import {updateBadge} from '../utilities/badge.js';
|
||||
|
||||
// Chromium action handler in service worker.
|
||||
export async function actionClicked(): Promise<void> {
|
||||
await nextItem();
|
||||
}
|
||||
|
||||
let timeoutId: number | undefined;
|
||||
|
||||
// Firefox browser action handler in background script.
|
||||
export async function browserActionClicked(): Promise<void> {
|
||||
const settings = await Settings.fromSyncStorage();
|
||||
|
||||
// When the extension icon is initially clicked, create a timeout for 500ms
|
||||
// that will open the next queue item when it expires.
|
||||
if (timeoutId === undefined) {
|
||||
timeoutId = window.setTimeout(async () => {
|
||||
timeoutId = undefined;
|
||||
|
||||
const nextItem = settings.nextQueueItem();
|
||||
|
||||
if (nextItem === undefined) {
|
||||
await browser.runtime.openOptionsPage();
|
||||
return;
|
||||
}
|
||||
|
||||
await browser.tabs.update({url: nextItem.url});
|
||||
await settings.removeQueueItem(nextItem.id);
|
||||
await updateBadge(settings);
|
||||
await nextItem();
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
|
@ -33,3 +27,17 @@ export async function browserActionClicked(): Promise<void> {
|
|||
timeoutId = undefined;
|
||||
await browser.runtime.openOptionsPage();
|
||||
}
|
||||
|
||||
async function nextItem(): Promise<void> {
|
||||
const settings = await Settings.fromSyncStorage();
|
||||
const nextItem = settings.nextQueueItem();
|
||||
|
||||
if (nextItem === undefined) {
|
||||
await browser.runtime.openOptionsPage();
|
||||
return;
|
||||
}
|
||||
|
||||
await browser.tabs.update({url: nextItem.url});
|
||||
await settings.removeQueueItem(nextItem.id);
|
||||
await updateBadge(settings);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import browser from 'webextension-polyfill';
|
|||
import {Settings} from '../settings/settings.js';
|
||||
import {updateBadge} from '../utilities/badge.js';
|
||||
import {History} from '../utilities/history.js';
|
||||
import {browserActionClicked} from './browser-action.js';
|
||||
import {actionClicked, browserActionClicked} from './browser-action.js';
|
||||
import {initializeContextMenus} from './context-menus.js';
|
||||
|
||||
browser.runtime.onStartup.addListener(async () => {
|
||||
|
@ -12,12 +12,17 @@ browser.runtime.onStartup.addListener(async () => {
|
|||
await updateBadge(await Settings.fromSyncStorage());
|
||||
});
|
||||
|
||||
browser.browserAction.onClicked.addListener(browserActionClicked);
|
||||
if (import.meta.env.VITE_BROWSER === 'chromium') {
|
||||
browser.action.onClicked.addListener(actionClicked);
|
||||
} else {
|
||||
browser.browserAction.onClicked.addListener(browserActionClicked);
|
||||
}
|
||||
|
||||
browser.runtime.onInstalled.addListener(async () => {
|
||||
if (import.meta.env.DEV) {
|
||||
await browser.runtime.openOptionsPage();
|
||||
}
|
||||
await initializeContextMenus();
|
||||
await updateBadge(await Settings.fromSyncStorage());
|
||||
});
|
||||
|
||||
initializeContextMenus();
|
||||
if (import.meta.env.DEV) {
|
||||
void browser.runtime.openOptionsPage();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue