-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelectron.js
85 lines (66 loc) · 1.71 KB
/
electron.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
// Designed by Ericarthurc
// https://github.com/Ericarthurc
// October 24, 2019
// Wildwood Tech
const electron = require('electron');
const ipcMain = require('electron').ipcMain;
const BrowserWindow = electron.BrowserWindow;
const isDev = require('electron-is-dev');
const app = electron.app;
let mainWindow;
const createWindow = () => {
mainWindow = new BrowserWindow({
backgroundColor: '#2A2A2A',
width: 1280,
height: 720,
minWidth: 720,
minHeight: 480,
frame: false,
webPreferences: { nodeIntegration: true }
});
mainWindow.setMenu(null)
if (isDev) {
mainWindow.loadURL('http://localhost:3000')
} else {
mainWindow.loadFile('build/index.html')
}
if (isDev) {
mainWindow.webContents.openDevTools();
}
mainWindow.on('closed', () => mainWindow = null);
mainWindow.on('maximize', () => {
mainWindow.webContents.send('maximized')
})
mainWindow.on('unmaximize', () => {
mainWindow.webContents.send('unmaximized')
})
}
ipcMain.handle('minimize-event', () => {
mainWindow.minimize()
})
ipcMain.handle('maximize-event', () => {
mainWindow.maximize()
})
ipcMain.handle('unmaximize-event', () => {
mainWindow.unmaximize()
})
ipcMain.handle('close-event', () => {
app.quit()
})
app.on('browser-window-focus', () => {
mainWindow.webContents.send('focused')
})
app.on('browser-window-blur', () => {
mainWindow.webContents.send('blurred')
})
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});