Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 27 additions & 8 deletions browser/main/modals/InitModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import _ from 'lodash'
const CSON = require('@rokt33r/season')
const path = require('path')
const electron = require('electron')
const fs = require('fs')
const { remote } = electron

function browseFolder () {
Expand All @@ -31,8 +32,10 @@ class InitModal extends React.Component {
constructor (props) {
super(props)

const initPath = path.join(remote.app.getPath('home'), 'Boostnote')
this.state = {
path: path.join(remote.app.getPath('home'), 'Boostnote'),
path: initPath,
pathAlreadyExists: pathExists(initPath),
migrationRequested: true,
isLoading: true,
data: null,
Expand All @@ -42,9 +45,12 @@ class InitModal extends React.Component {
}

handlePathChange (e) {
this.setState({
path: e.target.value
})
this.updatePath(e.target.value)
}

updatePath(path) {
const pathAlreadyExists = pathExists(path)
this.setState({ path, pathAlreadyExists })
}

componentDidMount () {
Expand All @@ -70,9 +76,7 @@ class InitModal extends React.Component {
browseFolder()
.then((targetPath) => {
if (targetPath.length > 0) {
this.setState({
path: targetPath
})
this.updatePath(targetPath)
}
})
.catch((err) => {
Expand Down Expand Up @@ -237,7 +241,7 @@ class InitModal extends React.Component {
? <span>
<i className='fa fa-spin fa-spinner' /> Loading...
</span>
: 'CREATE'
: (this.state.pathAlreadyExists ? 'USE' : 'CREATE')
}
</button>
</div>
Expand All @@ -252,3 +256,18 @@ InitModal.propTypes = {
}

export default CSSModules(InitModal, styles)


function pathExists(path) {
try {
fs.statSync(path)
return true
} catch(e) {
if (e.errno === -2) {
// no such file or dir
return false
} else {
throw e
}
}
}
3 changes: 2 additions & 1 deletion browser/main/modals/PreferencesModal/StoragesTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class StoragesTab extends React.Component {
newStorage: {
name: 'Unnamed',
type: 'FILESYSTEM',
path: ''
path: '',
pathAlreadyExists: false,
}
}, () => {
this.refs.addStorageName.select()
Expand Down