From 3e7d12b6e4d970e17e271eed0fab68e86cddc9c8 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Wed, 12 Dec 2018 00:03:17 -0800 Subject: [PATCH] Add notification sending functionality. --- src/Scylla/Notification.elm | 11 +++++++++++ static/js/notifications.js | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/Scylla/Notification.elm create mode 100644 static/js/notifications.js diff --git a/src/Scylla/Notification.elm b/src/Scylla/Notification.elm new file mode 100644 index 0000000..295077f --- /dev/null +++ b/src/Scylla/Notification.elm @@ -0,0 +1,11 @@ +port module Scylla.Notification exposing (..) +import Scylla.Model exposing (..) +import Json.Decode + +type alias Notification = + { name : String + , text : String + } + +port sendNotificationPort : Notification -> Cmd msg +port onNotificationClockPort : (Json.Decode.Value -> msg) -> Sub msg diff --git a/static/js/notifications.js b/static/js/notifications.js new file mode 100644 index 0000000..20d9ab4 --- /dev/null +++ b/static/js/notifications.js @@ -0,0 +1,12 @@ +if("Notification" in window) { + Notification.requestPermission(); +} + +function setupNotificationPorts(app) { + app.ports.sendNotificationPort.subscribe(function(data) { + var options = { + "body" : data.text + } + new Notification(data.name, options) + }) +}