Refactoring Electron IPC
This commit is contained in:
56
src/renderer/ipc/ConfigIPC.js
Normal file
56
src/renderer/ipc/ConfigIPC.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const Constants = require('../../constants');
|
||||
const helpers = require('../../helpers');
|
||||
|
||||
const addListeners = (ipcMain, standardIPCReply) => {
|
||||
ipcMain.on(Constants.IPC_Get_Config, (event, data) => {
|
||||
helpers
|
||||
.getConfig(data.Version, data.Provider)
|
||||
.then((data) => {
|
||||
if (data.Code === 0) {
|
||||
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {
|
||||
Config: data.Data,
|
||||
});
|
||||
} else {
|
||||
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {}, data.Code);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
standardIPCReply(event, Constants.IPC_Get_Config_Reply, {}, error);
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => {
|
||||
helpers
|
||||
.getConfigTemplate(data.Version, data.Provider)
|
||||
.then((data) => {
|
||||
standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, {
|
||||
Template: data,
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
standardIPCReply(event, Constants.IPC_Get_Config_Template_Reply, {}, error);
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Set_Config_Values, (event, data) => {
|
||||
const setConfigValue = (i) => {
|
||||
if (i < data.Items.length) {
|
||||
helpers
|
||||
.setConfigValue(data.Items[i].Name, data.Items[i].Value, data.Provider, data.Version)
|
||||
.then(() => {
|
||||
setConfigValue(++i);
|
||||
})
|
||||
.catch(() => {
|
||||
setConfigValue(++i);
|
||||
});
|
||||
} else {
|
||||
standardIPCReply(event, Constants.IPC_Set_Config_Values_Reply, {});
|
||||
}
|
||||
};
|
||||
setConfigValue(0);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addListeners
|
||||
};
|
||||
Reference in New Issue
Block a user