-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
40 lines (34 loc) · 1.28 KB
/
renderer.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
'use strict';
const { ipcRenderer } = require('electron');
const releasePony= (pname) => {
let pony = document.getElementById(`${pname}-image`);
if (pony.style.filter != '') {
pony.style.filter = '';
} else {
pony.style.filter="brightness(30%)";
}
};
const togglePony = (event) => {
console.log('Pony to toggle: %s', event.target.id);
ipcRenderer.send('togglePony', event.target.id);
releasePony(event.target.id);
};
ipcRenderer.on('ponies', (event, ponies) => {
console.log('received Ponies %s', ponies);
console.log(ponies);
const ponySpace = document.getElementById('Ponies');
const formattedPonies = ponies.reduce( (html, pony) => {
html += `<div class="Pony" id="${pony.name}">\n`;
html += `<div class=PonyName>${pony.name}</div>\n`;
html += `<div><img src="${pony.staticImage}" class=PonyImage id="${pony.name}-image"></div>\n`;
html += '</div>\n';
return html;
}, '');
ponySpace.innerHTML = formattedPonies;
ponySpace.querySelectorAll('.Pony').forEach(item => item.addEventListener('click', togglePony));
});
ipcRenderer.on('releasePony', (evt, pname) => {
releasePony(pname);
});
console.log('loaded renderer.js');
ipcRenderer.send('loaded', 'MainWindow loaded. Send me PONIES!');