Skip to content

Instantly share code, notes, and snippets.

@afterburn
Last active October 29, 2017 16:06
Show Gist options
  • Save afterburn/31bcc8d5bf59bfaba4b4aa9fbeff1524 to your computer and use it in GitHub Desktop.
Save afterburn/31bcc8d5bf59bfaba4b4aa9fbeff1524 to your computer and use it in GitHub Desktop.
const electron = require('electron');
const { app, BrowserWindow } = electron;
const path = require('path');
const url = require('url');
class Application {
constructor() {
this.windows = {};
app.on('ready', () => this.createWindow('main'));
app.on('activate', () => this.createWindow('main'));
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
}
createWindow(name) {
if(!this.windows.hasOwnProperty(name)) {
const window = this.windows[name] = new BrowserWindow({ width: 800, height: 600 });
window.loadURL(url.format({
pathname: path.join(__dirname, 'gui', 'index.html'),
protocol: 'file:',
slashes: true
}));
window.webContents.openDevTools();
window.on('closed', () => {
this.windows[name] = null;
});
}
}
}
new Application();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment