Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 7, 2024. It is now read-only.
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
12 changes: 2 additions & 10 deletions app/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,14 @@ export function setClientInstance (client) {
}

/**
* initIPFSClient will set up a new ipfs-api instance. It will try to get an
* existing instance and the configuration (api endpoint) from global vars
* initIPFSClient will set up a new ipfs-api instance. It will try to get
* the configuration (api endpoint) from global vars
*
* @returns Promise<IPFS_CLIENT>
*/
export function initIPFSClient () {
if (IPFS_CLIENT !== null) return Promise.resolve(IPFS_CLIENT)

// get IPFS client from the main process
if (remote) {
const globalClient = remote.getGlobal('IPFS_CLIENT')
if (globalClient) {
setClientInstance(globalClient)
return Promise.resolve(IPFS_CLIENT)
}
}
// Configure the endpoint for the api. It will try to get the value from the
// global variables IPFS_MULTIADDR_APIs
let apiMultiaddr
Expand Down
2 changes: 0 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ app.mainWindow = null

// A little space for IPFS processes
global.IPFS_PROCESS = null
global.IPFS_CLIENT = null

// Sets default values for IPFS configurations
global.IPFS_BINARY_PATH = `${rootDir.get()}/go-ipfs/ipfs`
Expand Down Expand Up @@ -184,7 +183,6 @@ function startOrion () {
.then(initIPFSClient)
.then(client => {
console.log('Connecting to the IPFS Daemon')
global.IPFS_CLIENT = client
loadingWindow.webContents.send('set-progress', {
text: 'Connecting to the IPFS Daemon...',
percentage: 40
Expand Down
20 changes: 8 additions & 12 deletions app/windows/Details/renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
saveFileToPath,
isObjectPinned,
pinObject,
promiseIPFSReady,
unpinObject
} from '../../api'
import { openInBrowser } from '../Storage/fileIntegration'
Expand All @@ -32,16 +33,11 @@ class DetailsWindow extends React.Component {
currentTab: 0
}

constructor (props) {
super(props)

this.handleDownload = this.handleDownload.bind(this)
this.handleOpenInBrowser = this.handleOpenInBrowser.bind(this)
this.handlePin = this.handlePin.bind(this)
this.handleUnpin = this.handleUnpin.bind(this)
componentDidMount () {
promiseIPFSReady().then(this.fetchData)
}

componentDidMount () {
fetchData = () => {
Promise.all([
getObjectStat(hash),
getObjectDag(hash),
Expand All @@ -54,7 +50,7 @@ class DetailsWindow extends React.Component {
}))
}

handleDownload () {
handleDownload = () => {
const options = {
title: 'Where should I save?',
properties: ['openDirectory'],
Expand All @@ -76,11 +72,11 @@ class DetailsWindow extends React.Component {
}
}

handleOpenInBrowser () {
handleOpenInBrowser = () => {
openInBrowser([hash])
}

handlePin () {
handlePin = () => {
this.setState({ isUpdatingPin: true })
pinObject(hash)
.then(result => this.setState({ isPinned: true, isUpdatingPin: false }))
Expand All @@ -90,7 +86,7 @@ class DetailsWindow extends React.Component {
})
}

handleUnpin () {
handleUnpin = () => {
this.setState({ isUpdatingPin: true })
unpinObject(hash)
.then(result => this.setState({ isPinned: false, isUpdatingPin: false }))
Expand Down
4 changes: 2 additions & 2 deletions app/windows/Settings/renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
PaneGroup
} from 'react-photonkit'

import { initIPFSClient } from '../../api'
import { initIPFSClient, promiseIPFSReady } from '../../api'

import Sidebar from './Components/Sidebar'
import RepositoryPanel from './Components/RepositoryPanel'
Expand All @@ -23,7 +23,7 @@ import InformationStore from './Stores/Information'

class SettingsWindow extends React.Component {
componentDidMount () {
InformationStore.loadData()
promiseIPFSReady().then(() => InformationStore.loadData())
}

render () {
Expand Down
5 changes: 3 additions & 2 deletions app/windows/Storage/renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
getPeersInfo,
getRepoInfo,
getStorageList,
getObjectList
getObjectList,
promiseIPFSReady
} from '../../api'
import { setupAddAppOnDrop } from './fileIntegration'

Expand Down Expand Up @@ -60,7 +61,7 @@ function startLoop () {

class App extends React.Component {
componentDidMount () {
startLoop()
promiseIPFSReady().then(startLoop)
}

componentWillUnmount () {
Expand Down