@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
|
@@ -0,0 +1,49 @@
|
|
|
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 { RpcConfiguration, RpcManager, RpcRegistry } from "@itwin/core-common";
|
|
6
|
+
import { ElectronRpcProtocol } from "./ElectronRpcProtocol.js";
|
|
7
|
+
/** RPC interface configuration for an Electron-based application.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export class ElectronRpcConfiguration extends RpcConfiguration {
|
|
11
|
+
static targetWindowId;
|
|
12
|
+
}
|
|
13
|
+
/** Coordinates usage of RPC interfaces for an Electron-based application.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export class ElectronRpcManager extends RpcManager {
|
|
17
|
+
/** Initializes ElectronRpcManager for the frontend of an application. */
|
|
18
|
+
static initializeFrontend(ipcFrontend, interfaces) {
|
|
19
|
+
return ElectronRpcManager.performInitialization(ipcFrontend, interfaces);
|
|
20
|
+
}
|
|
21
|
+
/** Initializes ElectronRpcManager for the backend of an application. */
|
|
22
|
+
static initializeBackend(ipcBackend, interfaces) {
|
|
23
|
+
return ElectronRpcManager.performInitialization(ipcBackend, interfaces);
|
|
24
|
+
}
|
|
25
|
+
static performInitialization(ipcSocket, rpcs) {
|
|
26
|
+
const interfaces = rpcs ?? [];
|
|
27
|
+
const config = class extends ElectronRpcConfiguration {
|
|
28
|
+
interfaces = () => interfaces;
|
|
29
|
+
protocol = new ElectronRpcProtocol(this, ipcSocket);
|
|
30
|
+
};
|
|
31
|
+
for (const def of interfaces) {
|
|
32
|
+
RpcConfiguration.assign(def, () => config);
|
|
33
|
+
}
|
|
34
|
+
const instance = RpcConfiguration.obtain(config);
|
|
35
|
+
RpcConfiguration.initializeInterfaces(instance);
|
|
36
|
+
return instance;
|
|
37
|
+
}
|
|
38
|
+
/** Terminates ElectronRpcManager for the frontend of an application. */
|
|
39
|
+
static terminateFrontend() {
|
|
40
|
+
return ElectronRpcManager.performTermination();
|
|
41
|
+
}
|
|
42
|
+
static performTermination() {
|
|
43
|
+
const definitions = RpcRegistry.instance.definitionClasses;
|
|
44
|
+
for (const [, interfaceDef] of definitions) {
|
|
45
|
+
RpcManager.terminateInterface(interfaceDef);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ElectronRpcManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronRpcManager.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcManager.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAkD,gBAAgB,EAA0B,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACvJ,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;GAEG;AACH,MAAM,OAAgB,wBAAyB,SAAQ,gBAAgB;IAE9D,MAAM,CAAC,cAAc,CAAU;CAIvC;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,UAAU;IAChD,yEAAyE;IAClE,MAAM,CAAC,kBAAkB,CAAC,WAA8B,EAAE,UAAqC;QACpG,OAAO,kBAAkB,CAAC,qBAAqB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAC3E,CAAC;IAED,wEAAwE;IACjE,MAAM,CAAC,iBAAiB,CAAC,UAA4B,EAAE,UAAqC;QACjG,OAAO,kBAAkB,CAAC,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC1E,CAAC;IAEO,MAAM,CAAC,qBAAqB,CAAC,SAAoB,EAAE,IAA+B;QACxF,MAAM,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;QAC9B,MAAM,MAAM,GAAG,KAAM,SAAQ,wBAAwB;YAC5C,UAAU,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC;YAC9B,QAAQ,GAAwB,IAAI,mBAAmB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;SACjF,CAAC;QAEF,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,gBAAgB,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,QAAQ,GAAG,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACjD,gBAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAEhD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,wEAAwE;IACjE,MAAM,CAAC,iBAAiB;QAC7B,OAAO,kBAAkB,CAAC,kBAAkB,EAAE,CAAC;IACjD,CAAC;IAEO,MAAM,CAAC,kBAAkB;QAC/B,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAE3D,KAAK,MAAM,CAAC,EAAE,YAAY,CAAC,IAAI,WAAW,EAAE,CAAC;YAC3C,UAAU,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;QAC9C,CAAC;IACH,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 { IpcSocket, IpcSocketBackend, IpcSocketFrontend, RpcConfiguration, RpcInterfaceDefinition, RpcManager, RpcRegistry } from \"@itwin/core-common\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol.js\";\r\n\r\n/** RPC interface configuration for an Electron-based application.\r\n * @internal\r\n */\r\nexport abstract class ElectronRpcConfiguration extends RpcConfiguration {\r\n\r\n public static targetWindowId?: number;\r\n\r\n /** The protocol of the configuration. */\r\n public abstract override protocol: ElectronRpcProtocol;\r\n}\r\n\r\n/** Coordinates usage of RPC interfaces for an Electron-based application.\r\n * @internal\r\n */\r\nexport class ElectronRpcManager extends RpcManager {\r\n /** Initializes ElectronRpcManager for the frontend of an application. */\r\n public static initializeFrontend(ipcFrontend: IpcSocketFrontend, interfaces?: RpcInterfaceDefinition[]): ElectronRpcConfiguration {\r\n return ElectronRpcManager.performInitialization(ipcFrontend, interfaces);\r\n }\r\n\r\n /** Initializes ElectronRpcManager for the backend of an application. */\r\n public static initializeBackend(ipcBackend: IpcSocketBackend, interfaces?: RpcInterfaceDefinition[]): ElectronRpcConfiguration {\r\n return ElectronRpcManager.performInitialization(ipcBackend, interfaces);\r\n }\r\n\r\n private static performInitialization(ipcSocket: IpcSocket, rpcs?: RpcInterfaceDefinition[]): ElectronRpcConfiguration {\r\n const interfaces = rpcs ?? [];\r\n const config = class extends ElectronRpcConfiguration {\r\n public interfaces = () => interfaces;\r\n public protocol: ElectronRpcProtocol = new ElectronRpcProtocol(this, ipcSocket);\r\n };\r\n\r\n for (const def of interfaces) {\r\n RpcConfiguration.assign(def, () => config);\r\n }\r\n\r\n const instance = RpcConfiguration.obtain(config);\r\n RpcConfiguration.initializeInterfaces(instance);\r\n\r\n return instance;\r\n }\r\n\r\n /** Terminates ElectronRpcManager for the frontend of an application. */\r\n public static terminateFrontend() {\r\n return ElectronRpcManager.performTermination();\r\n }\r\n\r\n private static performTermination() {\r\n const definitions = RpcRegistry.instance.definitionClasses;\r\n\r\n for (const [, interfaceDef] of definitions) {\r\n RpcManager.terminateInterface(interfaceDef);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module RpcInterface
|
|
3
|
+
*/
|
|
4
|
+
import { IpcSocket, RpcInterface, RpcInterfaceDefinition, RpcProtocol } from "@itwin/core-common";
|
|
5
|
+
import { ElectronIpcTransport, IpcTransportMessage } from "./ElectronIpcTransport.js";
|
|
6
|
+
import { ElectronRpcConfiguration } from "./ElectronRpcManager.js";
|
|
7
|
+
import { ElectronRpcRequest } from "./ElectronRpcRequest.js";
|
|
8
|
+
/** RPC interface protocol for an Electron-based application.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare class ElectronRpcProtocol extends RpcProtocol {
|
|
12
|
+
static instances: Map<string, ElectronRpcProtocol>;
|
|
13
|
+
ipcSocket: IpcSocket;
|
|
14
|
+
/** The RPC request class for this protocol. */
|
|
15
|
+
readonly requestType: typeof ElectronRpcRequest;
|
|
16
|
+
/** Specifies where to break large binary request payloads. */
|
|
17
|
+
transferChunkThreshold: number;
|
|
18
|
+
/** @internal */
|
|
19
|
+
requests: Map<string, ElectronRpcRequest>;
|
|
20
|
+
/** @internal */
|
|
21
|
+
readonly transport: ElectronIpcTransport<IpcTransportMessage, IpcTransportMessage>;
|
|
22
|
+
/** Constructs an Electron protocol. */
|
|
23
|
+
constructor(configuration: ElectronRpcConfiguration, ipcSocket: IpcSocket);
|
|
24
|
+
/** @internal */
|
|
25
|
+
onRpcClientInitialized(definition: RpcInterfaceDefinition, _client: RpcInterface): void;
|
|
26
|
+
/** @internal */
|
|
27
|
+
onRpcImplInitialized(definition: RpcInterfaceDefinition, _impl: RpcInterface): void;
|
|
28
|
+
/** @internal */
|
|
29
|
+
onRpcClientTerminated(definition: RpcInterfaceDefinition, _client: RpcInterface): void;
|
|
30
|
+
/** @internal */
|
|
31
|
+
onRpcImplTerminated(definition: RpcInterfaceDefinition, _impl: RpcInterface): void;
|
|
32
|
+
private registerInterface;
|
|
33
|
+
private purgeInterface;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=ElectronRpcProtocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronRpcProtocol.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronRpcProtocol.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAe,SAAS,EAAE,YAAY,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/G,OAAO,EAAE,oBAAoB,EAAiB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACrG,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;IAClD,OAAc,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAa;IAC/D,SAAS,EAAE,SAAS,CAAC;IAE5B,+CAA+C;IAC/C,SAAgB,WAAW,4BAAsB;IAEjD,8DAA8D;IAC9C,sBAAsB,SAAoB;IAE1D,gBAAgB;IACT,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAa;IAE7D,gBAAgB;IAChB,SAAgB,SAAS,EAAE,oBAAoB,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;IAE1F,uCAAuC;gBACpB,aAAa,EAAE,wBAAwB,EAAE,SAAS,EAAE,SAAS;IAMhF,gBAAgB;IACA,sBAAsB,CAAC,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAIvG,gBAAgB;IACA,oBAAoB,CAAC,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAInG,gBAAgB;IACA,qBAAqB,CAAC,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAItG,gBAAgB;IACA,mBAAmB,CAAC,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAIlG,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,cAAc;CAGvB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
import { BentleyStatus } from "@itwin/core-bentley";
|
|
9
|
+
import { IModelError, RpcProtocol } from "@itwin/core-common";
|
|
10
|
+
import { initializeIpc } from "./ElectronIpcTransport.js";
|
|
11
|
+
import { ElectronRpcRequest } from "./ElectronRpcRequest.js";
|
|
12
|
+
/** RPC interface protocol for an Electron-based application.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export class ElectronRpcProtocol extends RpcProtocol {
|
|
16
|
+
static instances = new Map();
|
|
17
|
+
ipcSocket;
|
|
18
|
+
/** The RPC request class for this protocol. */
|
|
19
|
+
requestType = ElectronRpcRequest;
|
|
20
|
+
/** Specifies where to break large binary request payloads. */
|
|
21
|
+
transferChunkThreshold = 48 * 1024 * 1024;
|
|
22
|
+
/** @internal */
|
|
23
|
+
requests = new Map();
|
|
24
|
+
/** @internal */
|
|
25
|
+
transport;
|
|
26
|
+
/** Constructs an Electron protocol. */
|
|
27
|
+
constructor(configuration, ipcSocket) {
|
|
28
|
+
super(configuration);
|
|
29
|
+
this.ipcSocket = ipcSocket;
|
|
30
|
+
this.transport = initializeIpc(this);
|
|
31
|
+
}
|
|
32
|
+
/** @internal */
|
|
33
|
+
onRpcClientInitialized(definition, _client) {
|
|
34
|
+
this.registerInterface(definition);
|
|
35
|
+
}
|
|
36
|
+
/** @internal */
|
|
37
|
+
onRpcImplInitialized(definition, _impl) {
|
|
38
|
+
this.registerInterface(definition);
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
onRpcClientTerminated(definition, _client) {
|
|
42
|
+
this.purgeInterface(definition);
|
|
43
|
+
}
|
|
44
|
+
/** @internal */
|
|
45
|
+
onRpcImplTerminated(definition, _impl) {
|
|
46
|
+
this.purgeInterface(definition);
|
|
47
|
+
}
|
|
48
|
+
registerInterface(definition) {
|
|
49
|
+
if (ElectronRpcProtocol.instances.has(definition.interfaceName))
|
|
50
|
+
throw new IModelError(BentleyStatus.ERROR, `RPC interface "${definition.interfaceName}"" is already associated with a protocol.`);
|
|
51
|
+
ElectronRpcProtocol.instances.set(definition.interfaceName, this);
|
|
52
|
+
}
|
|
53
|
+
purgeInterface(definition) {
|
|
54
|
+
ElectronRpcProtocol.instances.delete(definition.interfaceName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=ElectronRpcProtocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronRpcProtocol.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcProtocol.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAmD,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/G,OAAO,EAAwB,aAAa,EAAuB,MAAM,2BAA2B,CAAC;AAErG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAC3C,MAAM,CAAC,SAAS,GAAqC,IAAI,GAAG,EAAE,CAAC;IAC/D,SAAS,CAAY;IAE5B,+CAA+C;IAC/B,WAAW,GAAG,kBAAkB,CAAC;IAEjD,8DAA8D;IAC9C,sBAAsB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;IAE1D,gBAAgB;IACT,QAAQ,GAAoC,IAAI,GAAG,EAAE,CAAC;IAE7D,gBAAgB;IACA,SAAS,CAAiE;IAE1F,uCAAuC;IACvC,YAAmB,aAAuC,EAAE,SAAoB;QAC9E,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,gBAAgB;IACA,sBAAsB,CAAC,UAAkC,EAAE,OAAqB;QAC9F,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB;IACA,oBAAoB,CAAC,UAAkC,EAAE,KAAmB;QAC1F,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB;IACA,qBAAqB,CAAC,UAAkC,EAAE,OAAqB;QAC7F,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,gBAAgB;IACA,mBAAmB,CAAC,UAAkC,EAAE,KAAmB;QACzF,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAEO,iBAAiB,CAAC,UAAkC;QAC1D,IAAI,mBAAmB,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC;YAC7D,MAAM,IAAI,WAAW,CAAC,aAAa,CAAC,KAAK,EAAE,kBAAkB,UAAU,CAAC,aAAa,2CAA2C,CAAC,CAAC;QAEpI,mBAAmB,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC;IAEO,cAAc,CAAC,UAAkC;QACvD,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,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 { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError, IpcSocket, RpcInterface, RpcInterfaceDefinition, RpcProtocol } from \"@itwin/core-common\";\r\nimport { ElectronIpcTransport, initializeIpc, IpcTransportMessage } from \"./ElectronIpcTransport.js\";\r\nimport { ElectronRpcConfiguration } from \"./ElectronRpcManager.js\";\r\nimport { ElectronRpcRequest } from \"./ElectronRpcRequest.js\";\r\n\r\n/** RPC interface protocol for an Electron-based application.\r\n * @internal\r\n */\r\nexport class ElectronRpcProtocol extends RpcProtocol {\r\n public static instances: Map<string, ElectronRpcProtocol> = new Map();\r\n public ipcSocket: IpcSocket;\r\n\r\n /** The RPC request class for this protocol. */\r\n public readonly requestType = ElectronRpcRequest;\r\n\r\n /** Specifies where to break large binary request payloads. */\r\n public override transferChunkThreshold = 48 * 1024 * 1024;\r\n\r\n /** @internal */\r\n public requests: Map<string, ElectronRpcRequest> = new Map();\r\n\r\n /** @internal */\r\n public readonly transport: ElectronIpcTransport<IpcTransportMessage, IpcTransportMessage>;\r\n\r\n /** Constructs an Electron protocol. */\r\n public constructor(configuration: ElectronRpcConfiguration, ipcSocket: IpcSocket) {\r\n super(configuration);\r\n this.ipcSocket = ipcSocket;\r\n this.transport = initializeIpc(this);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcClientInitialized(definition: RpcInterfaceDefinition, _client: RpcInterface): void {\r\n this.registerInterface(definition);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcImplInitialized(definition: RpcInterfaceDefinition, _impl: RpcInterface): void {\r\n this.registerInterface(definition);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcClientTerminated(definition: RpcInterfaceDefinition, _client: RpcInterface): void {\r\n this.purgeInterface(definition);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcImplTerminated(definition: RpcInterfaceDefinition, _impl: RpcInterface): void {\r\n this.purgeInterface(definition);\r\n }\r\n\r\n private registerInterface(definition: RpcInterfaceDefinition) {\r\n if (ElectronRpcProtocol.instances.has(definition.interfaceName))\r\n throw new IModelError(BentleyStatus.ERROR, `RPC interface \"${definition.interfaceName}\"\" is already associated with a protocol.`);\r\n\r\n ElectronRpcProtocol.instances.set(definition.interfaceName, this);\r\n }\r\n\r\n private purgeInterface(definition: RpcInterfaceDefinition) {\r\n ElectronRpcProtocol.instances.delete(definition.interfaceName);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { RpcRequest, RpcRequestFulfillment } from "@itwin/core-common";
|
|
2
|
+
import { ElectronRpcProtocol } from "./ElectronRpcProtocol.js";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare class ElectronRpcRequest extends RpcRequest {
|
|
5
|
+
private _res;
|
|
6
|
+
private _fulfillment;
|
|
7
|
+
/** Convenience access to the protocol of this request. */
|
|
8
|
+
readonly protocol: ElectronRpcProtocol;
|
|
9
|
+
/** Sends the request. */
|
|
10
|
+
protected send(): Promise<number>;
|
|
11
|
+
/** Loads the request. */
|
|
12
|
+
protected load(): Promise<import("@itwin/core-common").RpcSerializedValue>;
|
|
13
|
+
/** Sets request header values. */
|
|
14
|
+
protected setHeader(_name: string, _value: string): void;
|
|
15
|
+
/** @internal */
|
|
16
|
+
notifyResponse(fulfillment: RpcRequestFulfillment): void;
|
|
17
|
+
/** @internal */
|
|
18
|
+
[Symbol.dispose](): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ElectronRpcRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronRpcRequest.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronRpcRequest.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,UAAU,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,gBAAgB;AAChB,qBAAa,kBAAmB,SAAQ,UAAU;IAChD,OAAO,CAAC,IAAI,CAA4C;IACxD,OAAO,CAAC,YAAY,CAAgD;IAEpE,0DAA0D;IAC1D,SAAyB,QAAQ,EAAE,mBAAmB,CAA6C;IAEnG,yBAAyB;cACT,IAAI;IAcpB,yBAAyB;cACT,IAAI;IASpB,kCAAkC;IAClC,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAIxD,gBAAgB;IACT,cAAc,CAAC,WAAW,EAAE,qBAAqB;IAKxD,gBAAgB;IACD,CAAC,MAAM,CAAC,OAAO,CAAC;CAIhC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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 { RpcProtocolEvent, RpcRequest } from "@itwin/core-common";
|
|
6
|
+
/** @internal */
|
|
7
|
+
export class ElectronRpcRequest extends RpcRequest {
|
|
8
|
+
_res = () => undefined;
|
|
9
|
+
_fulfillment = undefined;
|
|
10
|
+
/** Convenience access to the protocol of this request. */
|
|
11
|
+
protocol = this.client.configuration.protocol;
|
|
12
|
+
/** Sends the request. */
|
|
13
|
+
async send() {
|
|
14
|
+
try {
|
|
15
|
+
this.protocol.requests.set(this.id, this);
|
|
16
|
+
const request = await this.protocol.serialize(this);
|
|
17
|
+
this.protocol.transport.sendRequest(request);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
this.protocol.events.raiseEvent(RpcProtocolEvent.ConnectionErrorReceived, this); // eslint-disable-line @typescript-eslint/no-deprecated
|
|
21
|
+
}
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
this._res = resolve;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/** Loads the request. */
|
|
27
|
+
async load() {
|
|
28
|
+
const fulfillment = this._fulfillment;
|
|
29
|
+
if (!fulfillment) {
|
|
30
|
+
throw new Error("No request fulfillment available.");
|
|
31
|
+
}
|
|
32
|
+
return fulfillment.result;
|
|
33
|
+
}
|
|
34
|
+
/** Sets request header values. */
|
|
35
|
+
setHeader(_name, _value) {
|
|
36
|
+
// No implementation
|
|
37
|
+
}
|
|
38
|
+
/** @internal */
|
|
39
|
+
notifyResponse(fulfillment) {
|
|
40
|
+
this._fulfillment = fulfillment;
|
|
41
|
+
this._res(fulfillment.status);
|
|
42
|
+
}
|
|
43
|
+
/** @internal */
|
|
44
|
+
[Symbol.dispose]() {
|
|
45
|
+
this.protocol.requests.delete(this.id);
|
|
46
|
+
super[Symbol.dispose]();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ElectronRpcRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronRpcRequest.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcRequest.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAyB,MAAM,oBAAoB,CAAC;AAGzF,gBAAgB;AAChB,MAAM,OAAO,kBAAmB,SAAQ,UAAU;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,gBAAgB,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","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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module RpcInterface
|
|
3
|
+
*/
|
|
4
|
+
/** These methods are stored on `window.itwinjs` */
|
|
5
|
+
export interface ITwinElectronApi {
|
|
6
|
+
addListener: (channel: string, listener: ElectronListener) => void;
|
|
7
|
+
removeListener: (channel: string, listener: ElectronListener) => void;
|
|
8
|
+
invoke: (channel: string, ...data: any[]) => Promise<any>;
|
|
9
|
+
once: (channel: string, listener: ElectronListener) => void;
|
|
10
|
+
send: (channel: string, ...data: any[]) => void;
|
|
11
|
+
}
|
|
12
|
+
export type ElectronListener = (event: any, ...args: any[]) => void;
|
|
13
|
+
//# sourceMappingURL=ITwinElectronApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITwinElectronApi.d.ts","sourceRoot":"","sources":["../../../src/common/ITwinElectronApi.ts"],"names":[],"mappings":"AAKA;;GAEG;AAEH,mDAAmD;AACnD,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACnE,cAAc,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACtE,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC5D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CACjD;AAED,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,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 {};
|
|
6
|
+
//# sourceMappingURL=ITwinElectronApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITwinElectronApi.js","sourceRoot":"","sources":["../../../src/common/ITwinElectronApi.ts"],"names":[],"mappings":"AAAA;;;+FAG+F","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 RpcInterface\r\n */\r\n\r\n/** These methods are stored on `window.itwinjs` */\r\nexport interface ITwinElectronApi {\r\n addListener: (channel: string, listener: ElectronListener) => void;\r\n removeListener: (channel: string, listener: ElectronListener) => void;\r\n invoke: (channel: string, ...data: any[]) => Promise<any>;\r\n once: (channel: string, listener: ElectronListener) => void;\r\n send: (channel: string, ...data: any[]) => void; // only valid for render -> main\r\n}\r\n\r\nexport type ElectronListener = (event: any, ...args: any[]) => void;\r\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { NativeAppOpts } from "@itwin/core-frontend";
|
|
2
|
+
import type { ITwinElectronApi } from "../common/ITwinElectronApi.js";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
itwinjs: ITwinElectronApi;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** @beta */
|
|
9
|
+
export type ElectronAppOpts = NativeAppOpts;
|
|
10
|
+
/**
|
|
11
|
+
* Frontend of an Electron App.
|
|
12
|
+
* @beta
|
|
13
|
+
*/
|
|
14
|
+
export declare class ElectronApp {
|
|
15
|
+
private static _ipc?;
|
|
16
|
+
static get isValid(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Start the frontend of an Electron application.
|
|
19
|
+
* @param opts Options for your ElectronApp
|
|
20
|
+
* @note This method must only be called from the frontend of an Electron app (i.e. when [ProcessDetector.isElectronAppFrontend]($bentley) is `true`).
|
|
21
|
+
*/
|
|
22
|
+
static startup(opts?: ElectronAppOpts): Promise<void>;
|
|
23
|
+
static shutdown(): Promise<void>;
|
|
24
|
+
/** Proxy object for calling methods of `Electron.Dialog` */
|
|
25
|
+
static dialogIpc: import("@itwin/core-bentley").PickAsyncMethods<Electron.Dialog>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ElectronApp.d.ts.map
|
|
@@ -0,0 +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,+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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
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 Renderer
|
|
7
|
+
*/
|
|
8
|
+
import { expectDefined, ProcessDetector } from "@itwin/core-bentley";
|
|
9
|
+
import { IpcApp, NativeApp } from "@itwin/core-frontend";
|
|
10
|
+
import { electronIpcStrings } from "../common/ElectronIpcInterface.js";
|
|
11
|
+
import { ElectronRpcManager } from "../common/ElectronRpcManager.js";
|
|
12
|
+
/**
|
|
13
|
+
* Frontend Ipc support for Electron apps.
|
|
14
|
+
*/
|
|
15
|
+
class ElectronIpc {
|
|
16
|
+
_api;
|
|
17
|
+
addListener(channelName, listener) {
|
|
18
|
+
this._api.addListener(channelName, listener);
|
|
19
|
+
return () => this._api.removeListener(channelName, listener);
|
|
20
|
+
}
|
|
21
|
+
removeListener(channelName, listener) {
|
|
22
|
+
this._api.removeListener(channelName, listener);
|
|
23
|
+
}
|
|
24
|
+
send(channel, ...data) {
|
|
25
|
+
this._api.send(channel, ...data);
|
|
26
|
+
}
|
|
27
|
+
async invoke(channel, ...args) {
|
|
28
|
+
return this._api.invoke(channel, ...args);
|
|
29
|
+
}
|
|
30
|
+
constructor() {
|
|
31
|
+
// use the methods on window.itwinjs exposed by ElectronPreload.ts, or ipcRenderer directly if running with nodeIntegration=true (**only** for tests).
|
|
32
|
+
// Note that `require("electron")` doesn't work with nodeIntegration=false - that's what it stops
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
34
|
+
this._api = window.itwinjs ?? require("electron").ipcRenderer;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Frontend of an Electron App.
|
|
39
|
+
* @beta
|
|
40
|
+
*/
|
|
41
|
+
export class ElectronApp {
|
|
42
|
+
static _ipc;
|
|
43
|
+
static get isValid() { return undefined !== this._ipc; }
|
|
44
|
+
/**
|
|
45
|
+
* Start the frontend of an Electron application.
|
|
46
|
+
* @param opts Options for your ElectronApp
|
|
47
|
+
* @note This method must only be called from the frontend of an Electron app (i.e. when [ProcessDetector.isElectronAppFrontend]($bentley) is `true`).
|
|
48
|
+
*/
|
|
49
|
+
static async startup(opts) {
|
|
50
|
+
if (!ProcessDetector.isElectronAppFrontend)
|
|
51
|
+
throw new Error("Not running under Electron");
|
|
52
|
+
if (!this.isValid) {
|
|
53
|
+
this._ipc = new ElectronIpc();
|
|
54
|
+
ElectronRpcManager.initializeFrontend(this._ipc, opts?.iModelApp?.rpcInterfaces); // eslint-disable-line @typescript-eslint/no-deprecated
|
|
55
|
+
}
|
|
56
|
+
const ipc = expectDefined(this._ipc, "Electron IPC channel was not initialized.");
|
|
57
|
+
await NativeApp.startup(ipc, opts);
|
|
58
|
+
}
|
|
59
|
+
static async shutdown() {
|
|
60
|
+
this._ipc = undefined;
|
|
61
|
+
await NativeApp.shutdown();
|
|
62
|
+
ElectronRpcManager.terminateFrontend();
|
|
63
|
+
}
|
|
64
|
+
/** Proxy object for calling methods of `Electron.Dialog` */
|
|
65
|
+
static dialogIpc = IpcApp.makeIpcFunctionProxy(electronIpcStrings.dialogChannel, "callDialog");
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=ElectronApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElectronApp.js","sourceRoot":"","sources":["../../../src/frontend/ElectronApp.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAmB,MAAM,EAAE,SAAS,EAAiB,MAAM,sBAAsB,CAAC;AAEzF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;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,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC;IACD;QACE,sJAAsJ;QACtJ,iGAAiG;QACjG,iEAAiE;QACjE,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC;IAChE,CAAC;CACF;AAKD;;;GAGG;AACH,MAAM,OAAO,WAAW;IACd,MAAM,CAAC,IAAI,CAAe;IAC3B,MAAM,KAAK,OAAO,KAAc,OAAO,SAAS,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAExE;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAsB;QAChD,IAAI,CAAC,eAAe,CAAC,qBAAqB;YACxC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,kBAAkB,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,uDAAuD;QAC3I,CAAC;QACD,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,2CAA2C,CAAC,CAAC;QAClF,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,QAAQ;QAC1B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC3B,kBAAkB,CAAC,iBAAiB,EAAE,CAAC;IACzC,CAAC;IAED,4DAA4D;IACrD,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,oBAAoB,CAAkB,kBAAkB,CAAC,aAAa,EAAE,YAAY,CAAC,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\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
|
+
{"type":"module"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-electron",
|
|
3
|
-
"version": "5.14.0-dev.
|
|
3
|
+
"version": "5.14.0-dev.21",
|
|
4
4
|
"description": "iTwin.js ElectronHost and ElectronApp",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./renderer": {
|
|
7
|
+
"import": {
|
|
8
|
+
"types": "./lib/esm/ElectronFrontend.d.ts",
|
|
9
|
+
"default": "./lib/esm/ElectronFrontend.js"
|
|
10
|
+
},
|
|
11
|
+
"require": {
|
|
12
|
+
"types": "./lib/cjs/ElectronFrontend.d.ts",
|
|
13
|
+
"default": "./lib/cjs/ElectronFrontend.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"./main": {
|
|
17
|
+
"types": "./lib/cjs/ElectronBackend.d.ts",
|
|
18
|
+
"import": "./lib/cjs/ElectronBackend.js",
|
|
19
|
+
"require": "./lib/cjs/ElectronBackend.js"
|
|
20
|
+
},
|
|
21
|
+
"./lib/cjs/*.js": "./lib/cjs/*.js",
|
|
22
|
+
"./lib/cjs/*": {
|
|
23
|
+
"types": "./lib/cjs/*.d.ts",
|
|
24
|
+
"default": "./lib/cjs/*.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"typesVersions": {
|
|
29
|
+
"*": {
|
|
30
|
+
"renderer": [
|
|
31
|
+
"lib/cjs/ElectronFrontend.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"main": [
|
|
34
|
+
"lib/cjs/ElectronBackend.d.ts"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
5
38
|
"license": "MIT",
|
|
6
39
|
"repository": {
|
|
7
40
|
"type": "git",
|
|
@@ -18,11 +51,11 @@
|
|
|
18
51
|
"url": "http://www.bentley.com"
|
|
19
52
|
},
|
|
20
53
|
"peerDependencies": {
|
|
21
|
-
"electron": ">=35.0.0 <
|
|
22
|
-
"@itwin/core-backend": "5.14.0-dev.
|
|
23
|
-
"@itwin/core-
|
|
24
|
-
"@itwin/core-
|
|
25
|
-
"@itwin/core-common": "5.14.0-dev.
|
|
54
|
+
"electron": ">=35.0.0 <45.0.0",
|
|
55
|
+
"@itwin/core-backend": "5.14.0-dev.21",
|
|
56
|
+
"@itwin/core-frontend": "5.14.0-dev.21",
|
|
57
|
+
"@itwin/core-bentley": "5.14.0-dev.21",
|
|
58
|
+
"@itwin/core-common": "5.14.0-dev.21"
|
|
26
59
|
},
|
|
27
60
|
"devDependencies": {
|
|
28
61
|
"@itwin/eslint-plugin": "^6.0.0",
|
|
@@ -31,7 +64,7 @@
|
|
|
31
64
|
"@types/node": "~20.17.0",
|
|
32
65
|
"chai": "^4.3.10",
|
|
33
66
|
"cpx2": "^8.0.0",
|
|
34
|
-
"electron": "^
|
|
67
|
+
"electron": "^44.0.0",
|
|
35
68
|
"eslint": "^9.31.0",
|
|
36
69
|
"glob": "^13.0.6",
|
|
37
70
|
"mocha": "^11.1.0",
|
|
@@ -40,16 +73,17 @@
|
|
|
40
73
|
"typescript": "~5.6.2",
|
|
41
74
|
"webpack": "^5.97.1",
|
|
42
75
|
"webpack-cli": "^5.0.1",
|
|
43
|
-
"@itwin/build-tools": "5.14.0-dev.
|
|
44
|
-
"@itwin/
|
|
45
|
-
"@itwin/
|
|
46
|
-
"@itwin/core-
|
|
47
|
-
"@itwin/core-
|
|
48
|
-
"@itwin/core-
|
|
76
|
+
"@itwin/build-tools": "5.14.0-dev.21",
|
|
77
|
+
"@itwin/certa": "5.14.0-dev.21",
|
|
78
|
+
"@itwin/core-frontend": "5.14.0-dev.21",
|
|
79
|
+
"@itwin/core-backend": "5.14.0-dev.21",
|
|
80
|
+
"@itwin/core-common": "5.14.0-dev.21",
|
|
81
|
+
"@itwin/core-bentley": "5.14.0-dev.21"
|
|
49
82
|
},
|
|
50
83
|
"scripts": {
|
|
51
|
-
"build": "npm run -s build:cjs && npm run -s webpack:test && npm run -s copy:test-assets",
|
|
84
|
+
"build": "npm run -s build:cjs && npm run -s build:esm && npm run -s webpack:test && npm run -s copy:test-assets",
|
|
52
85
|
"build:cjs": "tsc 1>&2 --outDir lib/cjs",
|
|
86
|
+
"build:esm": "rimraf -g lib/esm && tsc 1>&2 -p tsconfig.esm.json && node -e \"require('node:fs').writeFileSync('lib/esm/package.json', JSON.stringify({ type: 'module' }) + '\\n')\"",
|
|
53
87
|
"copy:test-assets": "cpx \"./src/test/assets/**/*\" ./lib/cjs/test/assets",
|
|
54
88
|
"clean": "rimraf -g lib .rush/temp/package-deps*.json",
|
|
55
89
|
"docs": "betools docs --json=../../generated-docs/core/core-electron/file.json --tsIndexFile=./core-electron.ts --onlyJson",
|