Refactoring Electron IPC
This commit is contained in:
31
src/renderer/ipc/FilesystemIPC.js
Normal file
31
src/renderer/ipc/FilesystemIPC.js
Normal 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
|
||||
};
|
||||
Reference in New Issue
Block a user