diff --git a/app/lnd/config/index.js b/app/lnd/config/index.js index 45d8b161..db8a740b 100644 --- a/app/lnd/config/index.js +++ b/app/lnd/config/index.js @@ -8,6 +8,7 @@ import { dirname, join, normalize } from 'path' import Store from 'electron-store' import { app } from 'electron' import isDev from 'electron-is-dev' +import untildify from 'untildify' // Get a path to prepend to any nodejs calls that are getting at files in the package, // so that it works both from source and in an asar-packaged mac app. @@ -22,9 +23,6 @@ import isDev from 'electron-is-dev' const appPath = app.getAppPath() const appRootPath = appPath.indexOf('default_app.asar') < 0 ? normalize(`${appPath}/..`) : '' -// Get an electromn store named 'connection' in which the saved connection detailes are stored. -const store = new Store({ name: 'connection' }) - // Get the name of the current platform which we can use to determine the tlsCertPathation of various lnd resources. const plat = platform() @@ -58,17 +56,34 @@ if (isDev) { export default { lnd: () => { - const cert = store.get('cert') - const host = store.get('host') - const macaroon = store.get('macaroon') + // Get an electromn store named 'connection' in which the saved connection detailes are stored. + const store = new Store({ name: 'connection' }) + + // Determine what hostname to use. + let host = store.get('host') + if (typeof host === 'undefined') { + host = 'localhost:10009' + } + + // Determine what cert to use. + let cert = store.get('cert') + if (typeof cert === 'undefined') { + cert = join(lndDataDir, 'tls.cert') + } + + // Determine what macaroon to use. + let macaroon = store.get('macaroon') + if (typeof macaroon === 'undefined') { + macaroon = join(lndDataDir, 'admin.macaroon') + } return { lndPath, configPath: join(appRootPath, 'resources', 'lnd.conf'), rpcProtoPath: join(appRootPath, 'resources', 'rpc.proto'), - host: typeof host === 'undefined' ? 'localhost:10009' : host, - cert: typeof cert === 'undefined' ? join(lndDataDir, 'tls.cert') : cert, - macaroon: typeof macaroon === 'undefined' ? join(lndDataDir, 'admin.macaroon') : macaroon + host, + cert: untildify(cert), + macaroon: untildify(macaroon) } } } diff --git a/package.json b/package.json index 0417115f..248ddb0b 100644 --- a/package.json +++ b/package.json @@ -277,6 +277,7 @@ "satoshi-bitcoin": "^1.0.4", "source-map-support": "^0.5.6", "split2": "^2.2.0", + "untildify": "^3.0.3", "validator": "^10.4.0" }, "main": "webpack.config.base.js", diff --git a/yarn.lock b/yarn.lock index 50b394e2..44c5f33d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11847,6 +11847,10 @@ unset-value@^1.0.0: has-value "^0.3.1" isobject "^3.0.0" +untildify@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/untildify/-/untildify-3.0.3.tgz#1e7b42b140bcfd922b22e70ca1265bfe3634c7c9" + unzip-response@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"