diff --git a/src/containers/MountItems/MountItems.js b/src/containers/MountItems/MountItems.js index 4d82010..eb9b662 100644 --- a/src/containers/MountItems/MountItems.js +++ b/src/containers/MountItems/MountItems.js @@ -6,7 +6,6 @@ import CSSModules from 'react-css-modules'; import styles from './MountItems.css'; import Modal from '../../components/UI/Modal/Modal'; import MountItem from '../../components/MountItem/MountItem'; -import RootElem from '../../hoc/RootElem/RootElem'; const Constants = require('../../constants'); @@ -18,6 +17,7 @@ if (!process.versions.hasOwnProperty('electron')) { class MountItems extends Component { constructor(props) { super(props); + for (const provider of Constants.PROVIDER_LIST) { this.state[provider] = { AllowMount: false, @@ -25,6 +25,7 @@ class MountItems extends Component { Mounted: false, }; } + if (ipcRenderer) { ipcRenderer.on(Constants.IPC_Detect_Mounts_Reply, this.onDetectMountsReply); ipcRenderer.on(Constants.IPC_Mount_Drive_Reply, this.onMountDriveReply); @@ -72,18 +73,19 @@ class MountItems extends Component { }; detectMounts = ()=> { - this.props.mountsBusy(true); - ipcRenderer.send(Constants.IPC_Detect_Mounts, { - Directory: this.props.directory, - Version: this.props.version, - }); + if (!this.state.DisplayRetry) { + this.props.mountsBusy(true); + ipcRenderer.send(Constants.IPC_Detect_Mounts, { + Directory: this.props.directory, + Version: this.props.version, + }); + } }; handleMountLocationChanged = (storageType, value) => { if (this.props.platform === 'win32') { this.props.changed(storageType, this.state[storageType].DriveLetters[value]); - } - else { + } else { this.props.changed(storageType, value); } }; @@ -91,54 +93,52 @@ class MountItems extends Component { handleMountUnMount = (storageType, mount, location) => { if (!location || (location.trim().length === 0)) { this.props.errorHandler('Mount location is not set'); - } else { - if (ipcRenderer) { - let allowAction = true; - if (mount && (this.props.platform !== 'win32')) { - const result = ipcRenderer.sendSync(Constants.IPC_Check_Mount_Location, { - Location: location, - }); - if (!result.Success) { - allowAction = false; - this.props.errorHandler(result.Error.toString()); + } else if (ipcRenderer) { + let allowAction = true; + if (mount && (this.props.platform !== 'win32')) { + const result = ipcRenderer.sendSync(Constants.IPC_Check_Mount_Location, { + Location: location, + }); + if (!result.Success) { + allowAction = false; + this.props.errorHandler(result.Error.toString()); + } + } + + if (allowAction) { + const storageState = { + ...this.state[storageType], + AllowMount: false, + }; + + this.props.mountsBusy(true); + + this.setState({ + [storageType]: storageState, + }, () => { + if (mount) { + ipcRenderer.send(Constants.IPC_Mount_Drive, { + Directory: this.props.directory, + Location: location, + NoConsoleSupported: this.props.noConsoleSupported, + StorageType: storageType, + Version: this.props.version, + }); + } else { + ipcRenderer.send(Constants.IPC_Unmount_Drive, { + Directory: this.props.directory, + Location: location, + StorageType: storageType, + Version: this.props.version, + }); } - } - - if (allowAction) { - const state = { - ...this.state[storageType], - AllowMount: false, - }; - - this.props.mountsBusy(true); - - this.setState({ - [storageType]: state, - }, () => { - if (mount) { - ipcRenderer.send(Constants.IPC_Mount_Drive, { - Directory: this.props.directory, - Location: location, - NoConsoleSupported: this.props.noConsoleSupported, - StorageType: storageType, - Version: this.props.version, - }); - } else { - ipcRenderer.send(Constants.IPC_Unmount_Drive, { - Directory: this.props.directory, - Location: location, - StorageType: storageType, - Version: this.props.version, - }); - } - }); - } + }); } } }; onDetectMountsReply = (event, arg) => { - if (arg.data.Success) { + if (!this.state.DisplayRetry && arg.data.Success) { let state = {}; let mountsBusy = false; for (const provider of Constants.PROVIDER_LIST) { @@ -199,7 +199,13 @@ class MountItems extends Component { retryItems[storageType] = { RetrySeconds: 10, }; + const storageState = { + ...this.state[arg.data.StorageType], + AllowMount: false, + Mounted: false, + }; this.setState({ + [storageType]: storageState, DisplayRetry: true, RetryItems: retryItems, }, () => { @@ -252,21 +258,18 @@ class MountItems extends Component { for (const storageType in this.state.RetryItems) { if (this.state.RetryItems.hasOwnProperty(storageType)) { retryListCount++; - retryList.push(( - -

Retrying {storageType} in {this.state.RetryItems[storageType].RetrySeconds}(s)

- -
- )); + retryList.push(); if (retryListCount < Object.keys(this.state.RetryItems).length) { - retryList.push(
); + retryList.push(
); } } } retryDisplay = ( - +

Mount Failed

{retryList}