Browse Source

Merge pull request #600 from mrfelton/fix/homedir-tilde

fix: home directory detection and tilde expansion
renovate/lint-staged-8.x
JimmyMow 7 years ago
committed by GitHub
parent
commit
e1eda3bc6b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 81
      app/lnd/config/index.js
  2. 1
      package.json
  3. 4
      yarn.lock

81
app/lnd/config/index.js

@ -1,12 +1,9 @@
// Cert will be located depending on your machine import { homedir, platform } from 'os'
// Mac OS X: /Users/user/Library/Application Support/Lnd/tls.cert
// Linux: ~/.lnd/tls.cert
// Windows: TODO find out where cert is located for windows machine
import { userInfo, platform } from 'os'
import { dirname, join, normalize } from 'path' import { dirname, join, normalize } from 'path'
import Store from 'electron-store' import Store from 'electron-store'
import { app } from 'electron' import { app } from 'electron'
import isDev from 'electron-is-dev' 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, // 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. // so that it works both from source and in an asar-packaged mac app.
@ -21,57 +18,75 @@ import isDev from 'electron-is-dev'
const appPath = app.getAppPath() const appPath = app.getAppPath()
const appRootPath = appPath.indexOf('default_app.asar') < 0 ? normalize(`${appPath}/..`) : '' const appRootPath = appPath.indexOf('default_app.asar') < 0 ? normalize(`${appPath}/..`) : ''
// Get an electromn store named 'connection' in which the saved connection detailes are stored. // Get the name of the current platform which we can use to determine the tlsCertPathation of various lnd resources.
const store = new Store({ name: 'connection' })
// Get the name of the current platform which we can use to determine the location of various lnd resources.
const plat = platform() const plat = platform()
let loc // Get the OS specific default lnd data dir and binary name.
let macaroonPath let lndDataDir
let lndBin let lndBin
let lndPath
switch (plat) { switch (plat) {
case 'darwin': case 'darwin':
loc = 'Library/Application Support/Lnd/tls.cert' lndDataDir = join(homedir(), 'Library', 'Application Support', 'Lnd')
macaroonPath = 'Library/Application Support/Lnd/admin.macaroon'
lndBin = 'lnd' lndBin = 'lnd'
break break
case 'linux': case 'linux':
loc = '.lnd/tls.cert' lndDataDir = join(homedir(), '.lnd')
macaroonPath = '.lnd/admin.macaroon'
lndBin = 'lnd' lndBin = 'lnd'
break break
case 'win32': case 'win32':
loc = join('Appdata', 'Local', 'Lnd', 'tls.cert') lndDataDir = join(process.env.APPDATA, 'Local', 'Lnd')
macaroonPath = join('Appdata', 'Local', 'Lnd', 'admin.macaroon')
lndBin = 'lnd.exe' lndBin = 'lnd.exe'
break break
default: default:
break break
} }
// Get the path to the lnd binary.
let lndPath
if (isDev) { if (isDev) {
const lndBinaryDir = dirname(require.resolve('lnd-binary/package.json')) lndPath = join(dirname(require.resolve('lnd-binary/package.json')), 'vendor', lndBin)
lndPath = join(lndBinaryDir, 'vendor', lndBin)
} else { } else {
lndPath = join(appRootPath, 'bin', lndBin) lndPath = join(appRootPath, 'bin', lndBin)
} }
export default { /**
lnd: () => { * Get current lnd configuration.
const cert = store.get('cert') *
const host = store.get('host') * Cert and Macaroon will be at one of the following destinations depending on your machine:
const macaroon = store.get('macaroon') * Mac OS X: ~/Library/Application Support/Lnd/tls.cert
* Linux: ~/.lnd/tls.cert
* Windows: C:\Users\...\AppData\Local\Lnd
*
* @return {object} current lnd configuration options.
*/
const lnd = () => {
// Get an electron store named 'connection' in which the saved connection detailes are stored.
const store = new Store({ name: 'connection' })
return { /**
lndPath, * Fetch a config option from the connection store.
configPath: join(appRootPath, 'resources', 'lnd.conf'), * if undefined fallback to a path relative to the lnd data dir.
rpcProtoPath: join(appRootPath, 'resources', 'rpc.proto'), *
host: typeof host === 'undefined' ? 'localhost:10009' : host, * @param {string} name name of property to fetch from the store.
cert: typeof cert === 'undefined' ? join(userInfo().homedir, loc) : cert, * @param {string} path path relative to the lnd data dir.
macaroon: typeof macaroon === 'undefined' ? join(userInfo().homedir, macaroonPath) : macaroon * @return {string} config param or filepath relative to the lnd data dir.
*/
const getFromStoreOrDataDir = (name, file) => {
let path = store.get(name)
if (typeof path === 'undefined') {
path = join(lndDataDir, file)
} }
return untildify(path)
}
return {
lndPath,
configPath: join(appRootPath, 'resources', 'lnd.conf'),
rpcProtoPath: join(appRootPath, 'resources', 'rpc.proto'),
host: store.get('host', 'localhost:10009'),
cert: getFromStoreOrDataDir('cert', 'tls.cert'),
macaroon: getFromStoreOrDataDir('macaroon', 'admin.macaroon')
} }
} }
export default { lnd }

1
package.json

@ -277,6 +277,7 @@
"satoshi-bitcoin": "^1.0.4", "satoshi-bitcoin": "^1.0.4",
"source-map-support": "^0.5.6", "source-map-support": "^0.5.6",
"split2": "^2.2.0", "split2": "^2.2.0",
"untildify": "^3.0.3",
"validator": "^10.4.0" "validator": "^10.4.0"
}, },
"main": "webpack.config.base.js", "main": "webpack.config.base.js",

4
yarn.lock

@ -11847,6 +11847,10 @@ unset-value@^1.0.0:
has-value "^0.3.1" has-value "^0.3.1"
isobject "^3.0.0" 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: unzip-response@^2.0.1:
version "2.0.1" version "2.0.1"
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97" resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97"

Loading…
Cancel
Save