From 3c5bf3d5cf1f35988a95b1e2ccde4bb9af06b3a8 Mon Sep 17 00:00:00 2001 From: Alice Zhao <66543449+alicelovescake@users.noreply.github.com> Date: Mon, 11 Mar 2024 09:45:44 -0700 Subject: [PATCH] docs: update forge create-electron-app template to match tutorial (#3528) * docs: update forge template to match best practices in tutorials * chore: run prettier * chore: use node prefix with path module --------- Co-authored-by: Alice Zhao --- packages/template/base/tmpl/index.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/template/base/tmpl/index.js b/packages/template/base/tmpl/index.js index f581a1abb1..8740fc55f5 100644 --- a/packages/template/base/tmpl/index.js +++ b/packages/template/base/tmpl/index.js @@ -1,5 +1,5 @@ const { app, BrowserWindow } = require('electron'); -const path = require('path'); +const path = require('node:path'); // Handle creating/removing shortcuts on Windows when installing/uninstalling. if (require('electron-squirrel-startup')) { @@ -26,7 +26,17 @@ const createWindow = () => { // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. -app.on('ready', createWindow); +app.whenReady().then(() => { + createWindow(); + + // On OS X it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + app.on('activate', () => { + if (BrowserWindow.getAllWindows().length === 0) { + createWindow(); + } + }); +}); // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits @@ -37,13 +47,5 @@ app.on('window-all-closed', () => { } }); -app.on('activate', () => { - // On OS X it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (BrowserWindow.getAllWindows().length === 0) { - createWindow(); - } -}); - // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and import them here.