From 7fbb5822f7829eea4401c33c5fef2410a4d692b0 Mon Sep 17 00:00:00 2001 From: Louis <133622055+louis-jan@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:17:41 +0700 Subject: [PATCH] chore: update plugin sdk - add appDataPath (#492) --- core/core.ts | 10 +++++++++- electron/main.ts | 9 +++++++++ electron/preload.ts | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/core/core.ts b/core/core.ts index 84b2524e6..1820d5b9a 100644 --- a/core/core.ts +++ b/core/core.ts @@ -28,6 +28,13 @@ const downloadFile: (url: string, fileName: string) => Promise = (url, file const deleteFile: (path: string) => Promise = (path) => window.coreAPI?.deleteFile(path) ?? window.electronAPI?.deleteFile(path); +/** + * Retrieves the path to the app data directory using the `coreAPI` object. + * If the `coreAPI` object is not available, the function returns `undefined`. + * @returns A Promise that resolves with the path to the app data directory, or `undefined` if the `coreAPI` object is not available. + */ +const appDataPath: () => Promise = () => window.coreAPI?.appDataPath(); + /** Register extension point function type definition * */ @@ -46,9 +53,10 @@ export const core = { invokePluginFunc, downloadFile, deleteFile, + appDataPath, }; /** * Functions exports */ -export { invokePluginFunc, downloadFile, deleteFile }; +export { invokePluginFunc, downloadFile, deleteFile, appDataPath }; diff --git a/electron/main.ts b/electron/main.ts index 3a2da0aca..88d981c14 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -193,6 +193,15 @@ function handleIPCs() { return join(app.getPath("userData"), "plugins"); }); + /** + * Retrieves the path to the app data directory using the `coreAPI` object. + * If the `coreAPI` object is not available, the function returns `undefined`. + * @returns A Promise that resolves with the path to the app data directory, or `undefined` if the `coreAPI` object is not available. + */ + ipcMain.handle("appDataPath", async (_event) => { + return app.getPath("userData"); + }); + /** * Returns the version of the app. * @param _event - The IPC event object. diff --git a/electron/preload.ts b/electron/preload.ts index dac5aef6f..ceaede049 100644 --- a/electron/preload.ts +++ b/electron/preload.ts @@ -19,6 +19,8 @@ contextBridge.exposeInMainWorld("electronAPI", { pluginPath: () => ipcRenderer.invoke("pluginPath"), + appDataPath: () => ipcRenderer.invoke("appDataPath"), + reloadPlugins: () => ipcRenderer.invoke("reloadPlugins"), appVersion: () => ipcRenderer.invoke("appVersion"),