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,31 @@
const Constants = require('../../constants');
const fs = require('fs');
const addListeners = (ipcMain, getMainWindow, dialog) => {
ipcMain.on(Constants.IPC_Browse_Directory + '_sync', (event, data) => {
dialog.showOpenDialog(getMainWindow(), {
defaultPath: data.Location,
properties: ['openDirectory'],
title: data.Title,
}, (filePaths) => {
if (filePaths && (filePaths.length > 0)) {
event.returnValue = filePaths[0];
} else {
event.returnValue = '';
}
});
});
ipcMain.on(Constants.IPC_Delete_File, (event, data) => {
try {
if (fs.existsSync(data.FilePath)) {
fs.unlinkSync(data.FilePath);
}
} catch (e) {
}
});
};
module.exports = {
addListeners
};