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_Delete_File = 'delete_file';
exports.IPC_Detect_Mounts = 'detect_mounts'; exports.IPC_Detect_Mount = 'detect_mount';
exports.IPC_Detect_Mounts_Reply = 'detect_mounts_reply'; exports.IPC_Detect_Mount_Reply = 'detect_mount_reply';
exports.IPC_Download_File = 'download_file'; exports.IPC_Download_File = 'download_file';
exports.IPC_Download_File_Complete = 'download_file_complete'; exports.IPC_Download_File_Complete = 'download_file_complete';

View File

@@ -22,12 +22,18 @@ const Constants = require('../../constants');
class MountItems extends IPCContainer { class MountItems extends IPCContainer {
retryIntervals = {}; retryIntervals = {};
activeDetections = [];
state = { state = {
DisplayRetry: false, DisplayRetry: false,
RetryItems: {}, RetryItems: {},
}; };
addMountsBusy = provider => {
this.props.setMountsBusy(true);
this.activeDetections.push(provider);
};
cancelRetryMount = (provider, stateCallback) => { cancelRetryMount = (provider, stateCallback) => {
clearInterval(this.retryIntervals[provider]); clearInterval(this.retryIntervals[provider]);
delete this.retryIntervals[provider]; delete this.retryIntervals[provider];
@@ -50,7 +56,7 @@ class MountItems extends IPCContainer {
}; };
componentDidMount() { 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_Mount_Drive_Reply, this.onMountDriveReply);
this.setRequestHandler(Constants.IPC_Unmount_Drive_Reply, this.onUnmountDriveReply); this.setRequestHandler(Constants.IPC_Unmount_Drive_Reply, this.onUnmountDriveReply);
this.props.resetMountsState(); this.props.resetMountsState();
@@ -68,12 +74,21 @@ class MountItems extends IPCContainer {
super.componentWillUnmount(); super.componentWillUnmount();
}; };
detectMount = provider => {
this.addMountsBusy(provider);
this.sendRequest(Constants.IPC_Detect_Mount, {
RemoteMounts: this.props.RemoteMounts,
Provider: provider,
Version: this.props.InstalledVersion,
});
};
detectMounts = ()=> { detectMounts = ()=> {
if (!this.state.DisplayRetry) { if (!this.state.DisplayRetry) {
this.props.setMountsBusy(true); const providerList = this.getProviderList();
this.sendRequest(Constants.IPC_Detect_Mounts, { providerList.forEach(provider => {
RemoteMounts: this.props.RemoteMounts, this.detectMount(provider);
Version: this.props.InstalledVersion,
}); });
} }
}; };
@@ -181,7 +196,7 @@ class MountItems extends IPCContainer {
} }
if (allowAction) { if (allowAction) {
this.props.setMountsBusy(true); this.addMountsBusy(provider);
this.props.setAllowMount(provider, false); this.props.setAllowMount(provider, false);
if (mount) { if (mount) {
@@ -211,67 +226,68 @@ class MountItems extends IPCContainer {
]; ];
}; };
onDetectMountsReply = (event, arg) => { onDetectMountReply = (event, arg) => {
if (!this.state.DisplayRetry && arg.data.Success) { if (!this.state.DisplayRetry && arg.data.Success) {
let mountsBusy = false; const provider = arg.data.Provider;
let mountStates = {};
for (const provider of this.getProviderList()) {
const mountState = { const mountState = {
AllowMount: true, AllowMount: true,
DriveLetters: (arg.data.DriveLetters[provider]), DriveLetters: (arg.data.DriveLetters),
Mounted: (arg.data.Locations[provider].length > 0), Mounted: (arg.data.Location.length > 0),
}; };
this.props.setMountState(provider, mountState); this.props.setMountState(provider, mountState);
mountsBusy = mountsBusy || mountState.Mounted; this.removeMountsBusy(provider);
mountStates[provider] = mountState;
}
this.props.setMountsBusy(mountsBusy);
const updateMountLocation = (data, provider) => { this.updateMountLocation(provider, arg.data.Location, mountState.Mounted, arg.data.DriveLetters);
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) { this.props.setAutoMountProcessed(provider,true);
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);
} else { } else {
this.props.notifyError(arg.data.Error); this.props.notifyError(arg.data.Error);
} }
}; };
onMountDriveReply = (event, arg) => { onMountDriveReply = (event, arg) => {
this.removeMountsBusy(arg.data.Provider);
this.props.setMounted(arg.data.Provider, arg.data.Success); this.props.setMounted(arg.data.Provider, arg.data.Success);
this.detectMounts(); this.detectMount(arg.data.Provider);
}; };
onUnmountDriveReply = (event, arg) => { onUnmountDriveReply = (event, arg) => {
if (arg && arg.data && !arg.data.Expected && arg.data.Location && this.props.ProviderState[arg.data.Provider].AutoRestart) { 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); this.displayRetryMount(arg.data.Provider, arg.data.Remote, arg.data.Location);
} else { } 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);
} }
}; };
@@ -286,7 +302,8 @@ class MountItems extends IPCContainer {
retryList.push(<p key={'rl_' + retryList.length}>{this.state.RetryItems[provider].RetryMessage}</p>); retryList.push(<p key={'rl_' + retryList.length}>{this.state.RetryItems[provider].RetryMessage}</p>);
} }
retryList.push(<Button clicked={() => this.cancelRetryMount(provider, () => this.detectMounts())} retryList.push(<Button clicked={() => this.cancelRetryMount(provider, () => this.detectMounts())}
key={'rl_' + retryList.length}>Cancel {provider} Remount ({this.state.RetryItems[provider].RetrySeconds}s)</Button>); key={'rl_' + retryList.length}>Cancel {provider} Remount
({this.state.RetryItems[provider].RetrySeconds}s)</Button>);
if (++retryCount < Object.keys(this.state.RetryItems).length) { if (++retryCount < Object.keys(this.state.RetryItems).length) {
retryList.push(<div style={{paddingTop: 'var(--default_spacing)'}} retryList.push(<div style={{paddingTop: 'var(--default_spacing)'}}
key={'rl_' + retryList.length}/>); key={'rl_' + retryList.length}/>);
@@ -376,7 +393,7 @@ const mapDispatchToProps = dispatch => {
notifyError: (msg, critical, callback) => dispatch(notifyError(msg, critical, callback)), notifyError: (msg, critical, callback) => dispatch(notifyError(msg, critical, callback)),
resetMountsState: () => dispatch(resetMountsState()), resetMountsState: () => dispatch(resetMountsState()),
setAllowMount: (provider, allow) => dispatch(setAllowMount(provider, allow)), 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)), setMounted: (provider, mounted) => dispatch(setMounted(provider, mounted)),
setMountsBusy: busy => dispatch(setBusy(busy)), setMountsBusy: busy => dispatch(setBusy(busy)),
setMountState: (provider, state) => dispatch(setMountState(provider, state)), 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) => { ipcRenderer.once(Constants.IPC_Set_Config_Values_Reply, (_, arg) => {
if (arg.data.Success) { if (arg.data.Success) {
ipcRenderer.send(Constants.IPC_Detect_Mounts, { ipcRenderer.send(Constants.IPC_Detect_Mount, {
Provider: provider,
RemoteMounts: getState().mounts.RemoteMounts, RemoteMounts: getState().mounts.RemoteMounts,
Version: getState().relver.InstalledVersion, 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 setBusy = createAction('mounts/setBusy');
export const SET_MOUNT_STATE = 'mounts/setMountState'; export const SET_MOUNT_STATE = 'mounts/setMountState';

View File

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

View File

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