@itwin/core-electron 5.14.0-dev.2 → 5.14.0-dev.21
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/CHANGELOG.md +40 -1
- package/README.md +4 -0
- package/lib/cjs/ElectronBackend.d.ts +1 -1
- package/lib/cjs/ElectronBackend.d.ts.map +1 -1
- package/lib/cjs/ElectronBackend.js +1 -1
- package/lib/cjs/ElectronBackend.js.map +1 -1
- package/lib/cjs/ElectronFrontend.d.ts +1 -1
- package/lib/cjs/ElectronFrontend.d.ts.map +1 -1
- package/lib/cjs/ElectronFrontend.js +1 -1
- package/lib/cjs/ElectronFrontend.js.map +1 -1
- package/lib/cjs/backend/ElectronHost.js +5 -5
- package/lib/cjs/backend/ElectronHost.js.map +1 -1
- package/lib/cjs/backend/ElectronPreload.js.map +1 -1
- package/lib/cjs/common/ElectronIpcTransport.d.ts +1 -1
- package/lib/cjs/common/ElectronIpcTransport.d.ts.map +1 -1
- package/lib/cjs/common/ElectronIpcTransport.js +5 -5
- package/lib/cjs/common/ElectronIpcTransport.js.map +1 -1
- package/lib/cjs/common/ElectronPush.d.ts +1 -1
- package/lib/cjs/common/ElectronPush.d.ts.map +1 -1
- package/lib/cjs/common/ElectronPush.js.map +1 -1
- package/lib/cjs/common/ElectronRpcManager.d.ts +1 -1
- package/lib/cjs/common/ElectronRpcManager.d.ts.map +1 -1
- package/lib/cjs/common/ElectronRpcManager.js +2 -2
- package/lib/cjs/common/ElectronRpcManager.js.map +1 -1
- package/lib/cjs/common/ElectronRpcProtocol.d.ts +3 -3
- package/lib/cjs/common/ElectronRpcProtocol.d.ts.map +1 -1
- package/lib/cjs/common/ElectronRpcProtocol.js +4 -4
- package/lib/cjs/common/ElectronRpcProtocol.js.map +1 -1
- package/lib/cjs/common/ElectronRpcRequest.d.ts +1 -1
- package/lib/cjs/common/ElectronRpcRequest.d.ts.map +1 -1
- package/lib/cjs/common/ElectronRpcRequest.js.map +1 -1
- package/lib/cjs/core-electron.d.ts +3 -3
- package/lib/cjs/core-electron.d.ts.map +1 -1
- package/lib/cjs/core-electron.js +3 -3
- package/lib/cjs/core-electron.js.map +1 -1
- package/lib/cjs/frontend/ElectronApp.d.ts +1 -1
- package/lib/cjs/frontend/ElectronApp.d.ts.map +1 -1
- package/lib/cjs/frontend/ElectronApp.js +5 -5
- package/lib/cjs/frontend/ElectronApp.js.map +1 -1
- package/lib/esm/ElectronFrontend.d.ts +2 -0
- package/lib/esm/ElectronFrontend.d.ts.map +1 -0
- package/lib/esm/ElectronFrontend.js +6 -0
- package/lib/esm/ElectronFrontend.js.map +1 -0
- package/lib/esm/common/ElectronIpcInterface.d.ts +14 -0
- package/lib/esm/common/ElectronIpcInterface.d.ts.map +1 -0
- package/lib/esm/common/ElectronIpcInterface.js +12 -0
- package/lib/esm/common/ElectronIpcInterface.js.map +1 -0
- package/lib/esm/common/ElectronIpcTransport.d.ts +45 -0
- package/lib/esm/common/ElectronIpcTransport.d.ts.map +1 -0
- package/lib/esm/common/ElectronIpcTransport.js +187 -0
- package/lib/esm/common/ElectronIpcTransport.js.map +1 -0
- package/lib/esm/common/ElectronPush.d.ts +18 -0
- package/lib/esm/common/ElectronPush.d.ts.map +1 -0
- package/lib/esm/common/ElectronPush.js +42 -0
- package/lib/esm/common/ElectronPush.js.map +1 -0
- package/lib/esm/common/ElectronRpcManager.d.ts +24 -0
- package/lib/esm/common/ElectronRpcManager.d.ts.map +1 -0
- package/lib/esm/common/ElectronRpcManager.js +49 -0
- package/lib/esm/common/ElectronRpcManager.js.map +1 -0
- package/lib/esm/common/ElectronRpcProtocol.d.ts +35 -0
- package/lib/esm/common/ElectronRpcProtocol.d.ts.map +1 -0
- package/lib/esm/common/ElectronRpcProtocol.js +57 -0
- package/lib/esm/common/ElectronRpcProtocol.js.map +1 -0
- package/lib/esm/common/ElectronRpcRequest.d.ts +20 -0
- package/lib/esm/common/ElectronRpcRequest.d.ts.map +1 -0
- package/lib/esm/common/ElectronRpcRequest.js +49 -0
- package/lib/esm/common/ElectronRpcRequest.js.map +1 -0
- package/lib/esm/common/ITwinElectronApi.d.ts +13 -0
- package/lib/esm/common/ITwinElectronApi.d.ts.map +1 -0
- package/lib/esm/common/ITwinElectronApi.js +6 -0
- package/lib/esm/common/ITwinElectronApi.js.map +1 -0
- package/lib/esm/frontend/ElectronApp.d.ts +27 -0
- package/lib/esm/frontend/ElectronApp.d.ts.map +1 -0
- package/lib/esm/frontend/ElectronApp.js +67 -0
- package/lib/esm/frontend/ElectronApp.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/package.json +48 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronRpcRequest.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcRequest.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,oDAAyF;AAGzF,gBAAgB;AAChB,MAAa,kBAAmB,SAAQ,wBAAU;IACxC,IAAI,GAA4B,GAAG,EAAE,CAAC,SAAS,CAAC;IAChD,YAAY,GAAsC,SAAS,CAAC;IAEpE,0DAA0D;IACjC,QAAQ,GAAwB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAe,CAAC;IAEnG,yBAAyB;IACf,KAAK,CAAC,IAAI;QAClB,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YAC1C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACpD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,8BAAgB,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC,CAAC,uDAAuD;QAC1I,CAAC;QAED,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;YACrC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,yBAAyB;IACf,KAAK,CAAC,IAAI;QAClB,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,WAAW,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,kCAAkC;IACxB,SAAS,CAAC,KAAa,EAAE,MAAc;QAC/C,oBAAoB;IACtB,CAAC;IAED,gBAAgB;IACT,cAAc,CAAC,WAAkC;QACtD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,gBAAgB;IACD,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACvC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1B,CAAC;CACF;AAhDD,gDAgDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { RpcProtocolEvent, RpcRequest, RpcRequestFulfillment } from \"@itwin/core-common\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol\";\r\n\r\n/** @internal */\r\nexport class ElectronRpcRequest extends RpcRequest {\r\n private _res: (value: number) => void = () => undefined;\r\n private _fulfillment: RpcRequestFulfillment | undefined = undefined;\r\n\r\n /** Convenience access to the protocol of this request. */\r\n public override readonly protocol: ElectronRpcProtocol = this.client.configuration.protocol as any;\r\n\r\n /** Sends the request. */\r\n protected async send() {\r\n try {\r\n this.protocol.requests.set(this.id, this);\r\n const request = await this.protocol.serialize(this);\r\n this.protocol.transport.sendRequest(request);\r\n } catch {\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.ConnectionErrorReceived, this); // eslint-disable-line @typescript-eslint/no-deprecated\r\n }\r\n\r\n return new Promise<number>((resolve) => {\r\n this._res = resolve;\r\n });\r\n }\r\n\r\n /** Loads the request. */\r\n protected async load() {\r\n const fulfillment = this._fulfillment;\r\n if (!fulfillment) {\r\n throw new Error(\"No request fulfillment available.\");\r\n }\r\n\r\n return fulfillment.result;\r\n }\r\n\r\n /** Sets request header values. */\r\n protected setHeader(_name: string, _value: string): void {\r\n // No implementation\r\n }\r\n\r\n /** @internal */\r\n public notifyResponse(fulfillment: RpcRequestFulfillment) {\r\n this._fulfillment = fulfillment;\r\n this._res(fulfillment.status);\r\n }\r\n\r\n /** @internal */\r\n public override[Symbol.dispose]() {\r\n this.protocol.requests.delete(this.id);\r\n super[Symbol.dispose]();\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ElectronRpcRequest.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcRequest.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,oDAAyF;AAGzF,gBAAgB;AAChB,MAAa,kBAAmB,SAAQ,wBAAU;IACxC,IAAI,GAA4B,GAAG,EAAE,CAAC,SAAS,CAAC;IAChD,YAAY,GAAsC,SAAS,CAAC;IAEpE,0DAA0D;IACjC,QAAQ,GAAwB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAe,CAAC;IAEnG,yBAAyB;IACf,KAAK,CAAC,IAAI;QAClB,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;YAC1C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACpD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC/C,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,8BAAgB,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC,CAAC,uDAAuD;QAC1I,CAAC;QAED,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;YACrC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,yBAAyB;IACf,KAAK,CAAC,IAAI;QAClB,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,WAAW,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,kCAAkC;IACxB,SAAS,CAAC,KAAa,EAAE,MAAc;QAC/C,oBAAoB;IACtB,CAAC;IAED,gBAAgB;IACT,cAAc,CAAC,WAAkC;QACtD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,gBAAgB;IACD,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACvC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1B,CAAC;CACF;AAhDD,gDAgDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { RpcProtocolEvent, RpcRequest, RpcRequestFulfillment } from \"@itwin/core-common\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol.js\";\r\n\r\n/** @internal */\r\nexport class ElectronRpcRequest extends RpcRequest {\r\n private _res: (value: number) => void = () => undefined;\r\n private _fulfillment: RpcRequestFulfillment | undefined = undefined;\r\n\r\n /** Convenience access to the protocol of this request. */\r\n public override readonly protocol: ElectronRpcProtocol = this.client.configuration.protocol as any;\r\n\r\n /** Sends the request. */\r\n protected async send() {\r\n try {\r\n this.protocol.requests.set(this.id, this);\r\n const request = await this.protocol.serialize(this);\r\n this.protocol.transport.sendRequest(request);\r\n } catch {\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.ConnectionErrorReceived, this); // eslint-disable-line @typescript-eslint/no-deprecated\r\n }\r\n\r\n return new Promise<number>((resolve) => {\r\n this._res = resolve;\r\n });\r\n }\r\n\r\n /** Loads the request. */\r\n protected async load() {\r\n const fulfillment = this._fulfillment;\r\n if (!fulfillment) {\r\n throw new Error(\"No request fulfillment available.\");\r\n }\r\n\r\n return fulfillment.result;\r\n }\r\n\r\n /** Sets request header values. */\r\n protected setHeader(_name: string, _value: string): void {\r\n // No implementation\r\n }\r\n\r\n /** @internal */\r\n public notifyResponse(fulfillment: RpcRequestFulfillment) {\r\n this._fulfillment = fulfillment;\r\n this._res(fulfillment.status);\r\n }\r\n\r\n /** @internal */\r\n public override[Symbol.dispose]() {\r\n this.protocol.requests.delete(this.id);\r\n super[Symbol.dispose]();\r\n }\r\n}\r\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./backend/ElectronHost";
|
|
2
|
-
export * from "./common/ElectronIpcInterface";
|
|
3
|
-
export * from "./frontend/ElectronApp";
|
|
1
|
+
export * from "./backend/ElectronHost.js";
|
|
2
|
+
export * from "./common/ElectronIpcInterface.js";
|
|
3
|
+
export * from "./frontend/ElectronApp.js";
|
|
4
4
|
/** @docs-package-description
|
|
5
5
|
*
|
|
6
6
|
* The core-electron package contains the electron utilities to write an iTwin.js application based on Electron.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-electron.d.ts","sourceRoot":"","sources":["../../src/core-electron.ts"],"names":[],"mappings":"AASA,cAAc,
|
|
1
|
+
{"version":3,"file":"core-electron.d.ts","sourceRoot":"","sources":["../../src/core-electron.ts"],"names":[],"mappings":"AASA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAE1C;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG"}
|
package/lib/cjs/core-electron.js
CHANGED
|
@@ -21,9 +21,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
// THIS FILE EXISTS ONLY FOR DOCUMENTATION GENERATION.
|
|
22
22
|
// It imports both frontend and backend code, which is not legal anywhere.
|
|
23
23
|
// Do not import it in real code!
|
|
24
|
-
__exportStar(require("./backend/ElectronHost"), exports);
|
|
25
|
-
__exportStar(require("./common/ElectronIpcInterface"), exports);
|
|
26
|
-
__exportStar(require("./frontend/ElectronApp"), exports);
|
|
24
|
+
__exportStar(require("./backend/ElectronHost.js"), exports);
|
|
25
|
+
__exportStar(require("./common/ElectronIpcInterface.js"), exports);
|
|
26
|
+
__exportStar(require("./frontend/ElectronApp.js"), exports);
|
|
27
27
|
/** @docs-package-description
|
|
28
28
|
*
|
|
29
29
|
* The core-electron package contains the electron utilities to write an iTwin.js application based on Electron.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core-electron.js","sourceRoot":"","sources":["../../src/core-electron.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;AAE/F,sDAAsD;AACtD,0EAA0E;AAC1E,iCAAiC;AAEjC,
|
|
1
|
+
{"version":3,"file":"core-electron.js","sourceRoot":"","sources":["../../src/core-electron.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;AAE/F,sDAAsD;AACtD,0EAA0E;AAC1E,iCAAiC;AAEjC,4DAA0C;AAC1C,mEAAiD;AACjD,4DAA0C;AAE1C;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n// THIS FILE EXISTS ONLY FOR DOCUMENTATION GENERATION.\r\n// It imports both frontend and backend code, which is not legal anywhere.\r\n// Do not import it in real code!\r\n\r\nexport * from \"./backend/ElectronHost.js\";\r\nexport * from \"./common/ElectronIpcInterface.js\";\r\nexport * from \"./frontend/ElectronApp.js\";\r\n\r\n/** @docs-package-description\r\n *\r\n * The core-electron package contains the electron utilities to write an iTwin.js application based on Electron.\r\n */\r\n\r\n/**\r\n * @docs-group-description Renderer\r\n * For use in the Electron renderer process\r\n */\r\n\r\n/**\r\n * @docs-group-description Main\r\n * For use in the Electron main process\r\n */\r\n\r\n/**\r\n * @docs-group-description RpcInterface\r\n * Functionality facilitate electron RPC\r\n */\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronApp.d.ts","sourceRoot":"","sources":["../../../src/frontend/ElectronApp.ts"],"names":[],"mappings":"AAWA,OAAO,EAAsC,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ElectronApp.d.ts","sourceRoot":"","sources":["../../../src/frontend/ElectronApp.ts"],"names":[],"mappings":"AAWA,OAAO,EAAsC,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAIzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,gBAAgB,CAAC;KAC3B;CACF;AA4BD,YAAY;AACZ,MAAM,MAAM,eAAe,GAAG,aAAa,CAAC;AAE5C;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAc;IAClC,WAAkB,OAAO,IAAI,OAAO,CAAoC;IAExE;;;;OAIG;WACiB,OAAO,CAAC,IAAI,CAAC,EAAE,eAAe;WAW9B,QAAQ;IAM5B,4DAA4D;IAC5D,OAAc,SAAS,kEAAgG;CACxH"}
|
|
@@ -10,8 +10,8 @@ exports.ElectronApp = void 0;
|
|
|
10
10
|
*/
|
|
11
11
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
12
|
const core_frontend_1 = require("@itwin/core-frontend");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const ElectronIpcInterface_js_1 = require("../common/ElectronIpcInterface.js");
|
|
14
|
+
const ElectronRpcManager_js_1 = require("../common/ElectronRpcManager.js");
|
|
15
15
|
/**
|
|
16
16
|
* Frontend Ipc support for Electron apps.
|
|
17
17
|
*/
|
|
@@ -54,7 +54,7 @@ class ElectronApp {
|
|
|
54
54
|
throw new Error("Not running under Electron");
|
|
55
55
|
if (!this.isValid) {
|
|
56
56
|
this._ipc = new ElectronIpc();
|
|
57
|
-
|
|
57
|
+
ElectronRpcManager_js_1.ElectronRpcManager.initializeFrontend(this._ipc, opts?.iModelApp?.rpcInterfaces); // eslint-disable-line @typescript-eslint/no-deprecated
|
|
58
58
|
}
|
|
59
59
|
const ipc = (0, core_bentley_1.expectDefined)(this._ipc, "Electron IPC channel was not initialized.");
|
|
60
60
|
await core_frontend_1.NativeApp.startup(ipc, opts);
|
|
@@ -62,10 +62,10 @@ class ElectronApp {
|
|
|
62
62
|
static async shutdown() {
|
|
63
63
|
this._ipc = undefined;
|
|
64
64
|
await core_frontend_1.NativeApp.shutdown();
|
|
65
|
-
|
|
65
|
+
ElectronRpcManager_js_1.ElectronRpcManager.terminateFrontend();
|
|
66
66
|
}
|
|
67
67
|
/** Proxy object for calling methods of `Electron.Dialog` */
|
|
68
|
-
static dialogIpc = core_frontend_1.IpcApp.makeIpcFunctionProxy(
|
|
68
|
+
static dialogIpc = core_frontend_1.IpcApp.makeIpcFunctionProxy(ElectronIpcInterface_js_1.electronIpcStrings.dialogChannel, "callDialog");
|
|
69
69
|
}
|
|
70
70
|
exports.ElectronApp = ElectronApp;
|
|
71
71
|
//# sourceMappingURL=ElectronApp.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronApp.js","sourceRoot":"","sources":["../../../src/frontend/ElectronApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,sDAAqE;AAErE,wDAAyF;AAEzF
|
|
1
|
+
{"version":3,"file":"ElectronApp.js","sourceRoot":"","sources":["../../../src/frontend/ElectronApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F;;GAEG;AAEH,sDAAqE;AAErE,wDAAyF;AAEzF,+EAAuE;AACvE,2EAAqE;AASrE;;GAEG;AACH,MAAM,WAAW;IACP,IAAI,CAAiC;IACtC,WAAW,CAAC,WAAmB,EAAE,QAAqB;QAC3D,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAC7C,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;IACM,cAAc,CAAC,WAAmB,EAAE,QAAqB;QAC9D,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAClD,CAAC;IACM,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;QACzC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACnC,CAAC;IACM,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,GAAG,IAAW;QACjD,OAAO,IAAI,CAAC,IAAI,C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kCA4BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @packageDocumentation\r\n * @module Renderer\r\n */\r\n\r\nimport { expectDefined, ProcessDetector } from \"@itwin/core-bentley\";\r\nimport { IpcListener, IpcSocketFrontend } from \"@itwin/core-common\";\r\nimport { _callIpcChannel, IpcApp, NativeApp, NativeAppOpts } from \"@itwin/core-frontend\";\r\nimport type { IpcRenderer } from \"electron\";\r\nimport { electronIpcStrings } from \"../common/ElectronIpcInterface.js\";\r\nimport { ElectronRpcManager } from \"../common/ElectronRpcManager.js\";\r\nimport type { ITwinElectronApi } from \"../common/ITwinElectronApi.js\";\r\n\r\ndeclare global {\r\n interface Window {\r\n itwinjs: ITwinElectronApi;\r\n }\r\n}\r\n\r\n/**\r\n * Frontend Ipc support for Electron apps.\r\n */\r\nclass ElectronIpc implements IpcSocketFrontend {\r\n private _api: ITwinElectronApi | IpcRenderer;\r\n public addListener(channelName: string, listener: IpcListener) {\r\n this._api.addListener(channelName, listener);\r\n return () => this._api.removeListener(channelName, listener);\r\n }\r\n public removeListener(channelName: string, listener: IpcListener) {\r\n this._api.removeListener(channelName, listener);\r\n }\r\n public send(channel: string, ...data: any[]) {\r\n this._api.send(channel, ...data);\r\n }\r\n public async invoke(channel: string, ...args: any[]) {\r\n return this._api.invoke(channel, ...args);\r\n }\r\n constructor() {\r\n // use the methods on window.itwinjs exposed by ElectronPreload.ts, or ipcRenderer directly if running with nodeIntegration=true (**only** for tests).\r\n // Note that `require(\"electron\")` doesn't work with nodeIntegration=false - that's what it stops\r\n // eslint-disable-next-line @typescript-eslint/no-require-imports\r\n this._api = window.itwinjs ?? require(\"electron\").ipcRenderer;\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport type ElectronAppOpts = NativeAppOpts;\r\n\r\n/**\r\n * Frontend of an Electron App.\r\n * @beta\r\n */\r\nexport class ElectronApp {\r\n private static _ipc?: ElectronIpc;\r\n public static get isValid(): boolean { return undefined !== this._ipc; }\r\n\r\n /**\r\n * Start the frontend of an Electron application.\r\n * @param opts Options for your ElectronApp\r\n * @note This method must only be called from the frontend of an Electron app (i.e. when [ProcessDetector.isElectronAppFrontend]($bentley) is `true`).\r\n */\r\n public static async startup(opts?: ElectronAppOpts) {\r\n if (!ProcessDetector.isElectronAppFrontend)\r\n throw new Error(\"Not running under Electron\");\r\n if (!this.isValid) {\r\n this._ipc = new ElectronIpc();\r\n ElectronRpcManager.initializeFrontend(this._ipc, opts?.iModelApp?.rpcInterfaces); // eslint-disable-line @typescript-eslint/no-deprecated\r\n }\r\n const ipc = expectDefined(this._ipc, \"Electron IPC channel was not initialized.\");\r\n await NativeApp.startup(ipc, opts);\r\n }\r\n\r\n public static async shutdown() {\r\n this._ipc = undefined;\r\n await NativeApp.shutdown();\r\n ElectronRpcManager.terminateFrontend();\r\n }\r\n\r\n /** Proxy object for calling methods of `Electron.Dialog` */\r\n public static dialogIpc = IpcApp.makeIpcFunctionProxy<Electron.Dialog>(electronIpcStrings.dialogChannel, \"callDialog\");\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronFrontend.d.ts","sourceRoot":"","sources":["../../src/ElectronFrontend.ts"],"names":[],"mappings":"AAKA,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export * from "./frontend/ElectronApp.js";
|
|
6
|
+
//# sourceMappingURL=ElectronFrontend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronFrontend.js","sourceRoot":"","sources":["../../src/ElectronFrontend.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,cAAc,2BAA2B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nexport * from \"./frontend/ElectronApp.js\";\r\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module RpcInterface
|
|
3
|
+
*/
|
|
4
|
+
import { AsyncMethodsOf } from "@itwin/core-bentley";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare const electronIpcStrings: {
|
|
7
|
+
readonly dialogChannel: "itwinjs-electron/dialog";
|
|
8
|
+
};
|
|
9
|
+
/** Asynchronous methods of dialog module in an Electron app.
|
|
10
|
+
* @beta
|
|
11
|
+
* @deprecated in 5.0 - might be removed in next major version. Use `Electron.Dialog` from `electron` instead.
|
|
12
|
+
*/
|
|
13
|
+
export type DialogModuleMethod = AsyncMethodsOf<Electron.Dialog>;
|
|
14
|
+
//# sourceMappingURL=ElectronIpcInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronIpcInterface.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronIpcInterface.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,gBAAgB;AAChB,eAAO,MAAM,kBAAkB;;CAErB,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module RpcInterface
|
|
7
|
+
*/
|
|
8
|
+
/** @internal */
|
|
9
|
+
export const electronIpcStrings = {
|
|
10
|
+
dialogChannel: "itwinjs-electron/dialog",
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=ElectronIpcInterface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronIpcInterface.js","sourceRoot":"","sources":["../../../src/common/ElectronIpcInterface.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,aAAa,EAAE,yBAAyB;CAChC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { AsyncMethodsOf } from \"@itwin/core-bentley\";\r\n\r\n/** @internal */\r\nexport const electronIpcStrings = {\r\n dialogChannel: \"itwinjs-electron/dialog\",\r\n} as const;\r\n\r\n/** Asynchronous methods of dialog module in an Electron app.\r\n * @beta\r\n * @deprecated in 5.0 - might be removed in next major version. Use `Electron.Dialog` from `electron` instead.\r\n */\r\nexport type DialogModuleMethod = AsyncMethodsOf<Electron.Dialog>;\r\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { RpcRequestFulfillment, RpcSerializedValue, SerializedRpcRequest } from "@itwin/core-common";
|
|
2
|
+
import { ElectronRpcProtocol } from "./ElectronRpcProtocol.js";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export interface IpcTransportMessage {
|
|
5
|
+
id: string;
|
|
6
|
+
parameters?: RpcSerializedValue;
|
|
7
|
+
result?: RpcSerializedValue;
|
|
8
|
+
}
|
|
9
|
+
/** @internal */
|
|
10
|
+
export declare abstract class ElectronIpcTransport<TIn extends IpcTransportMessage = IpcTransportMessage, TOut extends IpcTransportMessage = IpcTransportMessage> {
|
|
11
|
+
private _partials;
|
|
12
|
+
private _removeListeners;
|
|
13
|
+
protected _protocol: ElectronRpcProtocol;
|
|
14
|
+
get protocol(): ElectronRpcProtocol;
|
|
15
|
+
sendRequest(request: SerializedRpcRequest): void;
|
|
16
|
+
constructor(protocol: ElectronRpcProtocol);
|
|
17
|
+
protected setupPush(): void;
|
|
18
|
+
private _setupDataChannel;
|
|
19
|
+
private _setupObjectsChannel;
|
|
20
|
+
private _extractValue;
|
|
21
|
+
private _send;
|
|
22
|
+
protected performSend(channel: string, message: any, evt: any): void;
|
|
23
|
+
protected abstract handleComplete(id: string, evt: any): void;
|
|
24
|
+
/** @internal */
|
|
25
|
+
sendResponse(message: TOut, evt: any): void;
|
|
26
|
+
protected loadMessage(id: string): TIn;
|
|
27
|
+
cleanup(): void;
|
|
28
|
+
}
|
|
29
|
+
/** @internal */
|
|
30
|
+
export declare class FrontendIpcTransport extends ElectronIpcTransport<RpcRequestFulfillment> {
|
|
31
|
+
private _pushTransport?;
|
|
32
|
+
protected setupPush(): void;
|
|
33
|
+
protected handleComplete(id: string): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** @internal */
|
|
36
|
+
export declare class BackendIpcTransport extends ElectronIpcTransport<SerializedRpcRequest, RpcRequestFulfillment> {
|
|
37
|
+
private _browserWindow;
|
|
38
|
+
protected setupPush(): void;
|
|
39
|
+
protected handleComplete(id: string, evt: any): Promise<void>;
|
|
40
|
+
protected performSend(channel: string, message: any, evt: any): void;
|
|
41
|
+
private _requireBrowserWindow;
|
|
42
|
+
}
|
|
43
|
+
/** @internal */
|
|
44
|
+
export declare function initializeIpc(protocol: ElectronRpcProtocol): ElectronIpcTransport<IpcTransportMessage, IpcTransportMessage>;
|
|
45
|
+
//# sourceMappingURL=ElectronIpcTransport.d.ts.map
|
|
@@ -0,0 +1 @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,SAAQ,oBAAoB,CAAC,qBAAqB,CAAC;IACnF,OAAO,CAAC,cAAc,CAAC,CAAwB;cAE5B,SAAS;cAMZ,cAAc,CAAC,EAAE,EAAE,MAAM;CAe1C;AAED,gBAAgB;AAChB,qBAAa,mBAAoB,SAAQ,oBAAoB,CAAC,oBAAoB,EAAE,qBAAqB,CAAC;IACxG,OAAO,CAAC,cAAc,CAAM;cAET,SAAS;cAKZ,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;cAiBhC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAWtE,OAAO,CAAC,qBAAqB;CAW9B;AAID,gBAAgB;AAChB,wBAAgB,aAAa,CAAC,QAAQ,EAAE,mBAAmB,kEAU1D"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { BentleyError, BentleyStatus, ProcessDetector } from "@itwin/core-bentley";
|
|
6
|
+
import { IModelError, iTwinChannel, RpcPushChannel, RpcPushConnection, RpcRequestFulfillment, } from "@itwin/core-common";
|
|
7
|
+
import { ElectronPushConnection, ElectronPushTransport } from "./ElectronPush.js";
|
|
8
|
+
import { ElectronRpcConfiguration } from "./ElectronRpcManager.js";
|
|
9
|
+
const OBJECTS_CHANNEL = iTwinChannel("rpc.objects");
|
|
10
|
+
const DATA_CHANNEL = iTwinChannel("rpc.data");
|
|
11
|
+
/** @internal */
|
|
12
|
+
export class ElectronIpcTransport {
|
|
13
|
+
_partials;
|
|
14
|
+
_removeListeners = [];
|
|
15
|
+
_protocol;
|
|
16
|
+
get protocol() { return this._protocol; }
|
|
17
|
+
sendRequest(request) {
|
|
18
|
+
const value = this._extractValue(request);
|
|
19
|
+
this._send(request, value);
|
|
20
|
+
}
|
|
21
|
+
constructor(protocol) {
|
|
22
|
+
this._protocol = protocol;
|
|
23
|
+
this._partials = new Map();
|
|
24
|
+
this._setupDataChannel();
|
|
25
|
+
this._setupObjectsChannel();
|
|
26
|
+
this.setupPush();
|
|
27
|
+
}
|
|
28
|
+
setupPush() { }
|
|
29
|
+
_setupDataChannel() {
|
|
30
|
+
const removeListener = this.protocol.ipcSocket.addListener(DATA_CHANNEL, async (evt, chunk) => {
|
|
31
|
+
let pending = this._partials.get(chunk.id);
|
|
32
|
+
if (!pending) {
|
|
33
|
+
pending = [];
|
|
34
|
+
this._partials.set(chunk.id, pending);
|
|
35
|
+
}
|
|
36
|
+
if (Array.isArray(pending)) {
|
|
37
|
+
pending.push(chunk);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
++pending.received;
|
|
41
|
+
const value = this._extractValue(pending.message);
|
|
42
|
+
value.data[chunk.index] = chunk.data;
|
|
43
|
+
if (pending.received === (value.chunks || 0)) {
|
|
44
|
+
this.handleComplete(pending.message.id, evt);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
this._removeListeners.push(removeListener);
|
|
49
|
+
}
|
|
50
|
+
_setupObjectsChannel() {
|
|
51
|
+
const removeListener = this.protocol.ipcSocket.addListener(OBJECTS_CHANNEL, async (evt, message) => {
|
|
52
|
+
const pending = this._partials.get(message.id);
|
|
53
|
+
if (pending && !Array.isArray(pending)) {
|
|
54
|
+
throw new IModelError(BentleyStatus.ERROR, `Message already received for id "${message.id}".`);
|
|
55
|
+
}
|
|
56
|
+
const partial = { message, received: 0 };
|
|
57
|
+
this._partials.set(message.id, partial);
|
|
58
|
+
const value = this._extractValue(partial.message);
|
|
59
|
+
if (pending && Array.isArray(pending)) {
|
|
60
|
+
for (const chunk of pending) {
|
|
61
|
+
++partial.received;
|
|
62
|
+
value.data[chunk.index] = chunk.data;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (partial.received === (value.chunks || 0)) {
|
|
66
|
+
this.handleComplete(message.id, evt);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
this._removeListeners.push(removeListener);
|
|
70
|
+
}
|
|
71
|
+
_extractValue(t) {
|
|
72
|
+
if (t.parameters) {
|
|
73
|
+
return t.parameters;
|
|
74
|
+
}
|
|
75
|
+
if (t.result) {
|
|
76
|
+
return t.result;
|
|
77
|
+
}
|
|
78
|
+
throw new IModelError(BentleyStatus.ERROR, "Unknown value type.");
|
|
79
|
+
}
|
|
80
|
+
_send(message, value, evt) {
|
|
81
|
+
const chunks = value.data;
|
|
82
|
+
if (chunks.length) {
|
|
83
|
+
value.chunks = chunks.length;
|
|
84
|
+
value.data = [];
|
|
85
|
+
}
|
|
86
|
+
this.performSend(OBJECTS_CHANNEL, message, evt);
|
|
87
|
+
for (let index = 0; index !== chunks.length; ++index) {
|
|
88
|
+
const chunk = { id: message.id, index, data: chunks[index] };
|
|
89
|
+
this.performSend(DATA_CHANNEL, chunk, evt);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
performSend(channel, message, evt) {
|
|
93
|
+
(evt ? evt.sender : this.protocol.ipcSocket).send(channel, message);
|
|
94
|
+
}
|
|
95
|
+
/** @internal */
|
|
96
|
+
sendResponse(message, evt) {
|
|
97
|
+
const value = this._extractValue(message);
|
|
98
|
+
this._send(message, value, evt);
|
|
99
|
+
}
|
|
100
|
+
loadMessage(id) {
|
|
101
|
+
const partial = this._partials.get(id);
|
|
102
|
+
if (!partial || Array.isArray(partial)) {
|
|
103
|
+
throw new IModelError(BentleyStatus.ERROR, `Incomplete transmission for id "${id}".`);
|
|
104
|
+
}
|
|
105
|
+
this._partials.delete(id);
|
|
106
|
+
return partial.message;
|
|
107
|
+
}
|
|
108
|
+
cleanup() {
|
|
109
|
+
this._removeListeners.forEach((removeListener) => removeListener());
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** @internal */
|
|
113
|
+
export class FrontendIpcTransport extends ElectronIpcTransport {
|
|
114
|
+
_pushTransport;
|
|
115
|
+
setupPush() {
|
|
116
|
+
const pushTransport = new ElectronPushTransport(this);
|
|
117
|
+
this._pushTransport = pushTransport;
|
|
118
|
+
RpcPushChannel.setup(pushTransport);
|
|
119
|
+
}
|
|
120
|
+
async handleComplete(id) {
|
|
121
|
+
const message = this.loadMessage(id);
|
|
122
|
+
if (this._pushTransport && this._pushTransport.consume(message)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const protocol = this._protocol;
|
|
126
|
+
const request = protocol.requests.get(message.id);
|
|
127
|
+
// A response may arrive after shutdown has removed the request.
|
|
128
|
+
if (!request)
|
|
129
|
+
return;
|
|
130
|
+
request.notifyResponse(message);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** @internal */
|
|
134
|
+
export class BackendIpcTransport extends ElectronIpcTransport {
|
|
135
|
+
_browserWindow;
|
|
136
|
+
setupPush() {
|
|
137
|
+
RpcPushConnection.for = (channel, client) => new ElectronPushConnection(channel, client, this);
|
|
138
|
+
RpcPushChannel.enabled = true;
|
|
139
|
+
}
|
|
140
|
+
async handleComplete(id, evt) {
|
|
141
|
+
const message = this.loadMessage(id);
|
|
142
|
+
let response;
|
|
143
|
+
try {
|
|
144
|
+
const protocol = this._protocol;
|
|
145
|
+
response = await protocol.fulfill(message);
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
response = await RpcRequestFulfillment.forUnknownError(message, err);
|
|
149
|
+
}
|
|
150
|
+
const raw = response.rawResult;
|
|
151
|
+
response.rawResult = undefined; // Otherwise, it will be serialized in IPC layer and large responses will then crash the app
|
|
152
|
+
this.sendResponse(response, evt);
|
|
153
|
+
response.rawResult = raw;
|
|
154
|
+
}
|
|
155
|
+
performSend(channel, message, evt) {
|
|
156
|
+
if (evt) {
|
|
157
|
+
return super.performSend(channel, message, evt);
|
|
158
|
+
}
|
|
159
|
+
this._requireBrowserWindow();
|
|
160
|
+
const target = ElectronRpcConfiguration.targetWindowId;
|
|
161
|
+
const windows = target ? [this._browserWindow.fromId(target)] : this._browserWindow.getAllWindows();
|
|
162
|
+
windows.forEach((window) => window.webContents.send(channel, message));
|
|
163
|
+
}
|
|
164
|
+
_requireBrowserWindow() {
|
|
165
|
+
if (this._browserWindow) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
try { // Wrapping require in a try/catch signals to webpack that this is only an optional dependency
|
|
169
|
+
this._browserWindow = require("electron").BrowserWindow; // eslint-disable-line @typescript-eslint/no-require-imports
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
throw new IModelError(BentleyStatus.ERROR, `Error requiring electron`, () => BentleyError.getErrorProps(err));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
let transport;
|
|
177
|
+
/** @internal */
|
|
178
|
+
export function initializeIpc(protocol) {
|
|
179
|
+
if (transport && transport.protocol !== protocol) {
|
|
180
|
+
transport.cleanup();
|
|
181
|
+
transport = undefined;
|
|
182
|
+
}
|
|
183
|
+
if (undefined === transport)
|
|
184
|
+
transport = ProcessDetector.isElectronAppFrontend ? new FrontendIpcTransport(protocol) : new BackendIpcTransport(protocol);
|
|
185
|
+
return transport;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=ElectronIpcTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronIpcTransport.js","sourceRoot":"","sources":["../../../src/common/ElectronIpcTransport.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EACL,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,qBAAqB,GACpF,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;A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,aAAa,CAAC,KAAK,EAAE,0BAA0B,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;QAChH,CAAC;IACH,CAAC;CACF;AAED,IAAI,SAA2C,CAAC;AAEhD,gBAAgB;AAChB,MAAM,UAAU,aAAa,CAAC,QAA6B;IACzD,IAAI,SAAS,IAAI,SAAS,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjD,SAAS,CAAC,OAAO,EAAE,CAAC;QACpB,SAAS,GAAG,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,SAAS,KAAK,SAAS;QACzB,SAAS,GAAG,eAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAE7H,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { BentleyError, BentleyStatus, ProcessDetector } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelError, iTwinChannel, RpcPushChannel, RpcPushConnection, RpcRequestFulfillment, RpcSerializedValue, SerializedRpcRequest,\r\n} from \"@itwin/core-common\";\r\nimport { ElectronPushConnection, ElectronPushTransport } from \"./ElectronPush.js\";\r\nimport { ElectronRpcConfiguration } from \"./ElectronRpcManager.js\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol.js\";\r\n\r\nconst OBJECTS_CHANNEL = iTwinChannel(\"rpc.objects\");\r\nconst DATA_CHANNEL = iTwinChannel(\"rpc.data\");\r\n\r\ninterface PartialPayload { id: string, index: number, data: Uint8Array }\r\n\r\n/** @internal */\r\nexport interface IpcTransportMessage { id: string, parameters?: RpcSerializedValue, result?: RpcSerializedValue }\r\n\r\n/** @internal */\r\nexport abstract class ElectronIpcTransport<TIn extends IpcTransportMessage = IpcTransportMessage, TOut extends IpcTransportMessage = IpcTransportMessage> {\r\n private _partials: Map<string, { message: TIn, received: number } | PartialPayload[]>;\r\n private _removeListeners: VoidFunction[] = [];\r\n protected _protocol: ElectronRpcProtocol;\r\n\r\n public get protocol() { return this._protocol; }\r\n\r\n public sendRequest(request: SerializedRpcRequest) {\r\n const value = this._extractValue(request);\r\n this._send(request, value);\r\n }\r\n\r\n public constructor(protocol: ElectronRpcProtocol) {\r\n this._protocol = protocol;\r\n this._partials = new Map();\r\n this._setupDataChannel();\r\n this._setupObjectsChannel();\r\n this.setupPush();\r\n }\r\n\r\n protected setupPush() { }\r\n\r\n private _setupDataChannel() {\r\n const removeListener = this.protocol.ipcSocket.addListener(DATA_CHANNEL, async (evt: any, chunk: PartialPayload) => {\r\n let pending = this._partials.get(chunk.id);\r\n if (!pending) {\r\n pending = [];\r\n this._partials.set(chunk.id, pending);\r\n }\r\n\r\n if (Array.isArray(pending)) {\r\n pending.push(chunk);\r\n } else {\r\n ++pending.received;\r\n\r\n const value = this._extractValue(pending.message);\r\n value.data[chunk.index] = chunk.data;\r\n\r\n if (pending.received === (value.chunks || 0)) {\r\n this.handleComplete(pending.message.id, evt);\r\n }\r\n }\r\n });\r\n this._removeListeners.push(removeListener);\r\n }\r\n\r\n private _setupObjectsChannel() {\r\n const removeListener = this.protocol.ipcSocket.addListener(OBJECTS_CHANNEL, async (evt: any, message: TIn) => {\r\n const pending = this._partials.get(message.id);\r\n if (pending && !Array.isArray(pending)) {\r\n throw new IModelError(BentleyStatus.ERROR, `Message already received for id \"${message.id}\".`);\r\n }\r\n\r\n const partial = { message, received: 0 };\r\n this._partials.set(message.id, partial);\r\n const value = this._extractValue(partial.message);\r\n\r\n if (pending && Array.isArray(pending)) {\r\n for (const chunk of pending) {\r\n ++partial.received;\r\n value.data[chunk.index] = chunk.data;\r\n }\r\n }\r\n\r\n if (partial.received === (value.chunks || 0)) {\r\n this.handleComplete(message.id, evt);\r\n }\r\n });\r\n this._removeListeners.push(removeListener);\r\n }\r\n\r\n private _extractValue(t: IpcTransportMessage): RpcSerializedValue {\r\n if (t.parameters) {\r\n return t.parameters;\r\n }\r\n\r\n if (t.result) {\r\n return t.result;\r\n }\r\n\r\n throw new IModelError(BentleyStatus.ERROR, \"Unknown value type.\");\r\n }\r\n\r\n private _send(message: IpcTransportMessage, value: RpcSerializedValue, evt?: any) {\r\n const chunks = value.data;\r\n if (chunks.length) {\r\n value.chunks = chunks.length;\r\n value.data = [];\r\n }\r\n\r\n this.performSend(OBJECTS_CHANNEL, message, evt);\r\n\r\n for (let index = 0; index !== chunks.length; ++index) {\r\n const chunk: PartialPayload = { id: message.id, index, data: chunks[index] };\r\n this.performSend(DATA_CHANNEL, chunk, evt);\r\n }\r\n }\r\n\r\n protected performSend(channel: string, message: any, evt: any) {\r\n (evt ? evt.sender : this.protocol.ipcSocket).send(channel, message);\r\n }\r\n\r\n protected abstract handleComplete(id: string, evt: any): void;\r\n\r\n /** @internal */\r\n public sendResponse(message: TOut, evt: any) {\r\n const value = this._extractValue(message);\r\n this._send(message, value, evt);\r\n }\r\n\r\n protected loadMessage(id: string) {\r\n const partial = this._partials.get(id);\r\n if (!partial || Array.isArray(partial)) {\r\n throw new IModelError(BentleyStatus.ERROR, `Incomplete transmission for id \"${id}\".`);\r\n }\r\n\r\n this._partials.delete(id);\r\n return partial.message;\r\n }\r\n\r\n public cleanup() {\r\n this._removeListeners.forEach((removeListener) => removeListener());\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class FrontendIpcTransport extends ElectronIpcTransport<RpcRequestFulfillment> {\r\n private _pushTransport?: ElectronPushTransport;\r\n\r\n protected override setupPush() {\r\n const pushTransport = new ElectronPushTransport(this);\r\n this._pushTransport = pushTransport;\r\n RpcPushChannel.setup(pushTransport);\r\n }\r\n\r\n protected async handleComplete(id: string) {\r\n const message = this.loadMessage(id);\r\n\r\n if (this._pushTransport && this._pushTransport.consume(message)) {\r\n return;\r\n }\r\n\r\n const protocol = this._protocol;\r\n const request = protocol.requests.get(message.id);\r\n // A response may arrive after shutdown has removed the request.\r\n if (!request)\r\n return;\r\n\r\n request.notifyResponse(message);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class BackendIpcTransport extends ElectronIpcTransport<SerializedRpcRequest, RpcRequestFulfillment> {\r\n private _browserWindow: any;\r\n\r\n protected override setupPush() {\r\n RpcPushConnection.for = (channel, client) => new ElectronPushConnection(channel, client, this);\r\n RpcPushChannel.enabled = true;\r\n }\r\n\r\n protected async handleComplete(id: string, evt: any) {\r\n const message = this.loadMessage(id);\r\n\r\n let response: RpcRequestFulfillment;\r\n try {\r\n const protocol = this._protocol;\r\n response = await protocol.fulfill(message);\r\n } catch (err) {\r\n response = await RpcRequestFulfillment.forUnknownError(message, err);\r\n }\r\n\r\n const raw = response.rawResult;\r\n response.rawResult = undefined; // Otherwise, it will be serialized in IPC layer and large responses will then crash the app\r\n this.sendResponse(response, evt);\r\n response.rawResult = raw;\r\n }\r\n\r\n protected override performSend(channel: string, message: any, evt: any) {\r\n if (evt) {\r\n return super.performSend(channel, message, evt);\r\n }\r\n\r\n this._requireBrowserWindow();\r\n const target = ElectronRpcConfiguration.targetWindowId;\r\n const windows = target ? [this._browserWindow.fromId(target)] : this._browserWindow.getAllWindows();\r\n windows.forEach((window: any) => window.webContents.send(channel, message));\r\n }\r\n\r\n private _requireBrowserWindow() {\r\n if (this._browserWindow) {\r\n return;\r\n }\r\n\r\n try { // Wrapping require in a try/catch signals to webpack that this is only an optional dependency\r\n this._browserWindow = require(\"electron\").BrowserWindow; // eslint-disable-line @typescript-eslint/no-require-imports\r\n } catch (err) {\r\n throw new IModelError(BentleyStatus.ERROR, `Error requiring electron`, () => BentleyError.getErrorProps(err));\r\n }\r\n }\r\n}\r\n\r\nlet transport: ElectronIpcTransport | undefined;\r\n\r\n/** @internal */\r\nexport function initializeIpc(protocol: ElectronRpcProtocol) {\r\n if (transport && transport.protocol !== protocol) {\r\n transport.cleanup();\r\n transport = undefined;\r\n }\r\n\r\n if (undefined === transport)\r\n transport = ProcessDetector.isElectronAppFrontend ? new FrontendIpcTransport(protocol) : new BackendIpcTransport(protocol);\r\n\r\n return transport;\r\n}\r\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RpcPushChannel, RpcPushConnection, RpcPushTransport, RpcRequestFulfillment } from "@itwin/core-common";
|
|
2
|
+
import { BackendIpcTransport, FrontendIpcTransport } from "./ElectronIpcTransport.js";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare class ElectronPushTransport extends RpcPushTransport {
|
|
5
|
+
private _ipc;
|
|
6
|
+
private _last;
|
|
7
|
+
get last(): number;
|
|
8
|
+
constructor(ipc: FrontendIpcTransport);
|
|
9
|
+
consume(response: RpcRequestFulfillment): boolean;
|
|
10
|
+
}
|
|
11
|
+
/** @internal */
|
|
12
|
+
export declare class ElectronPushConnection<T> extends RpcPushConnection<T> {
|
|
13
|
+
private _ipc;
|
|
14
|
+
private _next;
|
|
15
|
+
constructor(channel: RpcPushChannel<T>, client: unknown, ipc: BackendIpcTransport);
|
|
16
|
+
send(messageData: any): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ElectronPush.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronPush.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronPush.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC/H,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAItF,gBAAgB;AAChB,qBAAa,qBAAsB,SAAQ,gBAAgB;IACzD,OAAO,CAAC,IAAI,CAAuB;IACnC,OAAO,CAAC,KAAK,CAAc;IAE3B,IAAW,IAAI,WAAyB;gBAErB,GAAG,EAAE,oBAAoB;IAKrC,OAAO,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO;CAczD;AAED,gBAAgB;AAChB,qBAAa,sBAAsB,CAAC,CAAC,CAAE,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,IAAI,CAAsB;IAClC,OAAO,CAAC,KAAK,CAAc;gBAER,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,mBAAmB;IAK3E,IAAI,CAAC,WAAW,EAAE,GAAG;CAKnC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { RpcMarshaling, RpcPushConnection, RpcPushTransport } from "@itwin/core-common";
|
|
6
|
+
const PUSH = "__push__";
|
|
7
|
+
/** @internal */
|
|
8
|
+
export class ElectronPushTransport extends RpcPushTransport {
|
|
9
|
+
_ipc;
|
|
10
|
+
_last = -1;
|
|
11
|
+
get last() { return this._last; }
|
|
12
|
+
constructor(ipc) {
|
|
13
|
+
super();
|
|
14
|
+
this._ipc = ipc;
|
|
15
|
+
}
|
|
16
|
+
consume(response) {
|
|
17
|
+
if (response.interfaceName !== PUSH) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
this._last = response.status;
|
|
21
|
+
if (this.onMessage) {
|
|
22
|
+
const messageData = RpcMarshaling.deserialize(this._ipc.protocol, response.result);
|
|
23
|
+
this.onMessage(response.id, messageData);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** @internal */
|
|
29
|
+
export class ElectronPushConnection extends RpcPushConnection {
|
|
30
|
+
_ipc;
|
|
31
|
+
_next = -1;
|
|
32
|
+
constructor(channel, client, ipc) {
|
|
33
|
+
super(channel, client);
|
|
34
|
+
this._ipc = ipc;
|
|
35
|
+
}
|
|
36
|
+
async send(messageData) {
|
|
37
|
+
const result = RpcMarshaling.serialize(this._ipc.protocol, messageData);
|
|
38
|
+
const fulfillment = { result, rawResult: messageData, interfaceName: PUSH, id: this.channel.id, status: ++this._next };
|
|
39
|
+
this._ipc.sendResponse(fulfillment, undefined);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=ElectronPush.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronPush.js","sourceRoot":"","sources":["../../../src/common/ElectronPush.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,aAAa,EAAkB,iBAAiB,EAAE,gBAAgB,EAAyB,MAAM,oBAAoB,CAAC;AAG/H,MAAM,IAAI,GAAG,UAAU,CAAC;AAExB,gBAAgB;AAChB,MAAM,OAAO,qBAAsB,SAAQ,gBAAgB;IACjD,IAAI,CAAuB;IAC3B,KAAK,GAAW,CAAC,CAAC,CAAC;IAE3B,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAExC,YAAmB,GAAyB;QAC1C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAEM,OAAO,CAAC,QAA+B;QAC5C,IAAI,QAAQ,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC;QAE7B,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnF,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,gBAAgB;AAChB,MAAM,OAAO,sBAA0B,SAAQ,iBAAoB;IACzD,IAAI,CAAsB;IAC1B,KAAK,GAAW,CAAC,CAAC,CAAC;IAE3B,YAAmB,OAA0B,EAAE,MAAe,EAAE,GAAwB;QACtF,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,WAAgB;QAChC,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACxE,MAAM,WAAW,GAA0B,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9I,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { RpcMarshaling, RpcPushChannel, RpcPushConnection, RpcPushTransport, RpcRequestFulfillment } from \"@itwin/core-common\";\r\nimport { BackendIpcTransport, FrontendIpcTransport } from \"./ElectronIpcTransport.js\";\r\n\r\nconst PUSH = \"__push__\";\r\n\r\n/** @internal */\r\nexport class ElectronPushTransport extends RpcPushTransport {\r\n private _ipc: FrontendIpcTransport;\r\n private _last: number = -1;\r\n\r\n public get last() { return this._last; }\r\n\r\n public constructor(ipc: FrontendIpcTransport) {\r\n super();\r\n this._ipc = ipc;\r\n }\r\n\r\n public consume(response: RpcRequestFulfillment): boolean {\r\n if (response.interfaceName !== PUSH) {\r\n return false;\r\n }\r\n\r\n this._last = response.status;\r\n\r\n if (this.onMessage) {\r\n const messageData = RpcMarshaling.deserialize(this._ipc.protocol, response.result);\r\n this.onMessage(response.id, messageData);\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class ElectronPushConnection<T> extends RpcPushConnection<T> {\r\n private _ipc: BackendIpcTransport;\r\n private _next: number = -1;\r\n\r\n public constructor(channel: RpcPushChannel<T>, client: unknown, ipc: BackendIpcTransport) {\r\n super(channel, client);\r\n this._ipc = ipc;\r\n }\r\n\r\n public async send(messageData: any) {\r\n const result = RpcMarshaling.serialize(this._ipc.protocol, messageData);\r\n const fulfillment: RpcRequestFulfillment = { result, rawResult: messageData, interfaceName: PUSH, id: this.channel.id, status: ++this._next };\r\n this._ipc.sendResponse(fulfillment, undefined);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IpcSocketBackend, IpcSocketFrontend, RpcConfiguration, RpcInterfaceDefinition, RpcManager } from "@itwin/core-common";
|
|
2
|
+
import { ElectronRpcProtocol } from "./ElectronRpcProtocol.js";
|
|
3
|
+
/** RPC interface configuration for an Electron-based application.
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class ElectronRpcConfiguration extends RpcConfiguration {
|
|
7
|
+
static targetWindowId?: number;
|
|
8
|
+
/** The protocol of the configuration. */
|
|
9
|
+
abstract protocol: ElectronRpcProtocol;
|
|
10
|
+
}
|
|
11
|
+
/** Coordinates usage of RPC interfaces for an Electron-based application.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export declare class ElectronRpcManager extends RpcManager {
|
|
15
|
+
/** Initializes ElectronRpcManager for the frontend of an application. */
|
|
16
|
+
static initializeFrontend(ipcFrontend: IpcSocketFrontend, interfaces?: RpcInterfaceDefinition[]): ElectronRpcConfiguration;
|
|
17
|
+
/** Initializes ElectronRpcManager for the backend of an application. */
|
|
18
|
+
static initializeBackend(ipcBackend: IpcSocketBackend, interfaces?: RpcInterfaceDefinition[]): ElectronRpcConfiguration;
|
|
19
|
+
private static performInitialization;
|
|
20
|
+
/** Terminates ElectronRpcManager for the frontend of an application. */
|
|
21
|
+
static terminateFrontend(): void;
|
|
22
|
+
private static performTermination;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ElectronRpcManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronRpcManager.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronRpcManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAa,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,UAAU,EAAe,MAAM,oBAAoB,CAAC;AACvJ,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;GAEG;AACH,8BAAsB,wBAAyB,SAAQ,gBAAgB;IAErE,OAAc,cAAc,CAAC,EAAE,MAAM,CAAC;IAEtC,yCAAyC;IACzC,SAAyB,QAAQ,EAAE,mBAAmB,CAAC;CACxD;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,UAAU;IAChD,yEAAyE;WAC3D,kBAAkB,CAAC,WAAW,EAAE,iBAAiB,EAAE,UAAU,CAAC,EAAE,sBAAsB,EAAE,GAAG,wBAAwB;IAIjI,wEAAwE;WAC1D,iBAAiB,CAAC,UAAU,EAAE,gBAAgB,EAAE,UAAU,CAAC,EAAE,sBAAsB,EAAE,GAAG,wBAAwB;IAI9H,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAiBpC,wEAAwE;WAC1D,iBAAiB;IAI/B,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAOlC"}
|