mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-29 05:51:26 +08:00
- Improved functionality for file management has been added. - Added file system management functionality through IPC. - Added functionality to interact with files including selection, upload, deletion, and batch operations. - Added new file operations to the custom API, including file select, upload, delete, batch upload, and batch delete functions. - Implemented feature to select and upload files via API.
42 lines
1.9 KiB
TypeScript
42 lines
1.9 KiB
TypeScript
import { electronAPI } from '@electron-toolkit/preload'
|
|
import { contextBridge, ipcRenderer, OpenDialogOptions } from 'electron'
|
|
|
|
// Custom APIs for renderer
|
|
const api = {
|
|
getAppInfo: () => ipcRenderer.invoke('get-app-info'),
|
|
checkForUpdate: () => ipcRenderer.invoke('check-for-update'),
|
|
openWebsite: (url: string) => ipcRenderer.invoke('open-website', url),
|
|
setProxy: (proxy: string) => ipcRenderer.invoke('set-proxy', proxy),
|
|
setTheme: (theme: 'light' | 'dark') => ipcRenderer.invoke('set-theme', theme),
|
|
minApp: (url: string) => ipcRenderer.invoke('minapp', url),
|
|
openFile: (options?: { decompress: boolean }) => ipcRenderer.invoke('open-file', options),
|
|
reload: () => ipcRenderer.invoke('reload'),
|
|
saveFile: (path: string, content: string, options?: { compress: boolean }) => {
|
|
ipcRenderer.invoke('save-file', path, content, options)
|
|
},
|
|
compress: (text: string) => ipcRenderer.invoke('zip:compress', text),
|
|
decompress: (text: Buffer) => ipcRenderer.invoke('zip:decompress', text),
|
|
fileSelect: (options?: OpenDialogOptions) => ipcRenderer.invoke('file:select', options),
|
|
fileUpload: (filePath: string) => ipcRenderer.invoke('file:upload', filePath),
|
|
fileDelete: (fileId: string) => ipcRenderer.invoke('file:delete', fileId),
|
|
fileBatchUpload: (filePaths: string[]) => ipcRenderer.invoke('file:batchUpload', filePaths),
|
|
fileBatchDelete: (fileIds: string[]) => ipcRenderer.invoke('file:batchDelete', fileIds)
|
|
}
|
|
|
|
// Use `contextBridge` APIs to expose Electron APIs to
|
|
// renderer only if context isolation is enabled, otherwise
|
|
// just add to the DOM global.
|
|
if (process.contextIsolated) {
|
|
try {
|
|
contextBridge.exposeInMainWorld('electron', electronAPI)
|
|
contextBridge.exposeInMainWorld('api', api)
|
|
} catch (error) {
|
|
console.error(error)
|
|
}
|
|
} else {
|
|
// @ts-ignore (define in dts)
|
|
window.electron = electronAPI
|
|
// @ts-ignore (define in dts)
|
|
window.api = api
|
|
}
|