Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jksmall0631/f3a2bfe3ac5f2ecdb07ed6cc48bd99e9 to your computer and use it in GitHub Desktop.
Save jksmall0631/f3a2bfe3ac5f2ecdb07ed6cc48bd99e9 to your computer and use it in GitHub Desktop.
Electron main process
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