[Fix new release detection] [IPC names to constants] [Refactoring]

This commit is contained in:
Scott E. Graves
2018-10-01 11:19:50 -05:00
parent cf6b5b68d7
commit f2a7d1c188
4 changed files with 295 additions and 201 deletions

View File

@@ -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);
}
}
};

View File

@@ -5,3 +5,53 @@ export const DATA_LOCATIONS = {
win32: '%LOCALAPPDATA%\\repertory\\ui',
};
export const UI_RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory-ui/raw/master/releases.json';
export const IPC_Check_Installed = 'check_installed';
export const IPC_Check_Installed_Reply = 'check_installed_reply';
export const IPC_Delete_File = 'delete_file';
export const IPC_Detect_Mounts = 'detect_mounts';
export const IPC_Detect_Mounts_Reply = 'detect_mounts_reply';
export const IPC_Download_File = 'download_file';
export const IPC_Download_File_Complete = 'download_file_complete';
export const IPC_Download_File_Progress = 'download_file_progress';
export const IPC_Extract_Release = 'extract_release';
export const IPC_Extract_Release_Complete = 'extract_release_complete';
export const IPC_Get_Config = 'get_config';
export const IPC_Get_Config_Reply = 'get_config_reply';
export const IPC_Get_Config_Template = 'get_config_template';
export const IPC_Get_Config_Template_Reply = 'get_config_template_reply';
export const IPC_Get_Platform = 'get_platform';
export const IPC_Get_Platform_Reply = 'get_platform_reply';
export const IPC_Get_State = 'get_state';
export const IPC_Get_State_Reply = 'get_state_reply';
export const IPC_Grab_Releases = 'grab_releases';
export const IPC_Grab_Releases_Reply = 'grab_releases_reply';
export const IPC_Grab_UI_Releases = 'grab_ui_releases';
export const IPC_Grab_UI_Releases_Reply = 'grab_ui_releases_reply';
export const IPC_Install_Dependency = 'install_dependency';
export const IPC_Install_Dependency_Reply = 'install_dependency_reply';
export const IPC_Install_Upgrade = 'install_upgrade';
export const IPC_Install_Upgrade_Reply = 'install_upgrade_reply';
export const IPC_Mount_Drive = 'mount_drive';
export const IPC_Mount_Drive_Reply = 'mount_drive_reply';
export const IPC_Save_State = 'save_state';
export const IPC_Set_Config_Values = 'set_config_values';
export const IPC_Set_Config_Values_Reply = 'set_config_values_reply';
export const IPC_Unmount_Drive = 'unmount_drive';
export const IPC_Unmount_Drive_Reply = 'unmount_drive_reply';

View File

@@ -3,6 +3,7 @@ import styles from './Configuration.css';
import Box from '../../components/UI/Box/Box';
import Button from '../../components/UI/Button/Button';
import ConfigurationItem from '../../components/ConfigurationItem/ConfigurationItem';
import * as Constants from '../../constants';
import CSSModules from 'react-css-modules';
import Modal from '../../components/UI/Modal/Modal';
@@ -15,11 +16,11 @@ class Configuration extends Component {
constructor(props) {
super(props);
if (ipcRenderer) {
ipcRenderer.on('get_config_template_reply', this.onGetConfigTemplateReply);
ipcRenderer.on('get_config_reply', this.onGetConfigReply);
ipcRenderer.on('set_config_values_reply', this.onSetConfigValuesReply);
ipcRenderer.on(Constants.IPC_Get_Config_Template_Reply, this.onGetConfigTemplateReply);
ipcRenderer.on(Constants.IPC_Get_Config_Reply, this.onGetConfigReply);
ipcRenderer.on(Constants.IPC_Set_Config_Values_Reply, this.onSetConfigValuesReply);
ipcRenderer.send('get_config_template', {
ipcRenderer.send(Constants.IPC_Get_Config_Template, {
Directory: this.props.directory,
StorageType: this.props.storageType,
Version: this.props.version,
@@ -78,9 +79,9 @@ class Configuration extends Component {
componentWillUnmount = () => {
if (ipcRenderer) {
ipcRenderer.removeListener('get_config_reply', this.onGetConfigReply);
ipcRenderer.removeListener('get_config_template_reply', this.onGetConfigTemplateReply);
ipcRenderer.removeListener('set_config_values', this.onSetConfigValuesReply);
ipcRenderer.removeListener(Constants.IPC_Get_Config_Reply, this.onGetConfigReply);
ipcRenderer.removeListener(Constants.IPC_Get_Config_Template_Reply, this.onGetConfigTemplateReply);
ipcRenderer.removeListener(Constants.IPC_Set_Config_Values_Reply, this.onSetConfigValuesReply);
}
};
@@ -161,7 +162,7 @@ class Configuration extends Component {
this.setState({
Template: arg.data.Template,
});
ipcRenderer.send('get_config', {
ipcRenderer.send(Constants.IPC_Get_Config, {
Directory: this.props.directory,
StorageType: this.props.storageType,
Version: this.props.version,
@@ -198,7 +199,7 @@ class Configuration extends Component {
}
}
ipcRenderer.send('set_config_values', {
ipcRenderer.send(Constants.IPC_Set_Config_Values, {
Directory: this.props.directory,
Items: changedItems,
StorageType: this.props.storageType,

View File

@@ -1,8 +1,12 @@
import React from 'react';
import {Component} from 'react';
import * as Constants from '../../constants';
import CSSModules from 'react-css-modules';
import styles from './MountItems.css';
import MountItem from '../../components/MountItem/MountItem';
import {IPC_Detect_Mounts} from "../../constants";
import {IPC_Mount_Drive} from "../../constants";
import {IPC_Unmount_Drive} from "../../constants";
let ipcRenderer = null;
if (!process.versions.hasOwnProperty('electron')) {
@@ -13,9 +17,9 @@ class MountItems extends Component {
constructor(props) {
super(props);
if (ipcRenderer) {
ipcRenderer.on('detect_mounts_reply', this.onDetectMountsReply);
ipcRenderer.on('mount_drive_reply', this.onMountDriveReply);
ipcRenderer.on('unmount_drive_reply', this.onUnmountDriveReply);
ipcRenderer.on(Constants.IPC_Detect_Mounts_Reply, this.onDetectMountsReply);
ipcRenderer.on(Constants.IPC_Mount_Drive_Reply, this.onMountDriveReply);
ipcRenderer.on(Constants.IPC_Unmount_Drive_Reply, this.onUnmountDriveReply);
this.detectMounts();
}
@@ -38,15 +42,15 @@ class MountItems extends Component {
componentWillUnmount = () => {
if (ipcRenderer) {
ipcRenderer.removeListener('detect_mounts_reply', this.onDetectMountsReply);
ipcRenderer.removeListener('mount_drive_reply', this.onMountDriveReply);
ipcRenderer.removeListener('unmount_drive_reply', this.onUnmountDriveReply);
ipcRenderer.removeListener(Constants.IPC_Detect_Mounts_Reply, this.onDetectMountsReply);
ipcRenderer.removeListener(Constants.IPC_Mount_Drive_Reply, this.onMountDriveReply);
ipcRenderer.removeListener(Constants.IPC_Unmount_Drive_Reply, this.onUnmountDriveReply);
}
};
detectMounts = ()=> {
this.props.mountsBusy(true);
ipcRenderer.send('detect_mounts', {
ipcRenderer.send(IPC_Detect_Mounts, {
Directory: this.props.directory,
Version: this.props.version,
});
@@ -74,14 +78,14 @@ class MountItems extends Component {
this.props.mountsBusy(true);
if (mount) {
ipcRenderer.send('mount_drive', {
ipcRenderer.send(IPC_Mount_Drive, {
Directory: this.props.directory,
Location: location,
StorageType: storageType,
Version: this.props.version,
});
} else {
ipcRenderer.send('unmount_drive', {
ipcRenderer.send(IPC_Unmount_Drive, {
Directory: this.props.directory,
Location: location,
PID: pid,