1
0
Fork 0
forked from fte/fteqw
fteqw/engine/web/fte_pwa_sw.js
Shpoike 8dadfb4878 Added sys_openfile console command(and menu option) to web and flatpak(via cmake+dbus) builds, to 'install' packages on sandboxed systems a bit more easily.
Cmake: Add FTE_WERROR option, defaults to true in debug builds and off in release builds (in case future compilers have issues).
Cmake: Pull in libXscreensaver so we don't get interrupted by screensavers when playing demos.
Make: Added `make webcl-rel` for a web build without server bloat (eg for sites focused on demo playback. Yes, this means you XantoM).
fteqcc: Include the decompiler in fteqcc (non-gui) builds ('-d' arg).
fteqcc: Decompiler can now mostly handle hexen2 mods without any unknown opcodes.
Allow ezHud and OpenSSL to be compiled as in-engine plugins, potentially for web and windows ports respectively.
Web: Fix support for ogg vorbis. Add support for voip.
Web: Added basic support for WebXR.
QTV: Don't try seeking on unseekable qtv streams. Don't spam when developer 1 is set.
QTV: add support for some eztv extensions.
MVD: added hack to use ktx's vweps in mvd where mvdsv doesn't bother to record the info.
qwfwd: hack around a hack in qwfwd, allowing it to work again.
recording: favour qwd in single player, instead of mvd.
Protocol: reduce client memory used for precache names. Bump maximum precache counts - some people are just abusive, yes you Orl.
hexen2: add enough clientside protocol compat to play the demo included with h2mp. lacks effects.
in_xflip: restored this setting.
fs_hidesyspaths: new cvar, defaults to enabled so you won't find your username or whatever turning up in screenshots or the like. change it to 0 before debuging stuff eg via 'path'.
gl_overbright_models: Added cvar to match QS.
netchan: Added MTU determination, we'll no longer fail to connect when routers stupidly drop icmp packets.
Win: try a few other versions of xinput too.
CSQC: Added a CSQC_GenerateMaterial function, to give the csqc a chance to generate custom materials.
MenuQC: Added support for the skeletal objects API.
2024-07-14 19:58:24 +01:00

101 lines
2.3 KiB
JavaScript

const addResourcesToCache = async (resources) =>
{
const cache = await caches.open('v1');
await cache.addAll(resources);
};
const putInCache = async (request, response) =>
{
const cache = await caches.open('v1');
await cache.put(request, response);
};
function shouldcache(name)
{
if (name.indexOf("/raw/"))
return false;
if (name.indexOf("/downloadables"))
return false;
return true;
};
const cacheFirst = async ({ request, preloadResponsePromise }) =>
{
// First try to get the resource from the cache
const responseFromCache = await caches.match(request);
if (responseFromCache)
{
// console.log("cacheFirst - from cache", request, preloadResponsePromise, responseFromCache);
return responseFromCache;
}
// Next try to use the preloaded response, if it's there
const preloadResponse = await preloadResponsePromise;
if (preloadResponse)
{
// console.info('using preload response', preloadResponse);
if (shouldcache(request.url))
putInCache(request, preloadResponse.clone());
return preloadResponse;
}
// Next try to get the resource from the network
try
{
const responseFromNetwork = await fetch(request.clone());
// response may be used only once
// we need to save clone to put one copy in cache
// and serve second one
if (shouldcache(request.url))
putInCache(request, responseFromNetwork.clone());
// console.info('fetching from network', responseFromNetwork);
return responseFromNetwork;
}
catch (error)
{
// console.info('failure', preloadResponse);
// there is nothing we can do, but we must always
// return a Response object
return new Response('Network error happened',
{
status: 408,
headers: { 'Content-Type': 'text/plain' },
});
}
};
const enableNavigationPreload = async () =>
{
if (self.registration.navigationPreload)
{
// Enable navigation preloads!
await self.registration.navigationPreload.enable();
}
};
self.addEventListener('activate', (event) =>
{
event.waitUntil(enableNavigationPreload());
});
self.addEventListener('install', (event) =>
{
event.waitUntil(
addResourcesToCache([
'./',
'./fte_pwa.json',
'./fte_pwa_sw.js',
'./ftewebgl.js',
'./ftewebgl.wasm'
])
);
});
self.addEventListener('fetch', (event) =>
{
event.respondWith(cacheFirst(
{
request: event.request,
preloadResponsePromise: event.preloadResponse
}));
});