chore: update plugin sdk - add appDataPath (#492)

This commit is contained in:
Louis 2023-10-30 15:17:41 +07:00 committed by GitHub
parent 80c4f53927
commit 7fbb5822f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -28,6 +28,13 @@ const downloadFile: (url: string, fileName: string) => Promise<any> = (url, file
const deleteFile: (path: string) => Promise<any> = (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<any> = () => 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 };

View File

@ -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.

View File

@ -19,6 +19,8 @@ contextBridge.exposeInMainWorld("electronAPI", {
pluginPath: () => ipcRenderer.invoke("pluginPath"),
appDataPath: () => ipcRenderer.invoke("appDataPath"),
reloadPlugins: () => ipcRenderer.invoke("reloadPlugins"),
appVersion: () => ipcRenderer.invoke("appVersion"),