forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebContents.ts
More file actions
50 lines (42 loc) · 1.59 KB
/
Copy pathwebContents.ts
File metadata and controls
50 lines (42 loc) · 1.59 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
import { BrowserWindow } from 'electron';
const fs = require('fs');
module.exports = (socket: SocketIO.Server) => {
socket.on('register-webContents-crashed', (id) => {
var browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners('crashed');
browserWindow.webContents.on('crashed', (event, killed) => {
socket.emit('webContents-crashed' + id, killed);
});
});
socket.on('register-webContents-didFinishLoad', (id) => {
let browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners('did-finish-load');
browserWindow.webContents.on('did-finish-load', () => {
socket.emit('webContents-didFinishLoad' + id);
});
});
socket.on('webContentsOpenDevTools', (id, options) => {
if (options) {
getWindowById(id).webContents.openDevTools(options);
} else {
getWindowById(id).webContents.openDevTools();
}
});
socket.on('webContents-printToPDF', (id, options, path) => {
getWindowById(id).webContents.printToPDF(options || {}, (error, data) => {
if (error) {
throw error;
}
fs.writeFile(path, data, (error) => {
if (error) {
socket.emit('webContents-printToPDF-completed', false);
} else {
socket.emit('webContents-printToPDF-completed', true);
}
});
});
});
function getWindowById(id: number): Electron.BrowserWindow {
return BrowserWindow.fromId(id);
}
};