initial commit
Some checks failed
Build and Deploy / build (push) Has been cancelled
Build and Deploy / deploy (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled

This commit is contained in:
2024-07-08 04:53:50 -05:00
parent 33ebd7d5c9
commit 2eeeb8b8c1
196 changed files with 12617 additions and 75 deletions

51
_javascript/pwa/app.js Normal file
View File

@@ -0,0 +1,51 @@
import { pwa, baseurl } from '../../_config.yml';
import Toast from 'bootstrap/js/src/toast';
if ('serviceWorker' in navigator) {
if (pwa.enabled) {
const swUrl = `${baseurl}/sw.min.js`;
const notification = document.getElementById('notification');
const btnRefresh = notification.querySelector('.toast-body>button');
const popupWindow = Toast.getOrCreateInstance(notification);
navigator.serviceWorker.register(swUrl).then((registration) => {
// In case the user ignores the notification
if (registration.waiting) {
popupWindow.show();
}
registration.addEventListener('updatefound', () => {
registration.installing.addEventListener('statechange', () => {
if (registration.waiting) {
if (navigator.serviceWorker.controller) {
popupWindow.show();
}
}
});
});
btnRefresh.addEventListener('click', () => {
if (registration.waiting) {
registration.waiting.postMessage('SKIP_WAITING');
}
popupWindow.hide();
});
});
let refreshing = false;
// Detect controller change and refresh all the opened tabs
navigator.serviceWorker.addEventListener('controllerchange', () => {
if (!refreshing) {
window.location.reload();
refreshing = true;
}
});
} else {
navigator.serviceWorker.getRegistrations().then(function (registrations) {
for (let registration of registrations) {
registration.unregister();
}
});
}
}