Refactoring

This commit is contained in:
Scott E. Graves
2018-12-08 23:36:43 -06:00
parent ff87b699ab
commit e95477f421
3 changed files with 107 additions and 125 deletions

View File

@@ -28,6 +28,14 @@ class App extends Component {
constructor(props) {
super(props);
for (const provider of Constants.PROVIDER_LIST) {
this.state[provider] = {
AutoMount: false,
AutoRestart: false,
MountLocation: '',
}
}
if (ipcRenderer) {
ipcRenderer.on(Constants.IPC_Check_Installed_Reply, this.onCheckInstalledReply);
ipcRenderer.on(Constants.IPC_Download_File_Complete, this.onDownloadFileComplete);
@@ -60,15 +68,9 @@ class App extends Component {
DownloadingRelease: false,
DownloadingUpgrade: false,
ExtractActive: false,
Hyperspace: {
AutoMount: false,
AutoRestart: false,
MountLocation: '',
},
LocationsLookup: {},
MissingDependencies: [],
MountsBusy: false,
Platform: 'unknown',
Release: 3,
ReleaseTypes: [
'Release',
@@ -77,16 +79,6 @@ class App extends Component {
'Alpha',
],
InstalledVersion: 'none',
Sia: {
AutoMount: false,
AutoRestart: false,
MountLocation: '',
},
SiaPrime: {
AutoMount: false,
AutoRestart: false,
MountLocation: '',
},
UpgradeAvailable: false,
UpgradeData: {},
UpgradeDismissed: false,
@@ -112,7 +104,7 @@ class App extends Component {
this.setState({
AllowDownload: false,
}, ()=> {
const selectedVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
const selectedVersion = this.getSelectedVersion();
if (selectedVersion !== 'unavailable') {
if (ipcRenderer) {
let dependencies = [];
@@ -161,6 +153,10 @@ class App extends Component {
}
};
getSelectedVersion = () => {
return this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
};
grabReleases = () => {
if (this.props.platform !== 'unknown') {
if (ipcRenderer) {
@@ -178,7 +174,7 @@ class App extends Component {
this.setState({
[storageType]: state,
}, ()=> {
this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime);
this.saveState();
});
};
@@ -190,7 +186,7 @@ class App extends Component {
this.setState({
[storageType]: state,
}, ()=> {
this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime);
this.saveState();
});
};
@@ -233,7 +229,7 @@ class App extends Component {
this.setState({
[storageType]: state,
}, ()=> {
this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime);
this.saveState();
});
};
@@ -244,13 +240,13 @@ class App extends Component {
Release: val,
Version: versionIndex
}, ()=> {
this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime);
this.saveState();
this.checkVersionInstalled( );
});
};
handleReleaseDownload = () => {
const selectedVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
const selectedVersion = this.getSelectedVersion();
const fileName = selectedVersion + '.zip';
if (ipcRenderer) {
this.setState({
@@ -289,7 +285,7 @@ class App extends Component {
this.setState({
Version: parseInt(e.target.value, 10),
}, ()=> {
this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime);
this.saveState();
this.checkVersionInstalled( );
});
};
@@ -335,7 +331,7 @@ class App extends Component {
onDownloadFileComplete = (event, arg) => {
if (this.state.DownloadingRelease) {
if (arg.data.Success) {
const selectedVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
const selectedVersion = this.getSelectedVersion();
ipcRenderer.send(Constants.IPC_Extract_Release, {
Directory: Constants.DATA_LOCATIONS[this.props.platform],
Source: arg.data.Destination,
@@ -406,37 +402,23 @@ class App extends Component {
onGetStateReply = (event, arg) => {
if (arg.data) {
let hyperspace = arg.data.Hyperspace || this.state.Hyperspace;
if (hyperspace.AutoMount === undefined) {
hyperspace['AutoMount'] = false;
}
if (hyperspace.AutoRestart === undefined) {
hyperspace['AutoRestart'] = false;
}
let sia = arg.data.Sia || this.state.Sia;
if (sia.AutoMount === undefined) {
sia['AutoMount'] = false;
}
if (sia.AutoRestart === undefined) {
sia['AutoRestart'] = false;
}
let siaPrime = arg.data.SiaPrime || this.state.SiaPrime;
if (siaPrime.AutoMount === undefined) {
siaPrime['AutoMount'] = false;
}
if (siaPrime.AutoRestart === undefined) {
siaPrime['AutoRestart'] = false;
}
this.setState({
Hyperspace: hyperspace,
let state = {
Release: arg.data.Release,
Sia: sia,
SiaPrime: siaPrime,
Version: arg.data.Version,
}, ()=> {
};
for (const provider of Constants.PROVIDER_LIST) {
let data = arg.data[provider] || this.state[provider];
if (data.AutoMount === undefined) {
data['AutoMount'] = false;
}
if (data.AutoRestart === undefined) {
data['AutoRestart'] = false;
}
state[provider] = data;
}
this.setState(state, ()=> {
this.grabReleases();
});
} else {
@@ -450,7 +432,7 @@ class App extends Component {
let version = this.state.Version;
if ((version === -1) || !versionLookup[this.state.ReleaseTypes[this.state.Release]][version]) {
version = latestVersion;
this.saveState(this.state.Release, version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime);
this.saveState(version);
}
this.setState({
@@ -541,17 +523,19 @@ class App extends Component {
});
};
saveState = (release, version, sia, hyperspace, siaPrime)=> {
saveState = version => {
if (ipcRenderer) {
let state = {
Release: this.state.Release,
Version: version || this.state.Version,
};
for (const provider of Constants.PROVIDER_LIST) {
state[provider] = this.state[provider];
}
ipcRenderer.send(Constants.IPC_Save_State, {
Directory: Constants.DATA_LOCATIONS[this.props.platform],
State: {
Hyperspace: hyperspace,
Release: release,
Sia: sia,
SiaPrime: siaPrime,
Version: version,
}
State: state
});
}
};
@@ -590,7 +574,7 @@ class App extends Component {
render() {
const selectedVersion = (this.state.Version === -1) ?
'unavailable' :
this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
this.getSelectedVersion();
const downloadEnabled = this.state.AllowDownload &&
!this.state.MountsBusy &&
@@ -697,9 +681,15 @@ class App extends Component {
));
if (allowMount) {
let providerProps = {};
for (const provider of Constants.PROVIDER_LIST) {
const providerLower = provider.toLowerCase();
providerProps[providerLower] = this.state[provider];
}
mainContent.push((
<div key={'md_' + key++}>
<MountItems allowConfig={allowConfig}
<MountItems {...providerProps}
allowConfig={allowConfig}
allowSiaPrime={allowSiaPrime}
autoMountChanged={this.handleAutoMountChanged}
autoMountProcessed={this.notifyAutoMountProcessed}
@@ -708,12 +698,9 @@ class App extends Component {
configClicked={this.handleConfigClicked}
directory={Constants.DATA_LOCATIONS[this.props.platform]}
errorHandler={this.setErrorState}
hyperspace={this.state.Hyperspace}
mountsBusy={this.notifyMountsBusy}
platform={this.props.platform}
processAutoMount={!this.state.AutoMountProcessed}
sia={this.state.Sia}
siaprime={this.state.SiaPrime}
version={this.state.InstalledVersion}/>
</div>
));