forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebContents.js
151 lines (151 loc) · 8.08 KB
/
webContents.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
const electron_1 = require("electron");
const fs = require('fs');
let electronSocket;
module.exports = (socket) => {
electronSocket = socket;
socket.on('register-webContents-crashed', (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners('crashed');
browserWindow.webContents.on('crashed', (event, killed) => {
electronSocket.emit('webContents-crashed' + id, killed);
});
});
socket.on('register-webContents-didFinishLoad', (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.removeAllListeners('did-finish-load');
browserWindow.webContents.on('did-finish-load', () => {
electronSocket.emit('webContents-didFinishLoad' + id);
});
});
socket.on('webContentsOpenDevTools', (id, options) => {
if (options) {
getWindowById(id).webContents.openDevTools(options);
}
else {
getWindowById(id).webContents.openDevTools();
}
});
socket.on('webContents-getPrinters', (id) => __awaiter(this, void 0, void 0, function* () {
const printers = yield getWindowById(id).webContents.getPrinters();
electronSocket.emit('webContents-getPrinters-completed', printers);
}));
socket.on('webContents-print', (id, options = {}) => __awaiter(this, void 0, void 0, function* () {
yield getWindowById(id).webContents.print(options);
electronSocket.emit('webContents-print-completed', true);
}));
socket.on('webContents-printToPDF', (id, options = {}, path) => __awaiter(this, void 0, void 0, function* () {
const buffer = yield getWindowById(id).webContents.printToPDF(options);
fs.writeFile(path, buffer, (error) => {
if (error) {
electronSocket.emit('webContents-printToPDF-completed', false);
}
else {
electronSocket.emit('webContents-printToPDF-completed', true);
}
});
}));
socket.on('webContents-getUrl', function (id) {
const browserWindow = getWindowById(id);
electronSocket.emit('webContents-getUrl' + id, browserWindow.webContents.getURL());
});
socket.on('webContents-session-allowNTLMCredentialsForDomains', (id, domains) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.session.allowNTLMCredentialsForDomains(domains);
});
socket.on('webContents-session-clearAuthCache', (id, options, guid) => __awaiter(this, void 0, void 0, function* () {
const browserWindow = getWindowById(id);
yield browserWindow.webContents.session.clearAuthCache(options);
electronSocket.emit('webContents-session-clearAuthCache-completed' + guid);
}));
socket.on('webContents-session-clearCache', (id, guid) => __awaiter(this, void 0, void 0, function* () {
const browserWindow = getWindowById(id);
yield browserWindow.webContents.session.clearCache();
electronSocket.emit('webContents-session-clearCache-completed' + guid);
}));
socket.on('webContents-session-clearHostResolverCache', (id, guid) => __awaiter(this, void 0, void 0, function* () {
const browserWindow = getWindowById(id);
yield browserWindow.webContents.session.clearHostResolverCache();
electronSocket.emit('webContents-session-clearHostResolverCache-completed' + guid);
}));
socket.on('webContents-session-clearStorageData', (id, guid) => __awaiter(this, void 0, void 0, function* () {
const browserWindow = getWindowById(id);
yield browserWindow.webContents.session.clearStorageData({});
electronSocket.emit('webContents-session-clearStorageData-completed' + guid);
}));
socket.on('webContents-session-clearStorageData-options', (id, options, guid) => __awaiter(this, void 0, void 0, function* () {
const browserWindow = getWindowById(id);
yield browserWindow.webContents.session.clearStorageData(options);
electronSocket.emit('webContents-session-clearStorageData-options-completed' + guid);
}));
socket.on('webContents-session-createInterruptedDownload', (id, options) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.session.createInterruptedDownload(options);
});
socket.on('webContents-session-disableNetworkEmulation', (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.session.disableNetworkEmulation();
});
socket.on('webContents-session-enableNetworkEmulation', (id, options) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.session.enableNetworkEmulation(options);
});
socket.on('webContents-session-flushStorageData', (id) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.session.flushStorageData();
});
socket.on('webContents-session-getBlobData', (id, identifier, guid) => __awaiter(this, void 0, void 0, function* () {
const browserWindow = getWindowById(id);
const buffer = yield browserWindow.webContents.session.getBlobData(identifier);
electronSocket.emit('webContents-session-getBlobData-completed' + guid, buffer.buffer);
}));
socket.on('webContents-session-getCacheSize', (id, guid) => __awaiter(this, void 0, void 0, function* () {
const browserWindow = getWindowById(id);
const size = yield browserWindow.webContents.session.getCacheSize();
electronSocket.emit('webContents-session-getCacheSize-completed' + guid, size);
}));
socket.on('webContents-session-getPreloads', (id, guid) => {
const browserWindow = getWindowById(id);
const preloads = browserWindow.webContents.session.getPreloads();
electronSocket.emit('webContents-session-getPreloads-completed' + guid, preloads);
});
socket.on('webContents-session-getUserAgent', (id, guid) => {
const browserWindow = getWindowById(id);
const userAgent = browserWindow.webContents.session.getUserAgent();
electronSocket.emit('webContents-session-getUserAgent-completed' + guid, userAgent);
});
socket.on('webContents-session-resolveProxy', (id, url, guid) => __awaiter(this, void 0, void 0, function* () {
const browserWindow = getWindowById(id);
const proxy = yield browserWindow.webContents.session.resolveProxy(url);
electronSocket.emit('webContents-session-resolveProxy-completed' + guid, proxy);
}));
socket.on('webContents-session-setDownloadPath', (id, path) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.session.setDownloadPath(path);
});
socket.on('webContents-session-setPreloads', (id, preloads) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.session.setPreloads(preloads);
});
socket.on('webContents-session-setProxy', (id, configuration, guid) => __awaiter(this, void 0, void 0, function* () {
const browserWindow = getWindowById(id);
yield browserWindow.webContents.session.setProxy(configuration);
electronSocket.emit('webContents-session-setProxy-completed' + guid);
}));
socket.on('webContents-session-setUserAgent', (id, userAgent, acceptLanguages) => {
const browserWindow = getWindowById(id);
browserWindow.webContents.session.setUserAgent(userAgent, acceptLanguages);
});
function getWindowById(id) {
return electron_1.BrowserWindow.fromId(id);
}
};
//# sourceMappingURL=webContents.js.map