-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
44 lines (38 loc) · 1.03 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict'
const { Notification, nativeImage } = require('electron')
const _ = require('lodash')
const config = require('./config.js')
const API = require('./api.js')
function showNotification() {
const icon = nativeImage.createFromDataURL(config.get('icon'))
if (STATUS.playbackInfo.playerState === 'Playing' && config.get('showNotifications')) {
const NOTIFICATION_TITLE = STATUS.playbackInfo.name
const NOTIFICATION_BODY = STATUS.playbackInfo.artist
new Notification({
title: NOTIFICATION_TITLE,
subtitle: NOTIFICATION_BODY,
icon: icon,
silent: true,
}).show()
}
}
module.exports = {
processNotification: function (event, info) {
try {
if (config.get('allowedEvents').includes(event)) {
//do the stuff with the things
switch (event) {
case 'com.spotify.client.PlaybackStateChanged':
STATUS.playbackInfo = _.mapKeys(info, (v, k) => _.camelCase(k))
API.sendUpdates()
showNotification()
break
default:
break
}
}
} catch (error) {
console.log(error)
}
},
}