Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: js-ipfsd-ctl daemon-remote #549

Merged
merged 3 commits into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"electron-compile": "^6.4.2",
"electron-menubar": "^1.0.1",
"electron-squirrel-startup": "^1.0.0",
"go-ipfs-dep": "^0.4.13",
"ipfsd-ctl": "^0.27.0",
"file-extension": "^4.0.1",
"ipfs-stats": "^1.0.4",
"ipfsd-ctl": "^0.26.0",
"is-ipfs": "^0.3.2",
"moment": "^2.20.1",
"multiaddr": "^3.0.2",
"is-ipfs": "^0.3.2",
"normalize.css": "^7.0.0",
"pretty-bytes": "^4.0.2",
"prop-types": "^15.6.0",
Expand Down
47 changes: 29 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Menubar} from 'electron-menubar'
import ipfsd from 'ipfsd-ctl'
import fs from 'fs'
import DaemonFactory from 'ipfsd-ctl'
import {join} from 'path'
import {dialog, ipcMain, app, BrowserWindow} from 'electron'

Expand Down Expand Up @@ -54,29 +55,31 @@ function onPollerChange (stats) {
}

function onRequestState (node, event) {
if (node.initialized) {
let status = 'stopped'
if (!node.initialized) {
return
}

if (node.daemonPid()) {
status = IPFS ? 'running' : 'starting'
}
let status = 'stopped'

send('node-status', status)
if (node.pid()) {
status = IPFS ? 'running' : 'starting'
}

send('node-status', status)
}

function onStartDaemon (node) {
debug('Starting daemon')
send('node-status', 'starting')

node.startDaemon((err, ipfsNode) => {
node.start((err, api) => {
if (err) {
handleKnownErrors(err)
return
}

debug('Daemon started')
poller = new StatsPoller(ipfsNode, 1000, debug)
poller = new StatsPoller(api, 1000, debug)

if (menubar.window && menubar.window.isVisible()) {
poller.start()
Expand All @@ -95,8 +98,8 @@ function onStartDaemon (node) {

menubar.tray.setImage(config.logo.ice)

IPFS = api
send('node-status', 'running')
IPFS = ipfsNode
})
}

Expand All @@ -114,8 +117,10 @@ function onStopDaemon (node, done) {
menubar.removeListener('hide', stopPolling)
}

node.stopDaemon((err) => {
if (err) { return debug(err.stack) }
node.stop((err) => {
if (err) {
return debug(err.stack)
}

debug('Stopped daemon')
menubar.tray.setImage(config.logo.black)
Expand Down Expand Up @@ -208,7 +213,7 @@ function initialize (path, node) {
return send('initialization-error', String(err))
}

config.settingsStore.set('ipfsPath', path)
config.settingsStore.set('ipfsPath', userPath)

send('initialization-complete')
send('node-status', 'stopped')
Expand All @@ -220,11 +225,16 @@ function initialize (path, node) {
}

// main entry point
ipfsd.local((e, node) => {
if (e) {
DaemonFactory.create().spawn({
repoPath: config.ipfsPath,
disposable: false,
init: false,
start: false
}, (err, node) => {
if (err) {
// We can't start if we fail to aquire
// a ipfs node
debug(e.stack)
debug(err.stack)
process.exit(1)
}

Expand All @@ -240,10 +250,11 @@ ipfsd.local((e, node) => {

registerControls(config)

if (!node.initialized) {
let exists = fs.existsSync(node.repoPath)

if (!exists) {
initialize(config.settingsStore.get('ipfsPath'), node)
} else {
// Start up the daemon
onStartDaemon(node)
}
}
Expand Down