Skip to content

Commit

Permalink
replace "event.sender.send" call with "event.reply"
Browse files Browse the repository at this point in the history
side changes:
- only electron 5+ is supported since earlier releases didn't have the "event.reply" method
- drop node 11 support
  • Loading branch information
vladimiry committed Jul 31, 2019
1 parent 1c9143f commit c00c154
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 131 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ branches:
- "master"
language: node_js
node_js:
- "lts/*"
- "12"
- "10"
- "8"
os:
- linux
- osx
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-rpc-api",
"version": "5.1.0",
"version": "6.0.0-beta2",
"description": "Wrapper around the Electron's IPC for building type-safe API based RPC-like and reactive interactions",
"author": "Vladimir Yakovlev <[email protected]> (https://github.com/vladimiry)",
"license": "MIT",
Expand All @@ -13,7 +13,7 @@
],
"main": "./lib/index.js",
"engines": {
"node": ">=8.9.4 <9 || >=10.0.0 < 11 || >=11"
"node": ">=8.9.4 <9 || >=10.0.0 <11 || >=12.0.0"
},
"scripts": {
"lib": "npm-run-all lib:clean lint lib:compile test",
Expand Down Expand Up @@ -50,7 +50,7 @@
"@types/sinon": "^7.0.13",
"ava": "^1.2.1",
"cross-env": "^5.2.0",
"electron": "^5.0.6",
"electron": "^6.0.0",
"husky": "^3.0.0",
"import-sort-cli": "^6.0.0",
"import-sort-parser-typescript": "^6.0.0",
Expand Down
13 changes: 4 additions & 9 deletions src/lib/ipc-main-api-service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as Lib from "pubsub-to-rpc-api";
import {IpcMain, IpcMessageEvent, IpcRenderer} from "electron";
import {IpcMain, IpcMainEvent, IpcRenderer} from "electron";

import * as PM from "./private/model";
import {curryOwnFunctionMembers} from "./private/util";
import {requireIpcMain, requireIpcRenderer} from "./private/electron-require";

// TODO infer from Electron.IpcMain["on"] listener arguments
type DefACA = [IpcMessageEvent, ...PM.Any[]];
type DefACA = [IpcMainEvent, ...PM.Any[]];

type IpcMainEventEmittersCache = Pick<IpcMain, "on" | "removeListener" | "emit">;
type IpcRendererEventEmittersCache = Pick<IpcRenderer, "on" | "removeListener" | "send">;
Expand Down Expand Up @@ -59,17 +59,12 @@ export function createIpcMainApiService<AD extends Lib.Model.ApiDefinition<AD>,
actions,
cachedEm,
{
onEventResolver: (...[{sender}, payload]) => {
onEventResolver: (...[event, payload]) => {
return {
payload,
emitter: {
emit: (...args) => {
if (!sender.isDestroyed()) {
return sender.send(...args);
}
if (logger) {
logger.warn(`[${PM.MODULE_NAME}]`, `Object has been destroyed: "sender"`);
}
event.reply(...args);
},
},
};
Expand Down
Loading

0 comments on commit c00c154

Please sign in to comment.