Skip to content

Commit

Permalink
Restoring the Fetch Last 100 for Instant Notifications only
Browse files Browse the repository at this point in the history
  • Loading branch information
FMaz008 committed Oct 5, 2024
1 parent 3bdfcd1 commit 2850498
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion page/notifications.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1>Notifications monitoring:</h1>
</i>
</div>
<div class="monitor-toolbar">
<label for="fetch-last-100" style="display: none">
<label for="fetch-last-100">
<button name="fetch-last-100">Fetch last 100</button>
</label>
<label for="auto-truncate">
Expand Down
17 changes: 13 additions & 4 deletions page/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const TYPE_HIGHLIGHT = 2;
const SOUND_NONE = 0;
const SOUND_NOW = 1;
const SOUND_QUEUE = 2;
var muteLiveSound = false;

if (typeof browser === "undefined") {
var browser = chrome;
Expand Down Expand Up @@ -124,7 +125,7 @@ window.onload = function () {
addItem(data);
}
if (data.type == "ETVUpdate") {
if (Settings.get("notification.websocket")) {
if (Settings.get("notification.websocket") && !muteLiveSound) {
if (items.get(data.asin) === null) {
console.log("ETV Update received for item " + data.asin + " @ " + data.etv);
}
Expand All @@ -135,7 +136,7 @@ window.onload = function () {
}

if (data.type == "newItemCheck") {
muteSound = false;
muteLiveSound = true;
//Display a notification that we have checked for items.
let note = new ScreenNotification();
note.template = "view/notification_loading.html";
Expand All @@ -149,17 +150,20 @@ window.onload = function () {
notification_added_item = false;
notification_highlight = false;
notification_zeroETV = false;
muteLiveSound = false;
}

if (data.type == "wsOpen") {
document.getElementById("statusWS").innerHTML =
"<strong>Server status: </strong><div class='vh-switch-32 vh-icon-switch-on'></div> Listening for notifications...";
document.querySelector("label[for=fetch-last-100]").display = "block";
document.querySelector("label[for='fetch-last-100']").style.display = "block";
document.getElementById("statusWS").style.display = "block";
muteLiveSound = false;
}
if (data.type == "wsClosed") {
document.getElementById("statusWS").innerHTML =
"<strong>Server status: </strong><div class='vh-switch-32 vh-icon-switch-off'></div> Not connected. Retrying in 30 sec.";
document.querySelector("label[for=fetch-last-100]").display = "none";
document.querySelector("label[for='fetch-last-100']").style.display = "none";
}
};

Expand Down Expand Up @@ -195,6 +199,7 @@ async function init() {

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

//Bind the event when changing the filter
Expand All @@ -216,6 +221,10 @@ 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")) {
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
6 changes: 3 additions & 3 deletions scripts/vh_service_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ if ("function" == typeof importScripts) {
//## LISTENERS
//#####################################################
browser.runtime.onMessage.addListener((data, sender, sendResponse) => {
/*
if (data.type == "fetchLast100Items") {
//Get the last 100 most recent items
fetchLast100Items(true);
if (Settings.get("notification.websocket")) {
fetchLast100Items(true);
}
sendResponse({ success: true });
}
*/

if (data.type == "wsStatus") {
sendResponse({ success: true });
Expand Down

0 comments on commit 2850498

Please sign in to comment.