Skip to content

Commit

Permalink
Fixed the distinction between batch notification and websocket notifi…
Browse files Browse the repository at this point in the history
…cations
  • Loading branch information
FMaz008 committed Oct 21, 2024
1 parent a4477b5 commit 2877a0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions page/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ window.onload = function () {
addItem(data);
}
if (data.type == "ETVUpdate") {
if (Settings.get("notification.websocket")) {
if (Settings.get("notification.websocket") == "1") {
if (items.get(data.asin) === null) {
console.log("ETV Update received for item " + data.asin + " @ " + data.etv);
}
Expand Down Expand Up @@ -193,7 +193,7 @@ async function init() {
Settings.get("notification.lastProduct") * 1000
);

if (!Settings.get("notification.websocket")) {
if (Settings.get("notification.websocket") == "0") {
document.getElementById("statusWS").style.display = "none";
document.querySelector("label[for='fetch-last-100']").style.display = "none";
}
Expand Down Expand Up @@ -221,7 +221,7 @@ async function init() {
//Bind fetch-last-100 button
const btnLast100 = document.querySelector("button[name='fetch-last-100']");
btnLast100.addEventListener("click", function () {
if (!Settings.get("notification.websocket")) {
if (Settings.get("notification.websocket") == "0") {
console.warn("Instant notifications must be enabled for the Fetch Last 100 button to be available.");
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions scripts/vh_service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ if (typeof browser === "undefined") {
browser.runtime.onMessage.addListener((data, sender, sendResponse) => {
if (data.type == "fetchLast100Items") {
//Get the last 100 most recent items
if (Settings.get("notification.websocket")) {
if (Settings.get("notification.websocket") == "1") {
fetchLast100Items(true);
}
sendResponse({ success: true });
Expand All @@ -128,11 +128,11 @@ browser.alarms.onAlarm.addListener(async (alarm) => {
await retrieveSettings();

if (alarm.name === "checkNewItems") {
if (!Settings.get("notification.websocket") || !Settings.get("notification.active")) {
if (Settings.get("notification.websocket") == "0" || !Settings.get("notification.active")) {
socket?.disconnect();
}
if (Settings.get("notification.active")) {
if (Settings.get("notification.websocket")) {
if (Settings.get("notification.websocket") == "1") {
connectWebSocket(); //Check the status of the websocket, reconnect if closed.
} else {
fetchLast100Items();
Expand Down Expand Up @@ -238,7 +238,7 @@ async function init() {
//Check for new items (if the option is disabled the method will return)
browser.alarms.create("checkNewItems", { periodInMinutes: newItemCheckInterval });

if (Settings.get("notification.active") && Settings.get("notification.websocket")) {
if (Settings.get("notification.active") && Settings.get("notification.websocket") == "1") {
//Firefox sometimes re-initialize the background script.
//Do not attempt to recreate a new websocket if this method is called when
//a websocket already exist.
Expand Down

0 comments on commit 2877a0b

Please sign in to comment.