mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:42:45 +08:00
FEATURE: Enable service worker for Apple devices (#19643)
This is necessary so MacOS Ventura (and in 2023 iOS) can use our new default push notifications. We still disable caching of dynamic routes on Apple devices due to it's always being buggy there.
This commit is contained in:
parent
a6b680f4fe
commit
587e9ed9ba
|
@ -6,12 +6,7 @@ export function registerServiceWorker(
|
|||
registerOptions = {}
|
||||
) {
|
||||
if (window.isSecureContext && "serviceWorker" in navigator) {
|
||||
const caps = container.lookup("capabilities:main");
|
||||
const isAppleBrowser =
|
||||
caps.isSafari ||
|
||||
(caps.isIOS && !window.matchMedia("(display-mode: standalone)").matches);
|
||||
|
||||
if (serviceWorkerURL && !isAppleBrowser) {
|
||||
if (serviceWorkerURL) {
|
||||
navigator.serviceWorker.getRegistrations().then((registrations) => {
|
||||
for (let registration of registrations) {
|
||||
if (
|
||||
|
|
|
@ -19,11 +19,12 @@ var externalCacheName = "external-" + cacheVersion;
|
|||
// https://bugs.chromium.org/p/chromium/issues/detail?id=1286367
|
||||
var chromeVersionMatch = navigator.userAgent.match(/Chrome\/97.0.(\d+)/);
|
||||
var isBrokenChrome97 = chromeVersionMatch && parseInt(chromeVersionMatch[1]) <= 4692;
|
||||
var isApple = /iPhone|iPod|Mac OS/.test(navigator.userAgent);
|
||||
|
||||
// Cache all GET requests, so Discourse can be used while offline
|
||||
workbox.routing.registerRoute(
|
||||
function(args) {
|
||||
return args.url.origin === location.origin && !authUrls.some(u => args.url.pathname.startsWith(u)) && !isBrokenChrome97;
|
||||
return args.url.origin === location.origin && !authUrls.some(u => args.url.pathname.startsWith(u)) && !isBrokenChrome97 && !isApple;
|
||||
}, // Match all except auth routes
|
||||
new workbox.strategies.NetworkFirst({ // This will only use the cache when a network request fails
|
||||
cacheName: discourseCacheName,
|
||||
|
|
Loading…
Reference in New Issue
Block a user