-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
66 lines (48 loc) · 1.57 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
import { app, BrowserWindow, ipcMain } from 'electron';
import Defaults from './defaults';
let mainWindow;
let backWindow;
ipcMain.on(Defaults.Messages.StartConvertion, function(event, path, crop) {
backWindow = new BrowserWindow({ show: false, });
let url = `file://${__dirname}/background.html?image=${path}`;
if (crop.x) {
url += `&x=${crop.x}&y=${crop.y}&width=${crop.width}&height=${crop.height}`
}
backWindow.loadURL(url);
backWindow.on('closed', () => backWindow = null);
});
ipcMain.on(Defaults.Messages.ConvertionComplete, function(event, outpath) {
backWindow.close();
mainWindow.webContents.send(Defaults.Messages.ConvertionComplete, outpath);
});
ipcMain.on(Defaults.Messages.ConvertionError, function(event, error) {
backWindow.close();
mainWindow.webContents.send(Defaults.Messages.ConvertionError, error);
});
const isDevMode = process.execPath.match(/[\\/]electron/);
const createMainWindow = () => {
mainWindow = new BrowserWindow({
width: 600,
height: 550,
});
mainWindow.loadURL(`file://${__dirname}/index.html`);
if (isDevMode) {
mainWindow.webContents.openDevTools();
} else {
mainWindow.setResizable(false);
}
mainWindow.on('closed', () => {
mainWindow = null;
});
};
app.on('ready', createMainWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit(); // when window closed quit except for MacOS
}
});
app.on('activate', () => {
if (mainWindow === null) {
createMainWindow();
}
});