Added polling for watcher.
This commit is contained in:
@@ -330,11 +330,11 @@ async function DecodeLinFile(extensionlessFilePath) {
|
||||
(jobline) =>
|
||||
jobline.part_type &&
|
||||
!jobline.db_ref.startsWith("900") &&
|
||||
!jobline.db_ref.toLowerCase().startsWith("urethane") &&
|
||||
!jobline.db_ref.toLowerCase().startsWith("wheel") &&
|
||||
!jobline.db_ref.toLowerCase().startsWith("hazardous") &&
|
||||
!jobline.db_ref.toLowerCase().startsWith("detail") &&
|
||||
!jobline.db_ref.toLowerCase().startsWith("clean") &&
|
||||
!jobline.line_desc.toLowerCase().startsWith("urethane") &&
|
||||
!jobline.line_desc.toLowerCase().startsWith("wheel") &&
|
||||
!jobline.line_desc.toLowerCase().startsWith("hazardous") &&
|
||||
!jobline.line_desc.toLowerCase().startsWith("detail") &&
|
||||
!jobline.line_desc.toLowerCase().startsWith("clean") &&
|
||||
jobline.part_type.toUpperCase() !== "PAG" &&
|
||||
jobline.part_type.toUpperCase() !== "PAS" &&
|
||||
jobline.part_type.toUpperCase() !== "PASL" &&
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
const Store = require("electron-store");
|
||||
|
||||
const store = new Store({ defaults: { filePaths: [], accepted_ins_co: [] } });
|
||||
const store = new Store({
|
||||
defaults: {
|
||||
filePaths: [],
|
||||
accepted_ins_co: [],
|
||||
polling: {
|
||||
enabled: false,
|
||||
pollingInterval: 100,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
exports.store = store;
|
||||
|
||||
@@ -7,35 +7,38 @@ const { store } = require("../electron-store");
|
||||
const {
|
||||
NewNotification,
|
||||
} = require("../notification-wrapper/notification-wrapper");
|
||||
|
||||
const log = require("electron-log");
|
||||
var watcher;
|
||||
|
||||
async function StartWatcher() {
|
||||
const filePaths =
|
||||
store.get("filePaths").map((fp) => path.join(fp, "**.[eE][nN][vV]")) || [];
|
||||
console.log("StartWatcher -> filePaths", filePaths);
|
||||
|
||||
log.info("StartWatcher -> filePaths", filePaths);
|
||||
log.info("Use polling? ", store.get("polling").enabled);
|
||||
|
||||
if (filePaths.length === 0) {
|
||||
NewNotification({
|
||||
title: "RPS Watcher cannot start",
|
||||
body: "Please set the appropriate file paths and try again.",
|
||||
}).show();
|
||||
log.warn("Cannot start watcher. No file paths set.");
|
||||
return [];
|
||||
}
|
||||
|
||||
if (watcher) {
|
||||
try {
|
||||
console.log("Trying to close watcher - it already existed.");
|
||||
log.info("Trying to close watcher - it already existed.");
|
||||
await watcher.close();
|
||||
|
||||
console.log("Watcher closed successfully!");
|
||||
log.info("Watcher closed successfully!");
|
||||
} catch (error) {
|
||||
console.log("Error trying to close Watcher.", error);
|
||||
log.error("Error trying to close Watcher.", error);
|
||||
}
|
||||
}
|
||||
|
||||
watcher = chokidar.watch(filePaths, {
|
||||
//ignored: /[\/\\]\./,
|
||||
usePolling: store.get("polling").enabled,
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
awaitWriteFinish: {
|
||||
@@ -88,7 +91,7 @@ function onWatcherReady() {
|
||||
|
||||
async function StopWatcher() {
|
||||
await watcher.close();
|
||||
console.log("Watcher stopped.");
|
||||
log.info("Watcher stopped.");
|
||||
const b = BrowserWindow.getAllWindows()[0];
|
||||
b.webContents.send(ipcTypes.default.fileWatcher.toRenderer.stopSuccess);
|
||||
NewNotification({
|
||||
@@ -111,12 +114,13 @@ async function HandleNewFile(path) {
|
||||
ipcTypes.default.estimate.toRenderer.estimateDecodeSuccess,
|
||||
newJob
|
||||
);
|
||||
|
||||
log.info(`Sent job for upload. ${newJob.clm_no}`);
|
||||
NewNotification({
|
||||
title: "Job Uploaded",
|
||||
body: "A new job has been uploaded.",
|
||||
}).show();
|
||||
} else {
|
||||
log.info(`Ignored job. ${newJob.ERROR}`);
|
||||
NewNotification({
|
||||
title: "Job Ignored",
|
||||
body: newJob.ERROR,
|
||||
|
||||
@@ -17,3 +17,20 @@ ipcMain.on("test", async (event, object) => {
|
||||
ipcMain.on(ipcTypes.app.toMain.setAcceptableInsCoNm, (event, insCos) => {
|
||||
store.set("accepted_ins_co", insCos);
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.store.get, (event, key) => {
|
||||
const val = store.get(key);
|
||||
event.sender.send(ipcTypes.store.response, { [key]: val });
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.store.set, (event, key, val) => {
|
||||
store.set(key, val);
|
||||
|
||||
const st = store.get();
|
||||
event.sender.send(ipcTypes.store.response, st);
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.store.getAll, (event, obj) => {
|
||||
const val = store.get();
|
||||
event.sender.send(ipcTypes.store.response, val);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user