notifications

This commit is contained in:
Jonas Weinz 2019-03-10 15:51:08 +01:00
parent 69f8ff2f64
commit acb1781a9f
5 changed files with 40 additions and 35 deletions

View File

@ -23,6 +23,8 @@ class GameManager
this.game_mode = "none";
this.use_notification = false;
this.game_server_connection = game_server_connection;
game_server_connection.set_game_manager(this);
@ -292,22 +294,24 @@ class GameManager
this.end_game();
}
activate_notifications()
{
this.use_notification = true;
}
notify(text) {
if (!("Notification" in window)) {
return;
}
else if (Notification.permission === "granted") {
var notification = new Notification(text);
}
Notification.requestPermission(function(result) {
if (result === 'granted') {
navigator.serviceWorker.ready.then(function(registration) {
registration.showNotification(text, {
icon: './icon.png',
vibrate: [200, 200],
tag: "tictactoe-notification"
});
});
}
});
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
if (permission === "granted") {
var notification = new Notification(text);
}
});
}
}
}
}

View File

@ -2,7 +2,7 @@
<link rel="stylesheet" type="text/css" href="style.css">
<head>
<meta name="viewport" content="width=device-width, user-scalable=no" />
<link rel="manifest" href="manifest.json" />
<link rel="manifest" href="./manifest.json" />
<link rel="icon" href="icon.png" type="image/png"/>
<script defer src="site.js"></script>
<title>ultimate tictactoe</title>

View File

@ -2,7 +2,8 @@
"name": "Ultimate TicTacToe",
"short_name": "Ultimate TicTacToe",
"display": "standalone",
"start_url": "/",
"start_url": "/website/ultimate_tictactoe/",
"scope": "/website/ultimate_tictactoe/",
"theme_color": "#4650e2",
"background_color": "#1e2477",
"icons": [

View File

@ -1,2 +1,2 @@
var server_url = "127.0.0.1";
var server_url = "the-cake-is-a-lie.net";
var server_port = "5555";

32
sw.js
View File

@ -3,22 +3,22 @@ self.addEventListener('install', function(e) {
e.waitUntil(
caches.open('your-magic-cache').then(function(cache) {
return cache.addAll([
'/',
'/index.html',
'/manifest.json',
'/icon.png',
'/LICENSE',
'/main.js',
'/grid.js',
'/game_manager.js',
'/game_server_connection.js',
'/sidebar.js',
'/settings.js',
'/subgrid.js',
'/tile.js',
'/README.md',
'/site.js',
'/style.css',
'/website/ultimate_tictactoe/',
'/website/ultimate_tictactoe/index.html',
'/website/ultimate_tictactoe/manifest.json',
'/website/ultimate_tictactoe/icon.png',
'/website/ultimate_tictactoe/LICENSE',
'/website/ultimate_tictactoe/main.js',
'/website/ultimate_tictactoe/grid.js',
'/website/ultimate_tictactoe/game_manager.js',
'/website/ultimate_tictactoe/game_server_connection.js',
'/website/ultimate_tictactoe/sidebar.js',
'/website/ultimate_tictactoe/settings.js',
'/website/ultimate_tictactoe/subgrid.js',
'/website/ultimate_tictactoe/tile.js',
'/website/ultimate_tictactoe/README.md',
'/website/ultimate_tictactoe/site.js',
'/website/ultimate_tictactoe/style.css',
]);
})
);