Basic storage of watched paths.
This commit is contained in:
@@ -2,6 +2,10 @@ import { ipcMain } from "electron";
|
||||
import ipcTypes from "../../util/ipcTypes.json";
|
||||
import log from "electron-log/main";
|
||||
import { ipcMainHandleAuthStateChanged } from "./ipcMainHandler.user";
|
||||
import {
|
||||
SettingsWatchedFilePathsGet,
|
||||
SettingsWatchedFilePathsAdd,
|
||||
} from "./ipcMainHandler.settings";
|
||||
// Log all IPC messages and their payloads
|
||||
|
||||
const logIpcMessages = () => {
|
||||
@@ -35,4 +39,12 @@ ipcMain.on(ipcTypes.toMain.test, (payload: any) =>
|
||||
|
||||
ipcMain.on(ipcTypes.toMain.authStateChanged, ipcMainHandleAuthStateChanged);
|
||||
|
||||
ipcMain.handle(
|
||||
ipcTypes.toMain.settings.filepaths.get,
|
||||
SettingsWatchedFilePathsGet
|
||||
);
|
||||
ipcMain.handle(
|
||||
ipcTypes.toMain.settings.filepaths.add,
|
||||
SettingsWatchedFilePathsAdd
|
||||
);
|
||||
logIpcMessages();
|
||||
|
||||
31
src/main/ipc/ipcMainHandler.settings.ts
Normal file
31
src/main/ipc/ipcMainHandler.settings.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { BrowserWindow, dialog, IpcMainInvokeEvent } from "electron";
|
||||
import log from "electron-log/main";
|
||||
import _ from "lodash";
|
||||
import Store from "../store/store";
|
||||
|
||||
const SettingsWatchedFilePathsAdd = async (event: IpcMainInvokeEvent) => {
|
||||
const mainWindow = BrowserWindow.getAllWindows()[0]; //TODO: Filter to only main window once a proper key has been set.
|
||||
if (!mainWindow) {
|
||||
log.error("No main window found when trying to open dialog");
|
||||
return;
|
||||
}
|
||||
const result = await dialog.showOpenDialog(mainWindow, {
|
||||
properties: ["openDirectory"],
|
||||
});
|
||||
|
||||
if (!result.canceled) {
|
||||
Store.set(
|
||||
"settings.filepaths",
|
||||
_.union(result.filePaths, Store.get("filepaths"))
|
||||
);
|
||||
}
|
||||
|
||||
return Store.get("settings.filepaths");
|
||||
};
|
||||
|
||||
const SettingsWatchedFilePathsGet = async (event: IpcMainInvokeEvent) => {
|
||||
const filepaths = Store.get("settings.filepaths");
|
||||
return filepaths;
|
||||
};
|
||||
|
||||
export { SettingsWatchedFilePathsAdd, SettingsWatchedFilePathsGet };
|
||||
@@ -3,11 +3,13 @@
|
||||
const Store = require("electron-store").default;
|
||||
const store = new Store({
|
||||
defaults: {
|
||||
filePaths: [],
|
||||
runWatcherOnStartup: true,
|
||||
polling: {
|
||||
enabled: false,
|
||||
pollingInterval: 30000,
|
||||
settings: {
|
||||
filepaths: [],
|
||||
runWatcherOnStartup: true,
|
||||
polling: {
|
||||
enabled: false,
|
||||
pollingInterval: 30000,
|
||||
},
|
||||
},
|
||||
user: null,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user