Skip to content

Commit

Permalink
fixup! TF-3157 Update web socket with background service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
tddang-linagora committed Oct 31, 2024
1 parent 981beb9 commit da93802
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
2 changes: 2 additions & 0 deletions web/web-sockets-worker.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
importScripts("flutter_service_worker.js?v=null");

var webSocket;
const broadcast = new BroadcastChannel("background-message");
var intervalId;
Expand Down
17 changes: 1 addition & 16 deletions web/worker_service/worker_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@ function fetchServiceWorker() {
// Wait for registration to finish before dropping the <script>tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
navigator.serviceWorker.register('web-sockets-worker.js').then(serviceWorkerRegistration => {
console.info('[TwakeMail] fetchServiceWorker(): Service worker web socket was registered.');
}).catch(error => {
console.error(
'[TwakeMail] fetchServiceWorker(): An error occurred while registering the service worker web socket.'
);
console.error(error);
});
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
navigator.serviceWorker.register('web-sockets-worker.js')
.then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => {
Expand All @@ -47,12 +38,6 @@ function fetchServiceWorker() {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing || reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('[TwakeMail] fetchServiceWorker(): New service worker available.');
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log('[TwakeMail] fetchServiceWorker(): Loading app from service worker.');
Expand Down

0 comments on commit da93802

Please sign in to comment.