Move more standalone methods to preload

This commit is contained in:
Manav Rathi 2024-03-16 17:51:43 +05:30
parent b3289f2b8d
commit 3ce8513e48
No known key found for this signature in database
3 changed files with 43 additions and 47 deletions

View file

@ -1,30 +1,5 @@
import { ipcRenderer } from "electron/renderer";
import { logError } from "../services/logging";
export const selectDirectory = async (): Promise<string> => {
try {
return await ipcRenderer.invoke("select-dir");
} catch (e) {
logError(e, "error while selecting root directory");
}
};
export const getAppVersion = async (): Promise<string> => {
try {
return await ipcRenderer.invoke("get-app-version");
} catch (e) {
logError(e, "failed to get release version");
throw e;
}
};
export const openDirectory = async (dirPath: string): Promise<void> => {
try {
await ipcRenderer.invoke("open-dir", dirPath);
} catch (e) {
logError(e, "error while opening directory");
throw e;
}
};
export { logToDisk, openLogDirectory } from "../services/logging";

View file

@ -16,15 +16,3 @@ export const registerForegroundEventListener = (onForeground: () => void) => {
onForeground();
});
};
export const updateAndRestart = () => {
ipcRenderer.send("update-and-restart");
};
export const skipAppUpdate = (version: string) => {
ipcRenderer.send("skip-app-update", version);
};
export const muteUpdateNotification = (version: string) => {
ipcRenderer.send("mute-update-notification", version);
};

View file

@ -33,13 +33,7 @@ import path from "path";
import * as fs from "promise-fs";
import { Readable } from "stream";
import { deleteDiskCache, openDiskCache } from "./api/cache";
import {
getAppVersion,
logToDisk,
openDirectory,
openLogDirectory,
selectDirectory,
} from "./api/common";
import { logToDisk, openLogDirectory } from "./api/common";
import { clearElectronStore } from "./api/electronStore";
import {
checkExistsAndCreateDir,
@ -52,11 +46,8 @@ import { getDirFiles } from "./api/fs";
import { convertToJPEG, generateImageThumbnail } from "./api/imageProcessor";
import { getEncryptionKey, setEncryptionKey } from "./api/safeStorage";
import {
muteUpdateNotification,
registerForegroundEventListener,
registerUpdateEventListener,
skipAppUpdate,
updateAndRestart,
} from "./api/system";
import {
getElectronFilesFromGoogleZip,
@ -313,6 +304,48 @@ const parseExecError = (err: any) => {
// -
const selectDirectory = async (): Promise<string> => {
try {
return await ipcRenderer.invoke("select-dir");
} catch (e) {
logError(e, "error while selecting root directory");
}
};
const getAppVersion = async (): Promise<string> => {
try {
return await ipcRenderer.invoke("get-app-version");
} catch (e) {
logError(e, "failed to get release version");
throw e;
}
};
const openDirectory = async (dirPath: string): Promise<void> => {
try {
await ipcRenderer.invoke("open-dir", dirPath);
} catch (e) {
logError(e, "error while opening directory");
throw e;
}
};
// -
const updateAndRestart = () => {
ipcRenderer.send("update-and-restart");
};
const skipAppUpdate = (version: string) => {
ipcRenderer.send("skip-app-update", version);
};
const muteUpdateNotification = (version: string) => {
ipcRenderer.send("mute-update-notification", version);
};
// -
setupLogging();
// These objects exposed here will become available to the JS code in our