mirror of
https://github.com/antebudimir/feishin.git
synced 2026-03-01 19:57:26 +00:00
[Remote] Full PWA support, misc bugfixes (#280)
- Fix setting remote port properly - Add web worker support (so it can be installed as an "app") - build fixes/removing stray console.log
This commit is contained in:
parent
fe298d3232
commit
9964f95d5d
11 changed files with 314 additions and 194 deletions
|
|
@ -6,6 +6,14 @@
|
|||
<meta http-equiv="Content-Security-Policy" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Feishin Remote</title>
|
||||
<link rel="manifest" href="manifest.json">
|
||||
<script>
|
||||
if ('serviceWorker' in navigator) {
|
||||
const version = encodeURIComponent("<%= version %>");
|
||||
const prod = encodeURIComponent("<%= prod %>");
|
||||
navigator.serviceWorker.register(`/worker.js?version=${version}&prod=${prod}`);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
|||
17
src/remote/manifest.json
Normal file
17
src/remote/manifest.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "Feishin Remote",
|
||||
"short_name": "Feishin Remote",
|
||||
"start_url": "/",
|
||||
"background_color": "#FFDCB5",
|
||||
"theme_color": "#1E003D",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable any"
|
||||
}
|
||||
],
|
||||
"display": "standalone",
|
||||
"orientation": "portrait"
|
||||
}
|
||||
48
src/remote/service-worker.ts
Normal file
48
src/remote/service-worker.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/// <reference lib="WebWorker" />
|
||||
|
||||
export type {};
|
||||
// eslint-disable-next-line no-undef
|
||||
declare const self: ServiceWorkerGlobalScope;
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
const url = new URL(location.toString());
|
||||
const version = url.searchParams.get('version');
|
||||
const prod = url.searchParams.get('prod') === 'true';
|
||||
const cacheName = `Feishin-remote-${version}`;
|
||||
|
||||
const resourcesToCache = ['./', './remote.js', './favicon.ico'];
|
||||
|
||||
if (prod) {
|
||||
resourcesToCache.push('./remote.css');
|
||||
}
|
||||
|
||||
self.addEventListener('install', (e) => {
|
||||
e.waitUntil(
|
||||
caches.open(cacheName).then((cache) => {
|
||||
return cache.addAll(resourcesToCache);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (e) => {
|
||||
e.respondWith(
|
||||
caches.match(e.request).then((response) => {
|
||||
return response || fetch(e.request);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (e) => {
|
||||
e.waitUntil(
|
||||
caches.keys().then((keyList) => {
|
||||
return Promise.all(
|
||||
keyList.map((key) => {
|
||||
if (key !== cacheName) {
|
||||
return caches.delete(key);
|
||||
}
|
||||
return Promise.resolve();
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
|
@ -194,7 +194,6 @@ export const useRemoteStore = create<SettingsSlice>()(
|
|||
});
|
||||
},
|
||||
send: (data: ClientEvent) => {
|
||||
console.log(data, get().socket);
|
||||
get().socket?.send(JSON.stringify(data));
|
||||
},
|
||||
toggleIsDark: () => {
|
||||
|
|
|
|||
0
src/remote/worker.js
Normal file
0
src/remote/worker.js
Normal file
Loading…
Add table
Add a link
Reference in a new issue