Skip to content

Commit 8425254

Browse files
committed
extension: Remove duplicate calls to getOptions
This hopefully will improve loading time.
1 parent ec5b725 commit 8425254

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

web/packages/extension/src/background.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as utils from "./utils";
22
import { isMessage } from "./messages";
3+
import { Options } from "./common";
34

45
async function contentScriptRegistered() {
56
const matchingScripts = await utils.scripting.getRegisteredContentScripts({
@@ -61,11 +62,11 @@ async function isHeaderConditionSupported() {
6162
}
6263
}
6364

64-
async function enableSWFTakeover() {
65+
async function enableSWFTakeover(opt: Options | null = null) {
66+
const options = opt || (await utils.getOptions());
6567
// Checks if the responseHeaders condition is supported and not behind a disabled flag.
6668
if (utils.declarativeNetRequest && (await isHeaderConditionSupported())) {
67-
const { ruffleEnable } = await utils.getOptions();
68-
if (ruffleEnable) {
69+
if (options.ruffleEnable) {
6970
const playerPage = utils.runtime.getURL("/player.html");
7071
const rules = [
7172
{
@@ -163,10 +164,10 @@ async function disableSWFTakeover() {
163164
}
164165
}
165166

166-
async function enable() {
167-
const { swfTakeover } = await utils.getOptions();
168-
if (swfTakeover) {
169-
await enableSWFTakeover();
167+
async function enable(opt: Options | null = null) {
168+
const options = opt || (await utils.getOptions());
169+
if (options.swfTakeover) {
170+
await enableSWFTakeover(options);
170171
}
171172
if (
172173
!utils.scripting ||
@@ -261,9 +262,9 @@ function onMessage(
261262
}
262263

263264
(async () => {
264-
const { ruffleEnable } = await utils.getOptions();
265-
if (ruffleEnable) {
266-
await enable();
265+
const options = await utils.getOptions();
266+
if (options.ruffleEnable) {
267+
await enable(options);
267268
}
268269
})();
269270

0 commit comments

Comments
 (0)