This repository was archived by the owner on Oct 11, 2026. It is now read-only.
Repository navigation
feat(web): make the web app an installable PWA #193
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "id": "/", | ||
| "name": "Switchify Remote", | ||
| "short_name": "Switchify Remote", | ||
| "description": "Control a Windows PC or Mac running Switchify PC over Bluetooth.", | ||
| "start_url": "/", | ||
| "scope": "/", | ||
| "display": "standalone", | ||
| "orientation": "any", | ||
| "background_color": "#050505", | ||
| "theme_color": "#050505", | ||
| "categories": ["accessibility", "utilities"], | ||
| "icons": [ | ||
| { "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" }, | ||
| { "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" }, | ||
| { "src": "/icons/maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Switchify Remote service worker. Pages come from the network first so a new | ||
| // deployment is never stuck behind the cache; content-hashed bundles and assets | ||
| // are cached once and reused, which lets the app open offline after a visit. | ||
| const CACHE = 'switchify-remote-v1'; | ||
| const SHELL = ['/', '/manifest.json', '/icons/icon-192.png', '/icons/icon-512.png']; | ||
| const IMMUTABLE = ['/_expo/static/', '/assets/']; | ||
|
|
||
| self.addEventListener('install', (event) => { | ||
| event.waitUntil(caches.open(CACHE).then((cache) => cache.addAll(SHELL)).then(() => self.skipWaiting())); | ||
| }); | ||
|
|
||
| self.addEventListener('activate', (event) => { | ||
| event.waitUntil( | ||
| caches.keys() | ||
| .then((keys) => Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key)))) | ||
| .then(() => self.clients.claim()), | ||
| ); | ||
| }); | ||
|
|
||
| async function networkFirst(request) { | ||
| const cache = await caches.open(CACHE); | ||
| try { | ||
| const response = await fetch(request); | ||
| if (response.ok) await cache.put(request, response.clone()); | ||
| return response; | ||
|
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If browser storage is full, Artifacts
Prompt To Fix With AIThis is a comment left during a code review.
Path: public/sw.js
Line: 23-25
Comment:
**Full storage breaks online loading**
If browser storage is full, `cache.put` can fail after a successful download. `networkFirst` then returns an old cached page, while `cacheFirst` rejects the bundle request instead of returning the downloaded code. Users can get an old build or an app that fails to load even while online. Catch cache-write failures separately in both functions and still return the downloaded response. This loading failure must be fixed before merging.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. |
||
| } catch (error) { | ||
| const cached = (await cache.match(request, { ignoreSearch: true })) ?? (await cache.match('/')); | ||
| if (cached) return cached; | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| async function cacheFirst(request) { | ||
| const cache = await caches.open(CACHE); | ||
| const cached = await cache.match(request); | ||
| if (cached) return cached; | ||
| const response = await fetch(request); | ||
| if (response.ok) await cache.put(request, response.clone()); | ||
| return response; | ||
| } | ||
|
|
||
| self.addEventListener('fetch', (event) => { | ||
| const { request } = event; | ||
| if (request.method !== 'GET') return; | ||
| const url = new URL(request.url); | ||
| if (url.origin !== self.location.origin) return; | ||
| if (request.mode === 'navigate') { | ||
| event.respondWith(networkFirst(request)); | ||
| } else if (IMMUTABLE.some((prefix) => url.pathname.startsWith(prefix))) { | ||
| event.respondWith(cacheFirst(request)); | ||
| } else { | ||
| event.respondWith(networkFirst(request)); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { ScrollViewStyleReset } from 'expo-router/html'; | ||
| import { type PropsWithChildren } from 'react'; | ||
|
|
||
| // Runs only in Node during static rendering, so it decides here whether the page | ||
| // registers the service worker. Development builds never do, which keeps Metro's | ||
| // live bundles out of the cache. | ||
| const registerServiceWorker = ` | ||
| if ('serviceWorker' in navigator && window.isSecureContext) { | ||
| window.addEventListener('load', function () { | ||
| navigator.serviceWorker.register('/sw.js').catch(function () {}); | ||
| }); | ||
| }`; | ||
|
|
||
| export default function Root({ children }: PropsWithChildren) { | ||
| return ( | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charSet="utf-8" /> | ||
| <meta httpEquiv="X-UA-Compatible" content="IE=edge" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover" /> | ||
| <meta name="theme-color" content="#050505" /> | ||
| <meta name="description" content="Control a Windows PC or Mac running Switchify PC over Bluetooth." /> | ||
| <link rel="manifest" href="/manifest.json" /> | ||
| <link rel="apple-touch-icon" href="/icons/apple-touch-icon.png" /> | ||
| <ScrollViewStyleReset /> | ||
| {process.env.NODE_ENV === 'production' ? <script dangerouslySetInnerHTML={{ __html: registerServiceWorker }} /> : null} | ||
| </head> | ||
| <body>{children}</body> | ||
| </html> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Installation saves the root HTML but none of its required JavaScript bundles.
registerServiceWorkerruns afterload, when the first visit's bundles have already loaded without the worker. Until another controlled visit, offline startup depends on the browser's separate HTTP cache. If that cache is gone, the installed app cannot open offline. This is a non-blocking offline reliability gap: save the required bundles during installation as well.Artifacts
Evidence from the check
Evidence from the check
Command output from the check
▶ Recording of the check
Screenshot of the first online visit
▶ Recording of the check
Screenshot of the nonfunctional offline launch
Prompt To Fix With AI