-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
94 lines (84 loc) · 2.11 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
const electron = require("electron");
const {app, BrowserWindow, Menu} = electron;
const path = require("path");
const url = require("url");
const WebSocket = require("ws");
/*
Constants
*/
const WINDOW_WIDTH = 650;
const WINDOW_HEIGHT = 225;
const WINDOW_HTML_FILE = 'mainWindow.html';
const DEFAULT_HOST = "localhost";
const DEFAULT_PORT = 49152;
const DEFAULT_BACKLOG = 16;
app.on("window-all-closed", (e) =>
{
e.preventDefault();
});
app.on("ready", () =>
{
const wss = new WebSocket.Server(
{
host: DEFAULT_HOST,
port: DEFAULT_PORT,
backlog: DEFAULT_BACKLOG,
perMessageDeflate: false
});
wss.on("connection", function connection(ws)
{
console.log("Connection establised...");
ws.on("message", async function incoming(data)
{
try
{
const dataJSON = JSON.parse(data);
const mainWindow = new BrowserWindow(
{
width: WINDOW_WIDTH,
height: WINDOW_HEIGHT,
resizable: false,
show: false,
webPreferences:
{
nodeIntegration: true,
enableRemoteModule: true
}
});
mainWindow.loadURL(url.format(
{
pathname: path.join(__dirname, WINDOW_HTML_FILE),
protocol: "file:",
slashes: true
}));
mainWindow.on("ready-to-show", () =>
{
mainWindow.show();
// mainWindow.toggleDevTools();
});
Menu.setApplicationMenu(null);
/*
After the service gets ready, send necessary data for the electron window for
downloading process
*/
mainWindow.webContents.on("did-finish-load", () =>
{
mainWindow.webContents.send("downloading-data", JSON.stringify(
{
url: dataJSON["finalUrl"],
cookies: dataJSON["cookies"],
userAgent: dataJSON["userAgent"]
}));
});
}
catch (_error)
{
}
});
});
wss.on("close", () =>
{
console.log("Connection closed...");
});
});