Added cancel mount retry

This commit is contained in:
Scott E. Graves
2018-12-12 13:05:28 -06:00
parent e223eac541
commit 50d2bae836
2 changed files with 92 additions and 5 deletions

View File

@@ -1,11 +1,12 @@
# Changelog #
## 1.0.2 ##
* Launch hidden (notification icon only)
* Option to launch application hidden (notification icon only)
* Close window to notification area
* Unmount on application exit
* Ability to cancel mount retry on unexpected failure
* OS X support
* SiaPrime support
* Unmount on application exit
* Partial Linux support
* Close to notification area
## 1.0.1 ##
* Added configuration settings for Repertory 1.0.0-alpha.2 and above

View File

@@ -1,8 +1,12 @@
import React from 'react';
import {Component} from 'react';
import Box from '../../components/UI/Box/Box';
import Button from '../../components/UI/Button/Button';
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');
@@ -30,9 +34,36 @@ class MountItems extends Component {
}
}
state = {};
retryIntervals = {};
state = {
DisplayRetry: false,
RetryItems: {},
};
cancelRetryMount = (storageType, stateCallback) => {
clearInterval(this.retryIntervals[storageType]);
delete this.retryIntervals[storageType];
if (stateCallback) {
let retryItems = {
...this.state.RetryItems,
};
delete retryItems[storageType];
this.setState({
DisplayRetry: Object.keys(retryItems) > 0,
RetryItems: retryItems,
}, stateCallback);
}
};
componentWillUnmount = () => {
for (const storageType in this.state.RetryItems) {
if (this.state.RetryItems.hasOwnProperty(storageType)) {
this.cancelRetryMount(storageType);
}
}
if (ipcRenderer) {
ipcRenderer.removeListener(Constants.IPC_Detect_Mounts_Reply, this.onDetectMountsReply);
ipcRenderer.removeListener(Constants.IPC_Mount_Drive_Reply, this.onMountDriveReply);
@@ -160,7 +191,36 @@ class MountItems extends Component {
onUnmountDriveReply = (event, arg) => {
if (arg && arg.data && !arg.data.Expected && arg.data.Location && this.props[arg.data.StorageType.toLowerCase()].AutoRestart) {
this.handleMountUnMount(arg.data.StorageType, true, arg.data.Location)
const storageType = arg.data.StorageType;
if (!this.state.RetryItems[storageType]) {
let retryItems = {
...this.state.RetryItems
};
retryItems[storageType] = {
RetrySeconds: 10,
};
this.setState({
DisplayRetry: true,
RetryItems: retryItems,
}, () => {
this.retryIntervals[storageType] = setInterval(() => {
let retryItems = {
...this.state.RetryItems,
};
const retrySeconds = retryItems[storageType].RetrySeconds - 1;
if (retrySeconds === 0) {
this.cancelRetryMount(storageType, () => {
this.handleMountUnMount(storageType, true, arg.data.Location);
});
} else {
retryItems[storageType].RetrySeconds = retrySeconds;
this.setState({
RetryItems: retryItems,
});
}
},1000);
});
}
} else {
this.detectMounts();
}
@@ -177,6 +237,7 @@ class MountItems extends Component {
this.handleMountUnMount(provider, true, this.props[providerLower].MountLocation);
}
};
for (const provider of Constants.PROVIDER_LIST) {
processAutoMount(provider);
}
@@ -184,6 +245,30 @@ class MountItems extends Component {
};
render() {
let retryDisplay;
if (this.state.DisplayRetry) {
let retryList = [];
for (const storageType in this.state.RetryItems) {
if (this.state.RetryItems.hasOwnProperty(storageType)) {
retryList.push((
<RootElem key={retryList.length}>
<p>Retrying {storageType} in {this.state.RetryItems[storageType].RetrySeconds}(s)</p>
<Button clicked={()=>this.cancelRetryMount(storageType, ()=> this.detectMounts())}>Cancel {storageType}</Button>
</RootElem>
));
}
}
retryDisplay = (
<Modal>
<Box dxStyle={{padding: '8px', minWidth: '60vw'}}>
<h1 style={{textAlign: 'center'}}>Mount Failed</h1>
{retryList}
</Box>
</Modal>
)
}
let items = [];
for (const provider of Constants.PROVIDER_LIST) {
const providerLower = provider.toLowerCase();
@@ -212,6 +297,7 @@ class MountItems extends Component {
return (
<div styleName='MountItems'>
{retryDisplay}
{items}
</div>);
}