| 1 | import { StateStorage } from 'zustand/middleware'; |
| 2 | |
| 3 | /** |
| 4 | * 这里重写了 zustand 的读写逻辑 |
| 5 | * 使其存储依托于 electron-store |
| 6 | */ |
| 7 | class IndexedDBStorage implements StateStorage { |
| 8 | public async getItem(name: string): Promise<string | null> { |
| 9 | return window.ipcRenderer.getStoreValue(name); |
| 10 | } |
| 11 | |
| 12 | public async setItem(name: string, value: string): Promise<void> { |
| 13 | window.ipcRenderer.setStoreValue(name, value); |
| 14 | } |
| 15 | |
| 16 | public async removeItem(name: string): Promise<void> { |
| 17 | window.ipcRenderer.setStoreValue(name, '{}'); |
| 18 | } |
| 19 | |
| 20 | public async clear(): Promise<void> {} |
| 21 | } |
| 22 | |
| 23 | export const indexedDBStorage = new IndexedDBStorage(); |
| 24 |