/** * WerksWatcherBridge – Frontend logic for the Werksnummer renaming watcher. */ window.EDIBridge = window.EDIBridge || {}; class WerksWatcherBridge { constructor() { this.status = 'stopped'; this.onStatusChange = null; this.onLogEntry = null; this._setupListeners(); } _setupListeners() { if (!window.electronAPI) return; window.electronAPI.onWerksFileProcessed((data) => { this._addLog('success', data.fileName, `Werk erkannt: ${data.plant} → ${data.newName}`); }); window.electronAPI.onWerksWatcherError((data) => { this._addLog('error', data.fileName || '', data.error || 'Fehler beim Umbenennen'); }); window.electronAPI.onWerksWatcherReady((data) => { this._addLog('info', '', `Werks-Watcher bereit. Überwache: ${data.inputDir}`); }); } _addLog(level, fileName, message) { if (this.onLogEntry) { this.onLogEntry({ time: new Date().toLocaleTimeString('de-DE'), level, fileName, message: `[WerksWatcher] ${message}` }); } } async start(inputDir, outputDir) { if (!window.electronAPI) return { error: 'Electron erforderlich' }; const result = await window.electronAPI.startWerksWatcher({ inputDir, outputDir }); if (result.success) { this.status = 'running'; if (this.onStatusChange) this.onStatusChange(this.status); } return result; } async stop() { if (!window.electronAPI) return; const result = await window.electronAPI.stopWerksWatcher(); if (result.success) { this.status = 'stopped'; if (this.onStatusChange) this.onStatusChange(this.status); } return result; } async pause() { if (!window.electronAPI) return; const result = await window.electronAPI.pauseWerksWatcher(); if (result.success) { this.status = 'paused'; if (this.onStatusChange) this.onStatusChange(this.status); } return result; } async resume() { if (!window.electronAPI) return; const result = await window.electronAPI.resumeWerksWatcher(); if (result.success) { this.status = 'running'; if (this.onStatusChange) this.onStatusChange(this.status); } return result; } isElectron() { return !!window.electronAPI; } } window.EDIBridge.WerksWatcherBridge = WerksWatcherBridge;