-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·78 lines (68 loc) · 2.25 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
const { ipcRenderer, Menu, Tray } = require("electron");
var path = require("path");
var fs = require("fs");
function addSpeakerHole() {
var div = document.createElement("div");
div.className = "speaker-hole";
document.getElementById("speaker-box").appendChild(div);
}
function addBt(html) {
var div = document.createElement("div");
div.className = "button-wrap";
div.innerHTML = html;
document.getElementById("buttons").appendChild(div);
}
//speaker
for (var i = 0; i < 40; i++) {
addSpeakerHole();
}
let sounds = fs.readdirSync(__dirname + "/mp3/");
console.log("sounds", sounds);
var items = [];
var index = 0;
let keys = "1234567890qwertyuiopasdfghjklzxcvbnm".split("");
const alphabet = [...keys, ...["F1", "F2", "F3", "F4"]];
sounds.forEach(function(element) {
if (element.indexOf(".mp3") > 0) {
console.log(element);
let name = element.split(".")[0];
let bt = `
<div class="button-sound" data-sound="${name}">
<span class="button-icon"></span>
<span class="button-shortcut">${alphabet[index]}</span>
</div>
`;
addBt(bt);
index++;
}
});
var soundButtons = document.querySelectorAll(".button-sound");
var closeEl = document.querySelector(".close");
var settingsEl = document.querySelector(".settings");
var trayIcon = null;
var trayMenu = null;
for (var i = 0; i < soundButtons.length; i++) {
var soundButton = soundButtons[i];
var soundName = soundButton.attributes["data-sound"].value;
prepareButton(soundButton, soundName);
}
function prepareButton(buttonEl, soundName) {
buttonEl.querySelector("span").style.backgroundImage =
'url("img/icons/' + soundName + '.svg")';
var audio = new Audio(__dirname + "/mp3/" + soundName + ".mp3");
buttonEl.addEventListener("click", function() {
audio.currentTime = 0;
audio.play();
});
}
closeEl.addEventListener("click", function() {
ipcRenderer.send("close-main-window");
});
settingsEl.addEventListener("click", function() {
ipcRenderer.send("open-settings-window");
});
ipcRenderer.on("global-shortcut", (event, arg) => {
console.log("global-shortcut", arg);
var event = new MouseEvent("click");
soundButtons[arg].dispatchEvent(event);
});