v0.2.0: 全面代码质量优化
- ESLint flat config + Prettier + EditorConfig - Markdown处理器LRU缓存 - Zustand选择器优化减少重渲染 - CodeMirror Compartment主题热切换 - Preview防抖(150ms) + IndexedDB去抖(500ms) - 组件拆分: App.tsx 310→104行, Sidebar.tsx 244→90行 - 统一错误处理 errorHandler.ts - ConfirmDialog替代原生confirm - LoadingSpinner加载状态 - Toast多条堆叠+类型区分 - 可访问性增强(ARIA属性、键盘导航) - Vitest测试框架(78个测试用例) - Git hooks(husky + lint-staged) - 项目文档(README.md, CONTRIBUTING.md)
This commit is contained in:
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* DX-02: Preload 类型安全声明
|
||||
* 为 window.electronAPI 提供完整的 TypeScript 类型定义,
|
||||
* 确保渲染进程访问 API 时有完整的类型提示和编译时检查。
|
||||
*/
|
||||
|
||||
import type {
|
||||
OpenFileResponse,
|
||||
ReadFileResult,
|
||||
SaveFilePayload,
|
||||
SaveAsPayload,
|
||||
SaveFileResult,
|
||||
ReloadFileResult,
|
||||
FileStatsResult,
|
||||
ReadDirTreeResult,
|
||||
} from '../shared/types'
|
||||
|
||||
interface ElectronAPI {
|
||||
// File operations
|
||||
openFile: () => Promise<OpenFileResponse>
|
||||
readFile: (filePath: string) => Promise<ReadFileResult>
|
||||
saveFile: (data: SaveFilePayload) => Promise<SaveFileResult>
|
||||
saveFileAs: (data: SaveAsPayload) => Promise<SaveFileResult>
|
||||
getCurrentPath: () => Promise<string | null>
|
||||
getFileStats: (filePath: string) => Promise<FileStatsResult>
|
||||
reloadFile: () => Promise<ReloadFileResult>
|
||||
|
||||
// Tab management
|
||||
tabSwitched: (filePath: string | null) => Promise<void>
|
||||
|
||||
// Window control
|
||||
forceClose: () => Promise<void>
|
||||
cancelClose: () => Promise<void>
|
||||
|
||||
// Shell
|
||||
openExternal: (url: string) => void
|
||||
|
||||
// File Tree (Sidebar)
|
||||
readDirTree: (dirPath: string) => Promise<ReadDirTreeResult>
|
||||
openFolderDialog: () => Promise<{ canceled: boolean; filePaths: string[] }>
|
||||
watchDir: (dirPath: string) => Promise<void>
|
||||
unwatchDir: () => Promise<void>
|
||||
|
||||
// Events from main process — 返回取消订阅函数
|
||||
onFileOpenInTab: (callback: (data: { filePath: string; content: string }) => void) => () => void
|
||||
onMenuSave: (callback: () => void) => () => void
|
||||
onMenuSaveAs: (callback: () => void) => () => void
|
||||
onViewModeChange: (callback: (mode: string) => void) => () => void
|
||||
onExternalModification: (callback: (filePath: string) => void) => () => void
|
||||
onDirChanged: (callback: () => void) => () => void
|
||||
onConfirmClose: (callback: () => void) => () => void
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
electronAPI: ElectronAPI
|
||||
}
|
||||
}
|
||||
|
||||
export {}
|
||||
Reference in New Issue
Block a user