refactor: restructure project layout
- Move main process to electron/main/ - Move preload to electron/preload/ - Add shared types in electron/shared/ - Split redis-service into modular redis/ directory - Flatten renderer to src/ (remove src/renderer/ nesting) - Update electron.vite.config.ts paths - Update tsconfig paths - Output to electron-dist/
This commit is contained in:
Vendored
-106
@@ -1,106 +0,0 @@
|
||||
// src/preload/index.d.ts
|
||||
export interface ConnectionConfig {
|
||||
id: string
|
||||
name: string
|
||||
host: string
|
||||
port: number
|
||||
auth: string
|
||||
username: string
|
||||
tls: boolean
|
||||
tlsCaPath: string
|
||||
tlsCertPath: string
|
||||
tlsKeyPath: string
|
||||
sshEnabled: boolean
|
||||
sshHost: string
|
||||
sshPort: number
|
||||
sshUsername: string
|
||||
sshPassword: string
|
||||
sshPrivateKeyPath: string
|
||||
cluster: boolean
|
||||
sentinelMasterName: string
|
||||
separator: string
|
||||
order: number
|
||||
createdAt: number
|
||||
color?: string
|
||||
}
|
||||
|
||||
export interface ElectronAPI {
|
||||
window: {
|
||||
minimize: () => void
|
||||
maximize: () => void
|
||||
close: () => void
|
||||
}
|
||||
theme: {
|
||||
get: () => Promise<boolean>
|
||||
set: (theme: 'system' | 'dark' | 'light') => void
|
||||
onOsUpdated: (callback: (isDark: boolean) => void) => void
|
||||
}
|
||||
dialog: {
|
||||
openFile: (options: { title?: string; filters?: { name: string; extensions: string[] }[] }) =>
|
||||
Promise<{ path: string; content: string } | null>
|
||||
}
|
||||
credential: {
|
||||
encrypt: (text: string) => Promise<string>
|
||||
decrypt: (encoded: string) => Promise<string>
|
||||
}
|
||||
storage: {
|
||||
getConnections: () => Promise<ConnectionConfig[]>
|
||||
saveConnection: (conn: ConnectionConfig) => Promise<ConnectionConfig[]>
|
||||
deleteConnection: (id: string) => Promise<ConnectionConfig[]>
|
||||
reorderConnections: (ids: string[]) => Promise<ConnectionConfig[]>
|
||||
getSettings: () => Promise<any>
|
||||
saveSettings: (settings: any) => Promise<void>
|
||||
}
|
||||
redis: {
|
||||
connect: (id: string, opts: any) => Promise<{ success: boolean; error?: string }>
|
||||
disconnect: (id: string) => Promise<void>
|
||||
execute: (id: string, command: string, args: string[]) => Promise<any>
|
||||
getInfo: (id: string) => Promise<string>
|
||||
scanKeys: (id: string, cursor: string, pattern: string, count: number) =>
|
||||
Promise<{ cursor: string; keys: string[] }>
|
||||
getKeyType: (id: string, key: string) => Promise<string>
|
||||
getKeyTTL: (id: string, key: string) => Promise<number>
|
||||
getString: (id: string, key: string) => Promise<string | null>
|
||||
setString: (id: string, key: string, value: string) => Promise<void>
|
||||
deleteKey: (id: string, key: string) => Promise<void>
|
||||
hashScan: (id: string, key: string, cursor: string, count: number) =>
|
||||
Promise<{ cursor: string; fields: [string, string][] }>
|
||||
hashSet: (id: string, key: string, field: string, value: string) => Promise<void>
|
||||
hashDel: (id: string, key: string, field: string) => Promise<void>
|
||||
setTTL: (id: string, key: string, ttl: number) => Promise<void>
|
||||
selectDb: (id: string, db: number) => Promise<void>
|
||||
dbSize: (id: string) => Promise<number>
|
||||
listRange: (id: string, key: string, start: number, stop: number) => Promise<string[]>
|
||||
listLength: (id: string, key: string) => Promise<number>
|
||||
listPush: (id: string, key: string, values: string[]) => Promise<number>
|
||||
listSet: (id: string, key: string, index: number, value: string) => Promise<void>
|
||||
listRemove: (id: string, key: string, count: number, value: string) => Promise<number>
|
||||
setMembers: (id: string, key: string) => Promise<string[]>
|
||||
setSize: (id: string, key: string) => Promise<number>
|
||||
setAdd: (id: string, key: string, members: string[]) => Promise<number>
|
||||
setRemove: (id: string, key: string, members: string[]) => Promise<number>
|
||||
zsetRange: (id: string, key: string, start: number, stop: number, withScores: boolean) => Promise<string[]>
|
||||
zsetSize: (id: string, key: string) => Promise<number>
|
||||
zsetAdd: (id: string, key: string, score: number, member: string) => Promise<number>
|
||||
zsetRemove: (id: string, key: string, members: string[]) => Promise<number>
|
||||
slowLogGet: (id: string, count: number) => Promise<any[]>
|
||||
slowLogLen: (id: string) => Promise<number>
|
||||
memoryUsage: (id: string, key: string) => Promise<number | null>
|
||||
batchDelete: (id: string, keys: string[]) => Promise<number>
|
||||
streamInfo: (id: string, key: string) => Promise<any>
|
||||
streamRange: (id: string, key: string, start: string, end: string, count: number) => Promise<any[]>
|
||||
streamAdd: (id: string, key: string, streamId: string, fieldValues: string[]) => Promise<string>
|
||||
streamTrim: (id: string, key: string, maxLen: number) => Promise<number>
|
||||
streamDel: (id: string, key: string, ids: string[]) => Promise<number>
|
||||
renameKey: (id: string, oldKey: string, newKey: string) => Promise<void>
|
||||
existsKey: (id: string, key: string) => Promise<boolean>
|
||||
ping: (id: string) => Promise<string>
|
||||
isConnected: (id: string) => Promise<boolean>
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
electronAPI: ElectronAPI
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
// src/preload/index.ts
|
||||
import { contextBridge, ipcRenderer } from 'electron'
|
||||
|
||||
const electronAPI = {
|
||||
window: {
|
||||
minimize: () => ipcRenderer.send('window:minimize'),
|
||||
maximize: () => ipcRenderer.send('window:maximize'),
|
||||
close: () => ipcRenderer.send('window:close'),
|
||||
},
|
||||
theme: {
|
||||
get: (): Promise<boolean> => ipcRenderer.invoke('theme:get'),
|
||||
set: (theme: 'system' | 'dark' | 'light') => ipcRenderer.send('theme:set', theme),
|
||||
onOsUpdated: (callback: (isDark: boolean) => void) => {
|
||||
ipcRenderer.on('theme:os-updated', (_e, isDark: boolean) => callback(isDark))
|
||||
},
|
||||
},
|
||||
dialog: {
|
||||
openFile: (options: { title?: string; filters?: { name: string; extensions: string[] }[] }) =>
|
||||
ipcRenderer.invoke('dialog:openFile', options),
|
||||
},
|
||||
credential: {
|
||||
encrypt: (text: string): Promise<string> => ipcRenderer.invoke('credential:encrypt', text),
|
||||
decrypt: (encoded: string): Promise<string> => ipcRenderer.invoke('credential:decrypt', encoded),
|
||||
},
|
||||
storage: {
|
||||
getConnections: (): Promise<any[]> => ipcRenderer.invoke('storage:getConnections'),
|
||||
saveConnection: (conn: any): Promise<any[]> => ipcRenderer.invoke('storage:saveConnection', conn),
|
||||
deleteConnection: (id: string): Promise<any[]> => ipcRenderer.invoke('storage:deleteConnection', id),
|
||||
reorderConnections: (ids: string[]): Promise<any[]> => ipcRenderer.invoke('storage:reorderConnections', ids),
|
||||
getSettings: (): Promise<any> => ipcRenderer.invoke('storage:getSettings'),
|
||||
saveSettings: (settings: any): Promise<void> => ipcRenderer.invoke('storage:saveSettings', settings),
|
||||
},
|
||||
redis: {
|
||||
connect: (id: string, opts: any): Promise<any> => ipcRenderer.invoke('redis:connect', id, opts),
|
||||
disconnect: (id: string): Promise<void> => ipcRenderer.invoke('redis:disconnect', id),
|
||||
execute: (id: string, command: string, args: string[]): Promise<any> =>
|
||||
ipcRenderer.invoke('redis:execute', id, command, args),
|
||||
getInfo: (id: string): Promise<string> => ipcRenderer.invoke('redis:getInfo', id),
|
||||
scanKeys: (id: string, cursor: string, pattern: string, count: number): Promise<any> =>
|
||||
ipcRenderer.invoke('redis:scanKeys', id, cursor, pattern, count),
|
||||
getKeyType: (id: string, key: string): Promise<string> => ipcRenderer.invoke('redis:getKeyType', id, key),
|
||||
getKeyTTL: (id: string, key: string): Promise<number> => ipcRenderer.invoke('redis:getKeyTTL', id, key),
|
||||
getString: (id: string, key: string): Promise<string | null> => ipcRenderer.invoke('redis:getString', id, key),
|
||||
setString: (id: string, key: string, value: string): Promise<void> =>
|
||||
ipcRenderer.invoke('redis:setString', id, key, value),
|
||||
deleteKey: (id: string, key: string): Promise<void> => ipcRenderer.invoke('redis:deleteKey', id, key),
|
||||
hashScan: (id: string, key: string, cursor: string, count: number): Promise<any> =>
|
||||
ipcRenderer.invoke('redis:hashScan', id, key, cursor, count),
|
||||
hashSet: (id: string, key: string, field: string, value: string): Promise<void> =>
|
||||
ipcRenderer.invoke('redis:hashSet', id, key, field, value),
|
||||
hashDel: (id: string, key: string, field: string): Promise<void> =>
|
||||
ipcRenderer.invoke('redis:hashDel', id, key, field),
|
||||
setTTL: (id: string, key: string, ttl: number): Promise<void> =>
|
||||
ipcRenderer.invoke('redis:setTTL', id, key, ttl),
|
||||
selectDb: (id: string, db: number): Promise<void> =>
|
||||
ipcRenderer.invoke('redis:selectDb', id, db),
|
||||
dbSize: (id: string): Promise<number> => ipcRenderer.invoke('redis:dbSize', id),
|
||||
// List
|
||||
listRange: (id: string, key: string, start: number, stop: number): Promise<string[]> =>
|
||||
ipcRenderer.invoke('redis:listRange', id, key, start, stop),
|
||||
listLength: (id: string, key: string): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:listLength', id, key),
|
||||
listPush: (id: string, key: string, values: string[]): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:listPush', id, key, values),
|
||||
listSet: (id: string, key: string, index: number, value: string): Promise<void> =>
|
||||
ipcRenderer.invoke('redis:listSet', id, key, index, value),
|
||||
listRemove: (id: string, key: string, count: number, value: string): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:listRemove', id, key, count, value),
|
||||
// Set
|
||||
setMembers: (id: string, key: string): Promise<string[]> =>
|
||||
ipcRenderer.invoke('redis:setMembers', id, key),
|
||||
setSize: (id: string, key: string): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:setSize', id, key),
|
||||
setAdd: (id: string, key: string, members: string[]): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:setAdd', id, key, members),
|
||||
setRemove: (id: string, key: string, members: string[]): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:setRemove', id, key, members),
|
||||
// Sorted set
|
||||
zsetRange: (id: string, key: string, start: number, stop: number, withScores: boolean): Promise<string[]> =>
|
||||
ipcRenderer.invoke('redis:zsetRange', id, key, start, stop, withScores),
|
||||
zsetSize: (id: string, key: string): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:zsetSize', id, key),
|
||||
zsetAdd: (id: string, key: string, score: number, member: string): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:zsetAdd', id, key, score, member),
|
||||
zsetRemove: (id: string, key: string, members: string[]): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:zsetRemove', id, key, members),
|
||||
// Slow log
|
||||
slowLogGet: (id: string, count: number): Promise<any[]> =>
|
||||
ipcRenderer.invoke('redis:slowLogGet', id, count),
|
||||
slowLogLen: (id: string): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:slowLogLen', id),
|
||||
// Memory
|
||||
memoryUsage: (id: string, key: string): Promise<number | null> =>
|
||||
ipcRenderer.invoke('redis:memoryUsage', id, key),
|
||||
batchDelete: (id: string, keys: string[]): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:batchDelete', id, keys),
|
||||
// Stream
|
||||
streamInfo: (id: string, key: string): Promise<any> =>
|
||||
ipcRenderer.invoke('redis:streamInfo', id, key),
|
||||
streamRange: (id: string, key: string, start: string, end: string, count: number): Promise<any[]> =>
|
||||
ipcRenderer.invoke('redis:streamRange', id, key, start, end, count),
|
||||
streamAdd: (id: string, key: string, streamId: string, fieldValues: string[]): Promise<string> =>
|
||||
ipcRenderer.invoke('redis:streamAdd', id, key, streamId, fieldValues),
|
||||
streamTrim: (id: string, key: string, maxLen: number): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:streamTrim', id, key, maxLen),
|
||||
streamDel: (id: string, key: string, ids: string[]): Promise<number> =>
|
||||
ipcRenderer.invoke('redis:streamDel', id, key, ids),
|
||||
// Key ops
|
||||
renameKey: (id: string, oldKey: string, newKey: string): Promise<void> =>
|
||||
ipcRenderer.invoke('redis:renameKey', id, oldKey, newKey),
|
||||
existsKey: (id: string, key: string): Promise<boolean> =>
|
||||
ipcRenderer.invoke('redis:existsKey', id, key),
|
||||
ping: (id: string): Promise<string> =>
|
||||
ipcRenderer.invoke('redis:ping', id),
|
||||
isConnected: (id: string): Promise<boolean> =>
|
||||
ipcRenderer.invoke('redis:isConnected', id),
|
||||
},
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('electronAPI', electronAPI)
|
||||
Reference in New Issue
Block a user