init
This commit is contained in:
47
mc_test/src/preload.ts
Executable file
47
mc_test/src/preload.ts
Executable file
@ -0,0 +1,47 @@
|
||||
import { LogLevel, MachineAction, ElectronAPI } from './types/electron';
|
||||
import { Machine } from './renderer/types';
|
||||
const { contextBridge, ipcRenderer } = require('electron');
|
||||
|
||||
// Expose protected methods that allow the renderer process to use
|
||||
// the ipcRenderer without exposing the entire object
|
||||
contextBridge.exposeInMainWorld(
|
||||
'electronAPI', {
|
||||
// Connect to machine
|
||||
connectToMachine: (machine: Machine) =>
|
||||
ipcRenderer.invoke('connect-to-machine', machine),
|
||||
|
||||
// Control machine state
|
||||
controlMachine: (machineId: string, action: MachineAction) =>
|
||||
ipcRenderer.invoke('control-machine', { machineId, action }),
|
||||
|
||||
// Get machine status
|
||||
getMachineStatus: (machineId: string) =>
|
||||
ipcRenderer.invoke('get-machine-status', machineId),
|
||||
|
||||
// Get machine list
|
||||
getMachineList: () =>
|
||||
ipcRenderer.invoke('get-machine-list'),
|
||||
|
||||
// Logging
|
||||
logEvent: (level: LogLevel, tag: string, message: string, context?: Record<string, unknown>) =>
|
||||
ipcRenderer.send('log-event', { level, tag, message, context }),
|
||||
|
||||
// FIXED: Secure storage for JWT tokens (XSS protection)
|
||||
encryptData: (plaintext: string) =>
|
||||
ipcRenderer.invoke('encrypt-data', plaintext),
|
||||
|
||||
decryptData: (encrypted: string) =>
|
||||
ipcRenderer.invoke('decrypt-data', encrypted),
|
||||
|
||||
// Check safeStorage availability
|
||||
isEncryptionAvailable: () =>
|
||||
ipcRenderer.invoke('is-encryption-available'),
|
||||
} as ElectronAPI
|
||||
);
|
||||
|
||||
// TypeScript types
|
||||
declare global {
|
||||
interface Window {
|
||||
electronAPI: ElectronAPI;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user