fix(native): start without the server on Android and keep the offline start on iOS

A tester with a server on his home network could not open the Android app
away from it: after closing the app and turning Wi-Fi off it stayed on the
address screen ("No server answered at this address").

- Android keeps the server's UI itself (TrekOfflineShell): the start page
  and every file of the build, listed by native/offlineShell.ts from the
  server's manifest and downloaded natively. A web view runs no service
  worker on a plain-http server, the usual address of a server at home, so
  the old "Android has the service worker" assumption did not hold.
- Without a network, or once the server failed to load twice, the web view
  serves the copy under the server's origin with Capacitor's bridge; the UI
  runs on its own offline data and the API answers again once the server
  is back. The address screen opens the copy too (openOfflineCopy).
- The check an update asks for no longer locks the app out offline: on both
  platforms a server out of reach is put back on its copy and checked on
  the next launch that reaches it. iOS no longer throws its copy away when
  the update check runs.
This commit is contained in:
Maurice
2026-11-14 11:34:28 +01:00
parent 91f8deb3f3
commit c23518dae0
14 changed files with 537 additions and 38 deletions
+26
View File
@@ -99,4 +99,30 @@ describe('keepOfflineShellFresh', () => {
await keepOfflineShellFresh(fetchImpl, 'fr');
expect(fetched).toContain('/assets/fr-bbbb2222.js');
});
it('on Android hands the list to the native store instead of fetching it here', async () => {
vi.mocked(TrekShell.refreshOfflineCopy).mockResolvedValue({ saved: true, complete: true });
const fetchImpl = vi.fn(async (input: RequestInfo | URL) => {
if (String(input) === '/asset-manifest.json') return new Response(JSON.stringify(manifest));
throw new Error('the native side fetches the files');
}) as unknown as typeof fetch;
await keepOfflineShellFresh(fetchImpl, 'en', true);
expect(fetchImpl).toHaveBeenCalledTimes(1);
expect(TrekShell.refreshOfflineCopy).toHaveBeenCalledTimes(1);
const { files } = vi.mocked(TrekShell.refreshOfflineCopy).mock.calls[0][0] as { files: string[] };
expect(files).toContain('assets/index-a1b2c3d4.js');
expect(files).toContain('assets/AtlasPage-99887766.js');
});
it('on Android asks again on the next launch while the store is incomplete', async () => {
vi.mocked(TrekShell.refreshOfflineCopy).mockResolvedValue({ saved: true, complete: false });
const fetchImpl = vi.fn(async () => new Response(JSON.stringify(manifest))) as unknown as typeof fetch;
await keepOfflineShellFresh(fetchImpl, 'en', true);
await keepOfflineShellFresh(fetchImpl, 'en', true);
expect(TrekShell.refreshOfflineCopy).toHaveBeenCalledTimes(2);
});
});