Added base handled for job decode and watcher start/top

This commit is contained in:
Patrick Fic
2020-10-14 11:26:10 -07:00
parent 953ea832e2
commit e7614942e5
25 changed files with 285 additions and 189 deletions

View File

@@ -2,14 +2,13 @@ const { ipcMain } = require("electron");
const { StartWatcher, StopWatcher } = require("./file-watcher");
const ipcTypes = require("../../src/ipc.types").default;
ipcMain.on(ipcTypes.filewatcher.start, async (event, arg) => {
console.log(ipcTypes.filewatcher.start);
ipcMain.on(ipcTypes.fileWatcher.toMain.start, async (event, arg) => {
const filePaths = StartWatcher();
event.sender.send(ipcTypes.filewatcher.startSuccess, filePaths);
event.sender.send(ipcTypes.fileWatcher.toRenderer.startSuccess, filePaths);
event.sender.send(ipcTypes.fileWatcher.toRenderer.filepathsList, filePaths);
});
ipcMain.on(ipcTypes.filewatcher.stop, async (event, arg) => {
console.log(ipcTypes.filewatcher.start);
ipcMain.on(ipcTypes.fileWatcher.toMain.stop, async (event, arg) => {
StopWatcher();
event.sender.send(ipcTypes.filewatcher.start, { success: true });
event.sender.send(ipcTypes.fileWatcher.toRenderer.stopSuccess);
});

View File

@@ -1,6 +1,7 @@
const chokidar = require("chokidar");
const { file } = require("electron-settings");
const { ipcMain } = require("electron");
const settings = require("electron-settings");
const { default: ipcTypes } = require("../../src/ipc.types");
var watcher;
@@ -34,6 +35,7 @@ function StartWatcher() {
})
.on("error", function (error) {
console.log("Error happened", error);
ipcMain.emit(ipcTypes.fileWatcher.toRenderer.error, error);
})
.on("ready", onWatcherReady)
.on("raw", function (event, path, details) {
@@ -44,14 +46,14 @@ function StartWatcher() {
}
function onWatcherReady() {
console.info(
"From here can you check for real changes, the initial scan has been completed."
);
console.log("Ready!");
ipcMain.emit(ipcTypes.fileWatcher.toRenderer.startSuccess);
}
async function StopWatcher() {
await watcher.close();
console.log("closed", watcher);
ipcMain.emit(ipcTypes.fileWatcher.toRenderer.stopSuccess);
console.log("Watcher Stopped!", watcher);
}
exports.StartWatcher = StartWatcher;

View File

@@ -2,27 +2,25 @@ const { ipcMain, dialog } = require("electron");
const { mainWindow } = require("./main");
const settings = require("electron-settings");
const { DecodeEstimate } = require("./decoder/decoder");
const ipcTypes = require("../src/ipc.types");
//Import Ipc Handlers
require("./file-watcher/file-watcher-ipc");
console.log("*** Added IPC Handlers ***");
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("test", async (event, object) => {
console.log("Received test IPC Command");
const job = await DecodeEstimate("C:\\VPS\\EMS\\687_3_A.AD1");
event.reply("test-success", { status: 0, message: null, data: job });
});
// ipcMain.on("test-start", async (event, arg) => {
// console.log("Test Start Inbound.", arg);
// const result = await dialog.showOpenDialog(mainWindow, {
// properties: ["openDirectory"],
// });
// await settings.set("filePaths", [
// ...result.filePaths,
// ...(await settings.get("filePaths")),
// ]);
// console.log(await settings.get("filePaths"));
// event.sender.send("test-success", { success: true });
// });

View File

@@ -3,7 +3,7 @@ const { app, BrowserWindow } = require("electron");
const isDev = require("electron-is-dev");
const settings = require("electron-settings");
require("./ipc-handler");
require("./ipc-main-handler");
// Conditionally include the dev tools installer to load React Dev Tools
let installExtension, REACT_DEVELOPER_TOOLS;

View File

@@ -7,6 +7,7 @@ contextBridge.exposeInMainWorld("ipcRenderer", {
// whitelist channels
// let validChannels = ["toMain"];
// if (validChannels.includes(channel)) {
console.log("ipcRenderer Send", channel);
ipcRenderer.send(channel, data);
//}
},