forked from electron/electron-quick-start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
36 lines (29 loc) · 1.2 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
const { app, net } = require('electron');
const { exec } = require('child_process');
const USERNAME = '';
const PASSWORD = 'password';
const SERVER_PORT = 8888;
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {
// Make a request to the server
console.log('making request');
const req = net.request(`http://localhost:${SERVER_PORT}`);
// Handle the expected basic-auth request
req.on('login', (authInfo, callback) => {
console.log('handling login event');
callback(USERNAME, PASSWORD);
});
// We do not expect any error events.
req.on('error', err => console.log('error:', err));
// Handle the response and print the status code. We expect 200, but this bug appears to
// treat an empty string username or password as the cancellation of the login request,
// which is done by calling the callback with no arguments, as described here:
// https://electronjs.org/docs/api/client-request#event-login
req.on('response', response => {
console.log(`got response status code '${response.statusCode}'`);
app.quit();
});
req.end();
});