Added polling for watcher.

This commit is contained in:
Patrick Fic
2020-10-20 10:53:50 -07:00
parent 900724f660
commit c277f6d32d
20 changed files with 205 additions and 19 deletions

View File

@@ -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,