Refactoring
This commit is contained in:
10
src/App.js
10
src/App.js
@@ -5,6 +5,7 @@ import Configuration from './containers/Configuration/Configuration';
|
|||||||
import {connect} from 'react-redux';
|
import {connect} from 'react-redux';
|
||||||
import DependencyList from './components/DependencyList/DependencyList';
|
import DependencyList from './components/DependencyList/DependencyList';
|
||||||
import DownloadProgress from './components/DownloadProgress/DownloadProgress';
|
import DownloadProgress from './components/DownloadProgress/DownloadProgress';
|
||||||
|
import {extractFileNameFromURL} from './utils';
|
||||||
import ErrorDetails from './components/ErrorDetails/ErrorDetails';
|
import ErrorDetails from './components/ErrorDetails/ErrorDetails';
|
||||||
import Grid from './components/UI/Grid/Grid';
|
import Grid from './components/UI/Grid/Grid';
|
||||||
import IPCContainer from './containers/IPCContainer/IPCContainer';
|
import IPCContainer from './containers/IPCContainer/IPCContainer';
|
||||||
@@ -93,11 +94,6 @@ class App extends IPCContainer {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extractFileNameFromURL = url => {
|
|
||||||
const parts = url.split('/');
|
|
||||||
return parts[parts.length - 1];
|
|
||||||
};
|
|
||||||
|
|
||||||
getSelectedVersion = () => {
|
getSelectedVersion = () => {
|
||||||
return (this.props.ReleaseVersion === -1) ?
|
return (this.props.ReleaseVersion === -1) ?
|
||||||
'unavailable' :
|
'unavailable' :
|
||||||
@@ -105,7 +101,7 @@ class App extends IPCContainer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
handleDownloadDependency = url => {
|
handleDownloadDependency = url => {
|
||||||
this.props.downloadItem(this.extractFileNameFromURL(url), Constants.INSTALL_TYPES.Dependency, url, this.onDownloadFileComplete);
|
this.props.downloadItem(extractFileNameFromURL(url), Constants.INSTALL_TYPES.Dependency, url, this.onDownloadFileComplete);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDownloadRelease = () => {
|
handleDownloadRelease = () => {
|
||||||
@@ -116,7 +112,7 @@ class App extends IPCContainer {
|
|||||||
|
|
||||||
handleDownloadUpgrade = () => {
|
handleDownloadUpgrade = () => {
|
||||||
const url = this.props.UpgradeData.urls[0];
|
const url = this.props.UpgradeData.urls[0];
|
||||||
const name = this.props.Platform === 'win32' ? 'upgrade.exe' : this.extractFileNameFromURL(url);
|
const name = this.props.Platform === 'win32' ? 'upgrade.exe' : extractFileNameFromURL(url);
|
||||||
this.props.downloadItem(name, Constants.INSTALL_TYPES.Upgrade, url, this.onDownloadFileComplete);
|
this.props.downloadItem(name, Constants.INSTALL_TYPES.Upgrade, url, this.onDownloadFileComplete);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
import {Component} from 'react';
|
import {Component} from 'react';
|
||||||
|
import {getIPCRenderer} from '../../utils';
|
||||||
|
|
||||||
export default class extends Component {
|
export default class extends Component {
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
|
|
||||||
if (!process.versions.hasOwnProperty('electron')) {
|
|
||||||
this.ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handlerList = {};
|
handlerList = {};
|
||||||
ipcRenderer;
|
ipcRenderer = getIPCRenderer();
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
if (this.ipcRenderer) {
|
if (this.ipcRenderer) {
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ import ReactDOM from 'react-dom';
|
|||||||
import './index.css';
|
import './index.css';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import createAppStore from './redux/store/createAppStore';
|
import createAppStore from './redux/store/createAppStore';
|
||||||
|
import {getIPCRenderer} from './utils';
|
||||||
import packageJson from '../package.json';
|
import packageJson from '../package.json';
|
||||||
import {Provider} from 'react-redux';
|
import {Provider} from 'react-redux';
|
||||||
import * as serviceWorker from './serviceWorker';
|
import * as serviceWorker from './serviceWorker';
|
||||||
|
|
||||||
const Constants = require('./constants');
|
const Constants = require('./constants');
|
||||||
|
|
||||||
if (!process.versions.hasOwnProperty('electron')) {
|
const ipcRenderer = getIPCRenderer();
|
||||||
const ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
|
||||||
if (ipcRenderer) {
|
if (ipcRenderer) {
|
||||||
ipcRenderer.on(Constants.IPC_Get_Platform_Reply, (event, arg) => {
|
ipcRenderer.on(Constants.IPC_Get_Platform_Reply, (event, arg) => {
|
||||||
if (arg.Platform === 'linux') {
|
if (arg.Platform === 'linux') {
|
||||||
@@ -28,5 +28,4 @@ if (!process.versions.hasOwnProperty('electron')) {
|
|||||||
});
|
});
|
||||||
ipcRenderer.send(Constants.IPC_Get_Platform);
|
ipcRenderer.send(Constants.IPC_Get_Platform);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import * as Constants from '../../constants';
|
import * as Constants from '../../constants';
|
||||||
import {createAction} from 'redux-starter-kit';
|
import {createAction} from 'redux-starter-kit';
|
||||||
|
import {getIPCRenderer} from '../../utils';
|
||||||
|
|
||||||
let ipcRenderer;
|
const ipcRenderer = getIPCRenderer();
|
||||||
if (!process.versions.hasOwnProperty('electron')) {
|
|
||||||
ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const setApplicationReady = createAction('common/setApplicationReady');
|
export const setApplicationReady = createAction('common/setApplicationReady');
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as Constants from '../../constants';
|
import * as Constants from '../../constants';
|
||||||
import {createAction} from 'redux-starter-kit';
|
import {createAction} from 'redux-starter-kit';
|
||||||
|
import {getIPCRenderer} from '../../utils';
|
||||||
|
|
||||||
export const setAllowDownload = createAction('download/setAllowDownload');
|
export const setAllowDownload = createAction('download/setAllowDownload');
|
||||||
|
|
||||||
@@ -22,8 +23,7 @@ export const downloadItem = (name, type, url, completedCallback) => {
|
|||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
if (!state.download.DownloadActive && state.download.AllowDownload) {
|
if (!state.download.DownloadActive && state.download.AllowDownload) {
|
||||||
if (!process.versions.hasOwnProperty('electron')) {
|
const ipcRenderer = getIPCRenderer();
|
||||||
const ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
|
||||||
if (ipcRenderer) {
|
if (ipcRenderer) {
|
||||||
dispatch(setDownloadBegin(name, type, url));
|
dispatch(setDownloadBegin(name, type, url));
|
||||||
|
|
||||||
@@ -47,6 +47,5 @@ export const downloadItem = (name, type, url, completedCallback) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
import * as Constants from '../../constants';
|
import * as Constants from '../../constants';
|
||||||
import {createAction} from 'redux-starter-kit';
|
import {createAction} from 'redux-starter-kit';
|
||||||
|
import {getIPCRenderer} from '../../utils';
|
||||||
|
|
||||||
let ipcRenderer;
|
const ipcRenderer = getIPCRenderer();
|
||||||
if (!process.versions.hasOwnProperty('electron')) {
|
|
||||||
ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const installDependency = (source, url, completedCallback) => {
|
export const installDependency = (source, url, completedCallback) => {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
|
|||||||
13
src/utils.js
Normal file
13
src/utils.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
const ipcRenderer = (!process.versions.hasOwnProperty('electron') && window && window.require) ?
|
||||||
|
window.require('electron').ipcRenderer :
|
||||||
|
null;
|
||||||
|
|
||||||
|
export const extractFileNameFromURL = url => {
|
||||||
|
const parts = url.split('/');
|
||||||
|
return parts[parts.length - 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getIPCRenderer = () => {
|
||||||
|
return ipcRenderer;
|
||||||
|
};
|
||||||
|
|
||||||
Reference in New Issue
Block a user