Skip to content

Instantly share code, notes, and snippets.

@muhsin-k
Created February 9, 2020 15:21
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 muhsin-k/035cd096f06ab2d7ce18b5696381ab70 to your computer and use it in GitHub Desktop.
Save muhsin-k/035cd096f06ab2d7ce18b5696381ab70 to your computer and use it in GitHub Desktop.
Electron basic config
const electron = require("electron");
const { app, BrowserWindow } = electron;
const path = require("path");
const url = require("url");
const isDev = require("electron-is-dev");
let mainWindow;
const localUrl = "http://localhost:3000";
function createWindow() {
mainWindow = new BrowserWindow({
width: 760,
minWidth: 700,
minHeight: 620,
height: 620,
webPreferences: { nodeIntegration: true }
});
if (isDev) {
mainWindow.loadURL(localUrl);
mainWindow.webContents.openDevTools();
} else {
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "../build/index.html"),
protocol: "file:",
slashes: true
})
);
}
mainWindow.on("closed", () => (mainWindow = null));
}
app.on("ready", createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (mainWindow === null) {
createWindow();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment