Refactoring Electron IPC
This commit is contained in:
47
src/renderer/ipc/DaemonIPC.js
Normal file
47
src/renderer/ipc/DaemonIPC.js
Normal file
@@ -0,0 +1,47 @@
|
||||
const Constants = require('../../constants');
|
||||
const helpers = require('../../helpers');
|
||||
|
||||
const addListeners = (ipcMain, standardIPCReply) => {
|
||||
ipcMain.on(Constants.IPC_Check_Daemon_Version, (event, data) => {
|
||||
helpers
|
||||
.checkDaemonVersion(data.Version, data.Provider)
|
||||
.then(code => {
|
||||
standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, {
|
||||
Valid: (code === 0),
|
||||
Code: code,
|
||||
});
|
||||
})
|
||||
.catch(e => {
|
||||
standardIPCReply(event, Constants.IPC_Check_Daemon_Version_Reply, {
|
||||
Valid: false,
|
||||
}, e);
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Check_Daemon_Version + '_sync', (event, data) => {
|
||||
helpers
|
||||
.checkDaemonVersion(data.Version, data.Provider)
|
||||
.then(code => {
|
||||
event.returnValue = {
|
||||
data: {
|
||||
Success: true,
|
||||
Valid: (code === 0),
|
||||
Code: code,
|
||||
},
|
||||
};
|
||||
})
|
||||
.catch(e => {
|
||||
event.returnValue = {
|
||||
data: {
|
||||
Error: e.toString(),
|
||||
Success: false,
|
||||
Valid: false
|
||||
},
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addListeners
|
||||
};
|
||||
Reference in New Issue
Block a user