50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
const { ipcMain, dialog } = require("electron");
|
|
const { StartWatcher, StopWatcher } = require("./file-watcher");
|
|
const ipcTypes = require("../../src/ipc.types");
|
|
const settings = require("electron-settings");
|
|
const { mainWindow } = require("../main");
|
|
const _ = require("lodash");
|
|
|
|
ipcMain.on(
|
|
ipcTypes.default.fileWatcher.toMain.filepathsGet,
|
|
async (event, object) => {
|
|
const filePaths = await settings.get("filePaths");
|
|
event.reply(
|
|
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
|
|
filePaths
|
|
);
|
|
}
|
|
);
|
|
|
|
ipcMain.on(ipcTypes.default.fileWatcher.toMain.start, async (event, arg) => {
|
|
const filePaths = StartWatcher();
|
|
// event.sender.send(ipcTypes.default.fileWatcher.toRenderer.startSuccess);
|
|
event.sender.send(
|
|
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
|
|
filePaths
|
|
);
|
|
});
|
|
|
|
ipcMain.on(ipcTypes.default.fileWatcher.toMain.stop, async (event, arg) => {
|
|
StopWatcher();
|
|
event.sender.send(ipcTypes.default.fileWatcher.toRenderer.stopSuccess);
|
|
});
|
|
|
|
ipcMain.on(ipcTypes.default.fileWatcher.toMain.addPath, async (event, arg) => {
|
|
const result = await dialog.showOpenDialog(mainWindow, {
|
|
properties: ["openDirectory"],
|
|
});
|
|
|
|
await settings.set(
|
|
"filePaths",
|
|
_.union(result.filePaths, await settings.get("filePaths"))
|
|
);
|
|
|
|
const newFilePaths = await settings.get("filePaths");
|
|
|
|
event.sender.send(
|
|
ipcTypes.default.fileWatcher.toRenderer.filepathsList,
|
|
newFilePaths
|
|
);
|
|
});
|