Skip to content

Commit

Permalink
fix: Firefox wasn't recieving change events
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireChicken12 committed Nov 14, 2023
1 parent 476ef1a commit d696692
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/@types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export type RequestDataMessage<Type extends string, D> = Prettify<
>;
export type ContentSendOnlyMessageMappings = {
setRememberedVolume: SendDataMessage<"send_data", "content", "setRememberedVolume", { shortsPageVolume?: number; watchPageVolume?: number }>;
pageLoaded: SendDataMessage<"send_data", "content", "pageLoaded", undefined>;
};
export type ExtensionSendOnlyMessageMappings = {
volumeBoostChange: DataResponseMessage<"volumeBoostChange", { volumeBoostEnabled: boolean; volumeBoostAmount?: number }>;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import adjustVolumeOnScrollWheel from "@/src/features/scrollWheelVolumeControl";
import { promptUserToResumeVideo, setupVideoHistory } from "@/src/features/videoHistory";
import volumeBoost from "@/src/features/volumeBoost";
import eventManager from "@/utils/EventManager";
import { browserColorLog, formatError, waitForSpecificMessage } from "@/utils/utilities";
import { browserColorLog, formatError, sendContentOnlyMessage, waitForSpecificMessage } from "@/utils/utilities";

import type { ExtensionSendOnlyMessageMappings, Messages, YouTubePlayerDiv } from "@/src/@types";
import { enableHideScrollBar } from "@/src/features/hideScrollBar";
Expand Down Expand Up @@ -275,6 +275,7 @@ window.onload = async function () {
}
}
});
sendContentOnlyMessage("pageLoaded", undefined);
};
window.onbeforeunload = function () {
eventManager.removeAllEventListeners();
Expand Down
12 changes: 6 additions & 6 deletions src/pages/inject/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ document.documentElement.appendChild(script);
});
sendExtensionMessage("options", "data_response", { options });
})();
window.onload = () => {
chrome.storage.onChanged.addListener(storageListeners);
};
window.onunload = () => {
chrome.storage.onChanged.removeListener(storageListeners);
};

/**
* Listens for the "yte-message-from-youtube" event and handles incoming messages from the YouTube page.
Expand Down Expand Up @@ -126,6 +120,12 @@ document.addEventListener("yte-message-from-youtube", async () => {
});
break;
}
case "pageLoaded": {
chrome.storage.onChanged.addListener(storageListeners);
window.onunload = () => {
chrome.storage.onChanged.removeListener(storageListeners);
};
}
}
});
const storageListeners = async (changes: StorageChanges, areaName: string) => {
Expand Down

0 comments on commit d696692

Please sign in to comment.