Refactoring Electron IPC

This commit is contained in:
2019-08-29 16:24:05 -05:00
parent 083b2192d7
commit f8ec89413a
15 changed files with 988 additions and 836 deletions

View File

@@ -0,0 +1,30 @@
const Constants = require('../../constants');
const fs = require('fs');
const helpers = require('../../helpers');
const path = require('path');
const addListeners = ipcMain => {
ipcMain.on(Constants.IPC_Get_State, event => {
helpers.mkDirByPathSync(helpers.getDataDirectory());
const configFile = path.join(helpers.getDataDirectory(), 'settings.json');
if (fs.existsSync(configFile)) {
event.sender.send(Constants.IPC_Get_State_Reply, {
data: JSON.parse(fs.readFileSync(configFile, 'utf8')),
});
} else {
event.sender.send(Constants.IPC_Get_State_Reply, {
data: null,
});
}
});
ipcMain.on(Constants.IPC_Save_State, (event, data) => {
helpers.mkDirByPathSync(helpers.getDataDirectory());
const configFile = path.join(helpers.getDataDirectory(), 'settings.json');
fs.writeFileSync(configFile, JSON.stringify(data.State), 'utf8');
});
};
module.exports = {
addListeners
};