feat: setup IPC communication framework
- Add IPC types definition with all communication channels - Implement preload script with API surface for renderer process - Add IPC handler registration stub in main entry point Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -52,6 +52,12 @@ app.whenReady().then(() => {
|
||||
// IPC test
|
||||
ipcMain.on('ping', () => console.log('pong'))
|
||||
|
||||
// IPC Handler Registration
|
||||
// TODO: Register IPC handlers for:
|
||||
// - automation:clean, automation:extract, automation:stop, automation:progress
|
||||
// - database:query-production-orders, database:query-materials-to-delete
|
||||
// - auth:login, auth:logout
|
||||
|
||||
createWindow()
|
||||
|
||||
app.on('activate', function () {
|
||||
|
||||
10
src/main/models/ipc.types.ts
Normal file
10
src/main/models/ipc.types.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface IPCChannels {
|
||||
'automation:clean': any;
|
||||
'automation:extract': any;
|
||||
'automation:stop': any;
|
||||
'automation:progress': any;
|
||||
'database:query-production-orders': any;
|
||||
'database:query-materials-to-delete': any;
|
||||
'auth:login': any;
|
||||
'auth:logout': any;
|
||||
}
|
||||
@@ -1,8 +1,28 @@
|
||||
import { contextBridge } from 'electron'
|
||||
import { contextBridge, ipcRenderer } from 'electron'
|
||||
import { electronAPI } from '@electron-toolkit/preload'
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {}
|
||||
const API = {
|
||||
automation: {
|
||||
clean: (params: any) => ipcRenderer.invoke('automation:clean', params),
|
||||
extract: (params: any) => ipcRenderer.invoke('automation:extract', params),
|
||||
stop: () => ipcRenderer.invoke('automation:stop'),
|
||||
onProgress: (callback: (progress: any) => void) => {
|
||||
const listener = (_: any, progress: any) => callback(progress);
|
||||
ipcRenderer.on('automation:progress', listener);
|
||||
return () => ipcRenderer.removeListener('automation:progress', listener);
|
||||
},
|
||||
},
|
||||
database: {
|
||||
queryProductionOrders: (productionIds: string[]) =>
|
||||
ipcRenderer.invoke('database:query-production-orders', productionIds),
|
||||
queryMaterialsToDelete: (managerNames: string[] | null) =>
|
||||
ipcRenderer.invoke('database:query-materials-to-delete', managerNames),
|
||||
},
|
||||
auth: {
|
||||
login: (credentials: any) => ipcRenderer.invoke('auth:login', credentials),
|
||||
logout: () => ipcRenderer.invoke('auth:logout'),
|
||||
},
|
||||
}
|
||||
|
||||
// Use `contextBridge` APIs to expose Electron APIs to
|
||||
// renderer only if context isolation is enabled, otherwise
|
||||
@@ -10,7 +30,7 @@ const api = {}
|
||||
if (process.contextIsolated) {
|
||||
try {
|
||||
contextBridge.exposeInMainWorld('electron', electronAPI)
|
||||
contextBridge.exposeInMainWorld('api', api)
|
||||
contextBridge.exposeInMainWorld('api', API)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
@@ -18,5 +38,7 @@ if (process.contextIsolated) {
|
||||
// @ts-ignore (define in dts)
|
||||
window.electron = electronAPI
|
||||
// @ts-ignore (define in dts)
|
||||
window.api = api
|
||||
window.api = API
|
||||
}
|
||||
|
||||
export type API = typeof API
|
||||
|
||||
Reference in New Issue
Block a user