|
1 | | -// @ts-ignore |
2 | | -import * as Electron from "electron"; |
3 | | -import { Connector } from "./connector"; |
| 1 | +import { App } from "electron"; |
| 2 | +import { Socket } from "socket.io"; |
4 | 3 | import { ExcelCreator } from "./excelCreator"; |
5 | 4 |
|
6 | | -export class HookService extends Connector { |
7 | | - constructor(socket: SocketIO.Socket, public app: Electron.App) { |
8 | | - super(socket, app); |
9 | | - } |
| 5 | +export class HookService { |
| 6 | + constructor(private socket: Socket, public app: App) {} |
10 | 7 |
|
11 | | - onHostReady(): void { |
12 | | - // execute your own JavaScript Host logic here |
13 | | - this.on("create-excel-file", async (path, done) => { |
14 | | - const excelCreator: ExcelCreator = new ExcelCreator(); |
15 | | - const result: string = await excelCreator.create(path); |
| 8 | + private on(key: string, cb: (...args: Array<any>) => void): void { |
| 9 | + this.socket.on(key, (...args: Array<any>) => { |
| 10 | + const id: string = args.pop(); |
16 | 11 |
|
17 | | - done(result); |
| 12 | + try { |
| 13 | + cb(...args, (data) => { |
| 14 | + if (data) { |
| 15 | + this.socket.emit(`${key}Complete${id}`, data); |
| 16 | + } |
18 | 17 | }); |
19 | | - } |
20 | | -} |
| 18 | + } catch (error) { |
| 19 | + this.socket.emit(`${key}Error${id}`, `Host Hook Exception`, error); |
| 20 | + } |
| 21 | + }); |
| 22 | + } |
21 | 23 |
|
| 24 | + onHostReady(): void { |
| 25 | + // execute your own JavaScript Host logic here |
| 26 | + this.on("create-excel-file", async (path, done) => { |
| 27 | + const excelCreator: ExcelCreator = new ExcelCreator(); |
| 28 | + const result: string = await excelCreator.create(path); |
| 29 | + |
| 30 | + done(result); |
| 31 | + }); |
| 32 | + } |
| 33 | +} |
0 commit comments