From 45ab66a928eae49ff11d1e35f73d2b737bf25ad5 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 21 Mar 2018 19:11:37 +0000 Subject: [PATCH 1/2] feat: connect already running daemon --- package.json | 6 +++--- src/index.js | 44 ++++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index a8f439c67..a88a05e98 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "file-extension": "^4.0.2", "go-ipfs-dep": "^0.4.13", "ipfs-stats": "^1.2.4", - "ipfsd-ctl": "^0.30.3", + "ipfsd-ctl": "~0.30.4", "is-ipfs": "^0.3.2", "lodash.clonedeep": "^4.5.0", "moment": "^2.21.0", @@ -38,7 +38,7 @@ "codecov": "^3.0.0", "cross-env": "^5.1.4", "electron-forge": "^5.1.1", - "electron-prebuilt-compile": "1.8.3", + "electron-prebuilt-compile": "1.8.4", "enzyme": "^3.3.0", "enzyme-adapter-react-16": "^1.1.1", "eslint": "^4", @@ -53,7 +53,7 @@ "mocha": "^5.0.4", "nyc": "^11.6.0", "pre-commit": "^1.2.2", - "sinon": "^4.4.6", + "sinon": "^4.4.8", "spectron": "^3.8.0" }, "scripts": { diff --git a/src/index.js b/src/index.js index 7831161ae..ec65354c6 100644 --- a/src/index.js +++ b/src/index.js @@ -28,6 +28,7 @@ app.makeSingleInstance(() => { let IPFS let menubar +let state = 'stopped' function send (type, ...args) { if (menubar && menubar.window && menubar.window.webContents) { @@ -38,25 +39,18 @@ function send (type, ...args) { config.send = send config.ipfs = () => IPFS -function onRequestState (node, event) { - if (!node.started) { - return - } - - let status = 'stopped' - - node.pid((pid) => { - if (pid) { - status = IPFS ? 'running' : 'starting' - } +function updateState (st) { + state = st + onRequestState() +} - send('node-status', status) - }) +function onRequestState (node, event) { + send('node-status', state) } function onStartDaemon (node) { debug('Starting daemon') - send('node-status', 'starting') + updateState('starting') // Tries to remove the repo.lock file if it already exists. // This fixes a bug on Windows, where the daemon seems @@ -87,21 +81,23 @@ function onStartDaemon (node) { debug('Daemon started') config.events.emit('node:started') - // Stop the executation of the program if some error - // occurs on the node. - node.subprocess.on('error', (e) => { - send('node-status', 'stopped') - debug(e) - }) + if (node.subprocess) { + // Stop the executation of the program if some error + // occurs on the node. + node.subprocess.on('error', (e) => { + updateState('stopped') + debug(e) + }) + } menubar.tray.setImage(config.logo.ice) - send('node-status', 'running') + updateState('running') }) } function onStopDaemon (node, done) { debug('Stopping daemon') - send('node-status', 'stopping') + updateState('stopping') config.events.emit('node:stopped') @@ -114,7 +110,7 @@ function onStopDaemon (node, done) { menubar.tray.setImage(config.logo.black) IPFS = null - send('node-status', 'stopped') + updateState('stopped') done() }) } @@ -204,7 +200,7 @@ function initialize (path, node) { config.settingsStore.set('ipfsPath', userPath) send('initialization-complete') - send('node-status', 'stopped') + updateState('stopped') onStartDaemon(node) window.close() From f5b2c440733028c449929acc0c8dbc07b3ddff56 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 21 Mar 2018 19:12:44 +0000 Subject: [PATCH 2/2] mini fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a88a05e98..5f2d0ce0b 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "file-extension": "^4.0.2", "go-ipfs-dep": "^0.4.13", "ipfs-stats": "^1.2.4", - "ipfsd-ctl": "~0.30.4", + "ipfsd-ctl": "^0.30.4", "is-ipfs": "^0.3.2", "lodash.clonedeep": "^4.5.0", "moment": "^2.21.0",