diff --git a/.erboilerplate/config.js b/.erboilerplate/config.js index b455e65..8bc6e61 100644 --- a/.erboilerplate/config.js +++ b/.erboilerplate/config.js @@ -11,7 +11,7 @@ module.exports = { setNodeEnv: (nodeEnv) => { if ( nodeEnv && - (nodeEnv === 'production' || nodeEnv === 'development') + (nodeEnv === 'production' || nodeEnv === 'development' || nodeEnv === 'test') ) { console.log(`Overwriting NODE_ENV from ${process.env.NODE_ENV} -> ${nodeEnv}`); process.env.NODE_ENV = nodeEnv; @@ -20,7 +20,7 @@ module.exports = { return false; }, init: ()=>{ - console.log('\x1b[1;30;43m',`Application Running in ${process.env.NODE_ENV}`,'\x1b[0m'); + console.log('\x1b[1;31m',`Application Running in ${process.env.NODE_ENV}`,'\x1b[0m'); }, getIconsPath: ()=>{ const dirname = __dirname.split("/"); diff --git a/electron/main.js b/electron/main.js index 882a71f..f763a15 100644 --- a/electron/main.js +++ b/electron/main.js @@ -4,6 +4,7 @@ const { app, BrowserWindow, Menu, ipcMain } = electron; const db = require('../controller/db'); const killport = require('./util/kill').killProcessAtPort; const config = require('../.erboilerplate/config'); +const wcHandler = require('./winCreationHandler'); // for using package-linux,package-win and package-mac scripts please uncomment below line // config.setNodeEnv('production'); @@ -63,34 +64,6 @@ app.on('ready', () => { Menu.setApplicationMenu(mainMenu); }); -/** - * ADD WINDOW - **/ -function createAddWindow() { - // create new window - addWindow = new BrowserWindow({ - width: 500, - height: 500, - title: 'Add Shopping List Item', - webPreferences: { - nodeIntegration: false, // is default value after Electron v5 - contextIsolation: true, // protect against prototype pollution - enableRemoteModule: false, // turn off remote - preload: path.join(__dirname, "preload.js") // use a preload script - }, - }); - // load the add the component file - addWindow.loadURL( - process.env.NODE_ENV !== 'production' - ? path.join(config.DEV_SERVER_URL,'add') - : config.getProdServerURL('#/add') - ); - - addWindow.on('close', () => { - addWindow = null; - }); -} - /* * catching calls from the react UI */ @@ -114,7 +87,7 @@ ipcMain.handle('item:add', async (e, item)=>{ }); }) ipcMain.handle('item:openAddWindow', async()=>{ - createAddWindow(); + addWindow = wcHandler.createAddWindow(addWindow); }) ipcMain.handle('item:clearSelected', async (e,name)=>{ db.deleteSelectedItem(name) @@ -138,7 +111,7 @@ const mainMenuTemplate = [ accelerator: process.platform === 'darwin' ? 'Command+L' : 'Ctrl+L', click() { - createAddWindow(); + addWindow = wcHandler.createAddWindow(addWindow); }, }, { @@ -172,7 +145,7 @@ const mainMenuTemplate = [ }, ]; -// connection to be checked after 2 mins +// database connection to be checked after 2 mins setInterval(()=>{ console.log("Connected: ", process.env.CONNECTION==='true'); db.connectToDB(); diff --git a/electron/winCreationHandler.js b/electron/winCreationHandler.js new file mode 100644 index 0000000..0abf45a --- /dev/null +++ b/electron/winCreationHandler.js @@ -0,0 +1,33 @@ +const path = require('path'); +const { BrowserWindow } = require('electron'); +const config = require('../.erboilerplate/config'); + +const createAddWindow = (addWindow)=> { + // create new window + addWindow = new BrowserWindow({ + width: 500, + height: 500, + title: 'Add Shopping List Item', + webPreferences: { + nodeIntegration: false, // is default value after Electron v5 + contextIsolation: true, // protect against prototype pollution + enableRemoteModule: false, // turn off remote + preload: path.join(__dirname, "preload.js") // use a preload script + }, + }); + // load the add the component file + addWindow.loadURL( + process.env.NODE_ENV !== 'production' + ? path.join(config.DEV_SERVER_URL,'add') + : config.getProdServerURL('#/add') + ); + + addWindow.on('close', () => { + addWindow = null; + }); + return addWindow; +} + +module.exports = { + createAddWindow +} \ No newline at end of file