diff --git a/src/App.js b/src/App.js
index b434580..03b807b 100644
--- a/src/App.js
+++ b/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);
};
diff --git a/src/containers/IPCContainer/IPCContainer.js b/src/containers/IPCContainer/IPCContainer.js
index 9fde958..2e9e5e2 100644
--- a/src/containers/IPCContainer/IPCContainer.js
+++ b/src/containers/IPCContainer/IPCContainer.js
@@ -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) {
diff --git a/src/index.js b/src/index.js
index b0a33b7..b477baa 100644
--- a/src/index.js
+++ b/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((
-
-
-
- ), document.getElementById('root'));
- serviceWorker.unregister();
- });
- ipcRenderer.send(Constants.IPC_Get_Platform);
- }
+ const store = createAppStore(arg.Platform, arg.AppPlatform, packageJson.version);
+ ReactDOM.render((
+
+
+
+ ), document.getElementById('root'));
+ serviceWorker.unregister();
+ });
+ ipcRenderer.send(Constants.IPC_Get_Platform);
}
diff --git a/src/redux/actions/common_actions.js b/src/redux/actions/common_actions.js
index a33c93f..244da4f 100644
--- a/src/redux/actions/common_actions.js
+++ b/src/redux/actions/common_actions.js
@@ -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');
diff --git a/src/redux/actions/download_actions.js b/src/redux/actions/download_actions.js
index f774a22..204b1d8 100644
--- a/src/redux/actions/download_actions.js
+++ b/src/redux/actions/download_actions.js
@@ -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,
+ });
}
}
};
diff --git a/src/redux/actions/install_actions.js b/src/redux/actions/install_actions.js
index e69cd26..f8176bc 100644
--- a/src/redux/actions/install_actions.js
+++ b/src/redux/actions/install_actions.js
@@ -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) => {
diff --git a/src/utils.js b/src/utils.js
new file mode 100644
index 0000000..6d99055
--- /dev/null
+++ b/src/utils.js
@@ -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;
+};
+