-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
113 lines (97 loc) · 2.56 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
113
const path = require("path");
const url = require("url");
const { execFile } = require("child_process");
const { app, BrowserWindow, ipcMain } = require("electron");
const { stdout, stderr } = require("process");
let mainWindow;
let isDev = false;
let backend;
let auth;
ipcMain.on("AUTH", (_, arg) => (auth = arg));
const cleanup = () => {
const axios = require("axios");
axios
.get("http://127.7.3.0:1728/kill", {
headers: { "Auth-Key": auth },
})
.then((response) => {
stdout.write(response.data);
})
.catch((error) => {
stderr.write(error);
});
};
if (
process.env.NODE_ENV !== undefined &&
process.env.NODE_ENV === "development"
) {
isDev = true;
}
console.log("Creating backend");
backend = execFile(".\\python\\Vault.exe", (error, sout, stderr) => {
stdout.write(`Python : ${sout}`);
if (error) {
console.error(stderr);
throw error;
}
console.log(stdout);
});
function createMainWindow() {
mainWindow = new BrowserWindow({
width: 720,
height: 720,
minWidth: 900,
minHeight: 720,
title: "File Vault",
show: false,
resizable: true,
autoHideMenuBar: true,
icon: `${__dirname}/assets/locker.png`,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
webSecurity: false,
},
});
let indexPath;
if (isDev && process.argv.indexOf("--noDevServer") === -1) {
indexPath = url.format({
protocol: "http:",
host: "localhost:8080",
pathname: "index.html",
slashes: true,
});
} else {
indexPath = url.format({
protocol: "file:",
pathname: path.join(__dirname, "dist", "index.html"),
slashes: true,
});
}
mainWindow.loadURL(indexPath);
// Don't show until we are ready and loaded
mainWindow.once("ready-to-show", () => {
mainWindow.show();
});
mainWindow.on("closed", () => (mainWindow = null));
}
app.on("ready", createMainWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
backend.kill("SIGTERM");
app.quit();
stdout.write("JS Closed\n");
cleanup();
cleanup();
cleanup();
cleanup();
stdout.write("Python Closed\n");
}
});
app.on("activate", () => {
if (mainWindow === null) {
createMainWindow();
}
});
// Stop error
app.allowRendererProcessReuse = true;