Differences between revisions 1 and 5 (spanning 4 versions)
Revision 1 as of 2023-03-02 17:31:01
Size: 785
Comment:
Revision 5 as of 2023-03-02 17:37:56
Size: 956
Comment:
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
const { app } = require("electron"); const { app, BrowserWindow } = require('electron');
const path = require('path');
Line 23: Line 24:
      preload: filePreload,       preload: path.join(__dirname, 'preload.js'),
Line 27: Line 28:
  win.loadFile(fileIndex);   win.loadFile(path.join(__dirname, 'index.html'));
Line 29: Line 30:
  win.on("closed", () => {   win.on('closed', () => {
Line 34: Line 35:
app.on("ready", initializeWindow); app.on('ready', initializeWindow);
Line 36: Line 37:
app.on("window-all-closed", () => { app.on('window-all-closed', () => {
Line 40: Line 41:
app.on("activate", () => { app.on('activate', () => {
Line 44: Line 45:

For details on `BrowserWindow`, see [[Node/Electron/BrowserWindow|here]].

Electron App


App

const { app, BrowserWindow } = require('electron');
const path = require('path');

var win;

function initializeWindow() {
  win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      contextIsolation: true,
      nodeIntegration: false,
      preload: path.join(__dirname, 'preload.js'),
    }
  });

  win.loadFile(path.join(__dirname, 'index.html'));

  win.on('closed', () => {
    win = null;
  });
};

app.on('ready', initializeWindow);

app.on('window-all-closed', () => {
  if (process.platform !== "darwin") app.quit();
});

app.on('activate', () => {
  if (win === null) initializeWindow();
});

For details on BrowserWindow, see here.


See also

Electron API for app


CategoryRicottone

Node/Electron/App (last edited 2023-03-02 17:39:24 by DominicRicottone)