From 04e65006e845eb4c4807b6f56e530d3ca5ad9b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20S=C3=A1nchez-Gallego?= Date: Thu, 11 Aug 2022 22:01:44 -0400 Subject: [PATCH] Add mode to simulate tron data --- src/main/events.ts | 6 +++++- src/main/preload.ts | 13 ++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/events.ts b/src/main/events.ts index c897e45..5744093 100644 --- a/src/main/events.ts +++ b/src/main/events.ts @@ -96,7 +96,7 @@ export default function loadEvents() { ipcMain.handle( 'tron-send-command', async (event, commandString: string, raise: boolean = false) => { - let command = await tron.sendCommand(commandString); + let command = await tron.sendCommand(commandString).then(); if (command.status === CommandStatus.Failed && raise) { throw Error(`Command ${command.rawCommand} failed.`); } @@ -109,6 +109,10 @@ export default function loadEvents() { } ); + ipcMain.handle('tron-simulate-data', async (event, sender: string, line: string) => + tron.parseData(`.${sender} 666 ${sender} d ${line}`) + ); + ipcMain.handle( 'tron-register-model-listener', async (event, keys: string[], listenOn, refresh = true) => { diff --git a/src/main/preload.ts b/src/main/preload.ts index f545e4f..340a78b 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -8,17 +8,17 @@ * @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause) */ -import { contextBridge, dialog, ipcRenderer, IpcRenderer } from 'electron'; +import { contextBridge, dialog, ipcRenderer } from 'electron'; import log from 'electron-log'; import { TronEventReplyIFace } from './events'; import store from './store'; // TODO: According to https://bit.ly/38aeKXB, we should not expose the ipcRenderer -// directly. Instead, we should expose the channels from events.ts here. +// directly. Instead, we should expose the channels from events.ts here. We should also +// not expose the ipcRendered invoke, send, on functions. export interface IElectronAPI { log: log.LogFunctions; - ipcRenderer: IpcRenderer; invoke(arg0: string, ...arg1: any): Promise; send(arg0: string, ...arg1: any): void; on(arg0: string, listener: any): void; @@ -29,6 +29,7 @@ export interface IElectronAPI { }; tron: { send(commandString: string, raise?: boolean): Promise; + simulateTronData(sender: string, line: string): Promise; }; openInBrowser(path: string): void; openInApplication(command: string): Promise; @@ -40,7 +41,6 @@ export interface IElectronAPI { const API: IElectronAPI = { log: log.functions, - ipcRenderer: ipcRenderer, invoke: (channel, ...params) => { return ipcRenderer.invoke(channel, ...params); }, @@ -58,7 +58,10 @@ const API: IElectronAPI = { }, tron: { send: async (commandString, raise = false) => - ipcRenderer.invoke('tron-send-command', commandString, raise) + ipcRenderer.invoke('tron-send-command', commandString, raise), + simulateTronData: async (sender, line) => { + ipcRenderer.invoke('tron-simulate-data', sender, line); + } }, openInBrowser: (path) => { require('electron').shell.openExternal(path);