@3fv/electron-utility-process-manager 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -26
- package/examples/lib-examples/simple/simple-main.js +9 -2
- package/examples/lib-examples/simple/simple-main.js.map +1 -1
- package/examples/lib-examples/simple/simple-renderer.js +1 -1
- package/examples/lib-examples/simple/simple-renderer.js.map +1 -1
- package/lib/cjs/common/clients.d.ts +5 -1
- package/lib/cjs/common/clients.js +11 -11
- package/lib/cjs/common/clients.js.map +1 -1
- package/lib/cjs/common/guards.d.ts +1 -1
- package/lib/cjs/common/index.d.ts +3 -3
- package/lib/cjs/common/index.js +3 -3
- package/lib/cjs/common/index.js.map +1 -1
- package/lib/cjs/common/types.d.ts +23 -1
- package/lib/cjs/common/types.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +2 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/main/UPMMainService.d.ts +111 -29
- package/lib/cjs/main/UPMMainService.js +250 -136
- package/lib/cjs/main/UPMMainService.js.map +1 -1
- package/lib/cjs/main/UPMMainServiceManager.d.ts +4 -3
- package/lib/cjs/main/UPMMainServiceManager.js +6 -6
- package/lib/cjs/main/UPMMainServiceManager.js.map +1 -1
- package/lib/cjs/main/index.d.ts +2 -2
- package/lib/cjs/main/index.js +2 -2
- package/lib/cjs/main/index.js.map +1 -1
- package/lib/cjs/node/UPMNodeProcess.d.ts +4 -4
- package/lib/cjs/node/UPMNodeProcess.js +1 -1
- package/lib/cjs/node/UPMNodeProcess.js.map +1 -1
- package/lib/cjs/node/index.d.ts +2 -2
- package/lib/cjs/node/index.js +3 -3
- package/lib/cjs/node/index.js.map +1 -1
- package/lib/cjs/renderer/UPMRendererClientFactory.d.ts +1 -1
- package/lib/cjs/renderer/UPMRendererClientFactory.js +1 -1
- package/lib/cjs/renderer/UPMRendererClientFactory.js.map +1 -1
- package/lib/cjs/renderer/index.d.ts +2 -2
- package/lib/cjs/renderer/index.js +3 -3
- package/lib/cjs/renderer/index.js.map +1 -1
- package/lib/mjs/common/clients.d.ts +5 -1
- package/lib/mjs/common/clients.js +3 -3
- package/lib/mjs/common/clients.js.map +1 -1
- package/lib/mjs/common/guards.d.ts +1 -1
- package/lib/mjs/common/index.d.ts +3 -3
- package/lib/mjs/common/index.js +3 -3
- package/lib/mjs/common/index.js.map +1 -1
- package/lib/mjs/common/types.d.ts +23 -1
- package/lib/mjs/common/types.js.map +1 -1
- package/lib/mjs/index.d.ts +2 -2
- package/lib/mjs/index.js +2 -2
- package/lib/mjs/index.js.map +1 -1
- package/lib/mjs/main/UPMMainService.d.ts +111 -29
- package/lib/mjs/main/UPMMainService.js +252 -138
- package/lib/mjs/main/UPMMainService.js.map +1 -1
- package/lib/mjs/main/UPMMainServiceManager.d.ts +4 -3
- package/lib/mjs/main/UPMMainServiceManager.js +6 -6
- package/lib/mjs/main/UPMMainServiceManager.js.map +1 -1
- package/lib/mjs/main/index.d.ts +2 -2
- package/lib/mjs/main/index.js +2 -2
- package/lib/mjs/main/index.js.map +1 -1
- package/lib/mjs/node/UPMNodeProcess.d.ts +4 -4
- package/lib/mjs/node/UPMNodeProcess.js +1 -1
- package/lib/mjs/node/UPMNodeProcess.js.map +1 -1
- package/lib/mjs/node/index.d.ts +2 -2
- package/lib/mjs/node/index.js +2 -2
- package/lib/mjs/node/index.js.map +1 -1
- package/lib/mjs/renderer/UPMRendererClientFactory.d.ts +1 -1
- package/lib/mjs/renderer/UPMRendererClientFactory.js +1 -1
- package/lib/mjs/renderer/UPMRendererClientFactory.js.map +1 -1
- package/lib/mjs/renderer/index.d.ts +2 -2
- package/lib/mjs/renderer/index.js +2 -2
- package/lib/mjs/renderer/index.js.map +1 -1
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
#
|
|
2
|
-
---
|
|
1
|
+
# Electron UPM (Utility Process Manager)
|
|
3
2
|
|
|
4
3
|
## Overview
|
|
5
4
|
|
|
6
|
-
`@3fv/electron-utility-process-manager` manages `1..n` `Electron.utilityProcess` instances/services/processes via a
|
|
7
|
-
single library & provides fully typed client facades automatically
|
|
5
|
+
`@3fv/electron-utility-process-manager` manages `1..n` `Electron.utilityProcess` instances/services/processes via a
|
|
6
|
+
single library & provides fully typed client facades automatically
|
|
8
7
|
|
|
9
8
|
## Install
|
|
10
9
|
|
|
@@ -14,21 +13,42 @@ yarn add @3fv/electron-utility-process-manager
|
|
|
14
13
|
|
|
15
14
|
## Usage
|
|
16
15
|
|
|
17
|
-
This library integrates into the `node`, `main` and `renderer` processes to provide
|
|
16
|
+
This library integrates into the `node`, `main` and `renderer` processes to provide
|
|
18
17
|
transparent access from any process to a `node` (`Electron.utilityProcess`).
|
|
19
18
|
|
|
20
|
-
### Possible Use-cases
|
|
19
|
+
### Possible Use-cases
|
|
21
20
|
|
|
22
21
|
- main -> node
|
|
23
22
|
- renderer -> node
|
|
24
23
|
- node -> node
|
|
25
24
|
|
|
25
|
+
|
|
26
|
+
### Debugging Config (Applies to all examples)
|
|
27
|
+
|
|
28
|
+
In order to debug a service/utility process, simply add the following to
|
|
29
|
+
the `options` argument passed to `createService`
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// ENABLE DEBUGGING (standard node.js inspect config)
|
|
33
|
+
const options = {
|
|
34
|
+
inspect: {
|
|
35
|
+
break: true,
|
|
36
|
+
port: 9449
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
upmMainServiceManager.createService("example-service", "/path/to/entry.js", options)
|
|
40
|
+
```
|
|
41
|
+
> NOTE: If `break` is `true` the utility/service process
|
|
42
|
+
> will not be paused until a debugger is attached.
|
|
43
|
+
> the process will print a chrome debugging url (i.e. `ws://`)
|
|
44
|
+
|
|
45
|
+
|
|
26
46
|
### Examples
|
|
27
47
|
|
|
28
48
|
#### Simple Example
|
|
29
49
|
|
|
30
50
|
> NOTE: The simple example uses the bare-bones approach
|
|
31
|
-
> and basically avoids typing wherever possible.
|
|
51
|
+
> and basically avoids typing wherever possible. For a
|
|
32
52
|
> fully typed example, checkout the [complex example](#complex-example)
|
|
33
53
|
|
|
34
54
|
##### Node/Utility Process ([simple-node.ts](examples/simple/simple-node.ts))
|
|
@@ -41,13 +61,13 @@ upmNodeProcess.addEventHandler((clientId, port, payload) => {
|
|
|
41
61
|
return true
|
|
42
62
|
})
|
|
43
63
|
|
|
44
|
-
upmNodeProcess.addRequestHandler("ping", async (type, messageId, what:
|
|
64
|
+
upmNodeProcess.addRequestHandler("ping", async (type, messageId, what:string) => {
|
|
45
65
|
console.info(`Ping request received (${messageId})`, what)
|
|
46
66
|
return `pong: ${what}`
|
|
47
67
|
})
|
|
48
68
|
```
|
|
49
69
|
|
|
50
|
-
##### Main Process ([simple-main.ts](examples/simple/simple-main.ts))
|
|
70
|
+
##### Main Process ([simple-main.ts](examples/simple/simple-main.ts))
|
|
51
71
|
|
|
52
72
|
```typescript
|
|
53
73
|
import { app, BrowserWindow } from "electron"
|
|
@@ -55,15 +75,14 @@ import { UPM } from "@3fv/electron-utility-process-manager"
|
|
|
55
75
|
import type { UPMMainService } from "@3fv/electron-utility-process-manager/main"
|
|
56
76
|
import Path from "path"
|
|
57
77
|
|
|
58
|
-
let upmService:
|
|
78
|
+
let upmService:UPMMainService = null
|
|
59
79
|
|
|
60
80
|
async function start() {
|
|
61
81
|
const upm = await import("@3fv/electron-utility-process-manager/main")
|
|
62
82
|
const upmManager = upm.upmMainServiceManager
|
|
63
83
|
|
|
64
84
|
Object.assign(global, {
|
|
65
|
-
upm,
|
|
66
|
-
upmManager
|
|
85
|
+
upm, upmManager
|
|
67
86
|
})
|
|
68
87
|
|
|
69
88
|
console.info("UPM manager ready, now creating service", upmManager)
|
|
@@ -74,8 +93,7 @@ async function start() {
|
|
|
74
93
|
|
|
75
94
|
const clientPort = upmManager.createMainChannel("simple", "main-channel-01")
|
|
76
95
|
console.info("Start the client port")
|
|
77
|
-
if (UPM.isMessagePort(clientPort))
|
|
78
|
-
clientPort.start()
|
|
96
|
+
if (UPM.isMessagePort(clientPort)) clientPort.start()
|
|
79
97
|
|
|
80
98
|
console.info("Post a message directly")
|
|
81
99
|
clientPort.postMessage({
|
|
@@ -90,7 +108,7 @@ async function start() {
|
|
|
90
108
|
const client = upmManager.createMainClient("simple", "main-client-01")
|
|
91
109
|
console.info(`Send request/response: ping`)
|
|
92
110
|
|
|
93
|
-
const pongResult = await client.executeRequest("ping",
|
|
111
|
+
const pongResult = await client.executeRequest("ping", "main")
|
|
94
112
|
console.info(`Received pong response`, pongResult)
|
|
95
113
|
|
|
96
114
|
await createWindow()
|
|
@@ -110,15 +128,10 @@ async function start() {
|
|
|
110
128
|
*
|
|
111
129
|
* @returns {Promise<void>}
|
|
112
130
|
*/
|
|
113
|
-
async function createWindow():
|
|
131
|
+
async function createWindow():Promise<void> {
|
|
114
132
|
const mainWindow = new BrowserWindow({
|
|
115
|
-
width: 1000,
|
|
116
|
-
|
|
117
|
-
webPreferences: {
|
|
118
|
-
contextIsolation: false,
|
|
119
|
-
nodeIntegration: true,
|
|
120
|
-
sandbox: false,
|
|
121
|
-
devTools: true
|
|
133
|
+
width: 1000, height: 1000, webPreferences: {
|
|
134
|
+
contextIsolation: false, nodeIntegration: true, sandbox: false, devTools: true
|
|
122
135
|
}
|
|
123
136
|
})
|
|
124
137
|
|
|
@@ -144,13 +157,13 @@ import UPMRendererClientFactory from "@3fv/electron-utility-process-manager/rend
|
|
|
144
157
|
document.querySelector("#root").innerHTML = `simple-renderer-example`
|
|
145
158
|
|
|
146
159
|
async function simpleExampleUPM() {
|
|
147
|
-
const client = await UPMRendererClientFactory.createClient("simple"
|
|
148
|
-
const result = await client.executeRequest("ping",
|
|
160
|
+
const client = await UPMRendererClientFactory.createClient("simple", `${process.type}-01`)
|
|
161
|
+
const result = await client.executeRequest("ping", process.type)
|
|
149
162
|
console.info(`Result: ${result}`)
|
|
150
163
|
}
|
|
151
164
|
|
|
152
165
|
simpleExampleUPM()
|
|
153
|
-
|
|
166
|
+
.catch(err => console.error(`renderer error: ${err.message}`, err))
|
|
154
167
|
|
|
155
168
|
export {}
|
|
156
169
|
```
|
|
@@ -66,7 +66,14 @@ async function start() {
|
|
|
66
66
|
upmManager
|
|
67
67
|
});
|
|
68
68
|
log.info("UPM manager ready, now creating service", upmManager);
|
|
69
|
-
|
|
69
|
+
const entryFile = path_1.default.join(__dirname, "simple-node.js");
|
|
70
|
+
upmService = await upmManager.createService("simple", entryFile, {
|
|
71
|
+
// ENABLE DEBUGGING (standard node.js inspect config)
|
|
72
|
+
// inspect: {
|
|
73
|
+
// break: true,
|
|
74
|
+
// port: 9449
|
|
75
|
+
// }
|
|
76
|
+
});
|
|
70
77
|
log.info("UPM service ready");
|
|
71
78
|
upmService.sendEvent("test123");
|
|
72
79
|
const clientPort = upmManager.createMainChannel("simple", "main-channel-01");
|
|
@@ -83,7 +90,7 @@ async function start() {
|
|
|
83
90
|
log.info(`Creating port client`);
|
|
84
91
|
const client = upmManager.createMainClient("simple", "main-client-01");
|
|
85
92
|
log.info(`Send request/response: ping`);
|
|
86
|
-
const pongResult = await client.executeRequest("ping",
|
|
93
|
+
const pongResult = await client.executeRequest("ping", "main");
|
|
87
94
|
log.info(`Received pong response`, pongResult);
|
|
88
95
|
log.info(`Create the window/renderer`);
|
|
89
96
|
await createWindow();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-main.js","sourceRoot":"","sources":["../../simple/simple-main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uEAAuE;AACvE,uCAA6C;AAC7C,4FAA2D;AAG3D,oDAA2B;AAC3B,gDAAuB;AAEvB,MAAM,GAAG,GAAG,gBAAM,CAAC,YAAY,EAAE,CAAA;AACjC,IAAI,UAAU,GAAmB,IAAI,CAAA;AAErC;;;;;;;;GAQG;AACH,KAAK,UAAU,YAAY;IACzB,MAAM,UAAU,GAAG,IAAI,wBAAa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AAE,CAAC,mBAAmB,EAAE;IAC1B,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAAE,cAAG,CAAC,IAAI,EAAE,CAAA;AAC/C,CAAC,CAAC,CAAA;AAEF,4EAA4E;AAC5E,uEAAuE"}
|
|
@@ -9,7 +9,7 @@ const log = tracer_1.default.colorConsole();
|
|
|
9
9
|
document.querySelector("#root").innerHTML = `simple-renderer-example`;
|
|
10
10
|
async function simpleExampleUPM() {
|
|
11
11
|
const client = await renderer_1.default.createClient("simple", `${process.type}-01`);
|
|
12
|
-
const result = await client.executeRequest("ping",
|
|
12
|
+
const result = await client.executeRequest("ping", process.type);
|
|
13
13
|
log.info(`Result: ${result}`);
|
|
14
14
|
}
|
|
15
15
|
simpleExampleUPM()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-renderer.js","sourceRoot":"","sources":["../../simple/simple-renderer.ts"],"names":[],"mappings":";;;;;AAAA,8FAAqF;AACrF,oDAA2B;AAE3B,MAAM,GAAG,GAAG,gBAAM,CAAC,YAAY,EAAE,CAAA;AAEjC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,SAAS,GAAG,yBAAyB,CAAA;AAErE,KAAK,UAAU,gBAAgB;IAC7B,MAAM,MAAM,GAAG,MAAM,kBAAwB,CAAC,YAAY,CAAC,QAAQ,EAAC,GAAG,OAAO,CAAC,IAAI,KAAK,CAAC,CAAA;IACzF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"simple-renderer.js","sourceRoot":"","sources":["../../simple/simple-renderer.ts"],"names":[],"mappings":";;;;;AAAA,8FAAqF;AACrF,oDAA2B;AAE3B,MAAM,GAAG,GAAG,gBAAM,CAAC,YAAY,EAAE,CAAA;AAEjC,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,SAAS,GAAG,yBAAyB,CAAA;AAErE,KAAK,UAAU,gBAAgB;IAC7B,MAAM,MAAM,GAAG,MAAM,kBAAwB,CAAC,YAAY,CAAC,QAAQ,EAAC,GAAG,OAAO,CAAC,IAAI,KAAK,CAAC,CAAA;IACzF,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IAChE,GAAG,CAAC,IAAI,CAAC,WAAW,MAAM,EAAE,CAAC,CAAA;AAC/B,CAAC;AAED,gBAAgB,EAAE;KACf,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,mBAAmB,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MessageRequestFn, MessageRequestMap, MessageRequestNames, MessageRequestParams, MessageRequestReturnType, Port } from "./types";
|
|
1
|
+
import { MessageRequestFn, MessageRequestMap, MessageRequestNames, MessageRequestParams, MessageRequestReturnType, Port } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Service client interface maps a `MessageRequestMap`
|
|
4
4
|
* to its functional methods
|
|
@@ -10,6 +10,10 @@ export type IServiceClient<ReqMap extends MessageRequestMap, MType extends Messa
|
|
|
10
10
|
* Messaging client interface
|
|
11
11
|
*/
|
|
12
12
|
export interface IMessageClient<ReqMap extends MessageRequestMap, MType extends MessageRequestNames<ReqMap> = MessageRequestNames<ReqMap>> {
|
|
13
|
+
/**
|
|
14
|
+
* Get the clientId for the underlying port
|
|
15
|
+
*/
|
|
16
|
+
get clientId(): string;
|
|
13
17
|
/**
|
|
14
18
|
* A very low level function for sending `any` data
|
|
15
19
|
* to the `utilityProcess`
|
|
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.MessagePortClient = void 0;
|
|
7
7
|
const guard_1 = require("@3fv/guard");
|
|
8
|
-
const
|
|
8
|
+
const guards_js_1 = require("./guards.js");
|
|
9
9
|
const tracer_1 = __importDefault(require("tracer"));
|
|
10
|
-
const
|
|
10
|
+
const types_js_1 = require("./types.js");
|
|
11
11
|
const deferred_1 = require("@3fv/deferred");
|
|
12
12
|
const log = tracer_1.default.colorConsole();
|
|
13
13
|
/**
|
|
@@ -63,8 +63,8 @@ class MessagePortClient {
|
|
|
63
63
|
payloadOrEnvelopeOrData),
|
|
64
64
|
// FIND THE CHANNEL & PAYLOAD DEPENDING ON THE PROCESS & TRANSPORT
|
|
65
65
|
[channel, payload] = ((0, guard_1.isDefined)(payloadOrEnvelope === null || payloadOrEnvelope === void 0 ? void 0 : payloadOrEnvelope["payload"]) ?
|
|
66
|
-
[(_a = payloadOrEnvelope["channel"]) !== null && _a !== void 0 ? _a :
|
|
67
|
-
[
|
|
66
|
+
[(_a = payloadOrEnvelope["channel"]) !== null && _a !== void 0 ? _a : types_js_1.IPCChannel.UPMServiceMessage, payloadOrEnvelope["payload"]] :
|
|
67
|
+
[types_js_1.IPCChannel.UPMServiceMessage, payloadOrEnvelope]), { messageId, result, error } = payload;
|
|
68
68
|
try {
|
|
69
69
|
const pending = this.pendingMessages_.get(messageId);
|
|
70
70
|
if (!pending) {
|
|
@@ -90,8 +90,8 @@ class MessagePortClient {
|
|
|
90
90
|
sendEvent(data) {
|
|
91
91
|
const messageId = this.generateMessageId();
|
|
92
92
|
const payload = {
|
|
93
|
-
channel:
|
|
94
|
-
payload: { messageId, data, kind:
|
|
93
|
+
channel: types_js_1.IPCChannel.UPMServiceMessage,
|
|
94
|
+
payload: { messageId, eventData: data, kind: types_js_1.MessageKind.Event }
|
|
95
95
|
};
|
|
96
96
|
this.port.postMessage(payload);
|
|
97
97
|
}
|
|
@@ -99,12 +99,12 @@ class MessagePortClient {
|
|
|
99
99
|
const messageId = this.generateMessageId(), pending = {
|
|
100
100
|
deferred: new deferred_1.Deferred(),
|
|
101
101
|
messageId,
|
|
102
|
-
timeoutId: setTimeout(() => this.removePendingMessage(messageId),
|
|
102
|
+
timeoutId: setTimeout(() => this.removePendingMessage(messageId), types_js_1.Defaults.RequestTimeout)
|
|
103
103
|
};
|
|
104
104
|
this.pendingMessages_.set(messageId, pending);
|
|
105
105
|
const payload = {
|
|
106
|
-
channel:
|
|
107
|
-
payload: { type, messageId, args, kind:
|
|
106
|
+
channel: types_js_1.IPCChannel.UPMServiceMessage,
|
|
107
|
+
payload: { type, messageId, args, kind: types_js_1.MessageKind.Request }
|
|
108
108
|
};
|
|
109
109
|
this.port.postMessage(payload);
|
|
110
110
|
try {
|
|
@@ -159,7 +159,7 @@ class MessagePortClient {
|
|
|
159
159
|
* @private
|
|
160
160
|
*/
|
|
161
161
|
this.pendingMessages_ = new Map();
|
|
162
|
-
if ((0,
|
|
162
|
+
if ((0, guards_js_1.isMessagePort)(port) || (0, guards_js_1.isUtilityProcess)(port)) {
|
|
163
163
|
if ((0, guard_1.isFunction)(port === null || port === void 0 ? void 0 : port["addEventListener"])) {
|
|
164
164
|
;
|
|
165
165
|
port.addEventListener("message", this.onMessage.bind(this));
|
|
@@ -167,7 +167,7 @@ class MessagePortClient {
|
|
|
167
167
|
else {
|
|
168
168
|
port.on("message", this.onMessage.bind(this));
|
|
169
169
|
}
|
|
170
|
-
if ((0,
|
|
170
|
+
if ((0, guards_js_1.isMessagePort)(port))
|
|
171
171
|
port.start();
|
|
172
172
|
}
|
|
173
173
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../src/common/clients.ts"],"names":[],"mappings":";;;;;;AAAA,sCAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"clients.js","sourceRoot":"","sources":["../../../src/common/clients.ts"],"names":[],"mappings":";;;;;;AAAA,sCAAkD;AAClD,2CAA6D;AAC7D,oDAA2B;AAC3B,yCASmB;AACnB,4CAAwC;AAExC,MAAM,GAAG,GAAG,gBAAM,CAAC,YAAY,EAAE,CAAA;AA+DjC;;;;;;;;GAQG;AAC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E;qBACxC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,IAAa,EAAE,GAAG,IAAW,CAAC,CAAC,CAAA;YAEzE,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IAED;;;;;OAKG;IACH,YAAqB,QAAgB,EAAW,IAAU;QAArC,aAAQ,GAAR,QAAQ,CAAQ;QAAW,SAAI,GAAJ,IAAI,CAAM;QAtK1D;;;;WAIG;QACK,gBAAW,GAAW,CAAC,CAAA;QAE/B;;;;;WAKG;QACc,qBAAgB,GAAG,IAAI,GAAG,EAAiC,CAAA;QA0J1E,IAAI,IAAA,yBAAa,EAAC,IAAI,CAAC,IAAI,IAAA,4BAAgB,EAAC,IAAI,CAAC,EAAE,CAAC;YAClD,IAAI,IAAA,kBAAU,EAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAG,kBAAkB,CAAC,CAAC,EAAE,CAAC;gBAC3C,CAAC;gBACC,IACD,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;YAC1D,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;YAC/C,CAAC;YACD,IAAI,IAAA,yBAAa,EAAC,IAAI,CAAC;gBACrB,IAAI,CAAC,KAAK,EAAE,CAAA;QAChB,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,KAAK,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;YAC/B,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAA;QACjC,CAAC;IAEH,CAAC;CACF;AA5LD,8CA4LC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { UtilityProcess } from "electron";
|
|
2
|
-
import { Port } from "./types";
|
|
2
|
+
import { Port } from "./types.js";
|
|
3
3
|
export declare function isMessagePort(port: Port): port is Electron.MessagePortMain;
|
|
4
4
|
export declare function isUtilityProcess(port: Port): port is UtilityProcess;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./types";
|
|
2
|
-
export * from "./guards";
|
|
3
|
-
export * from "./clients";
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./guards.js";
|
|
3
|
+
export * from "./clients.js";
|
package/lib/cjs/common/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./types"), exports);
|
|
18
|
-
__exportStar(require("./guards"), exports);
|
|
19
|
-
__exportStar(require("./clients"), exports);
|
|
17
|
+
__exportStar(require("./types.js"), exports);
|
|
18
|
+
__exportStar(require("./guards.js"), exports);
|
|
19
|
+
__exportStar(require("./clients.js"), exports);
|
|
20
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,8CAA2B;AAC3B,+CAA4B"}
|
|
@@ -21,7 +21,7 @@ export type MessageRequestMap = {};
|
|
|
21
21
|
export type MessageRequestNames<ReqMap extends MessageRequestMap> = keyof ReqMap;
|
|
22
22
|
export type MessageRequestFn<ReqMap extends MessageRequestMap, Name extends MessageRequestNames<ReqMap>> = ReqMap[Name] extends MessageRequestFnBase ? ReqMap[Name] : never;
|
|
23
23
|
export type MessageRequestParams<ReqMap extends MessageRequestMap, Name extends MessageRequestNames<ReqMap>> = ReqMap[Name] extends MessageRequestFnBase ? Parameters<ReqMap[Name]> : never;
|
|
24
|
-
export type MessageRequestReturnType<ReqMap extends MessageRequestMap, Name extends MessageRequestNames<ReqMap>> = ReqMap[Name] extends MessageRequestFnBase ? ReturnType<ReqMap[Name]
|
|
24
|
+
export type MessageRequestReturnType<ReqMap extends MessageRequestMap, Name extends MessageRequestNames<ReqMap>> = ReqMap[Name] extends MessageRequestFnBase ? Awaited<ReturnType<ReqMap[Name]>> : never;
|
|
25
25
|
export interface Message<ReqMap extends MessageRequestMap = any, Type extends MessageRequestNames<ReqMap> = MessageRequestNames<ReqMap>, Args extends MessageRequestParams<ReqMap, Type> = MessageRequestParams<ReqMap, Type>, R extends MessageRequestReturnType<ReqMap, Type> = MessageRequestReturnType<ReqMap, Type>> {
|
|
26
26
|
type: Type;
|
|
27
27
|
kind: MessageKind;
|
|
@@ -46,4 +46,26 @@ export interface PendingRequestMessage<ReqMap extends MessageRequestMap = any, T
|
|
|
46
46
|
* @returns true if payload was handled, false if not
|
|
47
47
|
*/
|
|
48
48
|
export type EventHandler = (clientId: string, port: Port, payload: any) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Port of any kind
|
|
51
|
+
*/
|
|
49
52
|
export type Port = MessagePort | Electron.MessagePortMain | Electron.ParentPort | UtilityProcess;
|
|
53
|
+
/**
|
|
54
|
+
* Debugging & Inspection config
|
|
55
|
+
*/
|
|
56
|
+
export type ServiceInspectConfig = number | {
|
|
57
|
+
port: number;
|
|
58
|
+
break?: boolean;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Configuration to use when creating/launching
|
|
62
|
+
* a service (`Electron.UtilityProcess`)
|
|
63
|
+
*/
|
|
64
|
+
export interface CreateServiceConfig {
|
|
65
|
+
serviceName: string;
|
|
66
|
+
inspect: false | ServiceInspectConfig;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Optional/Partial `CreateServiceConfig`
|
|
70
|
+
*/
|
|
71
|
+
export type CreateServiceOptions = Partial<CreateServiceConfig>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/common/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/common/types.ts"],"names":[],"mappings":";;;AAIa,QAAA,QAAQ,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,CAAA;AAElD,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,kCAAmB,CAAA;IACnB,oCAAqB,CAAA;AACvB,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AAED,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,qDAAuC,CAAA;IACvC,yDAA2C,CAAA;AAC7C,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB;AAED,IAAY,eAGX;AAHD,WAAY,eAAe;IACzB,8DAA2C,CAAA;IAC3C,2EAAwD,CAAA;AAC1D,CAAC,EAHW,eAAe,+BAAf,eAAe,QAG1B"}
|
package/lib/cjs/index.d.ts
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -27,8 +27,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.UPM = void 0;
|
|
30
|
-
__exportStar(require("./common"), exports);
|
|
31
|
-
const UPM = __importStar(require("./common"));
|
|
30
|
+
__exportStar(require("./common/index.js"), exports);
|
|
31
|
+
const UPM = __importStar(require("./common/index.js"));
|
|
32
32
|
exports.UPM = UPM;
|
|
33
33
|
exports.default = UPM;
|
|
34
34
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAiC;AACjC,uDAAwC;AAGtC,kBAAG;AAGL,kBAAe,GAAG,CAAA"}
|
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
import { MessagePortMain } from "electron";
|
|
2
|
-
import * as UPM from "../common";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import * as UPM from "../common/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Contains & Manages a `Utility/Process`
|
|
5
|
+
* providing simplified messaging & event
|
|
6
|
+
* propagation.
|
|
7
|
+
*/
|
|
7
8
|
export declare class UPMMainService<ReqMap extends UPM.MessageRequestMap = any, MType extends UPM.MessageRequestNames<ReqMap> = UPM.MessageRequestNames<ReqMap>> implements UPM.IMessageClient<ReqMap, MType> {
|
|
8
9
|
readonly serviceName: string;
|
|
9
10
|
readonly entryFile: string;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
/**
|
|
12
|
+
* As this container/wrapper implements
|
|
13
|
+
* `IMessageClient`, it needs to provide
|
|
14
|
+
* a `clientId`, which is constant in the
|
|
15
|
+
* main process
|
|
16
|
+
*/
|
|
17
|
+
readonly clientId: string;
|
|
18
|
+
/**
|
|
19
|
+
* Send an event as `fire-and-forget`
|
|
20
|
+
*
|
|
21
|
+
* @param data
|
|
22
|
+
* @param port
|
|
23
|
+
*/
|
|
24
|
+
sendEvent(data: any, port?: UPM.Port): void;
|
|
25
|
+
/**
|
|
26
|
+
* Send request
|
|
27
|
+
*
|
|
28
|
+
* @param type
|
|
29
|
+
* @param args
|
|
30
|
+
*/
|
|
31
|
+
executeRequest<Type extends MType, R extends UPM.MessageRequestReturnType<ReqMap, Type> = UPM.MessageRequestReturnType<ReqMap, Type>>(type: Type, ...args: UPM.MessageRequestParams<ReqMap, Type>): Promise<R>;
|
|
32
|
+
close(): void;
|
|
19
33
|
/**
|
|
20
34
|
* Resolves when ready
|
|
21
35
|
*
|
|
@@ -26,7 +40,15 @@ export declare class UPMMainService<ReqMap extends UPM.MessageRequestMap = any,
|
|
|
26
40
|
* Return a simple proxy facade wrapping
|
|
27
41
|
* `executeRequest` into individual methods
|
|
28
42
|
*/
|
|
29
|
-
getServiceClient(): IServiceClient<ReqMap, MType>;
|
|
43
|
+
getServiceClient(): UPM.IServiceClient<ReqMap, MType>;
|
|
44
|
+
private readonly config_;
|
|
45
|
+
private readyDeferred_;
|
|
46
|
+
private killDeferred_;
|
|
47
|
+
private messageIdSeq_;
|
|
48
|
+
private childProcess_;
|
|
49
|
+
private pendingMessages_;
|
|
50
|
+
private messageChannels_;
|
|
51
|
+
private onServiceExit;
|
|
30
52
|
/**
|
|
31
53
|
* Returned client side port (for Renderer)
|
|
32
54
|
* @param clientId
|
|
@@ -37,33 +59,93 @@ export declare class UPMMainService<ReqMap extends UPM.MessageRequestMap = any,
|
|
|
37
59
|
* (useful to avoid congestion on default child_process channel)
|
|
38
60
|
*
|
|
39
61
|
* @param {string} clientId
|
|
40
|
-
* @returns {UPM.MessagePortClient
|
|
62
|
+
* @returns {UPM.MessagePortClient}
|
|
41
63
|
*/
|
|
42
64
|
createMainClient(clientId: string): UPM.MessagePortClient<ReqMap, MType>;
|
|
65
|
+
/**
|
|
66
|
+
* Service is still in a healthy/running/runnable state
|
|
67
|
+
*/
|
|
68
|
+
get isRunning(): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Stop the service (kill)
|
|
71
|
+
*/
|
|
72
|
+
stop(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Resource management & cleanup
|
|
75
|
+
*/
|
|
76
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Initialize the service
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
private init;
|
|
83
|
+
/**
|
|
84
|
+
* OnMessage really only handles `results` from
|
|
85
|
+
* `executeRequest(...)`; this may be expanded in
|
|
86
|
+
* the future
|
|
87
|
+
*
|
|
88
|
+
* @param payload
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
private onMessage;
|
|
92
|
+
/**
|
|
93
|
+
* This handler is currently unused, but
|
|
94
|
+
* could be attached to a `MessagePort.on('close')`
|
|
95
|
+
* event
|
|
96
|
+
*
|
|
97
|
+
* @param id
|
|
98
|
+
* @param channel
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
43
101
|
private onPortClose;
|
|
44
|
-
private closeMessageChannel;
|
|
45
|
-
close(): void;
|
|
46
102
|
/**
|
|
47
|
-
*
|
|
103
|
+
* Close a message channel
|
|
48
104
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
105
|
+
* @param id
|
|
106
|
+
* @param channel
|
|
107
|
+
* @private
|
|
51
108
|
*/
|
|
52
|
-
|
|
109
|
+
private closeMessageChannel;
|
|
53
110
|
/**
|
|
54
|
-
*
|
|
111
|
+
* Kill the service
|
|
55
112
|
*
|
|
56
|
-
* @
|
|
57
|
-
* @param args
|
|
113
|
+
* @private
|
|
58
114
|
*/
|
|
59
|
-
executeRequest<Type extends MType, R extends UPM.MessageRequestReturnType<ReqMap, Type> = UPM.MessageRequestReturnType<ReqMap, Type>>(type: Type, ...args: UPM.MessageRequestParams<ReqMap, Type>): Promise<R>;
|
|
60
|
-
stop(): Promise<void>;
|
|
61
115
|
private kill;
|
|
116
|
+
/**
|
|
117
|
+
* Close all message channels
|
|
118
|
+
*
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
62
121
|
private removeAllMessageChannels;
|
|
122
|
+
/**
|
|
123
|
+
* Remove all pending messages
|
|
124
|
+
*
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
63
127
|
private cancelAllPendingMessages;
|
|
64
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Remove a pending message from the queue,
|
|
130
|
+
* whether settled or not
|
|
131
|
+
*
|
|
132
|
+
* @param messageId
|
|
133
|
+
* @private
|
|
134
|
+
*/
|
|
65
135
|
private removePendingMessage;
|
|
136
|
+
/**
|
|
137
|
+
* Generate next message id
|
|
138
|
+
*
|
|
139
|
+
* @private
|
|
140
|
+
*/
|
|
66
141
|
private generateMessageId;
|
|
67
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Construct a new service
|
|
144
|
+
*
|
|
145
|
+
* @param serviceName
|
|
146
|
+
* @param entryFile
|
|
147
|
+
* @param options
|
|
148
|
+
*/
|
|
149
|
+
constructor(serviceName: string, entryFile: string, options?: UPM.CreateServiceOptions);
|
|
68
150
|
}
|
|
69
151
|
export default UPMMainService;
|