mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-09-23 23:45:19 +00:00
fix ElectronHostHook path, exception handling
This commit is contained in:
@@ -34,7 +34,15 @@ namespace ElectronNET.API
|
||||
|
||||
public void Call(string socketEventName, params dynamic[] arguments)
|
||||
{
|
||||
BridgeConnector.Socket.Emit(socketEventName, arguments);
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On(socketEventName + "Error" + guid, (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(socketEventName + "Error" + guid);
|
||||
Electron.Dialog.ShowErrorBox("Host Hook Exception", result.ToString());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.Emit(socketEventName, arguments, guid);
|
||||
}
|
||||
|
||||
public Task<T> CallAsync<T>(string socketEventName, params dynamic[] arguments)
|
||||
@@ -42,6 +50,12 @@ namespace ElectronNET.API
|
||||
var taskCompletionSource = new TaskCompletionSource<T>();
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
|
||||
BridgeConnector.Socket.On(socketEventName + "Error" + guid, (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(socketEventName + "Error" + guid);
|
||||
Electron.Dialog.ShowErrorBox("Host Hook Exception", result.ToString());
|
||||
});
|
||||
|
||||
BridgeConnector.Socket.On(socketEventName + "Complete" + guid, (result) =>
|
||||
{
|
||||
BridgeConnector.Socket.Off(socketEventName + "Complete" + guid);
|
||||
|
||||
@@ -5,9 +5,17 @@ export class Connector {
|
||||
this.socket.on(key, (...args: any[]) => {
|
||||
const id: string = args.pop();
|
||||
|
||||
javaScriptCode(args, (data) => {
|
||||
this.socket.emit(`${key}Complete${id}`, data);
|
||||
});
|
||||
try {
|
||||
javaScriptCode(...args, (data) => {
|
||||
if (isNaN(data)) {
|
||||
throw new Error('Result is NaN');
|
||||
} else {
|
||||
this.socket.emit(`${key}Complete${id}`, data);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
this.socket.emit(`${key}Error${id}`, 'Host Hook Exception', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as Electron from "electron";
|
||||
import { Connector } from "./connector";
|
||||
|
||||
export class HookService extends Connector {
|
||||
constructor(socket: SocketIO.Socket, public app: Electron.App) {
|
||||
|
||||
@@ -106,7 +106,7 @@ function startSocketApiBridge(port) {
|
||||
}
|
||||
|
||||
try {
|
||||
const hostHookScriptFilePath = path.join(__dirname, 'bin', 'ElectronHostHook', 'index.js');
|
||||
const hostHookScriptFilePath = path.join(__dirname, 'ElectronHostHook', 'index.js');
|
||||
const { HookService } = require(hostHookScriptFilePath);
|
||||
if (hostHook === undefined) {
|
||||
hostHook = new HookService(socket, app);
|
||||
|
||||
Reference in New Issue
Block a user