-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not build the service worker if the file is empty #104
- Loading branch information
Showing
9 changed files
with
207 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
/* do not edit! */ | ||
/** | ||
* Service worker browser client | ||
* @package GZip Plugin | ||
* @copyright Copyright (C) 2005 - 2018 Thierry Bela. | ||
* | ||
* dual licensed | ||
* | ||
* @license LGPL v3 | ||
* @license MIT License | ||
*/ | ||
// @ts-check | ||
// build d108aa3 2020-10-12 20:38:26-04:00 | ||
if ("serviceWorker" in navigator) { | ||
navigator.serviceWorker.register("{scope}worker{debug}.js", { | ||
scope: "{scope}" | ||
}).catch((function(error) { | ||
// console.log(error); | ||
console.error("😭", error); | ||
})); | ||
} | ||
/** | ||
* Service worker browser client | ||
* @package GZip Plugin | ||
* @copyright Copyright (C) 2005 - 2018 Thierry Bela. | ||
* | ||
* dual licensed | ||
* | ||
* @license LGPL v3 | ||
* @license MIT License | ||
*/ | ||
|
||
// @ts-check | ||
|
||
// build 77ad4d7 2020-10-14 21:54:44-04:00 | ||
|
||
if ("serviceWorker" in navigator) { | ||
navigator.serviceWorker. | ||
register("{scope}worker{debug}.js", {scope: "{scope}"}). | ||
// .then(function(registration) { | ||
|
||
// console.log("🍻"); | ||
// }) | ||
catch(function(error) { | ||
// console.log(error); | ||
console.error("😭", error); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,90 @@ | ||
/* do not edit! */ | ||
/** | ||
* Service worker browser client | ||
* @package GZip Plugin | ||
* @copyright Copyright (C) 2005 - 2018 Thierry Bela. | ||
* | ||
* dual licensed | ||
* | ||
* @license LGPL v3 | ||
* @license MIT License | ||
*/ | ||
// @ts-check | ||
// build d108aa3 2020-10-12 20:38:26-04:00 | ||
if ("serviceWorker" in navigator) { | ||
navigator.serviceWorker.register("{scope}worker{debug}.js", { | ||
scope: "{scope}" | ||
}).catch((function(error) { | ||
// console.log(error); | ||
console.error("😭", error); | ||
})); | ||
if ("onbeforeinstallprompt" in window) { | ||
let deferredPrompt; | ||
let button; | ||
const buttonHTML = '<div class="pwa-app-install pwa-app-install-bottom"><div class="alert alert-success"><div class=alert-body>' + "<button type=button class=close data-dismiss=alert aria-label=Close>" + "<span aria-hidden=true>×</span>" + "</button>" + "Click <a href=# data-action=install-pwa-app>here</a> to make this site available offline."; | ||
const clickHandler = function(e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
deferredPrompt.prompt(); | ||
button.removeEventListener("click", clickHandler, false); | ||
button = null; | ||
// log the platforms provided as options in an install prompt | ||
// console.log(deferredPrompt.platforms); // e.g., ["web", "android", "windows"] | ||
deferredPrompt.userChoice.then((function(outcome) { | ||
console.info(outcome); | ||
// either "installed", "dismissed", etc. | ||
}), (function(error) { | ||
console.error("😭", error); | ||
})); | ||
// e.target.closest('[data-action=install-pwa-app]').removeEventListener('click', clickHandler, false) | ||
}; | ||
const createButton = function() { | ||
document.body.insertAdjacentHTML("beforeend", buttonHTML); | ||
button = document.querySelector("a[data-action=install-pwa-app]"); | ||
button.addEventListener("click", clickHandler, false); | ||
}; | ||
window.addEventListener("beforeinstallprompt", (function(e) { | ||
// console.log("beforeinstallprompt", e); | ||
deferredPrompt = e; | ||
e.preventDefault(); | ||
// if ("getInstalledRelatedApps" in navigator) { | ||
// navigator.getInstalledRelatedApps().then(function(relatedApps) { | ||
// if (relatedApps.length == 0) { | ||
// createButton(); | ||
// } | ||
// }); | ||
// } else { | ||
createButton(); | ||
// } | ||
})); | ||
} | ||
} | ||
/** | ||
* Service worker browser client | ||
* @package GZip Plugin | ||
* @copyright Copyright (C) 2005 - 2018 Thierry Bela. | ||
* | ||
* dual licensed | ||
* | ||
* @license LGPL v3 | ||
* @license MIT License | ||
*/ | ||
|
||
// @ts-check | ||
|
||
// build 77ad4d7 2020-10-14 21:54:44-04:00 | ||
|
||
if ("serviceWorker" in navigator) { | ||
navigator.serviceWorker. | ||
register("{scope}worker{debug}.js", { | ||
scope: "{scope}" | ||
}). | ||
// .then(function(registration) { | ||
|
||
// console.log("🍻"); | ||
// }) | ||
catch(function (error) { | ||
// console.log(error); | ||
console.error("😭", error); | ||
}); | ||
|
||
if ("onbeforeinstallprompt" in window) { | ||
let deferredPrompt; | ||
let button; | ||
|
||
const buttonHTML = | ||
'<div class="pwa-app-install pwa-app-install-bottom"><div class="alert alert-success"><div class=alert-body>' + | ||
"<button type=button class=close data-dismiss=alert aria-label=Close>" + | ||
"<span aria-hidden=true>×</span>" + | ||
"</button>" + | ||
"Click <a href=# data-action=install-pwa-app>here</a> to make this site available offline."; | ||
|
||
const clickHandler = function (e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
deferredPrompt.prompt(); | ||
|
||
button.removeEventListener("click", clickHandler, false); | ||
button = null; | ||
|
||
// log the platforms provided as options in an install prompt | ||
// console.log(deferredPrompt.platforms); // e.g., ["web", "android", "windows"] | ||
|
||
deferredPrompt.userChoice.then( | ||
function (outcome) { | ||
console.info(outcome); // either "installed", "dismissed", etc. | ||
}, | ||
function (error) { | ||
console.error("😭", error); | ||
} | ||
); | ||
|
||
// e.target.closest('[data-action=install-pwa-app]').removeEventListener('click', clickHandler, false) | ||
}; | ||
|
||
const createButton = function () { | ||
document.body.insertAdjacentHTML("beforeend", buttonHTML); | ||
button = document.querySelector("a[data-action=install-pwa-app]"); | ||
|
||
button.addEventListener("click", clickHandler, false); | ||
}; | ||
|
||
window.addEventListener("beforeinstallprompt", function (e) { | ||
// console.log("beforeinstallprompt", e); | ||
|
||
deferredPrompt = e; | ||
|
||
e.preventDefault(); | ||
|
||
// if ("getInstalledRelatedApps" in navigator) { | ||
// navigator.getInstalledRelatedApps().then(function(relatedApps) { | ||
// if (relatedApps.length == 0) { | ||
// createButton(); | ||
// } | ||
// }); | ||
// } else { | ||
createButton(); | ||
// } | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,40 @@ | ||
/* do not edit! */ | ||
/** | ||
* Service worker browser client | ||
* @package GZip Plugin | ||
* @copyright Copyright (C) 2005 - 2018 Thierry Bela. | ||
* | ||
* dual licensed | ||
* | ||
* @license LGPL v3 | ||
* @license MIT License | ||
*/ | ||
// @ts-check | ||
if ("serviceWorker" in navigator) { | ||
if ("SyncManager" in window) { | ||
navigator.serviceWorker.ready.then((function(reg) { | ||
return reg.sync.getTags().then((function(tags) { | ||
if (!tags.includes("{SYNC_API_TAG}")) { | ||
reg.sync.register("{SYNC_API_TAG}"); | ||
} | ||
})); | ||
})).catch((function(error) { | ||
// system was unable to register for a sync, | ||
// this could be an OS-level restriction | ||
console.error("cannot setup native sync api, using fallback 😭", error); | ||
new Worker("{scope}sync-fallback{debug}.js"); | ||
})); | ||
} else { | ||
// serviceworker/sync not supported, use a worker instead | ||
console.info("background sync api not supported, using fallback 😭"); | ||
new Worker("{scope}sync-fallback{debug}.js"); | ||
} | ||
} | ||
/** | ||
* Service worker browser client | ||
* @package GZip Plugin | ||
* @copyright Copyright (C) 2005 - 2018 Thierry Bela. | ||
* | ||
* dual licensed | ||
* | ||
* @license LGPL v3 | ||
* @license MIT License | ||
*/ | ||
|
||
// @ts-check | ||
|
||
if ('serviceWorker' in navigator) { | ||
|
||
if ('SyncManager' in window) { | ||
|
||
navigator.serviceWorker.ready.then(function (reg) { | ||
|
||
return reg.sync.getTags().then(function (tags) { | ||
|
||
if (!tags.includes("{SYNC_API_TAG}")) { | ||
reg.sync.register("{SYNC_API_TAG}"); | ||
} | ||
}) | ||
}). | ||
catch(function (error) { | ||
// system was unable to register for a sync, | ||
// this could be an OS-level restriction | ||
console.error('cannot setup native sync api, using fallback 😭', error); | ||
new Worker("{scope}sync-fallback{debug}.js"); | ||
}); | ||
|
||
} else { | ||
|
||
// serviceworker/sync not supported, use a worker instead | ||
console.info('background sync api not supported, using fallback 😭'); | ||
new Worker("{scope}sync-fallback{debug}.js"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
"serviceWorker"in navigator&&("SyncManager"in window?navigator.serviceWorker.ready.then((function(n){return n.sync.getTags().then((function(e){e.includes("{SYNC_API_TAG}")||n.sync.register("{SYNC_API_TAG}")}))})).catch((function(n){console.error("cannot setup native sync api, using fallback 😭",n),new Worker("{scope}sync-fallback{debug}.js")})):new Worker("{scope}sync-fallback{debug}.js")); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
/* do not edit! */ | ||
/** | ||
* Service worker browser client uninstall | ||
* @package GZip Plugin | ||
* @copyright Copyright (C) 2005 - 2018 Thierry Bela. | ||
* | ||
* dual licensed | ||
* | ||
* @license LGPL v3 | ||
* @license MIT License | ||
*/ | ||
// @ts-check | ||
// build d108aa3 2020-10-12 20:38:26-04:00 | ||
if ("serviceWorker" in navigator && navigator.serviceWorker.controller) { | ||
navigator.serviceWorker.getRegistration().then((function(registration) { | ||
registration.unregister().then((function(result) { | ||
if (result) { | ||
console.info("The service worker has been successfully removed 😭"); | ||
} | ||
})); | ||
})); | ||
} | ||
/** | ||
* Service worker browser client uninstall | ||
* @package GZip Plugin | ||
* @copyright Copyright (C) 2005 - 2018 Thierry Bela. | ||
* | ||
* dual licensed | ||
* | ||
* @license LGPL v3 | ||
* @license MIT License | ||
*/ | ||
// @ts-check | ||
|
||
// build 77ad4d7 2020-10-14 21:54:44-04:00 | ||
|
||
if ("serviceWorker" in navigator && navigator.serviceWorker.controller) { | ||
navigator.serviceWorker.getRegistration().then(function (registration) { | ||
|
||
registration.unregister().then(function (result) { | ||
|
||
if (result) { | ||
|
||
console.info('The service worker has been successfully removed 😭'); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
da39a3ee5e6b4b0d3255bfef95601890afd80709 | ||
c22fadaa841cf95cf62c214f8edb67521ea00d0e |