build service worker from ui module

pull/5533/head
Niklas Fiekas 2019-09-17 19:59:50 +02:00
parent e84c6a6342
commit 33eb674d37
7 changed files with 35 additions and 4 deletions

View File

@ -45,6 +45,7 @@
"ui/notify",
"ui/puzzle",
"ui/round",
"ui/serviceWorker",
"ui/simul",
"ui/site",
"ui/tournament",

View File

@ -13,7 +13,7 @@ mkdir -p public/compiled
ts_apps1="common chess"
ts_apps2="ceval game tree chat nvui"
apps="site chat cli challenge notify learn insight editor puzzle round analyse lobby tournament tournamentSchedule tournamentCalendar simul dasher speech palantir"
apps="site chat cli challenge notify learn insight editor puzzle round analyse lobby tournament tournamentSchedule tournamentCalendar simul dasher speech palantir serviceWorker"
if [ $mode == "upgrade" ]; then
yarn upgrade --non-interactive

View File

@ -0,0 +1,3 @@
const lilaGulp = require('../gulp/tsProject.js');
lilaGulp(undefined, 'lichess.serviceWorker', __dirname);

View File

@ -0,0 +1,19 @@
{
"name": "serviceWorker",
"version": "1.0.0",
"description": "lichess.org service worker",
"author": "Thibault Duplessis",
"license": "AGPL-3.0",
"devDependencies": {
"browserify": "^16",
"fancy-log": "^1",
"gulp": "^4",
"gulp-size": "^3",
"gulp-terser": "^1",
"tsify": "^4",
"typescript": "^3",
"vinyl-source-stream": "^2",
"vinyl-buffer": "^1",
"watchify": "^3"
}
}

View File

@ -1,4 +1,4 @@
self.addEventListener('push', event => {
self.addEventListener('push', (event: any) => {
const data = event.data.json();
return self.registration.showNotification(data.title, {
badge: 'https://lichess1.org/assets/images/logo.256.png',
@ -10,7 +10,7 @@ self.addEventListener('push', event => {
});
});
self.addEventListener('notificationclick', event => {
self.addEventListener('notificationclick', (event: any) => {
event.waitUntil(self.registration.getNotifications().then(notifications => {
notifications.forEach(notification => notification.close());
return self.clients.matchAll({

View File

@ -0,0 +1,8 @@
{
"extends": "../tsconfig.base.json",
"include": ["src/*.ts"],
"lib": ["ES6"],
"compilerOptions": {
"noImplicitAny": false
}
}

View File

@ -978,7 +978,7 @@
////////////////////
if ('serviceWorker' in navigator && 'Notification' in window && 'PushManager' in window) {
const workerUrl = lichess.assetUrl('javascripts/service-worker.js', {noVersion: true, sameDomain: true});
const workerUrl = lichess.assetUrl(lichess.compiledScript('serviceWorker'), {noVersion: true, sameDomain: true});
navigator.serviceWorker.register(workerUrl, {scope: '/'});
}