Skip to content

Commit

Permalink
Removal of the batch notification system. Using Websocket (instant no…
Browse files Browse the repository at this point in the history
…tifications) by default.
  • Loading branch information
FMaz008 committed Oct 21, 2024
1 parent 2877a0b commit 202f50a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 45 deletions.
16 changes: 3 additions & 13 deletions page/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ window.onload = function () {
addItem(data);
}
if (data.type == "ETVUpdate") {
if (Settings.get("notification.websocket") == "1") {
if (items.get(data.asin) === null) {
console.log("ETV Update received for item " + data.asin + " @ " + data.etv);
}
if (items.get(data.asin) === null) {
console.log("ETV Update received for item " + data.asin + " @ " + data.etv);
}

setETV(data.asin, data.etv, data.etv);
}

Expand Down Expand Up @@ -193,11 +192,6 @@ async function init() {
Settings.get("notification.lastProduct") * 1000
);

if (Settings.get("notification.websocket") == "0") {
document.getElementById("statusWS").style.display = "none";
document.querySelector("label[for='fetch-last-100']").style.display = "none";
}

//Bind the event when changing the filter
const filter = document.querySelector("select[name='filter-type']");
filter.addEventListener("change", function () {
Expand All @@ -221,10 +215,6 @@ 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") == "0") {
console.warn("Instant notifications must be enabled for the Fetch Last 100 button to be available.");
return false;
}
browser.runtime.sendMessage(
{
type: "fetchLast100Items",
Expand Down
1 change: 0 additions & 1 deletion page/settings_loadsave.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ async function initiateSettings() {
manageCheckboxSetting("notification.hideList");
manageCheckboxSetting("notification.monitor.hideDuplicateThumbnail");
manageCheckboxSetting("notification.reduce");
manageSelectBox("notification.websocket");

//Sliders
manageSlider("notification.screen.regular.volume");
Expand Down
18 changes: 0 additions & 18 deletions page/settings_notifications.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,6 @@
status items are reported.
</div>

<div class="setting-container">
<label for="notification.websocket">
Notification mode:&nbsp;
<select name="notification.websocket">
<option value="0">Batch notifications (old)</option>
<option value="1">Instant notifications</option>
</select>
</label>
<div class="setting-summary">
<div class="vh-toolbar-icon vh-icon-question"></div>
<strong>Batch notifications:</strong> Old method: Query the server at regular interval to receive a list of
the recent products. Use more server resources and add a ~30 second delay between the updates.
<br />
<strong>Instant notifications:</strong> Use Websockets to try to establish a persistent connection with the
API to received notifications in real time.
</div>
</div>
<hr />
<div class="setting-container">
<label for="notification.pushNotificationsAFA">
<input type="checkbox" name="notification.pushNotificationsAFA" value="1" />
Expand Down
1 change: 0 additions & 1 deletion scripts/SettingsMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ class SettingsMgr {
notification: {
active: false,
reduce: false,
websocket: true,
lastProduct: 0,
pushNotifications: false,
soundCooldownDelay: 2000,
Expand Down
17 changes: 5 additions & 12 deletions scripts/vh_service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +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") == "1") {
fetchLast100Items(true);
}
fetchLast100Items(true);
sendResponse({ success: true });
}

Expand All @@ -128,15 +126,10 @@ browser.alarms.onAlarm.addListener(async (alarm) => {
await retrieveSettings();

if (alarm.name === "checkNewItems") {
if (Settings.get("notification.websocket") == "0" || !Settings.get("notification.active")) {
socket?.disconnect();
}
if (Settings.get("notification.active")) {
if (Settings.get("notification.websocket") == "1") {
connectWebSocket(); //Check the status of the websocket, reconnect if closed.
} else {
fetchLast100Items();
}
connectWebSocket(); //Check the status of the websocket, reconnect if closed.
} else {
socket?.disconnect();
}
}
});
Expand Down Expand Up @@ -238,7 +231,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") == "1") {
if (Settings.get("notification.active")) {
//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 202f50a

Please sign in to comment.