Wrote new Pushbullet handler for webpanel

This commit is contained in:
Fabio Manganiello 2019-06-08 17:16:47 +02:00
parent 46836374b0
commit 6019ba9db6
4 changed files with 29 additions and 30 deletions

View file

@ -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 {

View file

@ -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();
});

View file

@ -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();
});

View file

@ -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)