Refactoring
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user