From ec6f76520e33ff93d3ca199b8b1ef70278ad0292 Mon Sep 17 00:00:00 2001 From: suyao Date: Tue, 13 May 2025 00:37:52 +0800 Subject: [PATCH] fix: add File_DeleteDir channel and update deleteDir invocation in preload API --- packages/shared/IpcChannel.ts | 1 + src/preload/index.d.ts | 187 ---------------------------------- src/preload/index.ts | 2 +- 3 files changed, 2 insertions(+), 188 deletions(-) delete mode 100644 src/preload/index.d.ts diff --git a/packages/shared/IpcChannel.ts b/packages/shared/IpcChannel.ts index c28b32ed7..821ddd84d 100644 --- a/packages/shared/IpcChannel.ts +++ b/packages/shared/IpcChannel.ts @@ -99,6 +99,7 @@ export enum IpcChannel { File_Clear = 'file:clear', File_Read = 'file:read', File_Delete = 'file:delete', + File_DeleteDir = 'file:deleteDir', File_Get = 'file:get', File_SelectFolder = 'file:selectFolder', File_Create = 'file:create', diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts deleted file mode 100644 index c6cbf5c49..000000000 --- a/src/preload/index.d.ts +++ /dev/null @@ -1,187 +0,0 @@ -import { ExtractChunkData } from '@cherrystudio/embedjs-interfaces' -import { ElectronAPI } from '@electron-toolkit/preload' -import type { MCPServer, MCPTool } from '@renderer/types' -import { - AppInfo, - FileListResponse, - FileType, - FileUploadResponse, - KnowledgeBaseParams, - KnowledgeItem, - LanguageVarious, - WebDavConfig -} from '@renderer/types' -import type { LoaderReturn } from '@shared/config/types' -import type { OpenDialogOptions } from 'electron' -import type { UpdateInfo } from 'electron-updater' - -interface BackupFile { - fileName: string - modifiedTime: string - size: number -} - -declare global { - interface Window { - electron: ElectronAPI - api: { - getAppInfo: () => Promise - checkForUpdate: () => Promise<{ currentVersion: string; updateInfo: UpdateInfo | null }> - showUpdateDialog: () => Promise - openWebsite: (url: string) => void - setProxy: (proxy: string | undefined) => void - setLanguage: (theme: LanguageVarious) => void - setLaunchOnBoot: (isActive: boolean) => void - setLaunchToTray: (isActive: boolean) => void - setTray: (isActive: boolean) => void - setTrayOnClose: (isActive: boolean) => void - restartTray: () => void - setTheme: (theme: 'light' | 'dark') => void - minApp: (options: { url: string; windowOptions?: Electron.BrowserWindowConstructorOptions }) => void - reload: () => void - clearCache: () => Promise<{ success: boolean; error?: string }> - system: { - getDeviceType: () => Promise<'mac' | 'windows' | 'linux'> - } - zip: { - compress: (text: string) => Promise - decompress: (text: Buffer) => Promise - } - backup: { - backup: (fileName: string, data: string, destinationPath?: string) => Promise - restore: (backupPath: string) => Promise - backupToWebdav: (data: string, webdavConfig: WebDavConfig) => Promise - restoreFromWebdav: (webdavConfig: WebDavConfig) => Promise - listWebdavFiles: (webdavConfig: WebDavConfig) => Promise - checkConnection: (webdavConfig: WebDavConfig) => Promise - createDirectory: (webdavConfig: WebDavConfig, path: string, options?: CreateDirectoryOptions) => Promise - } - file: { - select: (options?: OpenDialogOptions) => Promise - upload: (file: FileType) => Promise - delete: (fileId: string) => Promise - deleteDir: (dirPath: string) => Promise - read: (fileId: string) => Promise - clear: () => Promise - get: (filePath: string) => Promise - selectFolder: () => Promise - create: (fileName: string) => Promise - write: (filePath: string, data: Uint8Array | string) => Promise - open: (options?: OpenDialogOptions) => Promise<{ fileName: string; filePath: string; content: Buffer } | null> - openPath: (path: string) => Promise - save: ( - path: string, - content: string | NodeJS.ArrayBufferView, - options?: SaveDialogOptions - ) => Promise - saveImage: (name: string, data: string) => void - base64Image: (fileId: string) => Promise<{ mime: string; base64: string; data: string }> - base64File: (filePath: string) => Promise<{ mime: string; data: string }> - download: (url: string) => Promise - copy: (fileId: string, destPath: string) => Promise - binaryFile: (fileId: string) => Promise<{ data: Buffer; mime: string }> - } - fs: { - read: (path: string) => Promise - } - export: { - toWord: (markdown: string, fileName: string) => Promise - } - openPath: (path: string) => Promise - shortcuts: { - update: (shortcuts: Shortcut[]) => Promise - } - knowledgeBase: { - create: (base: KnowledgeBaseParams) => Promise - reset: (base: KnowledgeBaseParams) => Promise - delete: (id: string) => Promise - add: ({ - base, - item, - forceReload = false - }: { - base: KnowledgeBaseParams - item: KnowledgeItem - forceReload?: boolean - }) => Promise - remove: ({ - uniqueId, - uniqueIds, - base - }: { - uniqueId: string - uniqueIds: string[] - base: KnowledgeBaseParams - }) => Promise - search: ({ search, base }: { search: string; base: KnowledgeBaseParams }) => Promise - rerank: ({ - search, - base, - results - }: { - search: string - base: KnowledgeBaseParams - results: ExtractChunkData[] - }) => Promise - } - window: { - setMinimumSize: (width: number, height: number) => Promise - resetMinimumSize: () => Promise - } - fileService: { - upload: (type: string, apiKey: string, file: FileType) => Promise - retrieve: (type: string, apiKey: string, fileId: string) => Promise - list: (type: string, apiKey: string) => Promise - delete: (type: string, apiKey: string, fileId: string) => Promise - } - selectionMenu: { - action: (action: string) => Promise - } - config: { - set: (key: string, value: any) => Promise - get: (key: string) => Promise - } - miniWindow: { - show: () => Promise - hide: () => Promise - close: () => Promise - toggle: () => Promise - } - aes: { - encrypt: (text: string, secretKey: string, iv: string) => Promise<{ iv: string; encryptedData: string }> - decrypt: (encryptedData: string, iv: string, secretKey: string) => Promise - } - shell: { - openExternal: (url: string, options?: OpenExternalOptions) => Promise - } - mcp: { - removeServer: (server: MCPServer) => Promise - listTools: (server: MCPServer) => Promise - callTool: ({ server, name, args }: { server: MCPServer; name: string; args: any }) => Promise - getInstallInfo: () => Promise<{ dir: string; uvPath: string; bunPath: string }> - } - copilot: { - getAuthMessage: ( - headers?: Record - ) => Promise<{ device_code: string; user_code: string; verification_uri: string }> - getCopilotToken: (device_code: string, headers?: Record) => Promise<{ access_token: string }> - saveCopilotToken: (access_token: string) => Promise - getToken: (headers?: Record) => Promise<{ token: string }> - logout: () => Promise - getUser: (token: string) => Promise<{ login: string; avatar: string }> - } - isBinaryExist: (name: string) => Promise - getBinaryPath: (name: string) => Promise - installUVBinary: () => Promise - installBunBinary: () => Promise - protocol: { - onReceiveData: (callback: (data: { url: string; params: any }) => void) => () => void - } - nutstore: { - getSSOUrl: () => Promise - decryptToken: (token: string) => Promise<{ username: string; access_token: string }> - getDirectoryContents: (token: string, path: string) => Promise - } - } - } -} diff --git a/src/preload/index.ts b/src/preload/index.ts index 56b02d437..96fbe4f46 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -53,7 +53,7 @@ const api = { select: (options?: OpenDialogOptions) => ipcRenderer.invoke(IpcChannel.File_Select, options), upload: (file: FileType) => ipcRenderer.invoke(IpcChannel.File_Upload, file), delete: (fileId: string) => ipcRenderer.invoke(IpcChannel.File_Delete, fileId), - deleteDir: (dirPath: string) => ipcRenderer.invoke('file:deleteDir', dirPath), + deleteDir: (dirPath: string) => ipcRenderer.invoke(IpcChannel.File_DeleteDir, dirPath), read: (fileId: string) => ipcRenderer.invoke(IpcChannel.File_Read, fileId), clear: () => ipcRenderer.invoke(IpcChannel.File_Clear), get: (filePath: string) => ipcRenderer.invoke(IpcChannel.File_Get, filePath),