@@ -28,8 +28,27 @@ const isProd = process.env.NODE_ENV === "production"
2828let splashScreen // The splash screen is the window that is displayed while the application is loading
2929export var mainWindow // The main window is the window of the application
3030
31+ //**** AUTO UPDATER ****//
32+ const { autoUpdater } = require ( "electron-updater" )
33+ const log = require ( "electron-log" )
34+
35+ autoUpdater . logger = log
36+ autoUpdater . logger . transports . file . level = "info"
37+ autoUpdater . autoDownload = false
38+ autoUpdater . autoInstallOnAppQuit = true
39+
40+ //*********** LOG **************// This is used to send the console.log messages to the main window
41+ //**** ELECTRON-LOG ****//
42+ // Electron log path
43+ // By default, it writes logs to the following locations:
44+ // on Linux: ~/.config/{app name}/logs/main.log
45+ // on macOS: ~/Library/Logs/{app name}/main.log
46+ // on Windows: %USERPROFILE%\AppData\Roaming\{app name}\logs\main.log
47+ const APP_NAME = isProd ? "medomicslab-application" : "medomicslab-application (development)"
48+ const WINDOWS_ELECTRON_LOG_PATH = path . join ( process . env . USERPROFILE , "AppData" , "Roaming" , APP_NAME , "logs" , "main.log" )
49+ const MAC_ELECTRON_LOG_PATH = path . join ( process . env . HOME , "Library" , "Logs" , APP_NAME , "main.log" )
50+ const LINUX_ELECTRON_LOG_PATH = path . join ( process . env . HOME , ".config" , APP_NAME , "logs" , "main.log" )
3151
32- //**** LOG ****// This is used to send the console.log messages to the main window
3352const originalConsoleLog = console . log
3453/**
3554 * @description Sends the console.log messages to the main window
@@ -39,6 +58,7 @@ const originalConsoleLog = console.log
3958console . log = function ( ) {
4059 try {
4160 originalConsoleLog ( ...arguments )
61+ log . log ( ...arguments )
4262 if ( mainWindow !== undefined ) {
4363 mainWindow . webContents . send ( "log" , ...arguments )
4464 }
@@ -47,54 +67,42 @@ console.log = function () {
4767 }
4868}
4969
50-
51- //**** AUTO UPDATER ****//
52- const { autoUpdater } = require ( 'electron-updater' )
53- const log = require ( 'electron-log' ) ;
54-
55- autoUpdater . logger = log ;
56- autoUpdater . logger . transports . file . level = 'info' ;
57- autoUpdater . autoDownload = false ;
58- autoUpdater . autoInstallOnAppQuit = true ;
59-
6070//**** AUTO-UPDATER ****//
6171
6272function sendStatusToWindow ( text ) {
6373 if ( mainWindow && mainWindow . webContents ) {
64- mainWindow . showMessage ( text ) ;
74+ mainWindow . showMessage ( text )
6575 }
6676}
67- autoUpdater . on ( ' checking-for-update' , ( ) => {
68- console . log ( ' DEBUG: checking for update' )
69- sendStatusToWindow ( ' Checking for update...' ) ;
77+ autoUpdater . on ( " checking-for-update" , ( ) => {
78+ console . log ( " DEBUG: checking for update" )
79+ sendStatusToWindow ( " Checking for update..." )
7080} )
71- autoUpdater . on ( ' update-available' , ( info ) => {
81+ autoUpdater . on ( " update-available" , ( info ) => {
7282 info = JSON . stringify ( info )
73- console . log ( ' DEBUG: update available' )
74- sendStatusToWindow ( `Update available. ${ info } ` ) ;
83+ console . log ( " DEBUG: update available" )
84+ sendStatusToWindow ( `Update available. ${ info } ` )
7585 let pth = autoUpdater . downloadUpdate ( )
76- console . log ( ' DEBUG: pth:' , pth )
77- sendStatusToWindow ( `Downloading update... ${ pth } ` ) ;
86+ console . log ( " DEBUG: pth:" , pth )
87+ sendStatusToWindow ( `Downloading update... ${ pth } ` )
7888} )
79- autoUpdater . on ( ' update-not-available' , ( info ) => {
89+ autoUpdater . on ( " update-not-available" , ( info ) => {
8090 info = JSON . stringify ( info )
81- sendStatusToWindow ( `Update not available. ${ info } ` ) ;
82- sendStatusToWindow ( `Current version: ${ app . getVersion ( ) } ` ) ;
91+ sendStatusToWindow ( `Update not available. ${ info } ` )
92+ sendStatusToWindow ( `Current version: ${ app . getVersion ( ) } ` )
8393} )
84- autoUpdater . on ( ' error' , ( err ) => {
85- sendStatusToWindow ( ' Error in auto-updater. ' + err ) ;
94+ autoUpdater . on ( " error" , ( err ) => {
95+ sendStatusToWindow ( " Error in auto-updater. " + err )
8696} )
87- autoUpdater . on ( 'download-progress' , ( progressObj ) => {
88- let log_message = "Download speed: " + progressObj . bytesPerSecond ;
89- log_message = log_message + ' - Downloaded ' + progressObj . percent + '%' ;
90- log_message = log_message + ' (' + progressObj . transferred + "/" + progressObj . total + ')' ;
91- sendStatusToWindow ( log_message ) ;
97+ autoUpdater . on ( "download-progress" , ( progressObj ) => {
98+ let log_message = "Download speed: " + progressObj . bytesPerSecond
99+ log_message = log_message + " - Downloaded " + progressObj . percent + "%"
100+ log_message = log_message + " (" + progressObj . transferred + "/" + progressObj . total + ")"
101+ sendStatusToWindow ( log_message )
102+ } )
103+ autoUpdater . on ( "update-downloaded" , ( info ) => {
104+ sendStatusToWindow ( "Update downloaded" )
92105} )
93- autoUpdater . on ( 'update-downloaded' , ( info ) => {
94- sendStatusToWindow ( 'Update downloaded' ) ;
95- } ) ;
96-
97-
98106
99107if ( isProd ) {
100108 serve ( { directory : "app" } )
@@ -222,7 +230,7 @@ if (isProd) {
222230 console . log ( "process.resourcesPath: " , process . resourcesPath )
223231 console . log ( MEDconfig . runServerAutomatically ? "Server will start automatically here (in background of the application)" : "Server must be started manually" )
224232 let bundledPythonPath = getBundledPythonEnvironment ( )
225- if ( MEDconfig . runServerAutomatically && bundledPythonPath !== null ) {
233+ if ( MEDconfig . runServerAutomatically && bundledPythonPath !== null ) {
226234 // Find the bundled python environment
227235 if ( bundledPythonPath !== null ) {
228236 runServer ( isProd , serverPort , serverProcess , serverState , bundledPythonPath )
@@ -286,8 +294,7 @@ if (isProd) {
286294 console . error ( `stderr: ${ stderr } ` )
287295 resolve ( )
288296 } )
289- }
290- )
297+ } )
291298 } else {
292299 try {
293300 execSync ( "killall mongod" )
@@ -320,10 +327,9 @@ if (isProd) {
320327 * @description Returns the version of the app
321328 * @returns {Promise<String> } The version of the app
322329 */
323- ipcMain . handle ( "getAppVersion" , async ( ) => {
324- return app . getVersion ( )
325- } )
326-
330+ ipcMain . handle ( "getAppVersion" , async ( ) => {
331+ return app . getVersion ( )
332+ } )
327333
328334 /**
329335 * @description Copies the source file to the destination file set by the user in the dialog
@@ -577,6 +583,21 @@ ipcMain.handle("checkMongoIsRunning", async (event) => {
577583 return isRunning
578584} )
579585
586+ /**
587+ * @description Prompts the user to download the log file
588+ */
589+ ipcMain . handle ( "download-log-file" , async ( event ) => {
590+ const { filePath } = await dialog . showSaveDialog ( {
591+ title : "Save log file" ,
592+ defaultPath : "medomicslab-log.txt" ,
593+ filters : [ { name : "Text" , extensions : [ "txt" ] } ]
594+ } )
595+ if ( filePath ) {
596+ fs . copyFileSync ( log . transports . file . getFile ( ) . path , filePath )
597+ return filePath
598+ }
599+ } )
600+
580601app . on ( "window-all-closed" , ( ) => {
581602 console . log ( "app quit" )
582603 stopMongoDB ( mongoProcess )
@@ -593,7 +614,7 @@ app.on("window-all-closed", () => {
593614} )
594615
595616app . on ( "ready" , async ( ) => {
596- if ( MEDconfig . useReactDevTools ) {
617+ if ( MEDconfig . useReactDevTools ) {
597618 await installExtension ( REACT_DEVELOPER_TOOLS , {
598619 loadExtensionOptions : {
599620 allowFileAccess : true
@@ -636,7 +657,7 @@ function startMongoDB(workspacePath) {
636657 if ( fs . existsSync ( getMongoDBPath ( ) ) ) {
637658 mongoProcess = spawn ( getMongoDBPath ( ) , [ "--config" , mongoConfigPath ] )
638659 } else {
639- mongoProcess = spawn ( "/opt/homebrew/Cellar/mongodb-community/7.0.12/bin/mongod" , [ "--config" , mongoConfigPath ] , { shell : true } )
660+ mongoProcess = spawn ( "/opt/homebrew/Cellar/mongodb-community/7.0.12/bin/mongod" , [ "--config" , mongoConfigPath ] , { shell : true } )
640661 }
641662 }
642663 mongoProcess . stdout . on ( "data" , ( data ) => {
@@ -713,29 +734,28 @@ export function getMongoDBPath() {
713734 console . error ( "mongod not found" )
714735 return null
715736 } else if ( process . platform === "darwin" ) {
716- // Check if it is installed in the .medomics directory
717- const binPath = path . join ( process . env . HOME , ".medomics" , "mongodb" , "bin" , "mongod" )
718- if ( fs . existsSync ( binPath ) ) {
719- console . log ( "mongod found in .medomics directory" )
720- return binPath
721- }
737+ // Check if it is installed in the .medomics directory
738+ const binPath = path . join ( process . env . HOME , ".medomics" , "mongodb" , "bin" , "mongod" )
739+ if ( fs . existsSync ( binPath ) ) {
740+ console . log ( "mongod found in .medomics directory" )
741+ return binPath
742+ }
722743 if ( process . env . NODE_ENV !== "production" ) {
723-
724- // Check if mongod is in the process.env.PATH
725- const paths = process . env . PATH . split ( path . delimiter )
726- for ( let i = 0 ; i < paths . length ; i ++ ) {
727- const binPath = path . join ( paths [ i ] , "mongod" )
744+ // Check if mongod is in the process.env.PATH
745+ const paths = process . env . PATH . split ( path . delimiter )
746+ for ( let i = 0 ; i < paths . length ; i ++ ) {
747+ const binPath = path . join ( paths [ i ] , "mongod" )
748+ if ( fs . existsSync ( binPath ) ) {
749+ console . log ( "mongod found in PATH" )
750+ return binPath
751+ }
752+ }
753+ // Check if mongod is in the default installation path on macOS - /usr/local/bin/mongod
754+ const binPath = "/usr/local/bin/mongod"
728755 if ( fs . existsSync ( binPath ) ) {
729- console . log ( "mongod found in PATH" )
730756 return binPath
731757 }
732758 }
733- // Check if mongod is in the default installation path on macOS - /usr/local/bin/mongod
734- const binPath = "/usr/local/bin/mongod"
735- if ( fs . existsSync ( binPath ) ) {
736- return binPath
737- }
738- }
739759 console . error ( "mongod not found" )
740760 return null
741761 } else if ( process . platform === "linux" ) {
@@ -747,18 +767,17 @@ export function getMongoDBPath() {
747767 return binPath
748768 }
749769 }
750- console . error ( "mongod not found in PATH" + paths )
770+ console . error ( "mongod not found in PATH" + paths )
751771 // Check if mongod is in the default installation path on Linux - /usr/bin/mongod
752772 if ( fs . existsSync ( "/usr/bin/mongod" ) ) {
753773 return "/usr/bin/mongod"
754774 }
755775 console . error ( "mongod not found in /usr/bin/mongod" )
756-
757- if ( fs . existsSync ( "/home/" + process . env . USER + "/.medomics/mongodb/bin/mongod" ) ) {
758- return "/home/" + process . env . USER + "/.medomics/mongodb/bin/mongod"
776+
777+ if ( fs . existsSync ( "/home/" + process . env . USER + "/.medomics/mongodb/bin/mongod" ) ) {
778+ return "/home/" + process . env . USER + "/.medomics/mongodb/bin/mongod"
759779 }
760780 return null
761-
762781 } else {
763782 return "mongod"
764783 }
0 commit comments