-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
68 lines (58 loc) · 1.98 KB
/
main.html
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
<html>
<head>
<style>
body {
font-family: "Helvetica Neue", "Calibri Light", Roboto, sans-serif;
}
#output {
background: #333;
height: 400px;
width: 80%;
color: #fff;
padding: 15px;
font-family: "monospace";
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}
</style>
<title></title>
<script>
const { ipcRenderer } = require("electron");
const { CUSTOM_IPC_EVENTS } = require("./ipcevents");
// Event listener for when the render process DOM load completes
document.addEventListener("DOMContentLoaded", function () {
// div to append results to
const outputDiv = document.getElementById("output");
// set max to refer to later, use pingPong to decrement upon
// receiving a pong
const maxPingPongs = 5;
let pingPong = maxPingPongs;
// Kick things off and decrement
ipcRenderer.send(CUSTOM_IPC_EVENTS.PING, pingPong);
pingPong--;
// Listener for render process
ipcRenderer.on(CUSTOM_IPC_EVENTS.PONG, function receivePong() {
// Add results to DOM
const text = `Render Process: received pong ${
maxPingPongs - pingPong
}`;
const content = document.createTextNode(text);
outputDiv.appendChild(content);
outputDiv.appendChild(document.createElement("br"));
// Check to see if there are still pings to send
if (pingPong > 0) {
// Use setTimeout to show delay of ping / pong
setTimeout(function () {
// send main process "PING" event with pingPong arg
ipcRenderer.send(CUSTOM_IPC_EVENTS.PING, pingPong);
pingPong--;
}, 1500);
}
});
});
</script>
</head>
<body>
<h1>IPC Ping Pong</h1>
<div id="output"></div>
</body>
</html>