@@ -18,7 +18,8 @@ var fs = require('fs'),
1818 tray = require ( 'tray' ) ,
1919 ini = require ( 'ini' ) ,
2020 dialog = require ( 'dialog' ) ,
21- ipcMain = require ( 'ipc-main' ) ;
21+ ipcMain = require ( 'ipc-main' )
22+ open = require ( 'open' ) ;
2223
2324var launched_from_installer = false ;
2425var platform = os . platform ( ) ;
@@ -30,6 +31,10 @@ var version = app.getVersion();
3031var trayMenu = null ;
3132var subpy = null ;
3233
34+ // Keep a global reference of the window object, if you don't, the window will
35+ // be closed automatically when the JavaScript object is GCed.
36+ var mainWindow = null ;
37+
3338var open_url = null ; // This is for if someone opens a URL before the client is open
3439
3540if ( argv . userData ) {
@@ -161,10 +166,20 @@ var start_local_server = function() {
161166 } ) ;
162167 subpy . stderr . on ( 'data' , function ( buf ) {
163168 console . log ( '[STR] stderr "%s"' , String ( buf ) ) ;
169+ fs . appendFile ( __dirname + path . sep + "python_error.log" , String ( buf ) , function ( err ) {
170+ if ( err ) {
171+ return console . log ( err ) ;
172+ }
173+ } ) ;
164174 stderr += buf ;
165175 } ) ;
166176 subpy . on ( 'error' , function ( err ) {
167177 console . log ( 'Python error %s' , String ( err ) ) ;
178+ fs . appendFile ( __dirname + path . sep + "python_error.log" , String ( err ) , function ( error ) {
179+ if ( error ) {
180+ return console . log ( error ) ;
181+ }
182+ } ) ;
168183 } ) ;
169184 subpy . on ( 'close' , function ( code ) {
170185 console . log ( 'exited with ' + code ) ;
@@ -173,6 +188,8 @@ var start_local_server = function() {
173188 serverRunning = false ;
174189 } ) ;
175190 subpy . unref ( ) ;
191+ } else {
192+ mainWindow && mainWindow . webContents . executeJavaScript ( "console.log('Unable to find OpenBazaar-Server at: '" + serverPath + "')" ) ;
176193 }
177194 if ( fs . existsSync ( __dirname + path . sep + '..' + path . sep + 'gpg' ) ) {
178195 process . env . PATH = __dirname + path . sep + '..' + path . sep + 'gpg' + path . sep + 'pub' + path . sep + ';' + process . env . PATH ;
@@ -197,10 +214,6 @@ ipcMain.on('activeServerChange', function(event, server) {
197214// Report crashes to our server.
198215//require('crash-reporter').start();
199216
200- // Keep a global reference of the window object, if you don't, the window will
201- // be closed automatically when the JavaScript object is GCed.
202- var mainWindow = null ;
203-
204217if ( process . platform === "win32" ) {
205218 initWin32 ( ) ;
206219}
@@ -521,7 +534,7 @@ app.on('ready', function() {
521534 var osTrayIcon = 'openbazaar-mac-system-tray.png' ;
522535
523536 trayMenu = new tray ( __dirname + '/imgs/' + osTrayIcon ) ;
524- var contextMenu = menu . buildFromTemplate ( [
537+ var template = [
525538 {
526539 label : 'Start Local Server' , type : 'normal' , click : function ( ) {
527540 start_local_server ( ) ;
@@ -547,8 +560,8 @@ app.on('ready', function() {
547560 dialog . showErrorBox ( 'Unable To Open Debug Log' ,
548561 'There was an error and we are unable to open the server debug log at this time.\n\n' + err ) ;
549562 }
550-
551- require ( ' open' ) ( debugPath ) ;
563+
564+ open ( debugPath ) ;
552565 } ) ;
553566 } } ,
554567 { label : 'Send Debug Package' , type : 'normal' , click : function ( ) {
@@ -561,16 +574,30 @@ app.on('ready', function() {
561574 body += 'Debug Log:\n' ;
562575 body += serverOut ;
563576
564- require ( ' open' ) ( 'mailto:[email protected] ?subject=OpenBazaar Debug Report&body=' + body ) ; 577+ open ( 'mailto:[email protected] ?subject=OpenBazaar Debug Report&body=' + body ) ; 565578
566- } } ,
567- { type : 'separator' } ,
579+ } }
580+ ] ;
581+
582+ if ( launched_from_installer ) {
583+ template . push ( { label : 'View Python Error Log' , type : 'normal' , click : function ( ) {
584+ var logPath = __dirname + path . sep + 'python_error.log' ;
585+ open ( logPath ) ;
586+ } } ) ;
587+ }
588+
589+ template . push (
590+ {
591+ type : 'separator'
592+ } ,
568593 {
569594 label : 'Quit' , type : 'normal' , accelerator : 'Command+Q' , click : function ( ) {
570- app . quit ( ) ;
571- }
595+ app . quit ( ) ;
596+ }
572597 }
573- ] ) ;
598+ ) ;
599+
600+ var contextMenu = menu . buildFromTemplate ( template ) ;
574601
575602 trayMenu . setContextMenu ( contextMenu ) ;
576603
@@ -677,4 +704,4 @@ app.on('open-url', function(event, uri) {
677704// some cleanup when our app is exiting
678705process . on ( 'exit' , ( ) => {
679706 kill_local_server ( ) ;
680- } ) ;
707+ } ) ;
0 commit comments