refactor: split preload api by domain

This commit is contained in:
Misaka
2026-03-21 10:49:13 +08:00
parent 26c05f3726
commit ed65312fff
13 changed files with 284 additions and 242 deletions

View File

@@ -0,0 +1,19 @@
import type {
CleanerInput,
CleanerProgress,
ExportResultItem
} from '../../main/types/cleaner.types'
import { IPC_CHANNELS } from '../../shared/ipc-channels'
import { invokeIpc, ipcRenderer } from '../lib/ipc'
export const cleanerApi = {
runCleaner: (input: CleanerInput) => invokeIpc(IPC_CHANNELS.CLEANER_RUN, input),
exportResults: (items: ExportResultItem[]) =>
invokeIpc(IPC_CHANNELS.CLEANER_EXPORT_RESULTS, items),
onProgress: (callback: (data: CleanerProgress) => void) => {
const subscription = (_event: Electron.IpcRendererEvent, data: CleanerProgress) =>
callback(data)
ipcRenderer.on(IPC_CHANNELS.CLEANER_PROGRESS, subscription)
return () => ipcRenderer.removeListener(IPC_CHANNELS.CLEANER_PROGRESS, subscription)
}
} as const