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

View File

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

View File

@ -2,7 +2,8 @@
"name": "Ultimate TicTacToe", "name": "Ultimate TicTacToe",
"short_name": "Ultimate TicTacToe", "short_name": "Ultimate TicTacToe",
"display": "standalone", "display": "standalone",
"start_url": "/", "start_url": "/website/ultimate_tictactoe/",
"scope": "/website/ultimate_tictactoe/",
"theme_color": "#4650e2", "theme_color": "#4650e2",
"background_color": "#1e2477", "background_color": "#1e2477",
"icons": [ "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"; var server_port = "5555";

32
sw.js
View File

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