Add watcher polling settings.
This commit is contained in:
@@ -7,7 +7,7 @@ import ipcTypes from "../../util/ipcTypes.json";
|
||||
import ImportJob from "../decoder/decoder";
|
||||
import store from "../store/store";
|
||||
|
||||
let watcher: FSWatcher;
|
||||
let watcher: FSWatcher | null;
|
||||
|
||||
async function StartWatcher(): Promise<boolean> {
|
||||
const filePaths: string[] = store.get("settings.filepaths") || [];
|
||||
@@ -33,13 +33,19 @@ async function StartWatcher(): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
const pollingSettings =
|
||||
(store.get("settings.polling") as {
|
||||
enabled?: boolean;
|
||||
interval?: number;
|
||||
}) || {};
|
||||
|
||||
watcher = chokidar.watch(filePaths, {
|
||||
ignored: (filepath, stats) => {
|
||||
const p = path.parse(filepath);
|
||||
return !stats?.isFile() && p.ext !== "" && p.ext.toUpperCase() !== ".ENV"; //Only watch for .ENV files.
|
||||
},
|
||||
usePolling: store.get("settings.polling").enabled || false,
|
||||
interval: store.get("settings.polling").pollingInterval || 1000,
|
||||
usePolling: pollingSettings.enabled || false,
|
||||
interval: pollingSettings.interval || 30000,
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
awaitWriteFinish: {
|
||||
@@ -73,34 +79,39 @@ async function StartWatcher(): Promise<boolean> {
|
||||
// errorTypeCheck(error)
|
||||
// );
|
||||
})
|
||||
.on("ready", onWatcherReady)
|
||||
.on("raw", function (event, path, details) {
|
||||
// This event should be triggered everytime something happens.
|
||||
// console.log("Raw event info:", event, path, details);
|
||||
});
|
||||
.on("ready", onWatcherReady);
|
||||
// .on("raw", function (event, path, details) {
|
||||
// // This event should be triggered everytime something happens.
|
||||
// // console.log("Raw event info:", event, path, details);
|
||||
// });
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function removeWatcherPath(path: string): void {
|
||||
watcher.unwatch(path);
|
||||
log.debug(`Stopped watching path: ${path}`);
|
||||
if (watcher) {
|
||||
watcher.unwatch(path);
|
||||
log.debug(`Stopped watching path: ${path}`);
|
||||
}
|
||||
}
|
||||
|
||||
function addWatcherPath(path: string | string[]): void {
|
||||
watcher.add(path);
|
||||
log.debug(`Started watching path: ${path}`);
|
||||
if (watcher) {
|
||||
watcher.add(path);
|
||||
log.debug(`Started watching path: ${path}`);
|
||||
}
|
||||
}
|
||||
|
||||
function onWatcherReady(): void {
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0]; //TODO: Filter to only main window once a proper key has been set.
|
||||
|
||||
new Notification({
|
||||
title: "Watcher Started",
|
||||
body: "Newly exported estimates will be automatically uploaded.",
|
||||
}).show();
|
||||
log.info("Confirmed watched paths:", watcher.getWatched());
|
||||
mainWindow.webContents.send(ipcTypes.toRenderer.watcher.started);
|
||||
if (watcher) {
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0]; //TODO: Filter to only main window once a proper key has been set.
|
||||
new Notification({
|
||||
title: "Watcher Started",
|
||||
body: "Newly exported estimates will be automatically uploaded.",
|
||||
}).show();
|
||||
log.info("Confirmed watched paths:", watcher.getWatched());
|
||||
mainWindow.webContents.send(ipcTypes.toRenderer.watcher.started);
|
||||
}
|
||||
}
|
||||
|
||||
async function StopWatcher(): Promise<boolean> {
|
||||
|
||||
Reference in New Issue
Block a user