From 6019ba9db608651c393683f451a7fb766e8f0217 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 8 Jun 2019 17:16:47 +0200 Subject: [PATCH] Wrote new Pushbullet handler for webpanel --- .../css/source/common/notifications.scss | 3 +-- .../static/js/plugins/pushbullet/index.js | 23 ++++++++++++++++ .../backend/http/static/js/pushbullet.js | 27 ------------------- platypush/backend/pushbullet/__init__.py | 6 ++++- 4 files changed, 29 insertions(+), 30 deletions(-) create mode 100644 platypush/backend/http/static/js/plugins/pushbullet/index.js delete mode 100644 platypush/backend/http/static/js/pushbullet.js diff --git a/platypush/backend/http/static/css/source/common/notifications.scss b/platypush/backend/http/static/css/source/common/notifications.scss index 989a55b3d..fdb829d0a 100644 --- a/platypush/backend/http/static/css/source/common/notifications.scss +++ b/platypush/backend/http/static/css/source/common/notifications.scss @@ -32,11 +32,10 @@ } .title { - border-bottom: $notification-title-border; padding: .4rem; - text-transform: uppercase; line-height: 3rem; letter-spacing: .1rem; + font-weight: bold; } .body { diff --git a/platypush/backend/http/static/js/plugins/pushbullet/index.js b/platypush/backend/http/static/js/plugins/pushbullet/index.js new file mode 100644 index 000000000..323a686a8 --- /dev/null +++ b/platypush/backend/http/static/js/plugins/pushbullet/index.js @@ -0,0 +1,23 @@ +const Pushbullet = { + onMsg: function(event) { + if (event.push_type === 'mirror') { + createNotification({ + title: event.title, + text: event.body, + image: { + src: event.icon ? 'data:image/png;base64, ' + event.icon : undefined, + icon: event.icon ? undefined : 'bell', + }, + }); + } + }, + + registerHandlers: function() { + registerEventHandler(this.onMsg, 'platypush.message.event.pushbullet.PushbulletEvent'); + }, +}; + +onReady(() => { + Pushbullet.registerHandlers(); +}); + diff --git a/platypush/backend/http/static/js/pushbullet.js b/platypush/backend/http/static/js/pushbullet.js deleted file mode 100644 index 65f1b081e..000000000 --- a/platypush/backend/http/static/js/pushbullet.js +++ /dev/null @@ -1,27 +0,0 @@ -$(document).ready(function() { - var onEvent = function(event) { - switch (event.args.type) { - case 'platypush.message.event.pushbullet.PushbulletEvent': - if (event.args.push_type === 'mirror') { - createNotification({ - 'title': event.args.title, - 'text': event.args.body, - 'image': 'data:image/png;base64, ' + event.args.icon, - }); - } - - break; - } - }; - - var initEvents = function() { - window.registerEventListener(onEvent); - }; - - var init = function() { - initEvents(); - }; - - init(); -}); - diff --git a/platypush/backend/pushbullet/__init__.py b/platypush/backend/pushbullet/__init__.py index 2f018badd..e0c080f18 100644 --- a/platypush/backend/pushbullet/__init__.py +++ b/platypush/backend/pushbullet/__init__.py @@ -65,7 +65,8 @@ class PushbulletBackend(Backend): def _get_latest_push(self): t = int(time.time()) - 5 pushes = self.pb.get_pushes(modified_after=str(t), limit=1) - return pushes[0] + if pushes: + return pushes[0] def on_push(self): def callback(data): @@ -84,6 +85,9 @@ class PushbulletBackend(Backend): push = data['push'] else: return # Not a push notification + if not push: + return + # Post an event, useful to react on mobile notifications if # you enabled notification mirroring on your PushBullet app event = PushbulletEvent(**push)