-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
112 lines (88 loc) · 2.83 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const path = require('path')
const expressManager = new require(path.join(__dirname, "/express-manager.js"))();
const {app, BrowserWindow, Menu} = require('electron')
const ipc = require('electron').ipcMain;
const ip = require("ip");
let currentFileList = [];
let currentFileId = 0;
ipc.on('closeApp', function () {
app.quit();
expressManager.close();
});
let currSendingSettings = {
usePassword: false,
password: "",
usePort: false,
port: 80
}
ipc.on('addFiles', function (event, data) {
data.forEach(file => {
file.id = currentFileId;
currentFileId++;
});
currentFileList = [].concat(currentFileList, data); // Merge two arrays
event.sender.send('fileListUpdate', currentFileList);
});
ipc.on('startHost', function (event, data) {
expressManager.open(data.usePort ? data.port : 80, data.usePassword ? data.password : null, currentFileList);
currSendingSettings = data;
event.sender.send('runningUpdate', getRunningUpdate());
});
ipc.on('stopHost', function (event, data) {
expressManager.close();
event.sender.send('runningUpdate', getRunningUpdate());
});
ipc.on('requestSendingSettingsUpdate', function (event, data) {
event.sender.send('runningUpdate', getRunningUpdate());
});
function getRunningUpdate() {
let subData = {}
if (!expressManager.running) {
subData = currSendingSettings;
} else {
subData =
{host: ip.address() + (currSendingSettings.usePort ? ":" + currSendingSettings.port : ""),
password: currSendingSettings.usePassword ? currSendingSettings.password : null};
}
let data = {
running: expressManager.running,
data: subData
}
return data;
}
ipc.on("removeFile", (event, id) => {
currentFileList = currentFileList.filter((currentValue, index, arr) => {
return currentValue.id != id;
});
event.sender.send('fileListUpdate', currentFileList);
});
let win;
function createWindow() {
// Create the browser window.
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true
},
resizable: false,
transparent: true,
frame: false
});
//win.openDevTools({detach: true});
win.loadFile('index.html')
}
app.on(`ready`, () => {
createWindow();
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
Menu.setApplicationMenu(null);
});
app.on('window-all-closed', function () {
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') app.quit()
})