The iOS app opens offline: the page is kept however it was loaded (#506)
The phone in airplane mode opened to "Cannot reach ipodderx.sdf1.net". The service worker kept the page only when a navigation passed through it, and the app's own load from Swift may not, so it had no page to answer with. The page now asks the worker to keep / on every load, and the app, when a load fails for want of a connection, tries once more from the web view's cache (returnCacheDataDontLoad) before the alert. The Swift is not compiled here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RqkrVCCH8YcP2Y3i8VNYWA
This commit is contained in:
@@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- The page is kept for opening offline however it was loaded, so the iOS app opens with no connection too (#506).
|
||||
- On a phone, an episode's row is one line like the rest: its length, which took a line of its own, is in the reader, and the date sits on the title's line (#500).
|
||||
- On an iPhone, the reader rebuilds its scrolling each time an item opens, and again after a drag that did not move it, so a freshly opened item scrolls on the first try (#450).
|
||||
- The count under All Subscriptions counts only its own unread items, not those of feeds hidden from it, so it agrees with the header (#499).
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
// it was.
|
||||
const worker=('serviceWorker' in navigator) ? navigator.serviceWorker : null;
|
||||
worker?.register('/sw.js').catch(()=>{});
|
||||
// The worker keeps this page for opening offline, however it was loaded (#506).
|
||||
void worker?.ready.then(r=>r.active?.postMessage({keepPage:true}));
|
||||
const toWorker=(msg: object)=>worker?.controller?.postMessage(msg);
|
||||
/// What waited for the connection goes now: on its return, and when the live stream comes back.
|
||||
function flushOutbox(){ toWorker({flush:true}); }
|
||||
|
||||
11
web/sw/sw.ts
11
web/sw/sw.ts
@@ -53,8 +53,11 @@ sw.addEventListener('fetch', e => {
|
||||
});
|
||||
|
||||
sw.addEventListener('message', e => {
|
||||
const m = e.data as {flush?: boolean, pictures?: string[]} | null;
|
||||
const m = e.data as {flush?: boolean, pictures?: string[], keepPage?: boolean} | null;
|
||||
if (m?.flush) e.waitUntil(flush());
|
||||
// Asked by the page each time it loads, since what loaded it may not have come through here:
|
||||
// the iOS app's own load of the page never did, so the worker had no page to open offline (#506).
|
||||
if (m?.keepPage) e.waitUntil(fetch('/', { credentials: 'same-origin', redirect: 'manual' }).then(keepPage, () => {}));
|
||||
if (Array.isArray(m?.pictures)) e.waitUntil(keepPictures(m.pictures));
|
||||
});
|
||||
|
||||
@@ -63,13 +66,17 @@ sw.addEventListener('message', e => {
|
||||
async function page(req: Request): Promise<Response> {
|
||||
try {
|
||||
const r = await fetch(req);
|
||||
if (r.ok && r.type === 'basic' && new URL(req.url).pathname === '/') (await caches.open(PAGE)).put('/', r.clone());
|
||||
if (new URL(req.url).pathname === '/') await keepPage(r);
|
||||
return r;
|
||||
} catch {
|
||||
return (await caches.match('/', { cacheName: PAGE })) || Response.error();
|
||||
}
|
||||
}
|
||||
|
||||
async function keepPage(r: Response) {
|
||||
if (r.ok && r.type === 'basic') await (await caches.open(PAGE)).put('/', r.clone());
|
||||
}
|
||||
|
||||
async function hashed(req: Request, client: string): Promise<Response> {
|
||||
const kept = await caches.match(req, { cacheName: PAGE });
|
||||
if (kept) return kept;
|
||||
|
||||
Reference in New Issue
Block a user