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

@@ -87,8 +87,8 @@ exports.IPC_Check_Mount_Location = 'check_mount_location';
exports.IPC_Delete_File = 'delete_file';
exports.IPC_Detect_Mounts = 'detect_mounts';
exports.IPC_Detect_Mounts_Reply = 'detect_mounts_reply';
exports.IPC_Detect_Mount = 'detect_mount';
exports.IPC_Detect_Mount_Reply = 'detect_mount_reply';
exports.IPC_Download_File = 'download_file';
exports.IPC_Download_File_Complete = 'download_file_complete';

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 provider = arg.data.Provider;
const mountState = {
AllowMount: true,
DriveLetters: (arg.data.DriveLetters[provider]),
Mounted: (arg.data.Locations[provider].length > 0),
DriveLetters: (arg.data.DriveLetters),
Mounted: (arg.data.Location.length > 0),
};
this.props.setMountState(provider, mountState);
mountsBusy = mountsBusy || mountState.Mounted;
mountStates[provider] = mountState;
}
this.props.setMountsBusy(mountsBusy);
this.removeMountsBusy(provider);
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;
}
this.updateMountLocation(provider, arg.data.Location, mountState.Mounted, arg.data.DriveLetters);
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);
}
};
for (const provider of this.getProviderList()) {
updateMountLocation(arg.data, provider);
}
this.props.setAutoMountProcessed(true);
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);
}
};
@@ -285,8 +301,9 @@ class MountItems extends IPCContainer {
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)),

View File

@@ -17,7 +17,8 @@ export const addRemoteMount = (hostNameOrIp, port, token) => {
ipcRenderer.once(Constants.IPC_Set_Config_Values_Reply, (_, arg) => {
if (arg.data.Success) {
ipcRenderer.send(Constants.IPC_Detect_Mounts, {
ipcRenderer.send(Constants.IPC_Detect_Mount, {
Provider: provider,
RemoteMounts: getState().mounts.RemoteMounts,
Version: getState().relver.InstalledVersion,
});
@@ -99,7 +100,17 @@ export const setAllowMount = (provider, allow) => {
};
};
export const setAutoMountProcessed = createAction('mounts/setAutoMountProcessed');
export const SET_AUTO_MOUNT_PROCESSED = 'mounts/setAutoMountProcessed';
export const setAutoMountProcessed = (provider, processed) => {
return {
type: SET_AUTO_MOUNT_PROCESSED,
payload: {
provider,
processed
}
};
};
export const setBusy = createAction('mounts/setBusy');
export const SET_MOUNT_STATE = 'mounts/setMountState';

View File

@@ -6,7 +6,7 @@ import {
removeRemoteMount3,
RESET_MOUNTS_STATE,
SET_ALLOW_MOUNT,
setAutoMountProcessed,
SET_AUTO_MOUNT_PROCESSED,
setBusy,
SET_MOUNT_STATE,
SET_MOUNTED,
@@ -48,8 +48,19 @@ export const createMountReducer = state => {
}
});
const autoMountProcessed = providerList.map(provider => {
return {
[provider]: false,
}
}).reduce((map, obj) => {
return {
...map,
...obj
}
});
return createReducer({
AutoMountProcessed: false,
AutoMountProcessed: autoMountProcessed,
DisplayConfiguration: null,
DisplayRemoteConfiguration: false,
MountsBusy: false,
@@ -71,8 +82,13 @@ export const createMountReducer = state => {
AutoRestart: false,
MountLocation: '',
};
let autoMountProcessed = {...state.AutoMountProcessed};
autoMountProcessed[action.payload] = true;
return {
...state,
AutoMountProcessed: autoMountProcessed,
MountState: mountState,
ProviderState: providerState,
RemoteMounts: [...state.RemoteMounts, action.payload],
@@ -86,11 +102,20 @@ export const createMountReducer = state => {
};
},
[removeRemoteMount3]: (state, action) => {
let mountState = {...state.MountState};
delete mountState[action.payload];
let providerState = {...state.ProviderState};
delete providerState[action.payload];
let autoMountProcessed = {...state.AutoMountProcessed};
delete autoMountProcessed[action.payload];
const remoteMounts = state.RemoteMounts.filter(i => i !== action.payload);
return {
...state,
AutoMountProcessed: autoMountProcessed,
MountState: mountState,
ProviderState: providerState,
RemoteMounts: remoteMounts,
};
@@ -102,10 +127,13 @@ export const createMountReducer = state => {
MountState: mountState,
}
},
[setAutoMountProcessed]: (state, action) => {
[SET_AUTO_MOUNT_PROCESSED]: (state, action) => {
return {
...state,
AutoMountProcessed: action.payload
AutoMountProcessed: {
...state.AutoMountProcessed,
[action.payload.provider]: action.payload.processed,
}
};
},
[SET_ALLOW_MOUNT]: (state, action) => {

View File

@@ -86,7 +86,9 @@ const addListeners = (ipcMain, setTrayImage, standardIPCReply) => {
event.returnValue = response;
});
ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
ipcMain.on(Constants.IPC_Detect_Mount, (event, data) => {
const provider = data.Provider;
let driveLetters = {};
const providerList = [
...Constants.PROVIDER_LIST,
@@ -174,9 +176,10 @@ const addListeners = (ipcMain, setTrayImage, standardIPCReply) => {
if (firstMountCheck) {
firstMountCheck = false;
}
standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, {
DriveLetters: driveLetters,
Locations: locations,
standardIPCReply(event, Constants.IPC_Detect_Mount_Reply, {
DriveLetters: driveLetters[provider],
Location: locations[provider],
Provider: provider,
});
})
.catch(error => {
@@ -184,8 +187,9 @@ const addListeners = (ipcMain, setTrayImage, standardIPCReply) => {
grabDriveLetters({});
}
setImage({});
standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, {
DriveLetters: driveLetters,
standardIPCReply(event, Constants.IPC_Detect_Mount_Reply, {
DriveLetters: driveLetters[provider],
Provider: provider,
}, error);
});
});