Skip to content

Commit

Permalink
added test mode and window creation handler
Browse files Browse the repository at this point in the history
  • Loading branch information
GauravWalia19 committed Jan 14, 2021
1 parent 2d7da74 commit f074185
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .erboilerplate/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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("/");
Expand Down
35 changes: 4 additions & 31 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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
*/
Expand All @@ -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)
Expand All @@ -138,7 +111,7 @@ const mainMenuTemplate = [
accelerator:
process.platform === 'darwin' ? 'Command+L' : 'Ctrl+L',
click() {
createAddWindow();
addWindow = wcHandler.createAddWindow(addWindow);
},
},
{
Expand Down Expand Up @@ -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();
Expand Down
33 changes: 33 additions & 0 deletions electron/winCreationHandler.js
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit f074185

Please sign in to comment.