Refactoring
This commit is contained in:
200
src/App.js
200
src/App.js
@@ -5,81 +5,51 @@ import Configuration from './containers/Configuration/Configuration';
|
||||
import {connect} from 'react-redux';
|
||||
import DependencyList from './components/DependencyList/DependencyList';
|
||||
import DownloadProgress from './components/DownloadProgress/DownloadProgress';
|
||||
import {extractFileNameFromURL} from './utils';
|
||||
import ErrorDetails from './components/ErrorDetails/ErrorDetails';
|
||||
import Grid from './components/UI/Grid/Grid';
|
||||
import IPCContainer from './containers/IPCContainer/IPCContainer';
|
||||
import Loading from './components/UI/Loading/Loading';
|
||||
import Modal from './components/UI/Modal/Modal';
|
||||
import MountItems from './containers/MountItems/MountItems';
|
||||
import {notifyError} from './redux/actions/error_actions';
|
||||
import ReleaseVersionDisplay from './components/ReleaseVersionDisplay/ReleaseVersionDisplay';
|
||||
import {setProviderState} from './redux/actions/mount_actions';
|
||||
import Text from './components/UI/Text/Text';
|
||||
import UpgradeIcon from './components/UpgradeIcon/UpgradeIcon';
|
||||
import UpgradeUI from './components/UpgradeUI/UpgradeUI';
|
||||
import {checkVersionInstalled} from './redux/actions/install_actions';
|
||||
import {
|
||||
downloadItem,
|
||||
setAllowDownload
|
||||
} from './redux/actions/download_actions';
|
||||
import {
|
||||
checkInstalled,
|
||||
installDependency,
|
||||
installRelease,
|
||||
installUpgrade
|
||||
} from './redux/actions/install_actions';
|
||||
import {
|
||||
detectUIUpgrade,
|
||||
loadReleases,
|
||||
setActiveRelease,
|
||||
setDismissUIUpgrade,
|
||||
setInstalledVersion,
|
||||
setReleaseUpgradeAvailable
|
||||
setDismissUIUpgrade
|
||||
} from './redux/actions/release_version_actions';
|
||||
import {saveState} from './redux/actions/common_actions';
|
||||
|
||||
const Constants = require('./constants');
|
||||
const Scheduler = require('node-schedule');
|
||||
|
||||
class App extends IPCContainer {
|
||||
checkVersionInstalled = () => {
|
||||
this.props.setAllowDownload(false);
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
if (selectedVersion !== 'unavailable') {
|
||||
let dependencies = [];
|
||||
if (this.props.LocationsLookup[selectedVersion] && this.props.LocationsLookup[selectedVersion].dependencies) {
|
||||
dependencies = this.props.LocationsLookup[selectedVersion].dependencies;
|
||||
}
|
||||
|
||||
this.props.checkInstalled(dependencies, selectedVersion);
|
||||
} else {
|
||||
this.props.setInstalledVersion('none');
|
||||
this.props.setAllowDownload(true);
|
||||
}
|
||||
};
|
||||
|
||||
_isMounted = false;
|
||||
|
||||
componentDidMount() {
|
||||
this._isMounted = true;
|
||||
this.scheduledUpdateJob = Scheduler.scheduleJob('23 11 * * *', this.updateCheckScheduledJob);
|
||||
this.detectUpgrades();
|
||||
const detectUpgrades = () => {
|
||||
if (this.props.AppPlatform !== 'unknown') {
|
||||
this.props.loadReleases();
|
||||
}
|
||||
};
|
||||
this.scheduledUpdateJob = Scheduler.scheduleJob('23 11 * * *', detectUpgrades);
|
||||
detectUpgrades();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if ((prevProps.Release !== this.props.Release) ||
|
||||
(prevProps.ReleaseVersion !== this.props.ReleaseVersion) ||
|
||||
(prevProps.VersionLookup !== this.props.VersionLookup)) {
|
||||
this.saveState();
|
||||
this.checkVersionInstalled();
|
||||
this.props.saveState();
|
||||
this.props.checkVersionInstalled();
|
||||
} else if (Object.keys(this.props.ProviderState).filter(k=> {
|
||||
return this.props.ProviderState[k] !== prevProps.ProviderState[k];
|
||||
}).length > 0) {
|
||||
this.saveState();
|
||||
this.props.saveState();
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this._isMounted = false;
|
||||
Scheduler.cancelJob(this.scheduledUpdateJob);
|
||||
super.componentWillUnmount();
|
||||
}
|
||||
@@ -89,129 +59,12 @@ class App extends IPCContainer {
|
||||
return condition ? (<Modal {...modalProps}>{jsx}</Modal>) : null;
|
||||
};
|
||||
|
||||
detectUpgrades = () => {
|
||||
if (this.props.AppPlatform !== 'unknown') {
|
||||
this.props.loadReleases();
|
||||
this.props.detectUIUpgrade();
|
||||
}
|
||||
};
|
||||
|
||||
getSelectedVersion = () => {
|
||||
return (this.props.ReleaseVersion === -1) ?
|
||||
'unavailable' :
|
||||
this.props.VersionLookup[Constants.RELEASE_TYPES[this.props.Release]][this.props.ReleaseVersion];
|
||||
};
|
||||
|
||||
handleDownloadDependency = url => {
|
||||
this.props.downloadItem(extractFileNameFromURL(url), Constants.INSTALL_TYPES.Dependency, url, this.onDownloadFileComplete);
|
||||
};
|
||||
|
||||
handleDownloadRelease = () => {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
const fileName = selectedVersion + '.zip';
|
||||
this.props.downloadItem(fileName, Constants.INSTALL_TYPES.Release, this.props.LocationsLookup[selectedVersion].urls, this.onDownloadFileComplete);
|
||||
};
|
||||
|
||||
handleDownloadUpgrade = () => {
|
||||
const name = (this.props.Platform === 'win32') ?
|
||||
'upgrade.exe' :
|
||||
(this.props.Platform === 'darwin') ?
|
||||
'upgrade.dmg' :
|
||||
'repertory-ui_' + this.props.UpgradeVersion + '_linux_x86_64.AppImage';
|
||||
this.props.downloadItem(name, Constants.INSTALL_TYPES.Upgrade, this.props.UpgradeData.urls, this.onDownloadFileComplete);
|
||||
};
|
||||
|
||||
installDependency = result => {
|
||||
if (result.Success) {
|
||||
this.props.installDependency(result.Destination, result.URL, this.onInstallDependencyComplete);
|
||||
}
|
||||
};
|
||||
|
||||
installRelease = result => {
|
||||
if (result.Success) {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
this.props.installRelease(result.Destination, selectedVersion, () => {
|
||||
if (this._isMounted) {
|
||||
this.checkVersionInstalled();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
installUpgrade = result => {
|
||||
if (result.Success) {
|
||||
//const info = this.props.LocationsLookup[this.props.AppPlatform][this.props.VersionLookup[this.props.AppPlatform][0]];
|
||||
const sha256 = null;//info.sha256;
|
||||
const signature = null;//info.sig;
|
||||
this.props.installUpgrade(result.Destination, sha256, signature, !!result.SkipVerification, this.onInstallUpgradeComplete);
|
||||
}
|
||||
};
|
||||
|
||||
onDownloadFileComplete = (name, type, url, result) => {
|
||||
if (this._isMounted) {
|
||||
switch (type) {
|
||||
case Constants.INSTALL_TYPES.Dependency:
|
||||
this.installDependency(result);
|
||||
break;
|
||||
case Constants.INSTALL_TYPES.Release:
|
||||
this.installRelease(result);
|
||||
break;
|
||||
case Constants.INSTALL_TYPES.Upgrade:
|
||||
this.installUpgrade(result);
|
||||
break;
|
||||
default:
|
||||
this.props.notifyError('Unknown download type: ' + type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onInstallDependencyComplete = () => {
|
||||
if (this._isMounted) {
|
||||
this.checkVersionInstalled();
|
||||
}
|
||||
};
|
||||
|
||||
onInstallUpgradeComplete = (source, result) => {
|
||||
if (this._isMounted && !result.Success) {
|
||||
this.props.notifyError(result.Error, false,() => {
|
||||
if (this._isMounted) {
|
||||
// TODO Prompt to verify
|
||||
if (result.AllowSkipVerification) {
|
||||
this.installUpgrade({
|
||||
SkipVerification: true,
|
||||
Source: source,
|
||||
Success: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
};
|
||||
|
||||
saveState = () => {
|
||||
if (this.props.AppReady) {
|
||||
let state = {
|
||||
Release: this.props.Release,
|
||||
Version: this.props.ReleaseVersion,
|
||||
};
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
state[provider] = this.props.ProviderState[provider];
|
||||
}
|
||||
|
||||
this.sendRequest(Constants.IPC_Save_State, {
|
||||
State: state
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
updateCheckScheduledJob = () => {
|
||||
if (this.props.AppPlatform !== 'unknown') {
|
||||
this.detectUpgrades();
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
|
||||
@@ -251,10 +104,10 @@ class App extends IPCContainer {
|
||||
!this.props.DownloadActive;
|
||||
|
||||
const configDisplay = this.createModalConditionally(showConfig, <Configuration version={selectedVersion} />);
|
||||
const dependencyDisplay = this.createModalConditionally(showDependencies, <DependencyList onDownload={this.handleDownloadDependency}/>);
|
||||
const dependencyDisplay = this.createModalConditionally(showDependencies, <DependencyList/>);
|
||||
const downloadDisplay = this.createModalConditionally(this.props.DownloadActive, <DownloadProgress/>);
|
||||
const errorDisplay = this.createModalConditionally(this.props.DisplayError, <ErrorDetails/>, true);
|
||||
const upgradeDisplay = this.createModalConditionally(showUpgrade, <UpgradeUI upgrade={this.handleDownloadUpgrade}/>);
|
||||
const upgradeDisplay = this.createModalConditionally(showUpgrade, <UpgradeUI/>);
|
||||
|
||||
let mainContent = [];
|
||||
if (this.props.AppReady) {
|
||||
@@ -262,8 +115,8 @@ class App extends IPCContainer {
|
||||
mainContent.push((
|
||||
<div key={'rvd_' + key++}
|
||||
style={{height: '32%'}}>
|
||||
<ReleaseVersionDisplay downloadClicked={this.handleDownloadRelease}
|
||||
downloadDisabled={!downloadEnabled}/>
|
||||
<ReleaseVersionDisplay downloadDisabled={!downloadEnabled}
|
||||
version={selectedVersion}/>
|
||||
</div>
|
||||
));
|
||||
|
||||
@@ -327,21 +180,16 @@ const mapStateToProps = state => {
|
||||
DisplayConfiguration: state.mounts.DisplayConfiguration,
|
||||
DisplayError: state.error.DisplayError,
|
||||
DownloadActive: state.download.DownloadActive,
|
||||
DownloadType: state.download.DownloadType,
|
||||
InstallActive: state.install.InstallActive,
|
||||
InstallType: state.install.InstallType,
|
||||
InstalledVersion: state.relver.InstalledVersion,
|
||||
LocationsLookup: state.relver.LocationsLookup,
|
||||
MissingDependencies: state.install.MissingDependencies,
|
||||
MountsBusy: state.mounts.MountsBusy,
|
||||
Platform: state.common.Platform,
|
||||
ProviderState: state.mounts.ProviderState,
|
||||
Release: state.relver.Release,
|
||||
ReleaseVersion: state.relver.Version,
|
||||
UpgradeAvailable: state.relver.UpgradeAvailable,
|
||||
UpgradeData: state.relver.UpgradeData,
|
||||
UpgradeDismissed: state.relver.UpgradeDismissed,
|
||||
UpgradeVersion: state.relver.UpgradeVersion,
|
||||
Version: state.common.Version,
|
||||
VersionLookup: state.relver.VersionLookup,
|
||||
};
|
||||
@@ -349,20 +197,10 @@ const mapStateToProps = state => {
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
checkInstalled: (dependencies, version) => dispatch(checkInstalled(dependencies, version)),
|
||||
detectUIUpgrade: () => dispatch(detectUIUpgrade()),
|
||||
downloadItem: (name, type, url, completedCallback) => dispatch(downloadItem(name, type, url, completedCallback)),
|
||||
installDependency: (source, url, completedCallback) => dispatch(installDependency(source, url, completedCallback)),
|
||||
installRelease: (source, version, completedCallback) => dispatch(installRelease(source, version, completedCallback)),
|
||||
installUpgrade: (source, sha256, signature, skipVerification, completedCallback) => dispatch(installUpgrade(source, sha256, signature, skipVerification, completedCallback)),
|
||||
checkVersionInstalled: () => dispatch(checkVersionInstalled()),
|
||||
loadReleases: ()=> dispatch(loadReleases()),
|
||||
notifyError: (msg, critical, callback) => dispatch(notifyError(msg, critical, callback)),
|
||||
setActiveRelease: (release, version) => dispatch(setActiveRelease(release, version)),
|
||||
setAllowDownload: allow => dispatch(setAllowDownload(allow)),
|
||||
saveState: () => dispatch(saveState()),
|
||||
setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)),
|
||||
setInstalledVersion: version => dispatch(setInstalledVersion(version)),
|
||||
setProviderState: (provider, state) => dispatch(setProviderState(provider, state)),
|
||||
setReleaseUpgradeAvailable: available => dispatch(setReleaseUpgradeAvailable(available)),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export default connect(mapStateToProps)(props => {
|
||||
<a
|
||||
href={void(0)}
|
||||
className={'DependencyLink'}
|
||||
onClick={()=>{props.onDownload(props.download); return false;}}><u>Install</u></a> :
|
||||
onClick={()=>{props.onDownload(); return false;}}><u>Install</u></a> :
|
||||
'Installing...'}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import React from 'react';
|
||||
import './DependencyList.css';
|
||||
import {connect} from 'react-redux';
|
||||
import * as Constants from '../../constants';
|
||||
import Dependency from './Dependency/Dependency';
|
||||
import Box from '../UI/Box/Box';
|
||||
import {downloadItem} from '../../redux/actions/download_actions';
|
||||
import {extractFileNameFromURL} from '../../utils';
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
@@ -10,13 +13,18 @@ const mapStateToProps = state => {
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(props => {
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
downloadItem: (name, type, url) => dispatch(downloadItem(name, type, url))
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(props => {
|
||||
const items = props.MissingDependencies.map((k, i)=> {
|
||||
return (
|
||||
<Dependency download={k.download}
|
||||
key={i}
|
||||
<Dependency key={i}
|
||||
name={k.display}
|
||||
onDownload={props.onDownload}/>
|
||||
onDownload={()=>props.downloadItem(extractFileNameFromURL(k.download), Constants.INSTALL_TYPES.Dependency, k.download)}/>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import Text from '../UI/Text/Text';
|
||||
import Button from '../UI/Button/Button';
|
||||
import UpgradeIcon from '../UpgradeIcon/UpgradeIcon';
|
||||
import {setActiveRelease} from "../../redux/actions/release_version_actions";
|
||||
import {downloadItem} from '../../redux/actions/download_actions';
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
@@ -16,6 +17,7 @@ const mapStateToProps = state => {
|
||||
InstallActive: state.install.InstallActive,
|
||||
InstallType: state.install.InstallType,
|
||||
InstalledVersion: state.relver.InstalledVersion,
|
||||
LocationsLookup: state.relver.LocationsLookup,
|
||||
MountsBusy: state.mounts.MountsBusy,
|
||||
Release: state.relver.Release,
|
||||
ReleaseUpgradeAvailable: state.relver.ReleaseUpgradeAvailable,
|
||||
@@ -26,11 +28,17 @@ const mapStateToProps = state => {
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
downloadItem: (name, type, urls) => dispatch(downloadItem(name, type, urls)),
|
||||
setActiveRelease: (release, version) => dispatch(setActiveRelease(release, version)),
|
||||
}
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(props => {
|
||||
const handleDownloadRelease = () => {
|
||||
const fileName = props.version + '.zip';
|
||||
props.downloadItem(fileName, Constants.INSTALL_TYPES.Release, props.LocationsLookup[props.version].urls);
|
||||
};
|
||||
|
||||
const handleReleaseChanged = e => {
|
||||
const release = parseInt(e.target.value, 10);
|
||||
const releaseVersion = props.VersionLookup[Constants.RELEASE_TYPES[release]].length - 1;
|
||||
@@ -88,7 +96,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(props => {
|
||||
));
|
||||
} else {
|
||||
optionsDisplay.push((
|
||||
<Button clicked={props.downloadClicked}
|
||||
<Button clicked={handleDownloadRelease}
|
||||
col={dimensions => (dimensions.columns / 3) * 2}
|
||||
colSpan={20}
|
||||
key={key++}
|
||||
|
||||
@@ -1,17 +1,37 @@
|
||||
import {connect} from 'react-redux';
|
||||
import Button from '../UI/Button/Button';
|
||||
import Box from '../UI/Box/Box';
|
||||
import * as Constants from '../../constants';
|
||||
import React from 'react';
|
||||
import './UpgradeUI.css';
|
||||
import {setDismissUIUpgrade} from '../../redux/actions/release_version_actions';
|
||||
import {downloadItem} from '../../redux/actions/download_actions';
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
Platform: state.common.Platform,
|
||||
UpgradeData: state.relver.UpgradeData,
|
||||
UpgradeVersion: state.relver.UpgradeVersion,
|
||||
}
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
downloadItem: (name, type, urls) => dispatch(downloadItem(name, type, urls)),
|
||||
setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)),
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(null, mapDispatchToProps)(props => {
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(props => {
|
||||
const handleDownload = () => {
|
||||
const name = (props.Platform === 'win32') ?
|
||||
'upgrade.exe' :
|
||||
(props.Platform === 'darwin') ?
|
||||
'upgrade.dmg' :
|
||||
'repertory-ui_' + props.UpgradeVersion + '_linux_x86_64.AppImage';
|
||||
props.downloadItem(name, Constants.INSTALL_TYPES.Upgrade, props.UpgradeData.urls);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box dxStyle={{width: '180px', height: 'auto', padding: '5px'}}>
|
||||
<div style={{width: '100%', height: 'auto'}}>
|
||||
@@ -22,7 +42,7 @@ export default connect(null, mapDispatchToProps)(props => {
|
||||
<tr>
|
||||
<td width="50%">
|
||||
<Button buttonStyles={{width: '100%'}}
|
||||
clicked={props.upgrade}>Install</Button>
|
||||
clicked={handleDownload}>Install</Button>
|
||||
</td>
|
||||
<td width="50%">
|
||||
<Button buttonStyles={{width: '100%'}}
|
||||
|
||||
@@ -27,37 +27,21 @@ exports.DEV_PUBLIC_KEY = '-----BEGIN PUBLIC KEY-----\n' +
|
||||
'9wIDAQAB\n' +
|
||||
'-----END PUBLIC KEY-----';
|
||||
|
||||
exports.RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory/raw/master/releases.json';
|
||||
exports.UI_RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory-ui/raw/master/releases.json';
|
||||
exports.RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory/raw/1.0.0-release_branch/releases.json';
|
||||
exports.UI_RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory-ui/raw/1.0.5_branch/releases.json';
|
||||
|
||||
exports.DATA_LOCATIONS = {
|
||||
arch: '~/.local/repertory/ui',
|
||||
centos7: '~/.local/repertory/ui',
|
||||
debian9: '~/.local/repertory/ui',
|
||||
debian10: '~/.local/repertory/ui',
|
||||
fedora28: '~/.local/repertory/ui',
|
||||
fedora29: '~/.local/repertory/ui',
|
||||
fedora30: '~/.local/repertory/ui',
|
||||
linux: '~/.local/repertory/ui',
|
||||
opensuse15: '~/.local/repertory/ui',
|
||||
'opensuse15.1': '~/.local/repertory/ui',
|
||||
solus: '~/.local/repertory/ui',
|
||||
tumbleweed: '~/.local/repertory/ui',
|
||||
'ubuntu18.04': '~/.local/repertory/ui',
|
||||
'ubuntu18.10': '~/.local/repertory/ui',
|
||||
'ubuntu19.04': '~/.local/repertory/ui',
|
||||
darwin: '~/Library/Application Support/repertory/ui',
|
||||
win32: '%LOCALAPPDATA%\\repertory\\ui'
|
||||
};
|
||||
|
||||
exports.PROVIDER_LIST = [
|
||||
//'Hyperspace',
|
||||
'Sia',
|
||||
'SiaPrime'
|
||||
];
|
||||
|
||||
exports.PROVIDER_ARG = {
|
||||
//hyperspace: '-hs',
|
||||
sia: '',
|
||||
siaprime: '-sp'
|
||||
};
|
||||
|
||||
@@ -21,4 +21,26 @@ export const shutdownApplication = () => {
|
||||
ipcRenderer.send(Constants.IPC_Shutdown);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const saveState = () => {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
if (state.common.AppReady) {
|
||||
let currentState = {
|
||||
Release: state.relver.Release,
|
||||
Version: state.relver.Version,
|
||||
};
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
currentState[provider] = currentState.mounts.ProviderState[provider];
|
||||
}
|
||||
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.send(Constants.IPC_Save_State, {
|
||||
State: currentState
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -1,6 +1,12 @@
|
||||
import * as Constants from '../../constants';
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
import {notifyError} from './error_actions';
|
||||
import {
|
||||
installDependency,
|
||||
installRelease,
|
||||
installUpgrade
|
||||
} from './install_actions';
|
||||
|
||||
export const setAllowDownload = createAction('download/setAllowDownload');
|
||||
|
||||
@@ -19,12 +25,36 @@ export const setDownloadBegin = (name, type, url) => {
|
||||
export const setDownloadEnd = createAction('download/setDownloadEnd');
|
||||
export const setDownloadProgress = createAction('download/setDownloadProgress');
|
||||
|
||||
export const downloadItem = (name, type, urls, completedCallback) => {
|
||||
export const downloadItem = (name, type, urls) => {
|
||||
return (dispatch, getState) => {
|
||||
if (!Array.isArray(urls)) {
|
||||
urls = [urls];
|
||||
}
|
||||
|
||||
const downloadComplete = result => {
|
||||
if (result.Success) {
|
||||
switch (type) {
|
||||
case Constants.INSTALL_TYPES.Dependency:
|
||||
dispatch(installDependency(result.Destination, result.URL));
|
||||
break;
|
||||
case Constants.INSTALL_TYPES.Release:
|
||||
dispatch(installRelease(result.Destination));
|
||||
break;
|
||||
case Constants.INSTALL_TYPES.Upgrade:
|
||||
//const info = this.props.LocationsLookup[this.props.AppPlatform][this.props.VersionLookup[this.props.AppPlatform][0]];
|
||||
const sha256 = null;//info.sha256;
|
||||
const signature = null;//info.sig;
|
||||
dispatch(installUpgrade(result.Destination, sha256, signature, !!result.SkipVerification));
|
||||
break;
|
||||
default:
|
||||
dispatch(notifyError('Unknown download type: ' + type));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
dispatch(notifyError(result.Error));
|
||||
}
|
||||
};
|
||||
|
||||
const downloadAtIndex = index => {
|
||||
const url = urls[index];
|
||||
const state = getState();
|
||||
@@ -42,7 +72,7 @@ export const downloadItem = (name, type, urls, completedCallback) => {
|
||||
if (!arg.data.Success && (++index < urls.length)) {
|
||||
downloadAtIndex(index);
|
||||
} else {
|
||||
completedCallback(name, type, url, arg.data);
|
||||
downloadComplete(arg.data);
|
||||
dispatch(setDownloadEnd(arg.data));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as Constants from '../../constants';
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
import {
|
||||
getIPCRenderer,
|
||||
getSelectedVersionFromState
|
||||
} from '../../utils';
|
||||
import {notifyError} from './error_actions';
|
||||
import {setAllowDownload} from './download_actions';
|
||||
import {
|
||||
@@ -55,7 +58,26 @@ export const checkInstalled = (dependencies, version) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const installDependency = (source, url, completedCallback) => {
|
||||
export const checkVersionInstalled = () => {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
|
||||
dispatch(setAllowDownload(false));
|
||||
const selectedVersion = getSelectedVersionFromState(state);
|
||||
if (selectedVersion && (selectedVersion !== 'unavailable')) {
|
||||
let dependencies = [];
|
||||
if (state.relver.LocationsLookup[selectedVersion] && state.relver.LocationsLookup[selectedVersion].dependencies) {
|
||||
dependencies = state.relver.LocationsLookup[selectedVersion].dependencies;
|
||||
}
|
||||
dispatch(checkInstalled(dependencies, selectedVersion));
|
||||
} else {
|
||||
dispatch(setInstalledVersion('none'));
|
||||
dispatch(setAllowDownload(true));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const installDependency = (source, url) => {
|
||||
return (dispatch, getState) => {
|
||||
if (ipcRenderer && !getState().install.InstallActive) {
|
||||
dispatch(setInstallActive(Constants.INSTALL_TYPES.Dependency));
|
||||
@@ -67,7 +89,7 @@ export const installDependency = (source, url, completedCallback) => {
|
||||
FilePath: source,
|
||||
});
|
||||
dispatch(setInstallComplete(result));
|
||||
completedCallback(source, url, result);
|
||||
dispatch(checkVersionInstalled());
|
||||
};
|
||||
|
||||
if (result.Success && source.toLowerCase().endsWith('.dmg')) {
|
||||
@@ -100,18 +122,19 @@ export const installDependency = (source, url, completedCallback) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const installRelease = (source, version, completedCallback) => {
|
||||
export const installRelease = source => {
|
||||
return (dispatch, getState) => {
|
||||
if (ipcRenderer && !getState().install.InstallActive) {
|
||||
dispatch(setInstallActive(Constants.INSTALL_TYPES.Release));
|
||||
|
||||
const version = getSelectedVersionFromState(getState());
|
||||
const extractReleaseComplete = (event, arg) => {
|
||||
ipcRenderer.send(Constants.IPC_Delete_File, {
|
||||
FilePath: source,
|
||||
});
|
||||
|
||||
dispatch(setInstallComplete(arg.data));
|
||||
completedCallback(source, version, arg.data);
|
||||
dispatch(checkVersionInstalled());
|
||||
};
|
||||
|
||||
ipcRenderer.once(Constants.IPC_Extract_Release_Complete, extractReleaseComplete);
|
||||
@@ -123,19 +146,25 @@ export const installRelease = (source, version, completedCallback) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const installUpgrade = (source, sha256, signature, skipVerification, completedCallback) => {
|
||||
export const installUpgrade = (source, sha256, signature, skipVerification) => {
|
||||
return (dispatch, getState) => {
|
||||
if (ipcRenderer && !getState().install.InstallActive) {
|
||||
dispatch(setInstallActive(Constants.INSTALL_TYPES.Upgrade));
|
||||
dispatch(setApplicationReady(false));
|
||||
|
||||
const installUpgradeComplete = (event, arg) => {
|
||||
if (arg.data.Success) {
|
||||
const result = arg.data;
|
||||
if (result.Success) {
|
||||
dispatch(shutdownApplication());
|
||||
} else {
|
||||
dispatch(setApplicationReady(true));
|
||||
dispatch(setInstallComplete(arg.data));
|
||||
completedCallback(source, arg.data);
|
||||
dispatch(setInstallComplete(result));
|
||||
dispatch(notifyError(result.Error, false, () => {
|
||||
// TODO Prompt to verify
|
||||
if (result.AllowSkipVerification) {
|
||||
dispatch(installUpgrade(source, sha256, signature, true));
|
||||
}
|
||||
}, false));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ export const loadReleases = () => {
|
||||
}
|
||||
dispatch(setReleaseUpgradeAvailable((version !== latestVersion)));
|
||||
dispatch(setApplicationReady(true));
|
||||
dispatch(detectUIUpgrade());
|
||||
};
|
||||
|
||||
axios
|
||||
|
||||
@@ -16,7 +16,7 @@ const versionLookup = Constants.RELEASE_TYPES.map(k=> {
|
||||
export const releaseVersionReducer = createReducer({
|
||||
InstalledVersion: 'none',
|
||||
LocationsLookup: {},
|
||||
Release: 1,
|
||||
Release: 0,
|
||||
ReleaseUpgradeAvailable: false,
|
||||
UpgradeAvailable: false,
|
||||
UpgradeData: null,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as Constants from './constants';
|
||||
|
||||
const ipcRenderer = (!process.versions.hasOwnProperty('electron') && window && window.require) ?
|
||||
window.require('electron').ipcRenderer :
|
||||
null;
|
||||
@@ -11,3 +13,9 @@ export const getIPCRenderer = () => {
|
||||
return ipcRenderer;
|
||||
};
|
||||
|
||||
export const getSelectedVersionFromState = state => {
|
||||
return (state.relver.Version === -1) ?
|
||||
'unavailable' :
|
||||
state.relver.VersionLookup[Constants.RELEASE_TYPES[state.relver.Release]][state.relver.Version];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user