-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
66 lines (52 loc) · 1.7 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
// Modules
const {app, BrowserWindow, ipcMain} = require('electron')
const windowStateKeeper = require('electron-window-state')
const readItem = require('./readItem')
const appMenu = require('./menu')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
// Listen for new item request
ipcMain.on('new-item', (e, itemUrl) => {
// Get new item and send back to renderer
readItem( itemUrl, item => {
e.sender.send('new-item-success', item)
})
})
// Create a new BrowserWindow when `app` is ready
function createWindow () {
// Win state keeper
let state = windowStateKeeper({
defaultWidth: 500, defaultHeight: 650
})
mainWindow = new BrowserWindow({
x: state.x, y: state.y,
width: state.width, height: state.height,
minWidth: 350, maxWidth: 650, minHeight: 300,
webPreferences: {
nodeIntegration: true
}
})
// Create main app menu
appMenu(mainWindow.webContents)
// Load index.html into the new BrowserWindow
mainWindow.loadFile('renderer/main.html')
// Manage new window state
state.manage(mainWindow)
// Open DevTools - Remove for PRODUCTION!
// mainWindow.webContents.openDevTools();
// Listen for window being closed
mainWindow.on('closed', () => {
mainWindow = null
})
}
// Electron `app` is ready
app.on('ready', createWindow)
// Quit when all windows are closed - (Not macOS - Darwin)
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})
// When app icon is clicked and app is running, (macOS) recreate the BrowserWindow
app.on('activate', () => {
if (mainWindow === null) createWindow()
})