Skip to content

Instantly share code, notes, and snippets.

@smkamranqadri
Last active September 27, 2018 19:24
Show Gist options
  • Save smkamranqadri/c5e432eb749ed147426e048487ecf624 to your computer and use it in GitHub Desktop.
Save smkamranqadri/c5e432eb749ed147426e048487ecf624 to your computer and use it in GitHub Desktop.
Sample Electron Main.js file.
const { app, BrowserWindow } = require('electron');
const path = require('path');
const url = require('url');
require('dotenv').config();
let win = null;
function createWindow() {
// Initialize the window to our specified dimensions
win = new BrowserWindow({ width: 1000, height: 600 });
// Specify entry point
if (process.env.PACKAGE === 'true') {
win.loadURL(
url.format({
pathname: path.join(__dirname, process.env.DISTPATH),
protocol: 'file:',
slashes: true
})
);
} else {
win.loadURL(process.env.HOST);
win.webContents.openDevTools();
}
win.on('closed', function() {
win = null;
});
}
app.on('ready', function() {
createWindow();
});
app.on('activate', () => {
if (win === null) {
createWindow();
}
});
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment