-
Notifications
You must be signed in to change notification settings - Fork 16
/
electronClient.js
executable file
·94 lines (70 loc) · 2.51 KB
/
electronClient.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
const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
const { exec } = require("child_process");
const url = require("url");
const fs = require("fs");
/* ----------------------------------------------------------- */
/* -------------------------- SETUP -------------------------- */
/* ----------------------------------------------------------- */
let mainWindow, sdnManagerWindow
function startMainWindow(){
mainWindow = new BrowserWindow({
width: 1280,
height: 760,
minWidth: 800,
minHeight: 600,
icon: '/src/static/images/icons/icon.png'
});
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
}));
mainWindow.setTitle('Netkit-Lab-Generator');
mainWindow.on("closed", function () {
mainWindow = null;
if(!sdnManagerWindow) app.quit();
});
}
function startSDNManagerWindow(){
sdnManagerWindow = new BrowserWindow({ minWidth: 770, minHeight: 500 });
sdnManagerWindow.loadURL(url.format({
pathname: path.join(__dirname, "src/sdn-manager", "index.html"),
protocol: "file:",
slashes: true
}));
sdnManagerWindow.setTitle('SDN-Manager');
sdnManagerWindow.on("closed", function () {
sdnManagerWindow = null;
if(!mainWindow) app.quit();
});
}
app.on("ready", startMainWindow);
// app.on("ready", startSDNManagerWindow); // DEV
/* ---------------------------------------------------------- */
/* ------------------------- EVENTS ------------------------- */
/* ---------------------------------------------------------- */
let _baseFolder = app.getPath("userData");
function _runKatharaCommand(command){
exec(command, (stderr) => { if(stderr) console.error(stderr) });
}
ipcMain.on("sdn:start", startSDNManagerWindow);
/* ------------------------- SCRIPT ------------------------- */
ipcMain.on("script:copy", function (_, script, filename) {
let pathTemp = path.join(_baseFolder, filename);
console.log("Saving script to " + pathTemp);
fs.writeFileSync(pathTemp, script)
console.log("Running " + pathTemp);
exec("bash \"" + pathTemp + "\"");
});
ipcMain.on("script:execute", function () {
let pathTemp = path.join(_baseFolder, "lab");
console.log("Running LStart on " + pathTemp);
_runKatharaCommand("kathara lstart -d \"" + pathTemp + "\"");
});
ipcMain.on("script:clean", function () {
let pathTemp = path.join(_baseFolder, "lab");
console.log("Running LClean on " + pathTemp);
_runKatharaCommand("kathara lclean -d \"" + pathTemp + "\"");
if(sdnManagerWindow) sdnManagerWindow.close();
});