This commit is contained in:
root
2025-11-25 09:56:15 +03:00
commit 68c8f0e80d
23717 changed files with 3200521 additions and 0 deletions

47
mc_test/src/preload.ts Executable file
View 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;
}
}