mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-14 00:01:03 +00:00
034cfb539a
A browser that ran TREK before 5.1.1 keeps that version's app in its service worker. When the app opened /native-handoff, the worker answered it from its cache with an app that has no such page, which sent the user to /, and the sign-in ended on the dashboard in the browser instead of in the app. The app now opens /api/auth/native/start, which every TREK service worker passes to the server. That page takes the workers off the browser and forwards to the handoff page. Until the sign-in is handed back, the web app registers no service worker and does not reload for a new version: a tab still open on the older TREK keeps its worker alive, and a registration or a reload in the middle of the sign-in brought it back to answer the next page.
19 lines
825 B
JavaScript
19 lines
825 B
JavaScript
// Registers the service worker, as vite-plugin-pwa's own registerSW.js does; this
|
|
// file in public/ takes its place. Not while the app's sign-in runs in this browser
|
|
// (src/native/browserSignInFlag.ts): a tab still open on an older TREK keeps that
|
|
// version's worker alive, and registering now would bring it back to answer the
|
|
// sign-in's next page with an app that has no handoff page.
|
|
(function () {
|
|
if (!('serviceWorker' in navigator)) return;
|
|
try {
|
|
var started = Number(localStorage.getItem('trek_native_signin'));
|
|
var age = Date.now() - started;
|
|
if (started > 0 && age >= 0 && age < 15 * 60 * 1000) return;
|
|
} catch (e) {
|
|
/* site data blocked: register as usual */
|
|
}
|
|
window.addEventListener('load', function () {
|
|
navigator.serviceWorker.register('/sw.js', { scope: '/' });
|
|
});
|
|
})();
|