Refactoring Electron IPC
This commit is contained in:
24
src/renderer/ipc/DownloadIPC.js
Normal file
24
src/renderer/ipc/DownloadIPC.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const Constants = require('../../constants');
|
||||
const helpers = require('../../helpers');
|
||||
|
||||
const addListeners = (ipcMain, standardIPCReply) => {
|
||||
ipcMain.on(Constants.IPC_Download_File, (event, data) => {
|
||||
const destination = path.join(helpers.getDataDirectory(), data.Filename);
|
||||
helpers.downloadFile(data.URL, destination, (progress) => {
|
||||
standardIPCReply(event, Constants.IPC_Download_File_Progress, {
|
||||
Destination: destination,
|
||||
Progress: progress,
|
||||
URL: data.URL,
|
||||
});
|
||||
}, error => {
|
||||
standardIPCReply(event, Constants.IPC_Download_File_Complete, {
|
||||
Destination: destination,
|
||||
URL: data.URL,
|
||||
}, error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addListeners
|
||||
};
|
||||
Reference in New Issue
Block a user