47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { BrowserWindow, dialog, IpcMainInvokeEvent } from "electron";
|
|
import log from "electron-log/main";
|
|
import _ from "lodash";
|
|
import Store from "../store/store";
|
|
|
|
const SettingsWatchedFilePathsAdd = async (): Promise<string[]> => {
|
|
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("settings.filepaths"))
|
|
);
|
|
}
|
|
|
|
return Store.get("settings.filepaths");
|
|
};
|
|
const SettingsWatchedFilePathsRemove = async (
|
|
event: IpcMainInvokeEvent,
|
|
path: string
|
|
): Promise<string[]> => {
|
|
Store.set(
|
|
"settings.filepaths",
|
|
_.without(Store.get("settings.filepaths"), path)
|
|
);
|
|
|
|
return Store.get("settings.filepaths");
|
|
};
|
|
|
|
const SettingsWatchedFilePathsGet = async (): Promise<string[]> => {
|
|
const filepaths: string[] = Store.get("settings.filepaths") || [];
|
|
return filepaths;
|
|
};
|
|
|
|
export {
|
|
SettingsWatchedFilePathsAdd,
|
|
SettingsWatchedFilePathsGet,
|
|
SettingsWatchedFilePathsRemove,
|
|
};
|