-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
44 lines (38 loc) · 1.16 KB
/
main.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
var menubar = require('menubar')
var electron = require('electron');
var path = require('path');
var spotify = require('spotify-node-applescript');
var ipcMain = electron.ipcMain;
var systemPreferences = electron.systemPreferences;
var mb = menubar({
'node-integration': true,
'height': 400,
'width': 350,
'transparent': true,
'vibrancy': 'ultra-dark',
'preloadWindow': true,
'resizable': false
});
var track = {};
mb.on('ready', function ready () {
console.log('app is ready')
ipcMain.on('quit', function(){
mb.app.quit()
});
})
mb.on('after-create-window', function(){
//mb.window.openDevTools()
spotify.getTrack(function(err, track){
if(track){
var currentTrack = {};
currentTrack['Track ID'] = track.id;
currentTrack['Name'] = track.name;
currentTrack['Artist'] = track.artist;
currentTrack['Album'] = track.album;
mb.window.webContents.send('playbackStateChanged', currentTrack);
}
});
systemPreferences.subscribeNotification('com.spotify.client.PlaybackStateChanged', function(event, userInfo){
mb.window.webContents.send('playbackStateChanged', userInfo);
});
});