-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.js
69 lines (54 loc) · 2.14 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
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
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
// Example 1 - IPC
// const pwdInputTxt = document.getElementById('primary-password')
// pwdInputTxt.addEventListener("input", calcEntr);
window.addEventListener("DOMContentLoaded", (event) => {
const el = document.getElementById('primary-password');
if (el) {
el.addEventListener('input', calcEntr);
}
});
window.onload = (event) => {
const pwdInputTxt = document.getElementById('primary-password')
pwdInputTxt.addEventListener("input", calcEntr);
};
function calcEntr(){
let input1 = document.getElementById("primary-password").value;
let input2 = document.getElementById("entropy");
let input3 = "void";
const {ipcRenderer} = require('electron')
// send username to main.js
ipcRenderer.send('asynchronous-message', { 'input1':input1, 'input2':input3} );
// receive message from main.js
ipcRenderer.on('asynchronous-reply', (event, arg) => {
// Address of native addon
const {passStrengthChk} = require('./backend/build/Release/passStrengthChk.node');
// Calling functions of native addon
let result = passStrengthChk((arg['input1']),(arg['input2']));
console.log(result);
document.getElementById('entropy').innerText = result;
})
};
// Example 2 - Worker JS
// calls worker.js script inside a web worker
// var worker = new Worker('./worker.js')
// // receive any message from web worker
// worker.onmessage = function(event) {
// // Print result on console and <h1> tag
// console.log("Worker : ", event.data);
// document.getElementById('tag_result').innerHTML =
// "C++ Native addon add() result (Worker): " + event.data;
// // Terminate WebWorker
// worker.terminate();
// // Set it to undefined
// worker = undefined;
// };
// // catches any error from web worker
// worker.onerror = function (event) {
// console.log(event.message, event);
// };