Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions web/packages/extension/src/background.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as utils from "./utils";
import { isMessage } from "./messages";
import { Options } from "./common";

async function contentScriptRegistered() {
const matchingScripts = await utils.scripting.getRegisteredContentScripts({
Expand Down Expand Up @@ -61,11 +62,11 @@ async function isHeaderConditionSupported() {
}
}

async function enableSWFTakeover() {
async function enableSWFTakeover(opt: Options | null = null) {
const options = opt || (await utils.getOptions());
// Checks if the responseHeaders condition is supported and not behind a disabled flag.
if (utils.declarativeNetRequest && (await isHeaderConditionSupported())) {
const { ruffleEnable } = await utils.getOptions();
if (ruffleEnable) {
if (options.ruffleEnable) {
const playerPage = utils.runtime.getURL("/player.html");
const rules = [
{
Expand Down Expand Up @@ -163,10 +164,10 @@ async function disableSWFTakeover() {
}
}

async function enable() {
const { swfTakeover } = await utils.getOptions();
if (swfTakeover) {
await enableSWFTakeover();
async function enable(opt: Options | null = null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be equivalent (same for enableSWFTakeover)?

async function enable(opt?: Options) {

const options = opt || (await utils.getOptions());
if (options.swfTakeover) {
await enableSWFTakeover(options);
}
if (
!utils.scripting ||
Expand Down Expand Up @@ -261,9 +262,9 @@ function onMessage(
}

(async () => {
const { ruffleEnable } = await utils.getOptions();
if (ruffleEnable) {
await enable();
const options = await utils.getOptions();
if (options.ruffleEnable) {
await enable(options);
}
})();

Expand Down