-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser.js
35 lines (31 loc) · 884 Bytes
/
browser.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
const {ipcRenderer} = require('electron');
const DecibelMeter = require('decibel-meter');
const conf = require('./conf.json');
const meter = new DecibelMeter('wildMicro');
const level = document.querySelector('h1');
const maxDisplay = document.querySelector('h2');
let max = 0;
let readyToNotify = true;
let realDb;
meter.connectTo('default');
meter.listen();
meter.on('sample', dB => {
realDb = Math.round(dB) + 100;
// Notification
if (realDb > conf.maxDb) {
console.log(readyToNotify, conf.secondsBetweenNotifications);
if (readyToNotify) {
ipcRenderer.send('tooLoud', 'ping');
readyToNotify = !readyToNotify;
setTimeout(() => {
readyToNotify = !readyToNotify;
}, conf.secondsBetweenNotifications * 1000);
}
}
// Rendering
level.textContent = `${realDb} dB`;
if (realDb > max) {
max = realDb;
maxDisplay.textContent = `Max : ${max} dB`;
}
});