Wrote new Pushbullet handler for webpanel
This commit is contained in:
parent
46836374b0
commit
6019ba9db6
4 changed files with 29 additions and 30 deletions
|
@ -32,11 +32,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
.title {
|
||||||
border-bottom: $notification-title-border;
|
|
||||||
padding: .4rem;
|
padding: .4rem;
|
||||||
text-transform: uppercase;
|
|
||||||
line-height: 3rem;
|
line-height: 3rem;
|
||||||
letter-spacing: .1rem;
|
letter-spacing: .1rem;
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.body {
|
.body {
|
||||||
|
|
23
platypush/backend/http/static/js/plugins/pushbullet/index.js
Normal file
23
platypush/backend/http/static/js/plugins/pushbullet/index.js
Normal 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();
|
||||||
|
});
|
||||||
|
|
|
@ -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();
|
|
||||||
});
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ class PushbulletBackend(Backend):
|
||||||
def _get_latest_push(self):
|
def _get_latest_push(self):
|
||||||
t = int(time.time()) - 5
|
t = int(time.time()) - 5
|
||||||
pushes = self.pb.get_pushes(modified_after=str(t), limit=1)
|
pushes = self.pb.get_pushes(modified_after=str(t), limit=1)
|
||||||
|
if pushes:
|
||||||
return pushes[0]
|
return pushes[0]
|
||||||
|
|
||||||
def on_push(self):
|
def on_push(self):
|
||||||
|
@ -84,6 +85,9 @@ class PushbulletBackend(Backend):
|
||||||
push = data['push']
|
push = data['push']
|
||||||
else: return # Not a push notification
|
else: return # Not a push notification
|
||||||
|
|
||||||
|
if not push:
|
||||||
|
return
|
||||||
|
|
||||||
# Post an event, useful to react on mobile notifications if
|
# Post an event, useful to react on mobile notifications if
|
||||||
# you enabled notification mirroring on your PushBullet app
|
# you enabled notification mirroring on your PushBullet app
|
||||||
event = PushbulletEvent(**push)
|
event = PushbulletEvent(**push)
|
||||||
|
|
Loading…
Reference in a new issue