-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
85 lines (73 loc) · 2.42 KB
/
index.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
const {app, BrowserWindow} = require("electron");
const remoteMain = require('@electron/remote/main');
remoteMain.initialize();
const spawn = require('child_process');
const process = require('process');
var kill = require('tree-kill');
var djangoBackend = null;
const startDjangoServer = () =>
{ //
//djangoBackend = spawn.spawn('python',
//['python\\manage.py','runserver','--noreload'], {shell : true,});
djangoBackend = spawn.spawn('python\\dist\\manage\\manage.exe',
['runserver','--noreload'], {shell : true,});
djangoBackend.stdout.on('data', data =>
{
console.log(`stdout:\n${data}`);
});
djangoBackend.stderr.on('data', data =>
{
console.log(`stderr: ${data}`);
});
djangoBackend.on('error', (error) =>
{
console.log(`error: ${error.message}`);
});
djangoBackend.on('close', (code) =>
{
kill(djangoBackend.pid);
console.log(`child process exited with code ${code}`);
});
djangoBackend.on('message', (message) =>
{
console.log(`message:\n${message}`);
});
return djangoBackend;
}
function checkStart(){
const launchWindow = new BrowserWindow({
title: "ffxivcalc",
width : 700,
height: 870,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
icon: 'icon.png'
});
remoteMain.enable(launchWindow.webContents);
const appURL = "http://127.0.0.1:8000/simulate/";
const loadURL = `loading.html`;
console.log('launching loading');
launchWindow.loadURL(`file://${__dirname}/loading.html`);
//launchWindow.loadURL(appURL)
}
function ElectronMainMethod(){
startDjangoServer(); // -> Starts Django server using appEnv (python virtual environment) and makes code wait for it
checkStart();
}
app.whenReady().then(ElectronMainMethod);
app.on('browser-window-created', (_, window) => {
require("@electron/remote/main").enable(window.webContents);
//window.setMenu(null);
//window.webContents.openDevTools();
window.webContents.session.clearCache();
})
app.on('before-quit', () => {
//console.log("Killing process");
// Killing both the django server and the current process
kill(djangoBackend.pid);
kill(process.pid);
//console.log("Killed process");
});