Skip to content

Commit

Permalink
Add mode to simulate tron data
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Aug 12, 2022
1 parent 805619b commit 04e6500
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/main/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
}
Expand All @@ -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) => {
Expand Down
13 changes: 8 additions & 5 deletions src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
send(arg0: string, ...arg1: any): void;
on(arg0: string, listener: any): void;
Expand All @@ -29,6 +29,7 @@ export interface IElectronAPI {
};
tron: {
send(commandString: string, raise?: boolean): Promise<TronEventReplyIFace>;
simulateTronData(sender: string, line: string): Promise<void>;
};
openInBrowser(path: string): void;
openInApplication(command: string): Promise<string>;
Expand All @@ -40,7 +41,6 @@ export interface IElectronAPI {

const API: IElectronAPI = {
log: log.functions,
ipcRenderer: ipcRenderer,
invoke: (channel, ...params) => {
return ipcRenderer.invoke(channel, ...params);
},
Expand All @@ -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);
Expand Down

0 comments on commit 04e6500

Please sign in to comment.