-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
74 lines (65 loc) · 1.93 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
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
const electron = require('electron');
const menubar = require('menubar');
const path = require('path');
const url = require('url');
const menu = require('./lib/menu');
// Numbers (remember to match in CSS!):
// video: 315 by 560
// arrow height: 10
// frame: 3
const mb = menubar({
width: 315 + 3 * 2,
height: 560 + 10 + 3 * 2,
icon: `${__dirname}/${process.platform == 'win32' ? 'fika.ico' : 'iconTemplate.png'}`,
alwaysOnTop: true,
preloadWindow: true,
transparent: true,
webPreferences: {experimentalFeatures: true},
});
const context = new menu.Manager([
{label: `${electron.app.getName()} v${electron.app.getVersion()}`, enabled: false},
{type: 'separator'},
{id: 'autoplay', label: 'Autoplay', type: 'checkbox', checked: true, click: menuItem => {
mb.window.webContents.send('status', 'autoplay', menuItem.checked);
}},
{type: 'separator'},
{id: 'logOut', label: 'Log Out', click: () => { mb.window.webContents.send('control', 'logOut'); }, enabled: false},
{role: 'quit', click: () => { electron.app.quit(); }},
]);
mb.on('after-create-window', () => {
mb.tray.on('right-click', () => {
mb.tray.popUpContextMenu(context.menu);
});
mb.window.on('hide', () => {
mb.window.webContents.send('status', 'visible', false);
});
mb.window.on('show', () => {
mb.window.webContents.send('status', 'visible', true);
});
});
electron.ipcMain.on('control', (event, action) => {
switch (action) {
case 'disableAutoplay':
context.update('autoplay', {checked: false});
break;
case 'enableAutoplay':
context.update('autoplay', {checked: true});
break;
case 'hide':
mb.hideWindow();
break;
case 'show':
mb.showWindow();
break;
}
});
electron.ipcMain.on('status', (event, status, value) => {
switch (status) {
case 'sessionAccount':
context.update('logOut', {
enabled: !!value,
label: value ? `Log Out ${value.display_name}` : 'Log Out',
});
break;
}
});