45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
|
const { app, BrowserWindow, ipcMain } = require('electron');
|
||
|
const http = require('http');
|
||
|
const path = require('path')
|
||
|
|
||
|
async function handleHttpRequest(_, options) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
console.log(options);
|
||
|
const req = http.request(options, res => {
|
||
|
console.log(`Status: ${res.statusCode}`);
|
||
|
res.setEncoding('utf-8');
|
||
|
res.on('data', data => {
|
||
|
console.log(data)
|
||
|
resolve(data)
|
||
|
});
|
||
|
res.on('error', data => {
|
||
|
console.error(data)
|
||
|
reject(data)
|
||
|
});
|
||
|
});
|
||
|
|
||
|
req.end();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
const createWindow = () => {
|
||
|
const win = new BrowserWindow({
|
||
|
width: 800,
|
||
|
height: 600,
|
||
|
webPreferences: {
|
||
|
preload: path.join(__dirname, 'preload.js'),
|
||
|
},
|
||
|
});
|
||
|
|
||
|
win.loadFile('index.html');
|
||
|
}
|
||
|
|
||
|
app.whenReady().then(() => {
|
||
|
createWindow();
|
||
|
ipcMain.handle('request', handleHttpRequest);
|
||
|
});
|
||
|
|
||
|
app.on('window-all-closed', () => {
|
||
|
if (process.platform !== 'darwin') app.quit();
|
||
|
});
|