Skip to content

Commit

Permalink
wip: conn manager
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Sep 26, 2018
1 parent 910804d commit 438fcea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import autoLaunch from './auto-launch'
import downloadHash from './download-hash'
import ipfs from './ipfs'
import launchWebUI from './launch-webui'
import takeScreenshot from './take-screenshot'

export default function (opts) {
autoLaunch(opts)
downloadHash(opts)
ipfs(opts)
launchWebUI(opts)
takeScreenshot(opts)
}
4 changes: 4 additions & 0 deletions src/hooks/ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ const addConfiguration = ({ send }) => async (_, { type, apiAddress, path, flags
export default function (opts) {
ipcMain.on('loadIpfsConfigurations', loadConfigurations(opts))
ipcMain.on('addIpfsConfiguration', addConfiguration(opts))

// TODO:
// ipcMain.on('connectIpfsConfiguration', )
// ipcMain.on('stopIpfs', )
}
15 changes: 13 additions & 2 deletions src/utils/conn-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { join } from 'path'
import fs from 'fs-extra'
import logger from './logger'

// TODO: imcomplete. Might change a lot

export default class ConnectionManager {
constructor () {
this.opts = {}
Expand All @@ -17,7 +19,7 @@ export default class ConnectionManager {
return this.justApi ? this.instance : this.instance.api
}

async disconnect () {
async stop () {
if (!this.running && !this.instance) {
return
}
Expand Down Expand Up @@ -57,9 +59,18 @@ export default class ConnectionManager {
})
}

async connect (opts) {
async start (opts) {
if (this.running) await this.disconnect()

if (!opts && !this.justApi) {
await new Promise((resolve, reject) => {
this.instance.start(this.opts.flags, err => {
if (err) return reject(err)
else resolve()
})
})
}

this.opts = opts
this.justApi = opts.type === 'api'

Expand Down

0 comments on commit 438fcea

Please sign in to comment.