Last active
September 27, 2018 19:24
-
-
Save smkamranqadri/c5e432eb749ed147426e048487ecf624 to your computer and use it in GitHub Desktop.
Sample Electron Main.js file.
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
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