From 23e7c209b6bc8c5a07208abbbf28465ea6930ef0 Mon Sep 17 00:00:00 2001 From: Devin Matte Date: Thu, 15 Aug 2019 11:13:22 -0400 Subject: [PATCH 1/2] Push Notifications Phase 1 --- config.env.py | 5 +++++ packet/routes/shared.py | 13 +++++++++++++ packet/static/js/sw.js | 2 ++ packet/static/js/update-sw.js | 2 ++ packet/static/manifest.json | 3 ++- packet/templates/include/head.html | 21 +++++++++++++++++++++ requirements.txt | 1 + 7 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packet/static/js/sw.js create mode 100644 packet/static/js/update-sw.js diff --git a/config.env.py b/config.env.py index e403b052..0eb3f4e6 100644 --- a/config.env.py +++ b/config.env.py @@ -38,5 +38,10 @@ MAIL_PASSWORD = environ.get("PACKET_MAIL_PASSWORD", None) MAIL_USE_TLS = strtobool(environ.get("PACKET_MAIL_TLS", 'True')) +# OneSignal Config +ONESIGNAL_USER_AUTH_KEY = environ.get("PACKET_ONESIGNAL_USER_AUTH_KEY", None) +ONESIGNAL_APP_AUTH_KEY = environ.get("PACKET_ONESIGNAL_APP_AUTH_KEY", None) +ONESIGNAL_APP_ID = environ.get("PACKET_ONESIGNAL_APP_ID", "6eff123a-0852-4027-804e-723044756f00") + # Slack URL for pushing to #general SLACK_WEBHOOK_URL = environ.get("PACKET_SLACK_URL", None) diff --git a/packet/routes/shared.py b/packet/routes/shared.py index 3d894baa..c4a04c6e 100644 --- a/packet/routes/shared.py +++ b/packet/routes/shared.py @@ -68,3 +68,16 @@ def packets(info=None): open_packets.sort(key=packet_sort_key, reverse=True) return render_template("active_packets.html", info=info, packets=open_packets) + + +@app.route('/sw.js', methods=['GET']) +@app.route('/OneSignalSDKWorker.js', methods=['GET']) +def service_worker(): + return app.send_static_file('js/sw.js') + + +@app.route('/update-sw.js', methods=['GET']) +@app.route('/OneSignalSDKUpdaterWorker.js', methods=['GET']) +def update_service_worker(): + return app.send_static_file('js/update-sw.js') + diff --git a/packet/static/js/sw.js b/packet/static/js/sw.js new file mode 100644 index 00000000..81157226 --- /dev/null +++ b/packet/static/js/sw.js @@ -0,0 +1,2 @@ +importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js'); + diff --git a/packet/static/js/update-sw.js b/packet/static/js/update-sw.js new file mode 100644 index 00000000..81157226 --- /dev/null +++ b/packet/static/js/update-sw.js @@ -0,0 +1,2 @@ +importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js'); + diff --git a/packet/static/manifest.json b/packet/static/manifest.json index 1425b006..d7916ac9 100644 --- a/packet/static/manifest.json +++ b/packet/static/manifest.json @@ -20,5 +20,6 @@ "sizes": "512x512", "type": "image/png" } - ] + ], + "gcm_sender_id": "482941778795" } diff --git a/packet/templates/include/head.html b/packet/templates/include/head.html index 677e611f..902889a5 100644 --- a/packet/templates/include/head.html +++ b/packet/templates/include/head.html @@ -34,6 +34,27 @@ + + + + +