#24: Add retry logic to version check

This commit is contained in:
Scott E. Graves
2019-06-08 20:27:59 -05:00
parent 8e34a978a7
commit f72a32adb1
2 changed files with 52 additions and 45 deletions

View File

@@ -78,6 +78,46 @@ class MountItems extends IPCContainer {
}
};
displayRetryMount = (provider, mountLocation, msg) => {
if (!this.state.RetryItems[provider]) {
let retryItems = {
...this.state.RetryItems
};
retryItems[provider] = {
RetrySeconds: 10,
RetryMessage: msg ? msg.toString() : null,
};
const mountState = {
AllowMount: false,
Mounted: false,
};
this.props.setMountState(provider, mountState);
this.setState({
DisplayRetry: true,
RetryItems: retryItems,
}, () => {
this.sendRequest(Constants.IPC_Show_Window);
this.retryIntervals[provider] = setInterval(() => {
let retryItems = {
...this.state.RetryItems,
};
const retrySeconds = retryItems[provider].RetrySeconds - 1;
if (retrySeconds === 0) {
this.cancelRetryMount(provider, () => {
this.handleMountUnMount(provider, true, mountLocation);
});
} else {
retryItems[provider].RetrySeconds = retrySeconds;
this.setState({
RetryItems: retryItems,
});
}
}, 1000);
});
}
};
handleBrowseLocation = (provider, location) => {
location = this.sendSyncRequest(Constants.IPC_Browse_Directory, {
Title: provider + ' Mount Location',
@@ -123,17 +163,17 @@ class MountItems extends IPCContainer {
}
} else {
allowAction = false;
if (result.Code === (new Uint32Array([-1]))[0]) {
this.props.notifyError('Failed to connect to ' + provider + ' daemon');
} else if (result.Code === (new Uint32Array([-3]))[0]) {
this.props.notifyError('Incompatible ' + provider + ' daemon. Please upgrade ' + provider);
if ((result.Code === new Uint32Array([-1])[0]) || (result.Code === new Uint8Array([-1])[0])) {
this.displayRetryMount(provider, location, 'Failed to connect to ' + provider + ' daemon');
} else if ((result.Code === new Uint32Array([-3])[0]) || (result.Code === new Uint8Array([-3])[0])) {
this.displayRetryMount(provider, location, 'Incompatible ' + provider + ' daemon. Please upgrade ' + provider);
} else {
this.props.notifyError('Version check failed: ' + result.Error);
this.displayRetryMount(provider, location, 'Version check failed: ' + result.Error);
}
}
} else {
allowAction = false;
this.props.notifyError(result.Error.toString());
this.displayRetryMount(provider, location, 'Version check failed: ' + result.Error);
}
}
@@ -213,43 +253,7 @@ class MountItems extends IPCContainer {
onUnmountDriveReply = (event, arg) => {
if (arg && arg.data && !arg.data.Expected && arg.data.Location && this.props.ProviderState[arg.data.Provider].AutoRestart) {
const provider = arg.data.Provider;
if (!this.state.RetryItems[provider]) {
let retryItems = {
...this.state.RetryItems
};
retryItems[provider] = {
RetrySeconds: 10,
};
const mountState = {
AllowMount: false,
Mounted: false,
};
this.props.setMountState(provider, mountState);
this.setState({
DisplayRetry: true,
RetryItems: retryItems,
}, () => {
this.sendRequest(Constants.IPC_Show_Window);
this.retryIntervals[provider] = setInterval(() => {
let retryItems = {
...this.state.RetryItems,
};
const retrySeconds = retryItems[provider].RetrySeconds - 1;
if (retrySeconds === 0) {
this.cancelRetryMount(provider, () => {
this.handleMountUnMount(provider, true, arg.data.Location);
});
} else {
retryItems[provider].RetrySeconds = retrySeconds;
this.setState({
RetryItems: retryItems,
});
}
},1000);
});
}
this.displayRetryMount(arg.data.Provider, arg.data.Location);
} else {
this.detectMounts();
}
@@ -263,6 +267,9 @@ class MountItems extends IPCContainer {
for (const provider in this.state.RetryItems) {
if (this.state.RetryItems.hasOwnProperty(provider)) {
retryListCount++;
if (this.state.RetryItems[provider].RetryMessage) {
retryList.push(<p key={'p' + retryListCount}>{this.state.RetryItems[provider].RetryMessage}</p>);
}
retryList.push(<Button
clicked={()=>this.cancelRetryMount(provider, ()=> this.detectMounts())}
key={'b' + retryListCount}>Cancel {provider} Remount ({this.state.RetryItems[provider].RetrySeconds}s)</Button>);
@@ -274,7 +281,7 @@ class MountItems extends IPCContainer {
retryDisplay = (
<Modal>
<Box dxStyle={{padding: '8px', minWidth: '70vw'}}>
<Box dxDark dxStyle={{padding: '8px', minWidth: '70vw'}}>
<h1 style={{textAlign: 'center', paddingBottom: '8px', color: 'var(--text_color_error)'}}>Mount Failed</h1>
{retryList}
</Box>