-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
56 lines (45 loc) · 1.44 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
const { app, BrowserWindow, screen: electronScreen, ipcMain, Notification } = require('electron');
const path = require('path');
function handleSetTitle (event, title) {
const webContents = event.sender
const win = BrowserWindow.fromWebContents(webContents)
win.setTitle(title)
}
function handleShowNotification (event, title, body) {
new Notification({ title, body }).show()
}
const createMainWindow = () => {
let mainWindow = new BrowserWindow({
width: electronScreen.getPrimaryDisplay().workArea.width,
height: electronScreen.getPrimaryDisplay().workArea.height,
show: false,
backgroundColor: 'white',
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: false,
contextIsolation: true
}
});
const startURL = app.isPackaged ? 'https://hylo.com' : 'http://localhost:3000';
mainWindow.loadURL(startURL);
mainWindow.once('ready-to-show', () => mainWindow.show());
mainWindow.on('closed', () => {
mainWindow = null;
});
};
app.whenReady().then(() => {
createMainWindow();
app.on('activate', () => {
if (!BrowserWindow.getAllWindows().length) {
createMainWindow();
}
});
ipcMain.on('set-badge-count', (event, count) => app.setBadgeCount(count))
ipcMain.on('set-title', handleSetTitle)
ipcMain.on('show-notification', handleShowNotification)
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});