diff --git a/src/constants.js b/src/constants.js index f6b6259..71f55a0 100644 --- a/src/constants.js +++ b/src/constants.js @@ -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'; diff --git a/src/containers/MountItems/MountItems.js b/src/containers/MountItems/MountItems.js index 2f94fa4..0ac4ee5 100644 --- a/src/containers/MountItems/MountItems.js +++ b/src/containers/MountItems/MountItems.js @@ -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(
{this.state.RetryItems[provider].RetryMessage}
); - } - retryList.push(); + } + retryList.push(); if (++retryCount < Object.keys(this.state.RetryItems).length) { retryList.push(); @@ -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)), diff --git a/src/redux/actions/mount_actions.js b/src/redux/actions/mount_actions.js index f7d85a6..e618779 100644 --- a/src/redux/actions/mount_actions.js +++ b/src/redux/actions/mount_actions.js @@ -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'; diff --git a/src/redux/reducers/mount_reducer.js b/src/redux/reducers/mount_reducer.js index 3cf1b2b..4499e11 100644 --- a/src/redux/reducers/mount_reducer.js +++ b/src/redux/reducers/mount_reducer.js @@ -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) => { diff --git a/src/renderer/ipc/MountsIPC.js b/src/renderer/ipc/MountsIPC.js index 6e26fcf..4d261b3 100644 --- a/src/renderer/ipc/MountsIPC.js +++ b/src/renderer/ipc/MountsIPC.js @@ -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); }); });