Use callback during setState()
This commit is contained in:
63
src/App.js
63
src/App.js
@@ -101,16 +101,11 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
checkVersionInstalled = (release, version, versionLookup) => {
|
checkVersionInstalled = () => {
|
||||||
if (!versionLookup) {
|
|
||||||
versionLookup = this.state.VersionLookup;
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectedVersion = versionLookup[this.state.ReleaseTypes[release]][version];
|
|
||||||
this.setState({
|
this.setState({
|
||||||
AllowDownload: false,
|
AllowDownload: false,
|
||||||
});
|
}, ()=> {
|
||||||
|
const selectedVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
|
||||||
if (selectedVersion !== 'unavailable') {
|
if (selectedVersion !== 'unavailable') {
|
||||||
if (ipcRenderer) {
|
if (ipcRenderer) {
|
||||||
let dependencies = [];
|
let dependencies = [];
|
||||||
@@ -125,6 +120,7 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
closeErrorDisplay = () => {
|
closeErrorDisplay = () => {
|
||||||
@@ -176,6 +172,8 @@ class App extends Component {
|
|||||||
...this.state.Hyperspace
|
...this.state.Hyperspace
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.saveState(this.state.Release, this.state.Version, sia, hyperspace);
|
||||||
|
|
||||||
if (storageType === 'Hyperspace') {
|
if (storageType === 'Hyperspace') {
|
||||||
hyperspace.AutoMount = e.target.checked;
|
hyperspace.AutoMount = e.target.checked;
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -188,7 +186,6 @@ class App extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveState(this.state.Release, this.state.Version, sia, hyperspace);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleConfigClicked = (storageType) => {
|
handleConfigClicked = (storageType) => {
|
||||||
@@ -212,13 +209,13 @@ class App extends Component {
|
|||||||
DownloadActive: true,
|
DownloadActive: true,
|
||||||
DownloadingDependency: true,
|
DownloadingDependency: true,
|
||||||
DownloadName: fileName,
|
DownloadName: fileName,
|
||||||
});
|
}, ()=> {
|
||||||
|
|
||||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||||
Filename: fileName,
|
Filename: this.state.DownloadName,
|
||||||
URL: url,
|
URL: url,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -227,9 +224,6 @@ class App extends Component {
|
|||||||
...this.state[storageType],
|
...this.state[storageType],
|
||||||
MountLocation: location,
|
MountLocation: location,
|
||||||
};
|
};
|
||||||
this.setState({
|
|
||||||
[storageType]: state,
|
|
||||||
});
|
|
||||||
const hyperspace = (storageType === 'Hyperspace') ? state : {
|
const hyperspace = (storageType === 'Hyperspace') ? state : {
|
||||||
...this.state.Hyperspace,
|
...this.state.Hyperspace,
|
||||||
};
|
};
|
||||||
@@ -238,17 +232,21 @@ class App extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.saveState(this.state.Release, this.state.Version, sia, hyperspace);
|
this.saveState(this.state.Release, this.state.Version, sia, hyperspace);
|
||||||
|
this.setState({
|
||||||
|
[storageType]: state,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
handleReleaseChanged = (e) => {
|
handleReleaseChanged = (e) => {
|
||||||
const val = parseInt(e.target.value, 10);
|
const val = parseInt(e.target.value, 10);
|
||||||
const versionIndex = this.state.VersionLookup[this.state.ReleaseTypes[val]].length - 1;
|
const versionIndex = this.state.VersionLookup[this.state.ReleaseTypes[val]].length - 1;
|
||||||
|
this.saveState(val, versionIndex, this.state.Sia, this.state.Hyperspace);
|
||||||
this.setState({
|
this.setState({
|
||||||
Release: val,
|
Release: val,
|
||||||
Version: versionIndex
|
Version: versionIndex
|
||||||
|
}, ()=> {
|
||||||
|
this.checkVersionInstalled( );
|
||||||
});
|
});
|
||||||
this.saveState(val, versionIndex, this.state.Sia, this.state.Hyperspace);
|
|
||||||
this.checkVersionInstalled(val, versionIndex);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleReleaseDownload = () => {
|
handleReleaseDownload = () => {
|
||||||
@@ -259,13 +257,13 @@ class App extends Component {
|
|||||||
DownloadActive: true,
|
DownloadActive: true,
|
||||||
DownloadingRelease: true,
|
DownloadingRelease: true,
|
||||||
DownloadName: fileName,
|
DownloadName: fileName,
|
||||||
});
|
}, () => {
|
||||||
|
|
||||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||||
Filename: fileName,
|
Filename: this.state.DownloadName,
|
||||||
URL: this.state.LocationsLookup[selectedVersion].urls[0],
|
URL: this.state.LocationsLookup[selectedVersion].urls[0],
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -275,13 +273,13 @@ class App extends Component {
|
|||||||
DownloadActive: true,
|
DownloadActive: true,
|
||||||
DownloadingUpgrade: true,
|
DownloadingUpgrade: true,
|
||||||
DownloadName: 'UI Upgrade',
|
DownloadName: 'UI Upgrade',
|
||||||
});
|
}, ()=> {
|
||||||
|
|
||||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||||
Filename: this.props.platform === 'win32' ? 'upgrade.exe' : 'upgrade',
|
Filename: this.props.platform === 'win32' ? 'upgrade.exe' : 'upgrade',
|
||||||
URL: this.state.UpgradeData.urls[0],
|
URL: this.state.UpgradeData.urls[0],
|
||||||
});
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.setState({UpgradeDismissed: true});
|
this.setState({UpgradeDismissed: true});
|
||||||
}
|
}
|
||||||
@@ -289,11 +287,12 @@ class App extends Component {
|
|||||||
|
|
||||||
handleVersionChanged = (e) => {
|
handleVersionChanged = (e) => {
|
||||||
const val = parseInt(e.target.value, 10);
|
const val = parseInt(e.target.value, 10);
|
||||||
|
this.saveState(this.state.Release, val, this.state.Sia, this.state.Hyperspace);
|
||||||
this.setState({
|
this.setState({
|
||||||
Version: val
|
Version: val
|
||||||
|
}, ()=> {
|
||||||
|
this.checkVersionInstalled( );
|
||||||
});
|
});
|
||||||
this.saveState(this.state.Release, val, this.state.Sia, this.state.Hyperspace);
|
|
||||||
this.checkVersionInstalled(this.state.Release, val);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
notifyAutoMountProcessed = () => {
|
notifyAutoMountProcessed = () => {
|
||||||
@@ -400,8 +399,9 @@ class App extends Component {
|
|||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
ExtractActive: false,
|
ExtractActive: false,
|
||||||
|
}, ()=> {
|
||||||
|
this.checkVersionInstalled( );
|
||||||
});
|
});
|
||||||
this.checkVersionInstalled(this.state.Release, this.state.Version);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
onGetStateReply = (event, arg) => {
|
onGetStateReply = (event, arg) => {
|
||||||
@@ -417,9 +417,12 @@ class App extends Component {
|
|||||||
Release: arg.data.Release,
|
Release: arg.data.Release,
|
||||||
Sia: arg.data.Sia,
|
Sia: arg.data.Sia,
|
||||||
Version: arg.data.Version,
|
Version: arg.data.Version,
|
||||||
});
|
}, ()=> {
|
||||||
}
|
|
||||||
this.grabReleases();
|
this.grabReleases();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.grabReleases();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onGrabReleasesReply = ()=> {
|
onGrabReleasesReply = ()=> {
|
||||||
@@ -437,9 +440,9 @@ class App extends Component {
|
|||||||
Version: version,
|
Version: version,
|
||||||
VersionAvailable: version !== latestVersion,
|
VersionAvailable: version !== latestVersion,
|
||||||
VersionLookup: versionLookup,
|
VersionLookup: versionLookup,
|
||||||
|
}, () => {
|
||||||
|
this.checkVersionInstalled( );
|
||||||
});
|
});
|
||||||
|
|
||||||
this.checkVersionInstalled(this.state.Release, version, versionLookup);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
axios.get(Constants.RELEASES_URL)
|
axios.get(Constants.RELEASES_URL)
|
||||||
@@ -500,7 +503,7 @@ class App extends Component {
|
|||||||
ipcRenderer.send(Constants.IPC_Delete_File, {
|
ipcRenderer.send(Constants.IPC_Delete_File, {
|
||||||
FilePath: arg.data.Source,
|
FilePath: arg.data.Source,
|
||||||
});
|
});
|
||||||
this.checkVersionInstalled(this.state.Release, this.state.Version);
|
this.checkVersionInstalled( );
|
||||||
};
|
};
|
||||||
|
|
||||||
onInstallUpgradeReply = (event, arg) => {
|
onInstallUpgradeReply = (event, arg) => {
|
||||||
|
|||||||
@@ -164,12 +164,13 @@ class Configuration extends Component {
|
|||||||
if (arg.data.Success) {
|
if (arg.data.Success) {
|
||||||
this.setState({
|
this.setState({
|
||||||
Template: arg.data.Template,
|
Template: arg.data.Template,
|
||||||
});
|
}, ()=> {
|
||||||
ipcRenderer.send(Constants.IPC_Get_Config, {
|
ipcRenderer.send(Constants.IPC_Get_Config, {
|
||||||
Directory: this.props.directory,
|
Directory: this.props.directory,
|
||||||
StorageType: this.props.storageType,
|
StorageType: this.props.storageType,
|
||||||
Version: this.props.version,
|
Version: this.props.version,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.props.errorHandler(arg.data.Error, () => {
|
this.props.errorHandler(arg.data.Error, () => {
|
||||||
this.props.closed();
|
this.props.closed();
|
||||||
@@ -185,8 +186,7 @@ class Configuration extends Component {
|
|||||||
if (ipcRenderer) {
|
if (ipcRenderer) {
|
||||||
this.setState({
|
this.setState({
|
||||||
Saving: true,
|
Saving: true,
|
||||||
});
|
}, ()=> {
|
||||||
|
|
||||||
const changedItems = [];
|
const changedItems = [];
|
||||||
for (const item of this.state.ChangedItems) {
|
for (const item of this.state.ChangedItems) {
|
||||||
changedItems.push({
|
changedItems.push({
|
||||||
@@ -212,6 +212,7 @@ class Configuration extends Component {
|
|||||||
StorageType: this.props.storageType,
|
StorageType: this.props.storageType,
|
||||||
Version: this.props.version,
|
Version: this.props.version,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -69,12 +69,12 @@ class MountItems extends Component {
|
|||||||
...this.state[storageType],
|
...this.state[storageType],
|
||||||
AllowMount: false,
|
AllowMount: false,
|
||||||
};
|
};
|
||||||
this.setState({
|
|
||||||
[storageType]: state,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.props.mountsBusy(true);
|
this.props.mountsBusy(true);
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
[storageType]: state,
|
||||||
|
}, ()=> {
|
||||||
if (mount) {
|
if (mount) {
|
||||||
ipcRenderer.send(Constants.IPC_Mount_Drive, {
|
ipcRenderer.send(Constants.IPC_Mount_Drive, {
|
||||||
Directory: this.props.directory,
|
Directory: this.props.directory,
|
||||||
@@ -91,6 +91,7 @@ class MountItems extends Component {
|
|||||||
Version: this.props.version,
|
Version: this.props.version,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -111,13 +112,12 @@ class MountItems extends Component {
|
|||||||
PID: arg.data.PIDS.Hyperspace,
|
PID: arg.data.PIDS.Hyperspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.props.mountsBusy(hs.Mounted || sia.Mounted);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
Hyperspace: hs,
|
Hyperspace: hs,
|
||||||
Sia: sia,
|
Sia: sia,
|
||||||
});
|
}, () => {
|
||||||
|
|
||||||
this.props.mountsBusy(hs.Mounted || sia.Mounted);
|
|
||||||
|
|
||||||
let hsLocation = arg.data.Locations.Hyperspace;
|
let hsLocation = arg.data.Locations.Hyperspace;
|
||||||
if ((hsLocation.length === 0) && (this.props.platform === 'win32')) {
|
if ((hsLocation.length === 0) && (this.props.platform === 'win32')) {
|
||||||
hsLocation = this.props.hyperspace.MountLocation || arg.data.DriveLetters.Hyperspace[0];
|
hsLocation = this.props.hyperspace.MountLocation || arg.data.DriveLetters.Hyperspace[0];
|
||||||
@@ -135,6 +135,7 @@ class MountItems extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.performAutoMount();
|
this.performAutoMount();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
this.props.errorHandler(arg.data.Error);
|
this.props.errorHandler(arg.data.Error);
|
||||||
}
|
}
|
||||||
@@ -148,9 +149,9 @@ class MountItems extends Component {
|
|||||||
};
|
};
|
||||||
this.setState({
|
this.setState({
|
||||||
[arg.data.StorageType]: state,
|
[arg.data.StorageType]: state,
|
||||||
});
|
}, ()=> {
|
||||||
|
|
||||||
this.detectMounts();
|
this.detectMounts();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
onUnmountDriveReply = (event, arg) => {
|
onUnmountDriveReply = (event, arg) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user