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 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';
|
||||
@@ -93,11 +94,6 @@ class App extends IPCContainer {
|
||||
}
|
||||
};
|
||||
|
||||
extractFileNameFromURL = url => {
|
||||
const parts = url.split('/');
|
||||
return parts[parts.length - 1];
|
||||
};
|
||||
|
||||
getSelectedVersion = () => {
|
||||
return (this.props.ReleaseVersion === -1) ?
|
||||
'unavailable' :
|
||||
@@ -105,7 +101,7 @@ class App extends IPCContainer {
|
||||
};
|
||||
|
||||
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 = () => {
|
||||
@@ -116,7 +112,7 @@ class App extends IPCContainer {
|
||||
|
||||
handleDownloadUpgrade = () => {
|
||||
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);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
import {Component} from 'react';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
|
||||
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 = {};
|
||||
ipcRenderer;
|
||||
ipcRenderer = getIPCRenderer();
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.ipcRenderer) {
|
||||
|
||||
35
src/index.js
35
src/index.js
@@ -3,30 +3,29 @@ import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import createAppStore from './redux/store/createAppStore';
|
||||
import {getIPCRenderer} from './utils';
|
||||
import packageJson from '../package.json';
|
||||
import {Provider} from 'react-redux';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
|
||||
const Constants = require('./constants');
|
||||
|
||||
if (!process.versions.hasOwnProperty('electron')) {
|
||||
const ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.on(Constants.IPC_Get_Platform_Reply, (event, arg) => {
|
||||
if (arg.Platform === 'linux') {
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty('--default_font_size', '15px');
|
||||
}
|
||||
const ipcRenderer = getIPCRenderer();
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.on(Constants.IPC_Get_Platform_Reply, (event, arg) => {
|
||||
if (arg.Platform === 'linux') {
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty('--default_font_size', '15px');
|
||||
}
|
||||
|
||||
const store = createAppStore(arg.Platform, arg.AppPlatform, packageJson.version);
|
||||
ReactDOM.render((
|
||||
<Provider store={store}>
|
||||
<App />
|
||||
</Provider>
|
||||
), document.getElementById('root'));
|
||||
serviceWorker.unregister();
|
||||
});
|
||||
ipcRenderer.send(Constants.IPC_Get_Platform);
|
||||
}
|
||||
const store = createAppStore(arg.Platform, arg.AppPlatform, packageJson.version);
|
||||
ReactDOM.render((
|
||||
<Provider store={store}>
|
||||
<App/>
|
||||
</Provider>
|
||||
), document.getElementById('root'));
|
||||
serviceWorker.unregister();
|
||||
});
|
||||
ipcRenderer.send(Constants.IPC_Get_Platform);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import * as Constants from '../../constants';
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
|
||||
let ipcRenderer;
|
||||
if (!process.versions.hasOwnProperty('electron')) {
|
||||
ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
||||
}
|
||||
const ipcRenderer = getIPCRenderer();
|
||||
|
||||
export const setApplicationReady = createAction('common/setApplicationReady');
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as Constants from '../../constants';
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
|
||||
export const setAllowDownload = createAction('download/setAllowDownload');
|
||||
|
||||
@@ -22,30 +23,28 @@ export const downloadItem = (name, type, url, completedCallback) => {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
if (!state.download.DownloadActive && state.download.AllowDownload) {
|
||||
if (!process.versions.hasOwnProperty('electron')) {
|
||||
const ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
||||
if (ipcRenderer) {
|
||||
dispatch(setDownloadBegin(name, type, url));
|
||||
const ipcRenderer = getIPCRenderer();
|
||||
if (ipcRenderer) {
|
||||
dispatch(setDownloadBegin(name, type, url));
|
||||
|
||||
const downloadFileProgress = (_, arg) => {
|
||||
dispatch(setDownloadProgress(arg.data.Progress));
|
||||
};
|
||||
const downloadFileProgress = (_, arg) => {
|
||||
dispatch(setDownloadProgress(arg.data.Progress));
|
||||
};
|
||||
|
||||
const downloadFileComplete = (_, arg) => {
|
||||
ipcRenderer.removeListener(Constants.IPC_Download_File_Progress, downloadFileProgress);
|
||||
ipcRenderer.removeListener(Constants.IPC_Download_File_Complete, downloadFileComplete);
|
||||
completedCallback(name, type, url, arg.data);
|
||||
dispatch(setDownloadEnd(arg.data));
|
||||
};
|
||||
const downloadFileComplete = (_, arg) => {
|
||||
ipcRenderer.removeListener(Constants.IPC_Download_File_Progress, downloadFileProgress);
|
||||
ipcRenderer.removeListener(Constants.IPC_Download_File_Complete, downloadFileComplete);
|
||||
completedCallback(name, type, url, arg.data);
|
||||
dispatch(setDownloadEnd(arg.data));
|
||||
};
|
||||
|
||||
ipcRenderer.on(Constants.IPC_Download_File_Progress, downloadFileProgress);
|
||||
ipcRenderer.on(Constants.IPC_Download_File_Complete, downloadFileComplete);
|
||||
ipcRenderer.on(Constants.IPC_Download_File_Progress, downloadFileProgress);
|
||||
ipcRenderer.on(Constants.IPC_Download_File_Complete, downloadFileComplete);
|
||||
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Filename: name,
|
||||
URL: url,
|
||||
});
|
||||
}
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Filename: name,
|
||||
URL: url,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import * as Constants from '../../constants';
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
|
||||
let ipcRenderer;
|
||||
if (!process.versions.hasOwnProperty('electron')) {
|
||||
ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
||||
}
|
||||
const ipcRenderer = getIPCRenderer();
|
||||
|
||||
export const installDependency = (source, url, completedCallback) => {
|
||||
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