Single mount detection

This commit is contained in:
2019-11-11 13:15:57 -06:00
parent 1f42d5cff4
commit c33f142f27
5 changed files with 129 additions and 69 deletions

View File

@@ -22,12 +22,18 @@ const Constants = require('../../constants');
class MountItems extends IPCContainer {
retryIntervals = {};
activeDetections = [];
state = {
DisplayRetry: false,
RetryItems: {},
};
addMountsBusy = provider => {
this.props.setMountsBusy(true);
this.activeDetections.push(provider);
};
cancelRetryMount = (provider, stateCallback) => {
clearInterval(this.retryIntervals[provider]);
delete this.retryIntervals[provider];
@@ -50,7 +56,7 @@ class MountItems extends IPCContainer {
};
componentDidMount() {
this.setRequestHandler(Constants.IPC_Detect_Mounts_Reply, this.onDetectMountsReply);
this.setRequestHandler(Constants.IPC_Detect_Mount_Reply, this.onDetectMountReply);
this.setRequestHandler(Constants.IPC_Mount_Drive_Reply, this.onMountDriveReply);
this.setRequestHandler(Constants.IPC_Unmount_Drive_Reply, this.onUnmountDriveReply);
this.props.resetMountsState();
@@ -68,12 +74,21 @@ class MountItems extends IPCContainer {
super.componentWillUnmount();
};
detectMount = provider => {
this.addMountsBusy(provider);
this.sendRequest(Constants.IPC_Detect_Mount, {
RemoteMounts: this.props.RemoteMounts,
Provider: provider,
Version: this.props.InstalledVersion,
});
};
detectMounts = ()=> {
if (!this.state.DisplayRetry) {
this.props.setMountsBusy(true);
this.sendRequest(Constants.IPC_Detect_Mounts, {
RemoteMounts: this.props.RemoteMounts,
Version: this.props.InstalledVersion,
const providerList = this.getProviderList();
providerList.forEach(provider => {
this.detectMount(provider);
});
}
};
@@ -181,7 +196,7 @@ class MountItems extends IPCContainer {
}
if (allowAction) {
this.props.setMountsBusy(true);
this.addMountsBusy(provider);
this.props.setAllowMount(provider, false);
if (mount) {
@@ -211,67 +226,68 @@ class MountItems extends IPCContainer {
];
};
onDetectMountsReply = (event, arg) => {
onDetectMountReply = (event, arg) => {
if (!this.state.DisplayRetry && arg.data.Success) {
let mountsBusy = false;
let mountStates = {};
for (const provider of this.getProviderList()) {
const mountState = {
AllowMount: true,
DriveLetters: (arg.data.DriveLetters[provider]),
Mounted: (arg.data.Locations[provider].length > 0),
};
this.props.setMountState(provider, mountState);
mountsBusy = mountsBusy || mountState.Mounted;
mountStates[provider] = mountState;
}
this.props.setMountsBusy(mountsBusy);
const updateMountLocation = (data, provider) => {
const providerState = this.props.ProviderState[provider];
let location = data.Locations[provider];
if (location.length === 0) {
location = (this.props.Platform === 'win32') ?
providerState.MountLocation || data.DriveLetters[provider][0] :
providerState.MountLocation;
}
if (location !== providerState.MountLocation) {
const value = (this.props.Platform === 'win32') ?
data.DriveLetters[provider].indexOf(location) :
location;
this.handleMountLocationChanged(provider, value);
}
if (!this.props.AutoMountProcessed &&
this.props.ProviderState[provider].AutoMount &&
!mountStates[provider].Mounted &&
(location.length > 0)) {
this.handleMountUnMount(provider, this.props.RemoteMounts.includes(provider),true, location);
}
const provider = arg.data.Provider;
const mountState = {
AllowMount: true,
DriveLetters: (arg.data.DriveLetters),
Mounted: (arg.data.Location.length > 0),
};
for (const provider of this.getProviderList()) {
updateMountLocation(arg.data, provider);
}
this.props.setMountState(provider, mountState);
this.removeMountsBusy(provider);
this.props.setAutoMountProcessed(true);
this.updateMountLocation(provider, arg.data.Location, mountState.Mounted, arg.data.DriveLetters);
this.props.setAutoMountProcessed(provider,true);
} else {
this.props.notifyError(arg.data.Error);
}
};
onMountDriveReply = (event, arg) => {
this.removeMountsBusy(arg.data.Provider);
this.props.setMounted(arg.data.Provider, arg.data.Success);
this.detectMounts();
this.detectMount(arg.data.Provider);
};
onUnmountDriveReply = (event, arg) => {
if (arg && arg.data && !arg.data.Expected && arg.data.Location && this.props.ProviderState[arg.data.Provider].AutoRestart) {
this.displayRetryMount(arg.data.Provider, arg.data.Remote, arg.data.Location);
} else {
this.detectMounts();
this.detectMount(arg.data.Provider);
}
this.removeMountsBusy(arg.data.Provider);
};
removeMountsBusy = provider => {
const idx = this.activeDetections.indexOf(provider);
if (idx > -1) {
this.activeDetections.splice(idx, 1);
}
this.props.setMountsBusy(this.activeDetections.length > 0);
};
updateMountLocation = (provider, location, mounted, driveLetters) => {
const providerState = this.props.ProviderState[provider];
if (location.length === 0) {
location = (this.props.Platform === 'win32') ?
providerState.MountLocation || driveLetters[0] :
providerState.MountLocation;
}
if (location !== providerState.MountLocation) {
const value = (this.props.Platform === 'win32') ?
driveLetters.indexOf(location) :
location;
this.handleMountLocationChanged(provider, value);
}
if (!this.props.AutoMountProcessed[provider] &&
this.props.ProviderState[provider].AutoMount &&
!mounted &&
(location.length > 0)) {
this.handleMountUnMount(provider, this.props.RemoteMounts.includes(provider),true, location);
}
};
@@ -284,9 +300,10 @@ class MountItems extends IPCContainer {
if (this.state.RetryItems.hasOwnProperty(provider)) {
if (this.state.RetryItems[provider].RetryMessage) {
retryList.push(<p key={'rl_' + retryList.length}>{this.state.RetryItems[provider].RetryMessage}</p>);
}
retryList.push(<Button clicked={()=>this.cancelRetryMount(provider, ()=> this.detectMounts())}
key={'rl_' + retryList.length}>Cancel {provider} Remount ({this.state.RetryItems[provider].RetrySeconds}s)</Button>);
}
retryList.push(<Button clicked={() => this.cancelRetryMount(provider, () => this.detectMounts())}
key={'rl_' + retryList.length}>Cancel {provider} Remount
({this.state.RetryItems[provider].RetrySeconds}s)</Button>);
if (++retryCount < Object.keys(this.state.RetryItems).length) {
retryList.push(<div style={{paddingTop: 'var(--default_spacing)'}}
key={'rl_' + retryList.length}/>);
@@ -376,7 +393,7 @@ const mapDispatchToProps = dispatch => {
notifyError: (msg, critical, callback) => dispatch(notifyError(msg, critical, callback)),
resetMountsState: () => dispatch(resetMountsState()),
setAllowMount: (provider, allow) => dispatch(setAllowMount(provider, allow)),
setAutoMountProcessed: processed => dispatch(setAutoMountProcessed(processed)),
setAutoMountProcessed: (provider, processed) => dispatch(setAutoMountProcessed(provider, processed)),
setMounted: (provider, mounted) => dispatch(setMounted(provider, mounted)),
setMountsBusy: busy => dispatch(setBusy(busy)),
setMountState: (provider, state) => dispatch(setMountState(provider, state)),