Move checkExistsAndCreateDir out of preload
This commit is contained in:
parent
f21dc84840
commit
81ba5379c9
|
@ -2,5 +2,11 @@
|
||||||
* @file file system related functions exposed over the context bridge.
|
* @file file system related functions exposed over the context bridge.
|
||||||
*/
|
*/
|
||||||
import { existsSync } from "node:fs";
|
import { existsSync } from "node:fs";
|
||||||
|
import * as fs from "node:fs/promises";
|
||||||
|
|
||||||
export const fsExists = (path: string) => existsSync(path);
|
export const fsExists = (path: string) => existsSync(path);
|
||||||
|
|
||||||
|
/* TODO: Audit below this */
|
||||||
|
|
||||||
|
export const checkExistsAndCreateDir = (dirPath: string) =>
|
||||||
|
fs.mkdir(dirPath, { recursive: true });
|
||||||
|
|
|
@ -8,11 +8,9 @@
|
||||||
|
|
||||||
import { ipcMain } from "electron/main";
|
import { ipcMain } from "electron/main";
|
||||||
import { appVersion } from "../services/appUpdater";
|
import { appVersion } from "../services/appUpdater";
|
||||||
|
import { checkExistsAndCreateDir, fsExists } from "./fs";
|
||||||
import { openDirectory, openLogDirectory } from "./general";
|
import { openDirectory, openLogDirectory } from "./general";
|
||||||
import { logToDisk } from "./log";
|
import { logToDisk } from "./log";
|
||||||
import { fsExists } from "./fs";
|
|
||||||
|
|
||||||
// - General
|
|
||||||
|
|
||||||
export const attachIPCHandlers = () => {
|
export const attachIPCHandlers = () => {
|
||||||
// Notes:
|
// Notes:
|
||||||
|
@ -40,7 +38,11 @@ export const attachIPCHandlers = () => {
|
||||||
ipcMain.handle("openLogDirectory", (_) => openLogDirectory());
|
ipcMain.handle("openLogDirectory", (_) => openLogDirectory());
|
||||||
|
|
||||||
// See: [Note: Catching exception during .send/.on]
|
// See: [Note: Catching exception during .send/.on]
|
||||||
ipcMain.on("logToDisk", (_, msg) => logToDisk(msg));
|
ipcMain.on("logToDisk", (_, message) => logToDisk(message));
|
||||||
|
|
||||||
ipcMain.handle("fsExists", (_, path) => fsExists(path));
|
ipcMain.handle("fsExists", (_, path) => fsExists(path));
|
||||||
|
|
||||||
|
ipcMain.handle("checkExistsAndCreateDir", (_, dirPath) =>
|
||||||
|
checkExistsAndCreateDir(dirPath),
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -95,6 +95,11 @@ const logToDisk = (message: string): void =>
|
||||||
const fsExists = (path: string): Promise<boolean> =>
|
const fsExists = (path: string): Promise<boolean> =>
|
||||||
ipcRenderer.invoke("fsExists", path);
|
ipcRenderer.invoke("fsExists", path);
|
||||||
|
|
||||||
|
// - AUDIT below this
|
||||||
|
|
||||||
|
const checkExistsAndCreateDir = (dirPath: string): Promise<void> =>
|
||||||
|
ipcRenderer.invoke("checkExistsAndCreateDir", dirPath);
|
||||||
|
|
||||||
// - FIXME below this
|
// - FIXME below this
|
||||||
|
|
||||||
/* preload: duplicated logError */
|
/* preload: duplicated logError */
|
||||||
|
@ -168,9 +173,6 @@ const writeNodeStream = async (
|
||||||
|
|
||||||
// - Export
|
// - Export
|
||||||
|
|
||||||
const checkExistsAndCreateDir = (dirPath: string) =>
|
|
||||||
fs.mkdir(dirPath, { recursive: true });
|
|
||||||
|
|
||||||
const saveStreamToDisk = writeStream;
|
const saveStreamToDisk = writeStream;
|
||||||
|
|
||||||
const saveFileToDisk = (path: string, contents: string) =>
|
const saveFileToDisk = (path: string, contents: string) =>
|
||||||
|
@ -439,8 +441,11 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
||||||
exists: fsExists,
|
exists: fsExists,
|
||||||
},
|
},
|
||||||
|
|
||||||
// - Export
|
// - FS legacy
|
||||||
|
// TODO: Move these into fs + document + rename if needed
|
||||||
checkExistsAndCreateDir,
|
checkExistsAndCreateDir,
|
||||||
|
|
||||||
|
// - Export
|
||||||
saveStreamToDisk,
|
saveStreamToDisk,
|
||||||
saveFileToDisk,
|
saveFileToDisk,
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,8 @@ export interface ElectronAPIsType {
|
||||||
|
|
||||||
/** TODO: AUDIT below this */
|
/** TODO: AUDIT below this */
|
||||||
checkExistsAndCreateDir: (dirPath: string) => Promise<void>;
|
checkExistsAndCreateDir: (dirPath: string) => Promise<void>;
|
||||||
|
|
||||||
|
/** TODO: FIXME or migrate below this */
|
||||||
saveStreamToDisk: (
|
saveStreamToDisk: (
|
||||||
path: string,
|
path: string,
|
||||||
fileStream: ReadableStream<any>,
|
fileStream: ReadableStream<any>,
|
||||||
|
|
Loading…
Reference in a new issue