forked from BlankSourceCode/qmk-hid-display
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
59 lines (51 loc) · 1.76 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
'use strict';
const { app, Menu, Tray, session } = require('electron');
const ScreenManager = require('./screenmanager.js');
const keyboardHid = require('./keyboardhid.js');
const { Config } = require('./config.js');
const path = require('path');
let screenManager = new ScreenManager();;
let tray = null;
let config = new Config();
function updateContextMenu() {
if (!app.isReady()) {
return;
}
let contextTemplate = [];
if (screenManager) {
contextTemplate.push(...screenManager.getContextMenus());
}
contextTemplate.push({ label: 'Configuration',
click: () => { config.createWindow(); } });
contextTemplate.push({ label: 'Quit', click: () => { app.quit(); } });
tray.setContextMenu(Menu.buildFromTemplate(contextTemplate));
}
function createTray () {
tray = new Tray(path.join(__dirname, './icon16.png'));
tray.setToolTip('QMK HID Display');
updateContextMenu();
// todo: make this init flow simpler
screenManager.init([tray, config, session],
config,
updateContextMenu,
() => { keyboardHid.sendToKeyboard(screenManager.getActiveOutput()); });
config.init(screenManager);
screenManager.initScreens();
initKeyboardHid();
config.store.onDidChange('keyboard-name', initKeyboardHid);
config.store.onDidChange('keyboard-id', initKeyboardHid);
config.store.onDidChange('keyboard-page', initKeyboardHid);
}
function initKeyboardHid() {
keyboardHid.init(config.store.get('keyboard-name'),
parseInt(config.store.get('keyboard-id')),
parseInt(config.store.get('keyboard-page')),
screenManager);
keyboardHid.initConnection();
}
app.on('window-all-closed', () => {
// keep running.
// the tray doesn't count as a window, so
// this will keep the app running when we only have the tray
})
app.whenReady().then(createTray);