-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
114 lines (95 loc) · 3.06 KB
/
index.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const menubar = require('menubar');
const electron = require('electron');
const AutoLaunch = require('auto-launch');
const Menu = electron.Menu;
const BrowserWindow = electron.BrowserWindow;
const mb = menubar();
mb.setOption('preload-window', true);
mb.setOption('height', 464);
const spotify = require('./spotify.js');
const ipcMain = require('electron').ipcMain;
let settingsWindow;
let aboutWindow;
let appLauncher = new AutoLaunch({
name: 'spotifymenubar'
});
let settings = {
showTrackTitle: true,
smallAlbumArt: false
};
const contextMenu = Menu.buildFromTemplate([
{ label: 'About Baritone', click: function() { openAbout(); } },
/*{ label: 'Preferences', click: function() { openSettings(); } },*/
{ type: 'separator' },
{ label: 'Launch on Login', type: 'checkbox', checked: false, click: function(item) {
appLauncher.isEnabled().then(function(enabled) {
if (enabled) {
return appLauncher.disable().then(function() {
item.checked = false;
});
}
else {
return appLauncher.enable().then(function() {
item.checked = true;
});
}
});
} },
{ label: 'Show Track Info', type: 'checkbox', checked: false, click: function(item) {
settings.showTrackTitle = !settings.showTrackTitle;
item.checked = settings.showTrackTitle;
mb.window.webContents.send('settings', settings);
}, enabled: true },
/*{ label: 'Smaller Album Art', type: 'checkbox', checked: false, click: function(item) {
settings.smallAlbumArt = !settings.smallAlbumArt;
item.checked = settings.smallAlbumArt;
mb.window.webContents.send('settings', settings);
}, enabled: false },*/
{ type: 'separator' },
{ label: 'Quit Baritone', click: function() { mb.app.quit(); } }
]);
appLauncher.isEnabled().then(function(enabled) {
contextMenu.items[2].checked = enabled;
});
contextMenu.items[3].checked = settings.showTrackTitle;
//contextMenu.items[4].checked = settings.smallAlbumArt;
function openSettings() {
settingsWindow = new BrowserWindow({width: 400, height: 500});
settingsWindow.loadURL('file://' + __dirname + '/settings.html');
settingsWindow.on('closed', function () {
settingsWindow = null;
});
}
function openAbout() {
aboutWindow = new BrowserWindow({width: 400, height: 320});
aboutWindow.loadURL('file://' + __dirname + '/about.html');
aboutWindow.on('closed', function () {
aboutWindow = null;
});
}
mb.on('ready', function ready() {
console.log('app is ready');
spotify.init();
mb.tray.on('right-click', function() {
mb.tray.popUpContextMenu(contextMenu);
});
});
mb.on('after-create-window', function() {
spotify.setWindow(mb.window);
mb.window.webContents.send('settings', settings);
});
ipcMain.on('seek', function(event, percent) {
spotify.seek(percent);
});
ipcMain.on('playpause', function(event, data) {
spotify.playpause();
});
ipcMain.on('skip', function(event, data) {
spotify.skip(data);
});
ipcMain.on('shuffle', function(event, data) {
spotify.shuffle(data);
});
ipcMain.on('repeat', function(event, data) {
spotify.repeat(data);
});