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: support for js-ipfs and external nodes #651

Merged
merged 10 commits into from
Aug 28, 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
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"dependencies": {
"auto-launch": "^5.0.5",
"bl": "^2.0.1",
"debug": "^3.1.0",
"electron-compile": "^6.4.3",
"electron-menubar": "^1.0.1",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^2.0.0",
"file-extension": "^4.0.5",
"fs-extra": "^7.0.0",
"go-ipfs-dep": "^0.4.17",
"ipfs": "^0.31.2",
"ipfs-stats": "^1.2.4",
"ipfsd-ctl": "^0.39.0",
"is-ipfs": "^0.4.2",
Expand All @@ -26,7 +28,8 @@
"react": "^16.4.1",
"react-dnd": "^5.0.0",
"react-dnd-html5-backend": "^5.0.1",
"react-dom": "^16.4.1"
"react-dom": "^16.4.1",
"winston": "^3.0.0"
},
"devDependencies": {
"babel-eslint": "^8.2.6",
Expand Down
11 changes: 6 additions & 5 deletions src/components/Heartbeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const blackLogo = resolve(join(__dirname, '../img/ipfs-logo-black.png'))
*
* @return {ReactElement}
*/
export default function Heartbeat (props) {
if (props.dead) {
export default function Heartbeat ({dead, className, ...props}) {
if (dead) {
return (
<img src={`file://${blackLogo}`} />
<img src={`file://${blackLogo}`} {...props} />
)
} else {
return (
<img src={`file://${icyLogo}`} className='heartbeat' />
<img src={`file://${icyLogo}`} className={`heartbeat ${className}`} {...props} />
)
}
}
Expand All @@ -32,5 +32,6 @@ Heartbeat.propTypes = {
}

Heartbeat.defaultProps = {
dead: false
dead: false,
className: ''
}
86 changes: 0 additions & 86 deletions src/config.js

This file was deleted.

31 changes: 16 additions & 15 deletions src/controls/main/auto-launch.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
const AutoLaunch = require('auto-launch')
import AutoLaunch from 'auto-launch'
import { store, logger } from '../../utils'

const settingsOption = 'autoLaunch'
const autoLauncher = new AutoLaunch({
name: 'IPFS Desktop'
})

export default function (opts) {
let {debug, settingsStore} = opts

let activate = (value, oldValue) => {
export default function () {
let activate = async (value, oldValue) => {
if (value === oldValue) return

if (value === true) {
autoLauncher.enable()
.then(() => { debug('Launch on startup enabled') })
.catch(e => { debug(e.stack) })
} else {
autoLauncher.disable()
.then(() => { debug('Launch on startup disabled') })
.catch(e => { debug(e.stack) })
try {
if (value === true) {
await autoLauncher.enable()
logger.info('Launch on startup enabled')
} else {
await autoLauncher.disable()
logger.info('Launch on startup disabled')
}
} catch (e) {
logger.error(e.stack)
}
}

activate(settingsStore.get(settingsOption))
settingsStore.on(settingsOption, activate)
activate(store.get(settingsOption))
store.onDidChange(settingsOption, activate)
}
93 changes: 44 additions & 49 deletions src/controls/main/download-hash.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import path from 'path'
import fs from 'fs'
import {clipboard, app, dialog, globalShortcut} from 'electron'
import {validateIPFS} from '../utils'
import fs from 'fs-extra'
import { clipboard, app, dialog, globalShortcut } from 'electron'
import { validateIPFS } from '../utils'
import { store, logger } from '../../utils'

const settingsOption = 'downloadHashShortcut'
const shortcut = 'CommandOrControl+Alt+D'

function selectDirectory (opts) {
const {menubar} = opts
const { menubar } = opts

return new Promise((resolve, reject) => {
return new Promise(resolve => {
dialog.showOpenDialog(menubar.window, {
title: 'Select a directory',
defaultPath: app.getPath('downloads'),
Expand All @@ -27,28 +28,26 @@ function selectDirectory (opts) {
})
}

function saveFile (opts, dir, file) {
const {debug} = opts
async function saveFile (dir, file) {
const location = path.join(dir, file.path)

if (fs.existsSync(location)) {
// Ignore the hash itself.
if (await fs.pathExists(location)) {
// ignore the hash itself
return
}

fs.writeFile(location, file.content, (err) => {
if (err) {
debug(err.stack)
} else {
debug(`File '${file.path}' downloaded to ${location}.`)
}
})
try {
await fs.writeFile(location, file.content)
logger.info(`File '${file.path}' downloaded to ${location}.`)
} catch (e) {
logger.error(e.stack)
}
}

function handler (opts) {
const {debug, ipfs} = opts
const { ipfs } = opts

return () => {
return async () => {
const text = clipboard.readText().trim()

if (!ipfs() || !text) {
Expand All @@ -63,49 +62,45 @@ function handler (opts) {
return
}

ipfs().get(text)
.then((files) => {
debug(`Hash ${text} downloaded.`)
selectDirectory(opts)
.then((dir) => {
if (!dir) {
debug(`Dropping hash ${text}: user didn't choose a path.`)
return
}

if (files.length > 1) {
fs.mkdirSync(path.join(dir, text))
}

files.forEach(file => { saveFile(opts, dir, file) })
})
.catch(e => debug(e.stack))
})
.catch(e => {
debug(e.stack)
dialog.showErrorBox(
'Error while downloading',
'Some error happened while getting the hash. Please check the logs.'
)
})
try {
const files = await ipfs().get(text)
logger.info(`Hash ${text} downloaded.`)

const dir = await selectDirectory(opts)

if (!dir) {
logger.info(`Dropping hash ${text}: user didn't choose a path.`)
return
}

if (files.length > 1) {
fs.mkdirSync(path.join(dir, text))
}

files.forEach(file => { saveFile(dir, file) })
} catch (e) {
logger.error(e.stack)
dialog.showErrorBox(
'Error while downloading',
'Some error happened while getting the hash. Please check the logs.'
)
}
}
}

export default function (opts) {
let {debug, settingsStore} = opts

let activate = (value, oldValue) => {
if (value === oldValue) return

if (value === true) {
globalShortcut.register(shortcut, handler(opts))
debug('Hash download shortcut enabled')
logger.info('Hash download shortcut enabled')
} else {
globalShortcut.unregister(shortcut)
debug('Hash download shortcut disabled')
logger.info('Hash download shortcut disabled')
}
}

activate(settingsStore.get(settingsOption))
settingsStore.on(settingsOption, activate)
activate(store.get(settingsOption))
store.onDidChange(settingsOption, activate)
}
Loading