Use callback during setState()
This commit is contained in:
@@ -69,28 +69,29 @@ class MountItems extends Component {
|
||||
...this.state[storageType],
|
||||
AllowMount: false,
|
||||
};
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
});
|
||||
|
||||
this.props.mountsBusy(true);
|
||||
|
||||
if (mount) {
|
||||
ipcRenderer.send(Constants.IPC_Mount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
StorageType: storageType,
|
||||
Version: this.props.version,
|
||||
});
|
||||
} else {
|
||||
ipcRenderer.send(Constants.IPC_Unmount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
PID: pid,
|
||||
StorageType: storageType,
|
||||
Version: this.props.version,
|
||||
});
|
||||
}
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
}, ()=> {
|
||||
if (mount) {
|
||||
ipcRenderer.send(Constants.IPC_Mount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
StorageType: storageType,
|
||||
Version: this.props.version,
|
||||
});
|
||||
} else {
|
||||
ipcRenderer.send(Constants.IPC_Unmount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
PID: pid,
|
||||
StorageType: storageType,
|
||||
Version: this.props.version,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -111,30 +112,30 @@ class MountItems extends Component {
|
||||
PID: arg.data.PIDS.Hyperspace,
|
||||
};
|
||||
|
||||
this.props.mountsBusy(hs.Mounted || sia.Mounted);
|
||||
|
||||
this.setState({
|
||||
Hyperspace: hs,
|
||||
Sia: sia,
|
||||
}, () => {
|
||||
let hsLocation = arg.data.Locations.Hyperspace;
|
||||
if ((hsLocation.length === 0) && (this.props.platform === 'win32')) {
|
||||
hsLocation = this.props.hyperspace.MountLocation || arg.data.DriveLetters.Hyperspace[0];
|
||||
}
|
||||
if (hsLocation !== this.props.hyperspace.MountLocation) {
|
||||
this.props.changed('Hyperspace', hsLocation);
|
||||
}
|
||||
|
||||
let siaLocation = arg.data.Locations.Sia;
|
||||
if ((siaLocation.length === 0) && (this.props.platform === 'win32')) {
|
||||
siaLocation = this.props.sia.MountLocation || arg.data.DriveLetters.Sia[0];
|
||||
}
|
||||
if (siaLocation !== this.props.sia.MountLocation) {
|
||||
this.props.changed('Sia', siaLocation);
|
||||
}
|
||||
|
||||
this.performAutoMount();
|
||||
});
|
||||
|
||||
this.props.mountsBusy(hs.Mounted || sia.Mounted);
|
||||
|
||||
let hsLocation = arg.data.Locations.Hyperspace;
|
||||
if ((hsLocation.length === 0) && (this.props.platform === 'win32')) {
|
||||
hsLocation = this.props.hyperspace.MountLocation || arg.data.DriveLetters.Hyperspace[0];
|
||||
}
|
||||
if (hsLocation !== this.props.hyperspace.MountLocation) {
|
||||
this.props.changed('Hyperspace', hsLocation);
|
||||
}
|
||||
|
||||
let siaLocation = arg.data.Locations.Sia;
|
||||
if ((siaLocation.length === 0) && (this.props.platform === 'win32')) {
|
||||
siaLocation = this.props.sia.MountLocation || arg.data.DriveLetters.Sia[0];
|
||||
}
|
||||
if (siaLocation !== this.props.sia.MountLocation) {
|
||||
this.props.changed('Sia', siaLocation);
|
||||
}
|
||||
|
||||
this.performAutoMount();
|
||||
} else {
|
||||
this.props.errorHandler(arg.data.Error);
|
||||
}
|
||||
@@ -148,9 +149,9 @@ class MountItems extends Component {
|
||||
};
|
||||
this.setState({
|
||||
[arg.data.StorageType]: state,
|
||||
}, ()=> {
|
||||
this.detectMounts();
|
||||
});
|
||||
|
||||
this.detectMounts();
|
||||
};
|
||||
|
||||
onUnmountDriveReply = (event, arg) => {
|
||||
|
||||
Reference in New Issue
Block a user