-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
59 lines (42 loc) · 1.39 KB
/
main.js
File metadata and controls
59 lines (42 loc) · 1.39 KB
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
const { app, BrowserWindow, ipcMain } = require('electron');
var client = require('socket.engine').client;
var c = new client(addr = '127.0.0.1', port = 8080, open = true);
c.start();
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow({
width: 1536,
height: 900,
frame: true,
webPreferences: {
nodeIntegration: true
}
});
mainWindow.loadURL('file://' + __dirname + '/index.html');
})
c.on("Test", (data) => {
c.msgBuffer = ''
var isFirst = data["isFirst"];
console.log(data)
var user = data['user'];
if (isFirst == 'True') {
changeInDom(user);
}
});
c.write("Test", "Hello there!");
//Method 2: Using webContents.executeJavaScript(code,[userGesture])
// function changeInDom(user) {
// let code = `
// var p = document.getElementById("content_styler");
// p.innerHTML = "I am the changed text. "+"${user}";
// `;
// mainWindow.webContents.executeJavaScript(code);
// }
// Method 3: Using ipcRenderer and ipcMain module
//ipcMain.on will receive the “btnclick” info from renderprocess
ipcMain.on("btnclick", function(event, arg) {
var url = "https://www.google.com";
// inform the render process that the assigned task finished.
// event.sender.send in ipcMain will return the reply to renderprocess
event.sender.send("btnclick-task-finished", url);
});