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) {
|
||||||
|
|||||||
35
src/index.js
35
src/index.js
@@ -3,30 +3,29 @@ 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') {
|
const root = document.documentElement;
|
||||||
const root = document.documentElement;
|
root.style.setProperty('--default_font_size', '15px');
|
||||||
root.style.setProperty('--default_font_size', '15px');
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const store = createAppStore(arg.Platform, arg.AppPlatform, packageJson.version);
|
const store = createAppStore(arg.Platform, arg.AppPlatform, packageJson.version);
|
||||||
ReactDOM.render((
|
ReactDOM.render((
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<App />
|
<App/>
|
||||||
</Provider>
|
</Provider>
|
||||||
), document.getElementById('root'));
|
), document.getElementById('root'));
|
||||||
serviceWorker.unregister();
|
serviceWorker.unregister();
|
||||||
});
|
});
|
||||||
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,30 +23,28 @@ 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));
|
|
||||||
|
|
||||||
const downloadFileProgress = (_, arg) => {
|
const downloadFileProgress = (_, arg) => {
|
||||||
dispatch(setDownloadProgress(arg.data.Progress));
|
dispatch(setDownloadProgress(arg.data.Progress));
|
||||||
};
|
};
|
||||||
|
|
||||||
const downloadFileComplete = (_, arg) => {
|
const downloadFileComplete = (_, arg) => {
|
||||||
ipcRenderer.removeListener(Constants.IPC_Download_File_Progress, downloadFileProgress);
|
ipcRenderer.removeListener(Constants.IPC_Download_File_Progress, downloadFileProgress);
|
||||||
ipcRenderer.removeListener(Constants.IPC_Download_File_Complete, downloadFileComplete);
|
ipcRenderer.removeListener(Constants.IPC_Download_File_Complete, downloadFileComplete);
|
||||||
completedCallback(name, type, url, arg.data);
|
completedCallback(name, type, url, arg.data);
|
||||||
dispatch(setDownloadEnd(arg.data));
|
dispatch(setDownloadEnd(arg.data));
|
||||||
};
|
};
|
||||||
|
|
||||||
ipcRenderer.on(Constants.IPC_Download_File_Progress, downloadFileProgress);
|
ipcRenderer.on(Constants.IPC_Download_File_Progress, downloadFileProgress);
|
||||||
ipcRenderer.on(Constants.IPC_Download_File_Complete, downloadFileComplete);
|
ipcRenderer.on(Constants.IPC_Download_File_Complete, downloadFileComplete);
|
||||||
|
|
||||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||||
Filename: name,
|
Filename: name,
|
||||||
URL: url,
|
URL: url,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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