-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
util.js
92 lines (75 loc) · 1.88 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
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
'use strict';
const {app, systemPreferences} = require('electron');
const config = require('./config.js');
const midi = require('./midi.js');
const mdns = require('./mdns.js');
const notifications = require('./notifications.js');
const contextmenu = require('./contextmenu.js');
function subscribeToNotifications() { //system events that can notify the app of a system change - perhaps like USB device being plugged in
let allowedEvents = config.get('allowedEvents');
for (let i = 0; i < allowedEvents.length; i++) {
systemPreferences.subscribeNotification(allowedEvents[i], (event, userInfo) => {
processNotification(event, userInfo);
});
}
}
function processNotification(event, info) { //process the system event
try {
if (config.get('allowedEvents').includes(event)) {
//do the stuff with the things
switch(event) {
default:
break;
}
}
}
catch(error) {
console.log(error);
}
}
function startRescanInterval() {
if (config.get('allowRescan')) {
global.RESCAN_INTERVAL = setInterval(() => {
midi.refreshPorts(false);
}, 60000);
}
else {
clearInterval(global.RESCAN_INTERVAL);
}
}
module.exports = {
startUp() {
contextmenu.buildContextMenu();
midi.startMIDI();
//mdns.startMDNS();
startRescanInterval();
subscribeToNotifications(); //for system notifications to alert the app of changes like usb devices detected
},
getMIDIOutputs() {
return global.MIDI_OUTPUTS
},
getMIDIInputs() {
return global.MIDI_INPUTS;
},
sendMIDI(midiObj, callback) {
midi.sendMIDI(midiObj, callback);
},
refreshPorts() {
midi.refreshPorts(true);
},
startRescanInterval() {
startRescanInterval();
},
getTriggers() {
return config.get('triggers');
},
addTrigger(triggerObj) {
midi.addTrigger(triggerObj);
},
updateTrigger(triggerObj) {
midi.updateTrigger(triggerObj);
},
deleteTrigger(triggerId) {
midi.deleteTrigger(triggerId);
}
}