Skip to content

Instantly share code, notes, and snippets.

@abhishekY495
Created November 11, 2022 08:15
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 abhishekY495/c28984acf3e5ea250dfa2471381d3ea4 to your computer and use it in GitHub Desktop.
Save abhishekY495/c28984acf3e5ea250dfa2471381d3ea4 to your computer and use it in GitHub Desktop.
Electron Main process
const path = require("path");
const { app, BrowserWindow, Menu } = require("electron");
const { menuTemplate } = require("./menuTemplate.js");
const isMac = process.platform === "darwin";
const isDev = false; // Set to true for DevTools
function createMainWindow() {
const mainWindow = new BrowserWindow({
title: "File encryptor",
width: 420,
height: 690,
resizable: isDev ? true : false ,
icon: path.join(__dirname, "./icons/app-icon.ico"),
webPreferences: {
contextIsolation: true,
nodeIntegration: true,
preload: path.join(__dirname, "./preload.js"),
},
});
if (isDev) {
mainWindow.webContents.openDevTools();
}
mainWindow.loadFile(path.join(__dirname, "../src/index.html"));
}
app.whenReady().then(() => {
createMainWindow();
const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createMainWindow();
}
});
});
app.on("window-all-closed", () => {
if (!isMac) {
app.quit();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment