@@ -10,37 +10,39 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
1010// Import parts of electron to use
1111// app - Control your application's event lifecycle
1212// ipcMain - Communicate asynchronously from the main process to renderer processes
13+
14+ // npm libraries
1315const { app, BrowserWindow, TouchBar, ipcMain, dialog } = require ( "electron" ) ;
14- const path = require ( "path" ) ;
15- const url = require ( "url" ) ;
16- const fs = require ( "fs" ) ;
1716const {
1817 default : installExtension ,
1918 REACT_DEVELOPER_TOOLS ,
2019 REDUX_DEVTOOLS ,
2120} = require ( "electron-devtools-installer" ) ;
22-
2321// Import Auto-Updater- Swell will update itself
2422const { autoUpdater } = require ( "electron-updater" ) ;
25- const log = require ( "electron-log" ) ;
2623// TouchBarButtons are our nav buttons(ex: Select All, Deselect All, Open Selected, Close Selected, Clear All)
2724const { TouchBarButton, TouchBarSpacer } = TouchBar ;
2825
26+ const path = require ( "path" ) ;
27+ const url = require ( "url" ) ;
28+ const fs = require ( "fs" ) ;
29+ const log = require ( "electron-log" ) ;
30+
2931// basic http cookie parser
3032const cookie = require ( "cookie" ) ;
3133// node-fetch for the fetch request
3234const fetch2 = require ( "node-fetch" ) ;
3335
34- // require menu file
35- require ( "./menu/mainMenu" ) ;
36-
3736// GraphQL imports
3837const { ApolloClient } = require ( "apollo-client" ) ;
3938const gql = require ( "graphql-tag" ) ;
4039const { InMemoryCache } = require ( "apollo-cache-inmemory" ) ;
4140const { createHttpLink } = require ( "apollo-link-http" ) ;
4241const { ApolloLink } = require ( "apollo-link" ) ;
4342
43+ // require menu file
44+ require ( "./menu/mainMenu" ) ;
45+
4446// configure logging
4547autoUpdater . logger = log ;
4648autoUpdater . logger . transports . file . level = "info" ;
@@ -127,23 +129,31 @@ const touchBar = new TouchBar([
127129 tbClearAllButton ,
128130] ) ;
129131
130- // Keep a reference for dev mode
131- let dev = false ;
132- console . log ( "process.defaultApp ->" , process . defaultApp ) ;
133- console . log ( "process.execPath -> " , process . execPath ) ;
134- if (
135- process . defaultApp ||
136- / [ \\ / ] e l e c t r o n - p r e b u i l t [ \\ / ] / . test ( process . execPath ) ||
137- / [ \\ / ] e l e c t r o n [ \\ / ] / . test ( process . execPath )
138- ) {
139- dev = true ;
140- }
141- console . log (
142- "current regex test -> " ,
143- / [ \\ / ] e l e c t r o n - p r e b u i l t [ \\ / ] / . test ( process . execPath )
144- ) ;
145- if ( dev ) console . log ( "dev is TRUE" ) ;
146- if ( dev === false ) console . log ( "dev is FALSE" ) ;
132+ // -----------------------------------------------
133+ // prod / dev mode determined by boolean 'isDev'
134+ // -----------------------------------------------
135+
136+ let isDev ;
137+ process . argv . includes ( "--noDevServer" ) ? ( isDev = false ) : ( isDev = true ) ;
138+
139+ console . log ( "isDev->" , isDev ) ;
140+ // let isDev = false;
141+ // console.log("process.defaultApp ->", process.defaultApp);
142+ // console.log("process.execPath -> ", process.execPath);
143+
144+ // if (
145+ // process.defaultApp ||
146+ // /[\\/]electron-prebuilt[\\/]/.test(process.execPath) ||
147+ // /[\\/]electron[\\/]/.test(process.execPath)
148+ // ) {
149+ // isDev = true;
150+ // }
151+ // console.log(
152+ // "current regex test -> ",
153+ // /[\\/]electron-prebuilt[\\/]/.test(process.execPath)
154+ // );
155+ // if (isDev) console.log("isDev is TRUE");
156+ // if (isDev === false) console.log("isDev is FALSE");
147157// Temporary fix broken high-dpi scale factor on Windows (125% scaling)
148158// info: https://github.com/electron/electron/issues/9691
149159if ( process . platform === "win32" ) {
@@ -152,6 +162,10 @@ if (process.platform === "win32") {
152162 app . commandLine . appendSwitch ( "force-device-scale-factor" , "1" ) ;
153163}
154164
165+ /***********************************************
166+ ******* createWindow function declaration ******
167+ ***********************************************/
168+
155169function createWindow ( ) {
156170 // Create the new browser window instance.
157171 mainWindow = new BrowserWindow ( {
@@ -171,7 +185,7 @@ function createWindow() {
171185 icon : `${ __dirname } /src/assets/icons/64x64.png` ,
172186 } ) ;
173187
174- if ( dev ) {
188+ if ( isDev ) {
175189 // If we are in developer mode Add React & Redux DevTools to Electon App
176190 installExtension ( REACT_DEVELOPER_TOOLS )
177191 . then ( ( name ) => console . log ( `Added Extension: ${ name } ` ) )
@@ -185,7 +199,7 @@ function createWindow() {
185199 // and load the index.html of the app.
186200 let indexPath ;
187201
188- if ( dev && process . argv . indexOf ( "--noDevServer" ) === - 1 ) {
202+ if ( isDev && process . argv . indexOf ( "--noDevServer" ) === - 1 ) {
189203 // if we are in dev mode load up 'http://localhost:8080/index.html'
190204 indexPath = url . format ( {
191205 protocol : "http:" ,
@@ -215,7 +229,7 @@ function createWindow() {
215229 mainWindow . once ( "ready-to-show" , ( ) => {
216230 mainWindow . show ( ) ;
217231 // Open the DevTools automatically if developing
218- if ( dev ) {
232+ if ( isDev ) {
219233 mainWindow . webContents . openDevTools ( ) ;
220234 }
221235 } ) ;
@@ -233,13 +247,21 @@ function createWindow() {
233247 // moved require mainmenu to top
234248}
235249
236- // This method will be called when Electron has finished
250+ /********* end of createWindow declaration ******/
251+
252+ /****************************************
253+ ************** EVENT LISTENERS **********
254+ ****************************************/
255+
256+ // app.on('ready') will be called when Electron has finished
237257// initialization and is ready to create browser windows.
238258// Some APIs can only be used after this event occurs.
259+
260+ // if in prod mode, checkForUpdates after the window is created
239261app . on ( "ready" , ( ) => {
240262 // createLoadingScreen();
241263 createWindow ( ) ;
242- if ( ! dev ) {
264+ if ( ! isDev ) {
243265 autoUpdater . checkForUpdates ( ) ;
244266 }
245267} ) ;
@@ -264,7 +286,7 @@ const sendStatusToWindow = (text) => {
264286
265287ipcMain . on ( "check-for-update" , ( ) => {
266288 //listens to ipcRenderer in UpdatePopUpContainer.jsx
267- if ( ! dev ) autoUpdater . checkForUpdates ( ) ;
289+ if ( ! isDev ) autoUpdater . checkForUpdates ( ) ;
268290} ) ;
269291// autoUpdater.on('checking-for-update', () => {
270292// sendStatusToWindow('Checking for update...');
@@ -276,7 +298,7 @@ ipcMain.on("check-for-update", () => {
276298// sendStatusToWindow('Update not available.');
277299// });
278300autoUpdater . on ( "error" , ( err ) => {
279- console . error ( err ) ;
301+ console . error ( "autoUpdater error -> " , err ) ;
280302 sendStatusToWindow ( `Error in auto-updater` ) ;
281303} ) ;
282304autoUpdater . on ( "download-progress" , ( progressObj ) => {
@@ -316,7 +338,7 @@ app.on("activate", () => {
316338
317339// export collection ipc now promise-based
318340ipcMain . on ( "export-collection" , ( event , args ) => {
319- let content = JSON . stringify ( args . collection ) ;
341+ const content = JSON . stringify ( args . collection ) ;
320342 dialog . showSaveDialog ( null ) . then ( ( resp ) => {
321343 if ( resp . filePath === undefined ) {
322344 console . log ( "You didn't save the file" ) ;
@@ -326,7 +348,7 @@ ipcMain.on("export-collection", (event, args) => {
326348 // fileName is a string that contains the path and filename created in the save file dialog.
327349 fs . writeFile ( resp . filePath , content , ( err ) => {
328350 if ( err ) {
329- console . log ( "An error ocurred creating the file " + err . message ) ;
351+ console . log ( "An error ocurred creating the file " , err . message ) ;
330352 }
331353 } ) ;
332354 } ) ;
@@ -351,7 +373,7 @@ ipcMain.on("import-collection", (event, args) => {
351373 }
352374
353375 // get first file path - not dynamic for multiple files
354- let filepath = fileNames . filePaths [ 0 ] ;
376+ const filepath = fileNames . filePaths [ 0 ] ;
355377
356378 // get file extension
357379 const ext = path . extname ( filepath ) ;
@@ -366,7 +388,7 @@ ipcMain.on("import-collection", (event, args) => {
366388
367389 fs . readFile ( filepath , "utf-8" , ( err , data ) => {
368390 if ( err ) {
369- alert ( "An error ocurred reading the file :" + err . message ) ;
391+ alert ( "An error ocurred reading the file :" , err . message ) ;
370392 return ;
371393 }
372394
@@ -464,7 +486,7 @@ ipcMain.on("open-gql", (event, args) => {
464486 return forward ( operation ) . map ( ( response ) => {
465487 const context = operation . getContext ( ) ;
466488 const headers = context . response . headers . entries ( ) ;
467- for ( let headerItem of headers ) {
489+ for ( const headerItem of headers ) {
468490 const key = headerItem [ 0 ]
469491 . split ( "-" )
470492 . map ( ( item ) => item [ 0 ] . toUpperCase ( ) + item . slice ( 1 ) )
0 commit comments