Skip to content

Commit

Permalink
Fix issue where listener wasn't removed and logic was called many times
Browse files Browse the repository at this point in the history
(reference #53 )
  • Loading branch information
piotrzarzycki21 committed May 9, 2024
1 parent efdfe5b commit 9da5186
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Super.Human.Portal_Royale/src/resources/nomadhelper.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
const hrefUrl = new URL(link);

if (navigator && navigator.serviceWorker && navigator.serviceWorker.controller) {
navigator.serviceWorker.onmessage = function(event) {
var messageFunction = function(event) {
if (event.data.type == 'numberOfWindowClients') {
if (event.data.clientCount > 1)
{
navigator.serviceWorker.controller.postMessage({
navigator.serviceWorker.controller.postMessage({
type: 'openNotesUri',
payload: {
notesUri: decodeURIComponent(
Expand All @@ -31,17 +31,20 @@
)
}
});

window.top.postMessage('[Success] Successfully called openNotesUri', '*');
}
else
{
console.error('Nomad Window is closed');
window.top.postMessage('[Error] Nomad Window is closed', '*');
}


navigator.serviceWorker.removeEventListener('message', messageFunction);
}
};


navigator.serviceWorker.addEventListener('message', messageFunction);
navigator.serviceWorker.controller.postMessage({type: 'numberOfWindowClients'});
} else {
console.error('No service worker registered');
Expand Down

0 comments on commit 9da5186

Please sign in to comment.