Files
app/nextjs/static/js/pwaInstaller.js
T

73 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function promptInstall() {
if (deferredPrompt == null) {
console.log('beforeinstallprompt has not been triggerred yet');
return;
}
// never show it if the app was launched standalone
if (navigator.standalone) {
return;
}
// Show the prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice
.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
} else {
console.log('User dismissed the A2HS prompt');
}
deferredPrompt = null;
});
}
var deferredPrompt;
/// cf https://developers.google.com/web/fundamentals/app-install-banners/
///
window.addEventListener('beforeinstallprompt', (e) => {
console.log('beforeinstallprompt triggered');
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
});
window.addEventListener('appinstalled', (evt) => {
console.log('a2hs installed');
});
const isInStandaloneMode = () =>
(window.matchMedia('(display-mode: standalone)').matches) || (window.navigator.standalone);
console.log('EdeclicLib loaded');
// window.addEventListener('error', function (e) {
// var errorText = [
// e.message,
// 'URL: ' + e.filename,
// 'Line: ' + e.lineno + ', Column: ' + e.colno,
// 'Stack: ' + (e.error && e.error.stack || '(no stack trace)')
// ].join('');
// console.log(errorText);
// // Example: log errors as visual output into the host page.
// // Note: you probably dont want to show such errors to users, or
// // have the errors get indexed by Googlebot; however, it may
// // be a useful feature while actively debugging the page.
// var DOM_ID = 'rendering-debug-pre';
// if (!document.getElementById(DOM_ID)) {
// var log = document.createElement('pre');
// log.id = DOM_ID;
// log.style.whiteSpace = 'pre-wrap';
// log.textContent = errorText;
// if (!document.body) document.body = document.createElement('body');
// document.body.insertBefore(log, document.body.firstChild);
// } else {
// document.getElementById(DOM_ID).textContent += ' ' + errorText;
// }
// });