Browse Source

fix(resources): fix up resource paths

Move rpc.proto into the resources directory along with all of the other
external resources.

Fix up the resource paths to reference external resources correctly
depending on wether the app is being run locally or from a release.
renovate/lint-staged-8.x
Tom Kirkpatrick 7 years ago
parent
commit
6eda55de0c
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 25
      app/lnd/config/index.js
  2. 3
      app/lnd/lib/lightning.js
  3. 3
      app/lnd/lib/walletUnlocker.js
  4. 0
      resources/rpc.proto

25
app/lnd/config/index.js

@ -3,10 +3,27 @@
// Linux: ~/.lnd/tls.cert
// Windows: TODO find out where cert is located for windows machine
import { userInfo, platform } from 'os'
import { join } from 'path'
import { join, normalize } from 'path'
import Store from 'electron-store'
import { app } from 'electron'
// 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.
// See https://github.com/electron-userland/electron-builder/issues/751
//
// windows from source: "C:\myapp\node_modules\electron\dist\resources\default_app.asar"
// mac from source: "/Users/me/dev/myapp/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar"
// mac from a package: <somewhere>"/my.app/Contents/Resources/app.asar"
//
// If we are run from outside of a packaged app, our working directory is the right place to be.
// And no, we can't just set our working directory to somewhere inside the asar. The OS can't handle that.
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 location of various lnd resources.
const plat = platform()
let loc
@ -35,15 +52,15 @@ switch (plat) {
}
if (process.env.NODE_ENV === 'development') {
lndPath = join(__dirname, '..', '..', '..', 'resources', 'bin', plat, lndBin)
lndPath = join(appRootPath, 'resources', 'bin', plat, lndBin)
} else {
lndPath = join(__dirname, '..', '..', '..', 'bin', lndBin)
lndPath = join(appRootPath, 'bin', lndBin)
}
export default {
lnd: () => ({
lndPath,
lightningRpc: join(__dirname, 'rpc.proto'),
lightningRpc: join(appRootPath, 'resources', 'rpc.proto'),
lightningHost: store.get('host') || 'localhost:10009',
cert: store.get('cert') || join(userInfo().homedir, loc),
macaroon: store.get('macaroon') || join(userInfo().homedir, macaroonPath)

3
app/lnd/lib/lightning.js

@ -1,5 +1,4 @@
import fs from 'fs'
import path from 'path'
import grpc from 'grpc'
import config from '../config'
@ -22,7 +21,7 @@ const lightning = (rpcpath, host) => {
const lndConfig = config.lnd()
const lndCert = fs.readFileSync(lndConfig.cert)
const sslCreds = grpc.credentials.createSsl(lndCert)
const rpc = grpc.load(path.join(__dirname, '..', 'rpc.proto'))
const rpc = grpc.load(lndConfig.lightningRpc)
const metadata = new grpc.Metadata()
const macaroonHex = fs.readFileSync(lndConfig.macaroon).toString('hex')

3
app/lnd/lib/walletUnlocker.js

@ -1,5 +1,4 @@
import fs from 'fs'
import path from 'path'
import grpc from 'grpc'
import config from '../config'
@ -22,7 +21,7 @@ const walletUnlocker = (rpcpath, host) => {
const lndConfig = config.lnd()
const lndCert = fs.readFileSync(lndConfig.cert)
const credentials = grpc.credentials.createSsl(lndCert)
const rpc = grpc.load(path.join(__dirname, '..', 'rpc.proto'))
const rpc = grpc.load(lndConfig.lightningRpc)
return new rpc.lnrpc.WalletUnlocker(host, credentials)
}

0
app/lnd/config/rpc.proto → resources/rpc.proto

Loading…
Cancel
Save