Created
April 3, 2017 05:31
-
-
Save jksmall0631/f3a2bfe3ac5f2ecdb07ed6cc48bd99e9 to your computer and use it in GitHub Desktop.
Electron main process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { app, BrowserWindow } from 'electron'; | |
import MenuBuilder from './menu'; | |
let mainWindow = null; | |
if (process.env.NODE_ENV === 'production') { | |
const sourceMapSupport = require('source-map-support'); | |
sourceMapSupport.install(); | |
} | |
if (process.env.NODE_ENV === 'development') { | |
require('electron-debug')(); | |
const path = require('path'); | |
const p = path.join(__dirname, '..', 'app', 'node_modules'); | |
require('module').globalPaths.push(p); | |
} | |
app.on('window-all-closed', () => { | |
if (process.platform !== 'darwin') app.quit(); | |
}); | |
const installExtensions = async () => { | |
if (process.env.NODE_ENV === 'development') { | |
const installer = require('electron-devtools-installer'); | |
const extensions = [ | |
'REACT_DEVELOPER_TOOLS', | |
'REDUX_DEVTOOLS' | |
]; | |
const forceDownload = !!process.env.UPGRADE_EXTENSIONS; | |
return Promise | |
.all(extensions.map(name => installer.default(installer[name], forceDownload))) | |
.catch(console.log); | |
} | |
}; | |
app.on('ready', async () => { | |
await installExtensions(); | |
mainWindow = new BrowserWindow({ | |
show: false, | |
width: 1024, | |
height: 728 | |
}); | |
mainWindow.loadURL(`file://${__dirname}/app.html`); | |
mainWindow.webContents.on('did-finish-load', () => { | |
if (!mainWindow) { | |
throw new Error('"mainWindow" is not defined'); | |
} | |
mainWindow.show(); | |
mainWindow.focus(); | |
}); | |
mainWindow.on('closed', () => { | |
mainWindow = null; | |
}); | |
const menuBuilder = new MenuBuilder(mainWindow); | |
menuBuilder.buildMenu(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment