-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
135 lines (112 loc) · 4.53 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//handle setupevents as quickly as possible
const setupEvents = require('./setupEvent')
if (setupEvents.handleSquirrelEvent()) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
} else {
/* main Electron working code */
const {app, BrowserWindow, Menu, Tray, nativeImage} = require('electron');
let win;
function createWindow() {
win = new BrowserWindow({
width: 1280,
height: 800,
minWidth: 320,
minHeight: 240,
acceptFirstMouse: true,
titleBarStyle: "hidden",
autoHideMenuBar: true,
frame: true,
backgroundColor: '#343a40',
icon: 'res/site_icon_x32.png'
});
/*
new BrowserWindow({
transparent:true
frame: false,
backgroundColor: '#00FFFFFF'
});*/
//win.webContents.openDevTools();
win.loadURL('file://' + __dirname + '/src/myLoaderView.html');
win.show();
var port = 9183;
// This twisted CWD argument is required to correctly drive django's Model.ImageFile path
var djangoSpawn = require('child_process').spawn;
var djangoWin = djangoSpawn(__dirname+'/djYMDB/venv/Scripts/python', ['-u', __dirname+'/djYMDB/manage.py', 'runserver', 'localhost:'+port], {cwd:__dirname+'/djYMDB'});
djangoWin.stdout.on('data', function (data) {
console.log(data.toString());
});
let myTray = null;
const nImage = nativeImage.createFromPath(__dirname+'/res/site_icon_x32.png');
const trayMeu = Menu.buildFromTemplate([
{label:'Добавить запись', type:"normal", click:function () {
win.restore();
win.loadURL('http://localhost:'+port+'/add/0');
win.show();
}},
{label:'Изменить колллекции', type:"normal", click:function () {
win.restore();
win.loadURL('http://localhost:'+port+'/prop/1');
win.show();
}},
{label:'Изменить жанры', type:"normal", click:function () {
win.restore();
win.loadURL('http://localhost:'+port+'/prop/2');
win.show();
}},
{label:'sep', type:"separator"},
{label:'Покинуть программу', type:"normal", click:function () {
app.exit(0);
}}
]);
var procsPIDS = new Array();
var redirs = 0;
win.webContents.on('did-finish-load', function () {
redirs += 1;
if (redirs == 2) {
// We have loaded main server.
// Now can collect python PIDs
const tasklist = require('tasklist');
tasklist({verbose: true, filter: ['Imagename eq python.exe']}).then(tasks => {
//console.log(tasks);
tasks.forEach(function (t) {
procsPIDS.push(t.pid);
});
console.log(procsPIDS);
});
// Also tray icon
myTray = new Tray(nImage);
myTray.setContextMenu(trayMeu);
myTray.setToolTip('YMDB - Ваша База Художественных Произведений');
myTray.on('click', function () {
win.restore();
win.show();
win.focus();
});
}
});
win.on('closed', function() {
procsPIDS.forEach(function (pypid) {
process.kill(pypid);
})
});
win.on('minimize', function() {
win.hide();
if (myTray){
myTray.displayBalloon({icon:'res/site_icon_x32.png',title:'YMDB',
content:'Программа продолжает работать.\nЩелкните чтобы отбразить окно.\nИли воспользутесь меню'})
}
})
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (win === null) {
createWindow();
}
});
}