File tree Expand file tree Collapse file tree 6 files changed +84
-0
lines changed Expand file tree Collapse file tree 6 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "name" : " Web Push Elixir" ,
3+ "display" : " standalone"
4+ }
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Web Push Elixir</ title >
6+ < link rel ="icon " type ="image/x-icon " href ="favicon.ico " />
7+ < link rel ="manifest " href ="app.webmanifest ">
8+ </ head >
9+ < body >
10+ < h1 > Web Push Elixir</ h1 >
11+ < button > Click</ button >
12+ < script src ="main.js "> </ script >
13+ </ body >
14+ </ html >
Original file line number Diff line number Diff line change 1+ navigator . serviceWorker
2+ . register ( '/service-worker.js' )
3+ . then ( registration => {
4+ console . log ( 'Service worker successfully registered.' ) ;
5+ } )
6+ . catch ( err => {
7+ console . error ( 'Unable to register service worker.' , err ) ;
8+ } ) ;
9+
10+ document . addEventListener ( 'DOMContentLoaded' , event => {
11+
12+ const button = document . querySelector ( 'button' ) ;
13+
14+ button . addEventListener ( 'click' , event => {
15+
16+ Notification . requestPermission ( ) . then ( permission => {
17+
18+ navigator . serviceWorker . ready . then ( registration => {
19+
20+ console . log ( 'Service worker is active' ) ;
21+
22+ registration . showNotification ( 'Notification Test' , {
23+ body : 'Some message' ,
24+ } ) ;
25+ } ) ;
26+ } )
27+ } ) ;
28+
29+ } ) ;
Original file line number Diff line number Diff line change @@ -8,4 +8,34 @@ defmodule WebPushElixir.MockServer do
88 conn
99 |> Plug.Conn . send_resp ( 200 , "ok" )
1010 end
11+
12+ get "/example" do
13+ conn
14+ |> put_resp_header ( "content-type" , "text/html; charset=utf-8" )
15+ |> Plug.Conn . send_file ( 200 , "./lib/web_push_elixir/index.html" )
16+ end
17+
18+ get "/app.webmanifest" do
19+ conn
20+ |> put_resp_header ( "content-type" , "application/manifest+json" )
21+ |> Plug.Conn . send_file ( 200 , "./lib/web_push_elixir/app.webmanifest" )
22+ end
23+
24+ get "/main.js" do
25+ conn
26+ |> put_resp_header ( "content-type" , "application/x-javascript" )
27+ |> Plug.Conn . send_file ( 200 , "./lib/web_push_elixir/main.js" )
28+ end
29+
30+ get "/service-worker.js" do
31+ conn
32+ |> put_resp_header ( "content-type" , "application/x-javascript" )
33+ |> Plug.Conn . send_file ( 200 , "./lib/web_push_elixir/service-worker.js" )
34+ end
35+
36+ get "/favicon.ico" do
37+ conn
38+ |> put_resp_header ( "content-type" , "image/x-icon" )
39+ |> Plug.Conn . send_file ( 200 , "./lib/web_push_elixir/favicon.ico" )
40+ end
1141end
Original file line number Diff line number Diff line change 1+ self . addEventListener ( 'push' , event => {
2+ if ( event . data ) {
3+ console . log ( 'This push event has data: ' , event . data . text ( ) ) ;
4+ } else {
5+ console . log ( 'This push event has no data.' ) ;
6+ }
7+ } ) ;
You can’t perform that action at this time.
0 commit comments