@@ -9,10 +9,8 @@ import cp from 'child_process'
99import ps from 'ps-node'
1010import fileLog from 'electron-log'
1111import os from 'os'
12- import lnd from './rpc-server'
13-
14- global . connection = lnd . connection
15- global . serverReady = lnd . serverReady
12+ import fs from 'fs'
13+ import grpc from 'grpc'
1614
1715app . commandLine . appendSwitch ( 'remote-debugging-port' , '9997' )
1816app . commandLine . appendSwitch ( 'host-rules' , 'MAP * 127.0.0.1' )
@@ -43,7 +41,7 @@ const runProcesses = (processes, logs) => {
4341 const filePath = path . join ( __dirname , 'bin' , plat , proc . name , plat === 'win32' ? '.exe' : '' )
4442
4543 try {
46- const instance = cp . execFile ( filePath , proc . args , { cwd : 'bin' } , ( error ) => {
44+ const instance = cp . execFile ( filePath , proc . args , ( error ) => {
4745 if ( error ) {
4846 logs . push ( error . code ? `${ error . code } : ${ error . errno } ` : JSON . stringify ( error ) )
4947 }
@@ -73,16 +71,50 @@ const processes = [
7371 '--neutrino.active' ,
7472 '--configfile=../lnd.conf' ,
7573 isDev ? '--bitcoin.simnet' : '--bitcoin.testnet' ,
76- isDev ? '--neutrino.addpeer =127.0.0.1:18335' : '--neutrino.addpeer =faucet.lightning.community:18333' ,
77- isDev ? '' : '--neutrino.addpeer =127.0.0.1:18333' ,
74+ isDev ? '--neutrino.connect =127.0.0.1:18335' : '--neutrino.connect =faucet.lightning.community:18333' ,
75+ isDev ? '' : '--neutrino.connect =127.0.0.1:18333' ,
7876 '--debuglevel=info' ,
77+ '--no-macaroons' ,
7978 ] ,
8079 } ,
8180]
8281
8382runProcesses ( processes , logs )
8483
84+ let intervalId
85+ let certPath
86+ const homedir = os . homedir ( )
87+
88+ switch ( os . platform ( ) ) {
89+ case 'darwin' :
90+ certPath = path . join ( homedir , 'Library/Application\ Support/Lnd/tls.cert' )
91+ break
92+ case 'linux' :
93+ certPath = path . join ( homedir , '.lnd/tls.cert' )
94+ break
95+ case 'win32' :
96+ certPath = path . join ( homedir , 'AppData' , 'Local' , 'Lnd' , 'tls.cert' )
97+ break
98+ }
99+
85100const createWindow = ( ) => {
101+ intervalId = setInterval ( ( ) => {
102+ if ( fs . existsSync ( certPath ) ) {
103+ clearInterval ( intervalId )
104+ const lndCert = fs . readFileSync ( certPath )
105+ const credentials = grpc . credentials . createSsl ( lndCert )
106+ const { lnrpc } = grpc . load ( path . join ( __dirname , 'rpc.proto' ) )
107+ const connection = new lnrpc . Lightning ( 'localhost:10009' , credentials )
108+ const serverReady = cb =>
109+ grpc . waitForClientReady ( connection , Infinity , cb )
110+ global . connection = connection
111+ global . serverReady = serverReady
112+ finishCreateWindow ( )
113+ }
114+ } , 500 )
115+ }
116+
117+ const finishCreateWindow = ( ) => {
86118 const mainWindowState = windowStateKeeper ( {
87119 defaultWidth : 750 ,
88120 defaultHeight : 500 ,
0 commit comments