[Fix new release detection] [IPC names to constants] [Refactoring]
This commit is contained in:
403
src/App.js
403
src/App.js
@@ -27,181 +27,18 @@ class App extends Component {
|
||||
super(props);
|
||||
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.on('get_platform_reply', (event, arg) => {
|
||||
this.setState({
|
||||
Platform: arg.data,
|
||||
});
|
||||
ipcRenderer.send('get_state', Constants.DATA_LOCATIONS[arg.data]);
|
||||
});
|
||||
ipcRenderer.on(Constants.IPC_Check_Installed_Reply, this.onCheckInstalledReply);
|
||||
ipcRenderer.on(Constants.IPC_Download_File_Complete, this.onDownloadFileComplete);
|
||||
ipcRenderer.on(Constants.IPC_Download_File_Progress, this.onDownloadFileProgress);
|
||||
ipcRenderer.on(Constants.IPC_Extract_Release_Complete, this.onExtractReleaseComplete);
|
||||
ipcRenderer.on(Constants.IPC_Get_Platform_Reply, this.onGetPlatformReply);
|
||||
ipcRenderer.on(Constants.IPC_Get_State_Reply, this.onGetStateReply);
|
||||
ipcRenderer.on(Constants.IPC_Grab_Releases_Reply, this.onGrabReleasesReply);
|
||||
ipcRenderer.on(Constants.IPC_Grab_UI_Releases_Reply, this.onGrabUiReleasesReply);
|
||||
ipcRenderer.on(Constants.IPC_Install_Dependency_Reply, this.onInstallDependencyReply);
|
||||
ipcRenderer.on(Constants.IPC_Install_Upgrade_Reply, this.onInstallUpgradeReply);
|
||||
|
||||
ipcRenderer.on('get_state_reply', (event, arg) => {
|
||||
if (arg.data) {
|
||||
if (arg.data.Hyperspace.AutoMount === undefined) {
|
||||
arg.data.Hyperspace['AutoMount'] = false;
|
||||
}
|
||||
if (arg.data.Sia.AutoMount === undefined) {
|
||||
arg.data.Sia['AutoMount'] = false;
|
||||
}
|
||||
this.setState({
|
||||
Hyperspace: arg.data.Hyperspace,
|
||||
Release: arg.data.Release,
|
||||
Sia: arg.data.Sia,
|
||||
Version: arg.data.Version,
|
||||
});
|
||||
}
|
||||
this.grabReleases();
|
||||
});
|
||||
|
||||
ipcRenderer.on('grab_releases_reply', ()=> {
|
||||
axios.get(Constants.RELEASES_URL)
|
||||
.then(response => {
|
||||
const versionLookup = {
|
||||
Alpha: response.data.Versions.Alpha[this.state.Platform],
|
||||
Beta: response.data.Versions.Beta[this.state.Platform],
|
||||
RC: response.data.Versions.RC[this.state.Platform],
|
||||
Release: response.data.Versions.Release[this.state.Platform],
|
||||
};
|
||||
const locationsLookup = {
|
||||
...response.data.Locations[this.state.Platform],
|
||||
};
|
||||
|
||||
const latestVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]].length - 1;
|
||||
let version = this.state.Version;
|
||||
if (version === -1) {
|
||||
version = latestVersion;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
AllowOptions: true,
|
||||
LocationsLookup: locationsLookup,
|
||||
Version: version,
|
||||
VersionAvailable: version !== latestVersion,
|
||||
VersionLookup: versionLookup,
|
||||
});
|
||||
this.checkVersionInstalled(this.state.Release, version, versionLookup);
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
|
||||
ipcRenderer.on('grab_ui_releases_reply', ()=> {
|
||||
axios.get(Constants.UI_RELEASES_URL)
|
||||
.then(response => {
|
||||
const data = response.data;
|
||||
if (data.Versions &&
|
||||
data.Versions[this.state.Platform] &&
|
||||
(data.Versions[this.state.Platform].length > 0) &&
|
||||
(data.Versions[this.state.Platform][0] !== this.props.version)) {
|
||||
this.setState({
|
||||
UpgradeAvailable: true,
|
||||
UpgradeDismissed: false,
|
||||
UpgradeData: data.Locations[this.state.Platform][data.Versions[this.state.Platform][0]],
|
||||
});
|
||||
}
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
});
|
||||
|
||||
ipcRenderer.on('download_file_progress', (event, arg) => {
|
||||
this.setState({
|
||||
DownloadProgress: arg.data.Progress,
|
||||
});
|
||||
});
|
||||
|
||||
ipcRenderer.on('download_file_complete', (event, arg) => {
|
||||
if (this.state.DownloadingRelease) {
|
||||
if (arg.data.Success) {
|
||||
const selectedVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
|
||||
ipcRenderer.send('extract_release', {
|
||||
Directory: Constants.DATA_LOCATIONS[this.state.Platform],
|
||||
Source: arg.data.Destination,
|
||||
Version: selectedVersion,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingRelease: false,
|
||||
ExtractActive: arg.data.Success,
|
||||
DownloadName: '',
|
||||
});
|
||||
} else if (this.state.DownloadingDependency) {
|
||||
if (arg.data.Success) {
|
||||
ipcRenderer.send('install_dependency', {
|
||||
Source: arg.data.Destination,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingDependency: arg.data.Success,
|
||||
DownloadName: '',
|
||||
});
|
||||
} else if (this.state.DownloadingUpgrade) {
|
||||
if (arg.data.Success) {
|
||||
ipcRenderer.send('install_upgrade', {
|
||||
Source: arg.data.Destination,
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingUpgrade: false,
|
||||
DownloadName: '',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadName: '',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ipcRenderer.on('extract_release_complete', (event, arg) => {
|
||||
ipcRenderer.send('delete_file', {
|
||||
FilePath: arg.data.Source,
|
||||
});
|
||||
|
||||
this.setState({
|
||||
ExtractActive: false,
|
||||
});
|
||||
this.checkVersionInstalled(this.state.Release, this.state.Version);
|
||||
});
|
||||
|
||||
ipcRenderer.on('check_installed_reply', (event, arg) => {
|
||||
this.setState({
|
||||
AllowDownload: true,
|
||||
DownloadingDependency: false,
|
||||
MissingDependencies: arg.data.Dependencies,
|
||||
RepertoryVersion: arg.data.Success && arg.data.Exists ? arg.data.Version : 'none',
|
||||
});
|
||||
});
|
||||
|
||||
ipcRenderer.on('install_dependency_reply', (event, arg) => {
|
||||
ipcRenderer.send('delete_file', {
|
||||
FilePath: arg.data.Source,
|
||||
});
|
||||
this.checkVersionInstalled(this.state.Release, this.state.Version);
|
||||
});
|
||||
|
||||
ipcRenderer.on('install_upgrade_reply', (event, arg) => {
|
||||
ipcRenderer.sendSync('delete_file', {
|
||||
FilePath: arg.data.Source,
|
||||
});
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadName: '',
|
||||
});
|
||||
});
|
||||
|
||||
ipcRenderer.send('get_platform');
|
||||
ipcRenderer.send(Constants.IPC_Get_Platform);
|
||||
Scheduler.scheduleJob('23 11 * * *', this.updateCheckScheduledJob);
|
||||
}
|
||||
}
|
||||
@@ -275,7 +112,7 @@ class App extends Component {
|
||||
dependencies = this.state.LocationsLookup[selectedVersion].dependencies;
|
||||
}
|
||||
|
||||
ipcRenderer.send('check_installed', {
|
||||
ipcRenderer.send(Constants.IPC_Check_Installed, {
|
||||
Dependencies: dependencies,
|
||||
Directory: Constants.DATA_LOCATIONS[this.state.Platform],
|
||||
Version: selectedVersion,
|
||||
@@ -283,11 +120,26 @@ class App extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
componentWillUnmount = () => {
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.removeListener(Constants.IPC_Check_Installed_Reply, this.onCheckInstalledReply);
|
||||
ipcRenderer.removeListener(Constants.IPC_Download_File_Complete, this.onDownloadFileComplete);
|
||||
ipcRenderer.removeListener(Constants.IPC_Download_File_Progress, this.onDownloadFileProgress);
|
||||
ipcRenderer.removeListener(Constants.IPC_Extract_Release_Complete, this.onExtractReleaseComplete);
|
||||
ipcRenderer.removeListener(Constants.IPC_Get_Platform_Reply, this.onGetPlatformReply);
|
||||
ipcRenderer.removeListener(Constants.IPC_Get_State_Reply, this.onGetStateReply);
|
||||
ipcRenderer.removeListener(Constants.IPC_Grab_Releases_Reply, this.onGrabReleasesReply);
|
||||
ipcRenderer.removeListener(Constants.IPC_Grab_UI_Releases_Reply, this.onGrabUiReleasesReply);
|
||||
ipcRenderer.removeListener(Constants.IPC_Install_Dependency_Reply, this.onInstallDependencyReply);
|
||||
ipcRenderer.removeListener(Constants.IPC_Install_Upgrade_Reply, this.onInstallUpgradeReply);
|
||||
}
|
||||
};
|
||||
|
||||
grabReleases = () => {
|
||||
if (this.state.Platform !== 'unknown') {
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.send('grab_releases');
|
||||
ipcRenderer.send('grab_ui_releases');
|
||||
ipcRenderer.send(Constants.IPC_Grab_Releases);
|
||||
ipcRenderer.send(Constants.IPC_Grab_UI_Releases);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -339,7 +191,7 @@ class App extends Component {
|
||||
DownloadName: fileName,
|
||||
});
|
||||
|
||||
ipcRenderer.send('download_file', {
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.state.Platform],
|
||||
Filename: fileName,
|
||||
URL: url,
|
||||
@@ -386,7 +238,7 @@ class App extends Component {
|
||||
DownloadName: fileName,
|
||||
});
|
||||
|
||||
ipcRenderer.send('download_file', {
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.state.Platform],
|
||||
Filename: fileName,
|
||||
URL: this.state.LocationsLookup[selectedVersion].urls[0],
|
||||
@@ -402,7 +254,7 @@ class App extends Component {
|
||||
DownloadName: 'UI Upgrade',
|
||||
});
|
||||
|
||||
ipcRenderer.send('download_file', {
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.state.Platform],
|
||||
Filename: this.state.Platform === 'win32' ? 'upgrade.exe' : 'upgrade',
|
||||
URL: this.state.UpgradeData.urls[0],
|
||||
@@ -429,9 +281,196 @@ class App extends Component {
|
||||
this.setState({MountsBusy: busy})
|
||||
};
|
||||
|
||||
onCheckInstalledReply = (event, arg) => {
|
||||
const repertoryVersion = arg.data.Success && arg.data.Exists ? arg.data.Version : 'none';
|
||||
let versionAvailable = false;
|
||||
|
||||
if (repertoryVersion !== 'none') {
|
||||
const latestVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]].length - 1;
|
||||
let version = this.state.Version;
|
||||
if (version === -1) {
|
||||
version = latestVersion;
|
||||
}
|
||||
versionAvailable = version !== latestVersion;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
AllowDownload: true,
|
||||
DownloadingDependency: false,
|
||||
MissingDependencies: arg.data.Dependencies,
|
||||
RepertoryVersion: repertoryVersion,
|
||||
VersionAvailable: versionAvailable,
|
||||
});
|
||||
};
|
||||
|
||||
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];
|
||||
ipcRenderer.send(Constants.IPC_Extract_Release, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.state.Platform],
|
||||
Source: arg.data.Destination,
|
||||
Version: selectedVersion,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingRelease: false,
|
||||
ExtractActive: arg.data.Success,
|
||||
DownloadName: '',
|
||||
});
|
||||
} else if (this.state.DownloadingDependency) {
|
||||
if (arg.data.Success) {
|
||||
ipcRenderer.send(Constants.IPC_Install_Dependency, {
|
||||
Source: arg.data.Destination,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingDependency: arg.data.Success,
|
||||
DownloadName: '',
|
||||
});
|
||||
} else if (this.state.DownloadingUpgrade) {
|
||||
if (arg.data.Success) {
|
||||
ipcRenderer.send(Constants.IPC_Install_Upgrade, {
|
||||
Source: arg.data.Destination,
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingUpgrade: false,
|
||||
DownloadName: '',
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadName: '',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onDownloadFileProgress = (event, arg) => {
|
||||
this.setState({
|
||||
DownloadProgress: arg.data.Progress,
|
||||
});
|
||||
};
|
||||
|
||||
onExtractReleaseComplete = (event, arg) => {
|
||||
ipcRenderer.send(Constants.IPC_Delete_File, {
|
||||
FilePath: arg.data.Source,
|
||||
});
|
||||
|
||||
this.setState({
|
||||
ExtractActive: false,
|
||||
});
|
||||
this.checkVersionInstalled(this.state.Release, this.state.Version);
|
||||
};
|
||||
|
||||
onGetPlatformReply = (event, arg) => {
|
||||
this.setState({
|
||||
Platform: arg.data,
|
||||
});
|
||||
ipcRenderer.send(Constants.IPC_Get_State, Constants.DATA_LOCATIONS[arg.data]);
|
||||
};
|
||||
|
||||
onGetStateReply = (event, arg) => {
|
||||
if (arg.data) {
|
||||
if (arg.data.Hyperspace.AutoMount === undefined) {
|
||||
arg.data.Hyperspace['AutoMount'] = false;
|
||||
}
|
||||
if (arg.data.Sia.AutoMount === undefined) {
|
||||
arg.data.Sia['AutoMount'] = false;
|
||||
}
|
||||
this.setState({
|
||||
Hyperspace: arg.data.Hyperspace,
|
||||
Release: arg.data.Release,
|
||||
Sia: arg.data.Sia,
|
||||
Version: arg.data.Version,
|
||||
});
|
||||
}
|
||||
this.grabReleases();
|
||||
};
|
||||
|
||||
onGrabReleasesReply = ()=> {
|
||||
axios.get(Constants.RELEASES_URL)
|
||||
.then(response => {
|
||||
const versionLookup = {
|
||||
Alpha: response.data.Versions.Alpha[this.state.Platform],
|
||||
Beta: response.data.Versions.Beta[this.state.Platform],
|
||||
RC: response.data.Versions.RC[this.state.Platform],
|
||||
Release: response.data.Versions.Release[this.state.Platform],
|
||||
};
|
||||
const locationsLookup = {
|
||||
...response.data.Locations[this.state.Platform],
|
||||
};
|
||||
|
||||
const latestVersion = versionLookup[this.state.ReleaseTypes[this.state.Release]].length - 1;
|
||||
let version = this.state.Version;
|
||||
if (version === -1) {
|
||||
version = latestVersion;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
AllowOptions: true,
|
||||
LocationsLookup: locationsLookup,
|
||||
Version: version,
|
||||
VersionAvailable: version !== latestVersion,
|
||||
VersionLookup: versionLookup,
|
||||
});
|
||||
this.checkVersionInstalled(this.state.Release, version, versionLookup);
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
};
|
||||
|
||||
onGrabUiReleasesReply = ()=> {
|
||||
axios.get(Constants.UI_RELEASES_URL)
|
||||
.then(response => {
|
||||
const data = response.data;
|
||||
if (data.Versions &&
|
||||
data.Versions[this.state.Platform] &&
|
||||
(data.Versions[this.state.Platform].length > 0) &&
|
||||
(data.Versions[this.state.Platform][0] !== this.props.version)) {
|
||||
this.setState({
|
||||
UpgradeAvailable: true,
|
||||
UpgradeDismissed: false,
|
||||
UpgradeData: data.Locations[this.state.Platform][data.Versions[this.state.Platform][0]],
|
||||
});
|
||||
}
|
||||
}).catch(error => {
|
||||
console.log(error);
|
||||
});
|
||||
};
|
||||
|
||||
onInstallDependencyReply = (event, arg) => {
|
||||
ipcRenderer.send(Constants.IPC_Delete_File, {
|
||||
FilePath: arg.data.Source,
|
||||
});
|
||||
this.checkVersionInstalled(this.state.Release, this.state.Version);
|
||||
};
|
||||
|
||||
onInstallUpgradeReply = (event, arg) => {
|
||||
ipcRenderer.sendSync(Constants.IPC_Delete_File, {
|
||||
FilePath: arg.data.Source,
|
||||
});
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadName: '',
|
||||
});
|
||||
};
|
||||
|
||||
saveState = (release, version, sia, hyperspace)=> {
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.send('save_state', {
|
||||
ipcRenderer.send(Constants.IPC_Save_State, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.state.Platform],
|
||||
State: {
|
||||
Hyperspace: hyperspace,
|
||||
@@ -446,7 +485,7 @@ class App extends Component {
|
||||
updateCheckScheduledJob = () => {
|
||||
if (this.state.Platform !== 'unknown') {
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.send('grab_ui_releases');
|
||||
ipcRenderer.send(Constants.IPC_Grab_UI_Releases);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user