-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.js
73 lines (60 loc) · 1.98 KB
/
main.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
70
71
72
73
// ------------------------------------------------------------------------------
// Twitter : @JeffProd
// Web : https://jeffprod.com
// ------------------------------------------------------------------------------
const url = require('url')
const path = require('path')
const { app, BrowserWindow, ipcMain } = require('electron')
let mainWindow = null
let childWindow = null
const mainUrl = url.format({
protocol: 'file',
slashes: true,
pathname: path.join(__dirname, 'app/index.html')
})
app.on('ready', function () {
mainWindow = new BrowserWindow({
center: true,
minWidth: 1024,
minHeight: 768,
show: false
})
mainWindow.webContents.openDevTools()
mainWindow.loadURL(mainUrl)
mainWindow.webContents.on('dom-ready', function () {
console.log('user-agent:', mainWindow.webContents.getUserAgent());
mainWindow.webContents.openDevTools()
mainWindow.maximize()
mainWindow.show()
})
mainWindow.on('closed', function () {
mainWindow = null
app.quit()
})
childWindow = new BrowserWindow({
parent: mainWindow,
center: true,
minWidth: 800,
minHeight: 600,
show: true,
webPreferences: {
nodeIntegration: false, // https://electronjs.org/docs/tutorial/security#2-d%C3%A9sactiver-lint%C3%A9gration-de-nodejs-dans-tous-les-renderers-affichant-des-contenus-distants
preload: path.join(__dirname, 'app/js/preload.js')
}
})
childWindow.webContents.openDevTools()
childWindow.webContents.on('dom-ready', function () {
console.log('childWindow DOM-READY => send back html')
childWindow.send('sendbackhtml')
})
}) // app.on('ready'
// Quit when all windows are closed.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') { app.exit() }
})
ipcMain.on('scrapeurl', (event, url) => {
childWindow.loadURL(url, { userAgent: 'My Super Browser v2.0 Youpi Tralala !' })
})
ipcMain.on('hereishtml', (event, html) => {
mainWindow.send('extracthtml', html)
})