-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.html
More file actions
41 lines (35 loc) · 1006 Bytes
/
background.html
File metadata and controls
41 lines (35 loc) · 1006 Bytes
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
<h1>Background</h1>
<script type="text/javascript">
// Send logs as messages to the main thread to show on the console
function log(value) {
window.api.log(value);
}
// let the main thread know this thread is ready to process something
function ready() {
window.api.ready();
}
// do some work that will tie up the processor for a while
function work() {
// see https://gist.github.com/tkrueger/3500612 for generating load
var start = new Date().getTime();
var result = 0;
var finished = false;
while (!finished) {
result += Math.random() * Math.random();
finished = new Date().getTime() > start + 10000;
}
}
// if message is received, pass it back to the renderer via the main thread
window.api.message((arg) => {
log("received: " + arg);
window.api.forRenderer(arg);
ready();
});
window.api.task((arg) => {
log("starting: " + arg);
work();
log("finished: " + arg);
ready();
});
ready();
</script>