Merge pull request #1331 from thecodingmachine/UpdatePWA
Update PWA design
62
front/dist/resources/service-worker.html
vendored
@ -1,62 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport"
|
|
||||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
||||||
|
|
||||||
<!-- TRACK CODE -->
|
|
||||||
<!-- END TRACK CODE -->
|
|
||||||
|
|
||||||
<link rel="apple-touch-icon" sizes="57x57" href="/static/images/favicons/apple-icon-57x57.png">
|
|
||||||
<link rel="apple-touch-icon" sizes="60x60" href="/static/images/favicons/apple-icon-60x60.png">
|
|
||||||
<link rel="apple-touch-icon" sizes="72x72" href="/static/images/favicons/apple-icon-72x72.png">
|
|
||||||
<link rel="apple-touch-icon" sizes="76x76" href="/static/images/favicons/apple-icon-76x76.png">
|
|
||||||
<link rel="apple-touch-icon" sizes="114x114" href="/static/images/favicons/apple-icon-114x114.png">
|
|
||||||
<link rel="apple-touch-icon" sizes="120x120" href="/static/images/favicons/apple-icon-120x120.png">
|
|
||||||
<link rel="apple-touch-icon" sizes="144x144" href="/static/images/favicons/apple-icon-144x144.png">
|
|
||||||
<link rel="apple-touch-icon" sizes="152x152" href="/static/images/favicons/apple-icon-152x152.png">
|
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="/static/images/favicons/apple-icon-180x180.png">
|
|
||||||
<link rel="icon" type="image/png" sizes="192x192" href="/static/images/favicons/android-icon-192x192.png">
|
|
||||||
<link rel="icon" type="image/png" sizes="32x32" href="/static/images/favicons/favicon-32x32.png">
|
|
||||||
<link rel="icon" type="image/png" sizes="96x96" href="/static/images/favicons/favicon-96x96.png">
|
|
||||||
<link rel="icon" type="image/png" sizes="16x16" href="/static/images/favicons/favicon-16x16.png">
|
|
||||||
<meta name="msapplication-TileColor" content="#000000">
|
|
||||||
<meta name="msapplication-TileImage" content="/static/images/favicons/ms-icon-144x144.png">
|
|
||||||
<meta name="theme-color" content="#000000">
|
|
||||||
|
|
||||||
<title>WorkAdventure PWA</title>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
body{
|
|
||||||
font-family: Whitney, Lato, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
|
||||||
}
|
|
||||||
body img{
|
|
||||||
position: absolute;
|
|
||||||
top: calc( 50% - 25px);
|
|
||||||
height: 59px;
|
|
||||||
width: 307px;
|
|
||||||
left: calc( 50% - 150px);
|
|
||||||
}
|
|
||||||
body p{
|
|
||||||
position: absolute;
|
|
||||||
text-align: center;
|
|
||||||
top: calc( 50% + 50px);
|
|
||||||
left: calc( 50% - 150px);
|
|
||||||
height: 59px;
|
|
||||||
width: 307px;
|
|
||||||
font-size: 20px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<img src="/static/images/logo.png" alt="WorkAdventure logo"/>
|
|
||||||
<p>Charging your workspace ...</p>
|
|
||||||
<script>
|
|
||||||
setTimeout(() => {
|
|
||||||
window.location = localStorage.getItem('lastRoomUrl');
|
|
||||||
}, 4000);
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
61
front/dist/resources/service-worker.js
vendored
@ -1,61 +0,0 @@
|
|||||||
let CACHE_NAME = 'workavdenture-cache-v1';
|
|
||||||
let urlsToCache = [
|
|
||||||
'/'
|
|
||||||
];
|
|
||||||
|
|
||||||
self.addEventListener('install', function(event) {
|
|
||||||
// Perform install steps
|
|
||||||
event.waitUntil(
|
|
||||||
caches.open(CACHE_NAME)
|
|
||||||
.then(function(cache) {
|
|
||||||
console.log('Opened cache');
|
|
||||||
return cache.addAll(urlsToCache);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener('fetch', function(event) {
|
|
||||||
event.respondWith(
|
|
||||||
caches.match(event.request)
|
|
||||||
.then(function(response) {
|
|
||||||
// Cache hit - return response
|
|
||||||
if (response) {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fetch(event.request).then(
|
|
||||||
function(response) {
|
|
||||||
// Check if we received a valid response
|
|
||||||
if(!response || response.status !== 200 || response.type !== 'basic') {
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
// IMPORTANT: Clone the response. A response is a stream
|
|
||||||
// and because we want the browser to consume the response
|
|
||||||
// as well as the cache consuming the response, we need
|
|
||||||
// to clone it so we have two streams.
|
|
||||||
var responseToCache = response.clone();
|
|
||||||
|
|
||||||
caches.open(CACHE_NAME)
|
|
||||||
.then(function(cache) {
|
|
||||||
cache.put(event.request, responseToCache);
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener('wait', function(event) {
|
|
||||||
//TODO wait
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener('update', function(event) {
|
|
||||||
//TODO update
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener('beforeinstallprompt', (e) => {
|
|
||||||
//TODO change prompt
|
|
||||||
});
|
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 978 B After Width: | Height: | Size: 950 B |
Before Width: | Height: | Size: 985 B After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
BIN
front/dist/static/images/favicons/apple-icon.png
vendored
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
front/dist/static/images/favicons/icon-512x512.png
vendored
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 3.4 KiB |
60
front/dist/static/images/favicons/manifest.json
vendored
@ -48,41 +48,10 @@
|
|||||||
"type": "image\/png"
|
"type": "image\/png"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"src": "/static/images/favicons/android-icon-36x36.png",
|
"src": "/static/images/favicons/apple-icon.png",
|
||||||
"sizes": "36x36",
|
"sizes": "192x192",
|
||||||
"type": "image\/png",
|
"type": "image\/png",
|
||||||
"density": "0.75"
|
"purpose": "any"
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/static/images/favicons/android-icon-48x48.png",
|
|
||||||
"sizes": "48x48",
|
|
||||||
"type": "image\/png",
|
|
||||||
"density": "1.0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/static/images/favicons/android-icon-72x72.png",
|
|
||||||
"sizes": "72x72",
|
|
||||||
"type": "image\/png",
|
|
||||||
"density": "1.5"
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
"src": "/static/images/favicons/favicon-16x16.png",
|
|
||||||
"sizes": "16x16",
|
|
||||||
"type": "image\/png",
|
|
||||||
"density": "1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/static/images/favicons/favicon-32x32.png",
|
|
||||||
"sizes": "32x32",
|
|
||||||
"type": "image\/png",
|
|
||||||
"density": "1.5"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"src": "/static/images/favicons/favicon-96x96.png",
|
|
||||||
"sizes": "96x96",
|
|
||||||
"type": "image\/png",
|
|
||||||
"density": "2.0"
|
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -122,18 +91,37 @@
|
|||||||
"density": "4.0",
|
"density": "4.0",
|
||||||
"purpose": "any maskable"
|
"purpose": "any maskable"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"src": "/static/images/favicons/favicon-16x16.png",
|
||||||
|
"sizes": "16x16",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/static/images/favicons/favicon-32x32.png",
|
||||||
|
"sizes": "32x32",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "1.5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/static/images/favicons/favicon-96x96.png",
|
||||||
|
"sizes": "96x96",
|
||||||
|
"type": "image\/png",
|
||||||
|
"density": "2.0"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"src": "/static/images/favicons/icon-512x512.png",
|
"src": "/static/images/favicons/icon-512x512.png",
|
||||||
"sizes": "512x512",
|
"sizes": "512x512",
|
||||||
"type": "image\/png"
|
"type": "image\/png"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"start_url": "/resources/service-worker.html",
|
"start_url": "/",
|
||||||
"background_color": "#000000",
|
"background_color": "#000000",
|
||||||
"display_override": ["window-control-overlay", "minimal-ui"],
|
"display_override": ["window-control-overlay", "minimal-ui"],
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"orientation": "portrait-primary",
|
"orientation": "portrait-primary",
|
||||||
"scope": "/resources/",
|
"scope": "/",
|
||||||
"lang": "en",
|
"lang": "en",
|
||||||
"theme_color": "#000000",
|
"theme_color": "#000000",
|
||||||
"shortcuts": [
|
"shortcuts": [
|
||||||
|
@ -105,6 +105,15 @@ class ConnectionManager {
|
|||||||
let roomPath: string;
|
let roomPath: string;
|
||||||
if (connexionType === GameConnexionTypes.empty) {
|
if (connexionType === GameConnexionTypes.empty) {
|
||||||
roomPath = window.location.protocol + "//" + window.location.host + START_ROOM_URL;
|
roomPath = window.location.protocol + "//" + window.location.host + START_ROOM_URL;
|
||||||
|
//get last room path from cache api
|
||||||
|
try {
|
||||||
|
const lastRoomUrl = await localUserStore.getLastRoomUrlCacheApi();
|
||||||
|
if (lastRoomUrl != undefined) {
|
||||||
|
roomPath = lastRoomUrl;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
roomPath =
|
roomPath =
|
||||||
window.location.protocol +
|
window.location.protocol +
|
||||||
|
@ -17,6 +17,8 @@ const authToken = "authToken";
|
|||||||
const state = "state";
|
const state = "state";
|
||||||
const nonce = "nonce";
|
const nonce = "nonce";
|
||||||
|
|
||||||
|
const cacheAPIIndex = "workavdenture-cache-v1";
|
||||||
|
|
||||||
class LocalUserStore {
|
class LocalUserStore {
|
||||||
saveUser(localUser: LocalUser) {
|
saveUser(localUser: LocalUser) {
|
||||||
localStorage.setItem("localUser", JSON.stringify(localUser));
|
localStorage.setItem("localUser", JSON.stringify(localUser));
|
||||||
@ -116,10 +118,23 @@ class LocalUserStore {
|
|||||||
|
|
||||||
setLastRoomUrl(roomUrl: string): void {
|
setLastRoomUrl(roomUrl: string): void {
|
||||||
localStorage.setItem(lastRoomUrl, roomUrl.toString());
|
localStorage.setItem(lastRoomUrl, roomUrl.toString());
|
||||||
|
caches.open(cacheAPIIndex).then((cache) => {
|
||||||
|
const stringResponse = new Response(JSON.stringify({ roomUrl }));
|
||||||
|
cache.put(`/${lastRoomUrl}`, stringResponse);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
getLastRoomUrl(): string {
|
getLastRoomUrl(): string {
|
||||||
return localStorage.getItem(lastRoomUrl) ?? "";
|
return localStorage.getItem(lastRoomUrl) ?? "";
|
||||||
}
|
}
|
||||||
|
getLastRoomUrlCacheApi(): Promise<string | undefined> {
|
||||||
|
return caches.open(cacheAPIIndex).then((cache) => {
|
||||||
|
return cache.match(`/${lastRoomUrl}`).then((res) => {
|
||||||
|
return res?.json().then((data) => {
|
||||||
|
return data.roomUrl;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setAuthToken(value: string | null) {
|
setAuthToken(value: string | null) {
|
||||||
value ? localStorage.setItem(authToken, value) : localStorage.removeItem(authToken);
|
value ? localStorage.setItem(authToken, value) : localStorage.removeItem(authToken);
|
||||||
|
@ -6,15 +6,13 @@ export class _ServiceWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
window.addEventListener("load", () => {
|
|
||||||
navigator.serviceWorker
|
navigator.serviceWorker
|
||||||
.register("/resources/service-worker.js")
|
.register("/service-worker.js")
|
||||||
.then((serviceWorker) => {
|
.then((serviceWorker) => {
|
||||||
console.info("Service Worker registered: ", serviceWorker);
|
console.info("Service Worker registered: ", serviceWorker);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error registering the Service Worker: ", error);
|
console.error("Error registering the Service Worker: ", error);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|