-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
299 lines (267 loc) · 8.52 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// Import
const fs = require('fs');
const process = require('process');
const path = require('path');
const { app, BrowserWindow, Menu, ipcMain } = require('electron');
const Main = require('electron/main');
let { PythonShell } = require('python-shell');
// Setup python environament
console.log('Setting up python environament ...');
let pyvenvContent;
if (process.platform === 'win32') {
pyvenvContent = `home = ${path.join(process.cwd(), 'python/interpreter/PCbuild/amd64')}
include-system-site-packages = false
version = 3.10.6
`;
}
else {
pyvenvContent = `home = ${path.join(process.cwd(), 'python/interpreter')}
include-system-site-packages = false
version = 3.10.6
`;
}
fs.writeFile(path.join(process.cwd(), 'python/interpreter/ViMag_venv/pyvenv.cfg'), pyvenvContent, err => {
if (err) {
console.error(err);
}
// file written successfully
});
console.log('Done');
// Add application icon
app.getFileIcon('./img/icon.ico');
// Define main window
const createWindow = () => {
const win = new BrowserWindow({
title: 'ViMag',
width: 1200,
height: 720,
icon: './img/icon.ico',
fullscreenable: false,
//frame: False,
webPreferences: {
nodeIntegration: true, // These arguments are now required since they are disabled by default for security reasons
contextIsolation: false,
devTools: !app.isPackaged,
},
});
win.toggleDevTools(); //For debug
win.loadFile('./html/index.html');
const menuTemplate = [
{
label: 'File',
submenu: [
{
label: 'New project',
accelerator: 'CmdOrCtrl+N',
click() {
win.webContents.send('newPrj', true);
}
},
{
label: 'Load project',
accelerator: 'CmdOrCtrl+O',
click() {
loadProject(win);
}
},
{
label: 'Save',
accelerator: 'CmdOrCtrl+S',
click() {
win.webContents.send('save', null);
}
},
{
label: 'Save As',
accelerator: 'CmdOrCtrl+Shift+S',
click() {
saveProject(win);
}
},
{
type: 'separator'
},
{
label: 'Import video',
accelerator: 'CmdOrCtrl+I',
click() {
importVid(win);
},
},
{
type: 'separator'
},
{
role: 'Quit'
}
]
},
{
label: 'Edit',
submenu: [
{
label: 'Preferences',
click() {
const aboutWin = new BrowserWindow({
title: 'Preferences',
width: 600,
height: 800,
icon: './img/icon.ico',
resizable: false,
fullscreenable: false,
webPreferences: {
nodeIntegration: true, // These arguments are now required since they are disabled by default for security reasons
contextIsolation: false,
devTools: !app.isPackaged,
},
});
aboutWin.toggleDevTools(); //For debug
aboutWin.removeMenu();
aboutWin.loadFile('./html/preferences.html');
},
}
]
},
/*{
label: 'View',
submenu: [
{
role: 'reload'
},
{
role: 'togglefullscreen'
}
]
},*/
{
role: 'help',
submenu: [
{
label: 'About',
click() {
const aboutWin = new BrowserWindow({
title: 'About',
width: 413,
height: 255,
icon: './img/icon.ico',
resizable: false,
fullscreenable: false,
});
aboutWin.removeMenu();
aboutWin.loadFile('./html/about.html');
},
}
]
},
];
const menu = Menu.buildFromTemplate(menuTemplate)
Menu.setApplicationMenu(menu)
// Renderer events ---------------------------------------------------------
// The renderer asks for a "Save As" dialog
ipcMain.on('saveAs', function (event, args) {
saveProject(win);
});
// Request for video import
ipcMain.on('vimportReq', function (event, args) {
importVid(win);
});
// Request for project load
ipcMain.on('loadReq', function (event, args) {
loadProject(win);
});
// Request for data export
ipcMain.on('dexportReq', function (event, args) {
exportData(win);
});
};
app.whenReady().then(() => {
createWindow()
});
// When all windows are closed quit the app
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
});
// Functions -------------------------------------------------------------------
async function loadProject(MainWindow) {
const { dialog } = require('electron');
let options = {
title: "Load project",
defaultPath: ".",
buttonLabel: "Load",
filters: [
{ name: 'ViMag projects', extensions: ['vl'] },
{ name: 'All Files', extensions: ['*'] }
],
properties: ['openFile']
};
dialog.showOpenDialog(MainWindow, options).then((filePaths) => {
console.log('Load dialog')
console.log({ filePaths })
if (!filePaths.canceled) {
MainWindow.webContents.send('loadPath', filePaths.filePaths[0]);
}
});
}
async function saveProject(MainWindow) {
const { dialog } = require('electron');
let options = {
title: "Save project",
defaultPath: ".",
buttonLabel: "Save As",
filters: [
{ name: 'ViMag projects', extensions: ['vl'] },
{ name: 'All Files', extensions: ['*'] }
],
properties: ['saveFile']
};
dialog.showSaveDialog(MainWindow, options).then((filePaths) => {
console.log('Save dialog:')
console.log({ filePaths })
if (!filePaths.canceled) {
if (filePaths.filePath.substring(filePaths.filePath.length - 3) != '.vl'){
filePaths.filePath += '.vl';
}
MainWindow.webContents.send('savePath', filePaths.filePath);
}
});
}
async function importVid(MainWindow) {
const { dialog } = require('electron');
let options = {
title: "Import video",
defaultPath: ".",
buttonLabel: "Import",
filters: [
{ name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] },
{ name: 'All Files', extensions: ['*'] }
],
properties: ['openFile', 'multiSelections']
};
dialog.showOpenDialog(MainWindow, options).then((filePaths) => {
console.log('Import dialog')
console.log({ filePaths })
if (!filePaths.canceled) {
MainWindow.webContents.send('vimport', filePaths.filePaths);
}
});
}
async function exportData(MainWindow) {
const { dialog } = require('electron');
let options = {
title: "Export data",
defaultPath: ".",
buttonLabel: "Export",
filters: [
{ name: 'Text CSV', extensions: ['csv'] },
{ name: 'All Files', extensions: ['*'] }
],
properties: ['saveFile']
};
dialog.showSaveDialog(MainWindow, options).then((filePaths) => {
console.log('Export dialog')
console.log({ filePaths })
if (!filePaths.canceled) {
MainWindow.webContents.send('dexport', filePaths.filePath);
}
});
}