Add watcher polling settings.

This commit is contained in:
Patrick Fic
2025-03-26 11:32:41 -07:00
parent 791c518920
commit e2ccbf7007
11 changed files with 247 additions and 65 deletions

View File

@@ -8,6 +8,8 @@ import {
SettingsWatchedFilePathsAdd,
SettingsWatchedFilePathsGet,
SettingsWatchedFilePathsRemove,
SettingsWatcherPollingGet,
SettingsWatcherPollingSet,
} from "./ipcMainHandler.settings";
import { ipcMainHandleAuthStateChanged } from "./ipcMainHandler.user";
import { autoUpdater } from "electron-updater";
@@ -78,6 +80,14 @@ ipcMain.handle(
ipcTypes.toMain.settings.filepaths.remove,
SettingsWatchedFilePathsRemove,
);
ipcMain.handle(
ipcTypes.toMain.settings.watcher.getpolling,
SettingsWatcherPollingGet,
);
ipcMain.handle(
ipcTypes.toMain.settings.watcher.setpolling,
SettingsWatcherPollingSet,
);
//Watcher Handlers
ipcMain.on(ipcTypes.toMain.watcher.start, () => {

View File

@@ -2,7 +2,13 @@ import { BrowserWindow, dialog, IpcMainInvokeEvent } from "electron";
import log from "electron-log/main";
import _ from "lodash";
import Store from "../store/store";
import { addWatcherPath, removeWatcherPath, watcher } from "../watcher/watcher";
import {
addWatcherPath,
removeWatcherPath,
StartWatcher,
StopWatcher,
watcher,
} from "../watcher/watcher";
const SettingsWatchedFilePathsAdd = async (): Promise<string[]> => {
const mainWindow = BrowserWindow.getAllWindows()[0]; //TODO: Filter to only main window once a proper key has been set.
@@ -41,8 +47,39 @@ const SettingsWatchedFilePathsGet = async (): Promise<string[]> => {
return filepaths;
};
const SettingsWatcherPollingGet = async (): Promise<{
enabled: boolean;
interval: number;
}> => {
const pollingEnabled: { enabled: boolean; interval: number } =
Store.get("settings.polling");
return { enabled: pollingEnabled.enabled, interval: pollingEnabled.interval };
};
const SettingsWatcherPollingSet = async (
event: IpcMainInvokeEvent,
pollingSettings: {
enabled: boolean;
interval: number;
},
): Promise<{
enabled: boolean;
interval: number;
}> => {
log.info("Polling set", pollingSettings);
const { enabled, interval } = pollingSettings;
Store.set("settings.polling", { enabled, interval });
//Restart the watcher with these new settings.
await StopWatcher();
StartWatcher();
return { enabled, interval };
};
export {
SettingsWatchedFilePathsAdd,
SettingsWatchedFilePathsGet,
SettingsWatchedFilePathsRemove,
SettingsWatcherPollingGet,
SettingsWatcherPollingSet,
};