@itwin/core-electron 3.0.0-extension.0 → 3.0.1
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 +100 -7
- package/LICENSE.md +1 -1
- package/lib/cjs/ElectronBackend.d.ts +0 -1
- package/lib/cjs/ElectronBackend.d.ts.map +1 -1
- package/lib/cjs/ElectronBackend.js +0 -1
- package/lib/cjs/ElectronBackend.js.map +1 -1
- package/lib/cjs/backend/ElectronHost.d.ts +1 -9
- package/lib/cjs/backend/ElectronHost.d.ts.map +1 -1
- package/lib/cjs/backend/ElectronHost.js +1 -9
- package/lib/cjs/backend/ElectronHost.js.map +1 -1
- package/package.json +16 -17
- package/lib/cjs/backend/ElectronAuthorizationBackend.d.ts +0 -71
- package/lib/cjs/backend/ElectronAuthorizationBackend.d.ts.map +0 -1
- package/lib/cjs/backend/ElectronAuthorizationBackend.js +0 -265
- package/lib/cjs/backend/ElectronAuthorizationBackend.js.map +0 -1
- package/lib/cjs/backend/ElectronAuthorizationEvents.d.ts +0 -20
- package/lib/cjs/backend/ElectronAuthorizationEvents.d.ts.map +0 -1
- package/lib/cjs/backend/ElectronAuthorizationEvents.js +0 -26
- package/lib/cjs/backend/ElectronAuthorizationEvents.js.map +0 -1
- package/lib/cjs/backend/ElectronAuthorizationRequestHandler.d.ts +0 -25
- package/lib/cjs/backend/ElectronAuthorizationRequestHandler.d.ts.map +0 -1
- package/lib/cjs/backend/ElectronAuthorizationRequestHandler.js +0 -63
- package/lib/cjs/backend/ElectronAuthorizationRequestHandler.js.map +0 -1
- package/lib/cjs/backend/ElectronTokenStore.d.ts +0 -18
- package/lib/cjs/backend/ElectronTokenStore.d.ts.map +0 -1
- package/lib/cjs/backend/ElectronTokenStore.js +0 -66
- package/lib/cjs/backend/ElectronTokenStore.js.map +0 -1
- package/lib/cjs/backend/LoopbackWebServer.d.ts +0 -19
- package/lib/cjs/backend/LoopbackWebServer.d.ts.map +0 -1
- package/lib/cjs/backend/LoopbackWebServer.js +0 -101
- package/lib/cjs/backend/LoopbackWebServer.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,99 @@
|
|
|
1
1
|
# Change Log - @itwin/core-electron
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 24 Feb 2022 15:26:55 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 3.0.1
|
|
6
|
+
Thu, 24 Feb 2022 15:26:55 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 3.0.0
|
|
11
|
+
Mon, 24 Jan 2022 14:00:52 GMT
|
|
12
|
+
|
|
13
|
+
### Updates
|
|
14
|
+
|
|
15
|
+
- Upgrade target to ES2019
|
|
16
|
+
- Updated to Electron 14
|
|
17
|
+
- use new @itwin package names
|
|
18
|
+
- rename to @itwin/core-electron
|
|
19
|
+
- remove ClientRequestContext and its subclasses
|
|
20
|
+
- remove ClientRequestContext.current
|
|
21
|
+
- Removed ElectronAuthorizationBackend and related files
|
|
22
|
+
|
|
23
|
+
## 2.19.28
|
|
24
|
+
Wed, 12 Jan 2022 14:52:38 GMT
|
|
25
|
+
|
|
26
|
+
_Version update only_
|
|
27
|
+
|
|
28
|
+
## 2.19.27
|
|
29
|
+
Wed, 05 Jan 2022 20:07:20 GMT
|
|
30
|
+
|
|
31
|
+
_Version update only_
|
|
32
|
+
|
|
33
|
+
## 2.19.26
|
|
34
|
+
Wed, 08 Dec 2021 20:54:52 GMT
|
|
35
|
+
|
|
36
|
+
_Version update only_
|
|
37
|
+
|
|
38
|
+
## 2.19.25
|
|
39
|
+
Fri, 03 Dec 2021 20:05:49 GMT
|
|
40
|
+
|
|
41
|
+
_Version update only_
|
|
42
|
+
|
|
43
|
+
## 2.19.24
|
|
44
|
+
Mon, 29 Nov 2021 18:44:31 GMT
|
|
45
|
+
|
|
46
|
+
_Version update only_
|
|
47
|
+
|
|
48
|
+
## 2.19.23
|
|
49
|
+
Mon, 22 Nov 2021 20:41:39 GMT
|
|
50
|
+
|
|
51
|
+
_Version update only_
|
|
52
|
+
|
|
53
|
+
## 2.19.22
|
|
54
|
+
Wed, 17 Nov 2021 01:23:26 GMT
|
|
55
|
+
|
|
56
|
+
_Version update only_
|
|
57
|
+
|
|
58
|
+
## 2.19.21
|
|
59
|
+
Wed, 10 Nov 2021 10:58:24 GMT
|
|
60
|
+
|
|
61
|
+
_Version update only_
|
|
62
|
+
|
|
63
|
+
## 2.19.20
|
|
64
|
+
Fri, 29 Oct 2021 16:14:22 GMT
|
|
65
|
+
|
|
66
|
+
_Version update only_
|
|
67
|
+
|
|
68
|
+
## 2.19.19
|
|
69
|
+
Mon, 25 Oct 2021 16:16:25 GMT
|
|
70
|
+
|
|
71
|
+
_Version update only_
|
|
72
|
+
|
|
73
|
+
## 2.19.18
|
|
74
|
+
Thu, 21 Oct 2021 20:59:44 GMT
|
|
75
|
+
|
|
76
|
+
_Version update only_
|
|
77
|
+
|
|
78
|
+
## 2.19.17
|
|
79
|
+
Thu, 14 Oct 2021 21:19:43 GMT
|
|
80
|
+
|
|
81
|
+
_Version update only_
|
|
82
|
+
|
|
83
|
+
## 2.19.16
|
|
84
|
+
Mon, 11 Oct 2021 17:37:46 GMT
|
|
85
|
+
|
|
86
|
+
_Version update only_
|
|
87
|
+
|
|
88
|
+
## 2.19.15
|
|
89
|
+
Fri, 08 Oct 2021 16:44:23 GMT
|
|
90
|
+
|
|
91
|
+
_Version update only_
|
|
92
|
+
|
|
93
|
+
## 2.19.14
|
|
94
|
+
Fri, 01 Oct 2021 13:07:03 GMT
|
|
95
|
+
|
|
96
|
+
_Version update only_
|
|
4
97
|
|
|
5
98
|
## 2.19.13
|
|
6
99
|
Tue, 21 Sep 2021 21:06:40 GMT
|
|
@@ -212,7 +305,7 @@ Fri, 30 Apr 2021 12:36:58 GMT
|
|
|
212
305
|
### Updates
|
|
213
306
|
|
|
214
307
|
- allow authConfig to be supplied from backend
|
|
215
|
-
- Fixes to desktop and iOS apps.
|
|
308
|
+
- Fixes to desktop and iOS apps.
|
|
216
309
|
- Saving & restoring Electron main window size, position & maximized state
|
|
217
310
|
|
|
218
311
|
## 2.14.4
|
|
@@ -419,7 +512,7 @@ Fri, 02 Oct 2020 18:03:32 GMT
|
|
|
419
512
|
|
|
420
513
|
### Updates
|
|
421
514
|
|
|
422
|
-
- Fixed desktop authorization after recent changes.
|
|
515
|
+
- Fixed desktop authorization after recent changes.
|
|
423
516
|
|
|
424
517
|
## 2.6.5
|
|
425
518
|
Sat, 26 Sep 2020 16:06:34 GMT
|
|
@@ -543,9 +636,9 @@ Wed, 06 May 2020 13:17:49 GMT
|
|
|
543
636
|
|
|
544
637
|
- Update to Electron 8
|
|
545
638
|
- react to changes in imodeljs-clients
|
|
546
|
-
- FrontendAuthorizationClient does not extend IDisposable.
|
|
639
|
+
- FrontendAuthorizationClient does not extend IDisposable.
|
|
547
640
|
- Update minimum Node version to 10.16.0
|
|
548
|
-
- Renamed OIDC constructs for consistency; Removed SAML support.
|
|
641
|
+
- Renamed OIDC constructs for consistency; Removed SAML support.
|
|
549
642
|
- order imports.
|
|
550
643
|
- Upgrade to Rush 5.23.2
|
|
551
644
|
- Update electron version to ^8.2.1
|
|
@@ -571,7 +664,7 @@ Wed, 12 Feb 2020 17:45:50 GMT
|
|
|
571
664
|
|
|
572
665
|
### Updates
|
|
573
666
|
|
|
574
|
-
- Setup oidc client for backend use in electron applications.
|
|
667
|
+
- Setup oidc client for backend use in electron applications.
|
|
575
668
|
|
|
576
669
|
## 1.11.0
|
|
577
670
|
Wed, 22 Jan 2020 19:24:12 GMT
|
|
@@ -653,7 +746,7 @@ Mon, 13 May 2019 15:52:05 GMT
|
|
|
653
746
|
|
|
654
747
|
- Adds parameter for api-extractor to validate missing release tags
|
|
655
748
|
- Fix broken links
|
|
656
|
-
- Setup a generic context for tracking client requests, and made various related enhancements to logging, usage tracking and authorization.
|
|
749
|
+
- Setup a generic context for tracking client requests, and made various related enhancements to logging, usage tracking and authorization.
|
|
657
750
|
- Upgrade TypeDoc dependency to 0.14.2
|
|
658
751
|
|
|
659
752
|
## 0.190.0
|
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright © 2017-
|
|
3
|
+
Copyright © 2017-2022 Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronBackend.d.ts","sourceRoot":"","sources":["../../src/ElectronBackend.ts"],"names":[],"mappings":"AAKA,cAAc,wBAAwB,CAAC
|
|
1
|
+
{"version":3,"file":"ElectronBackend.d.ts","sourceRoot":"","sources":["../../src/ElectronBackend.ts"],"names":[],"mappings":"AAKA,cAAc,wBAAwB,CAAC"}
|
|
@@ -15,5 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./backend/ElectronHost"), exports);
|
|
18
|
-
__exportStar(require("./backend/ElectronAuthorizationBackend"), exports);
|
|
19
18
|
//# sourceMappingURL=ElectronBackend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronBackend.js","sourceRoot":"","sources":["../../src/ElectronBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;AAE/F,yDAAuC
|
|
1
|
+
{"version":3,"file":"ElectronBackend.js","sourceRoot":"","sources":["../../src/ElectronBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;AAE/F,yDAAuC","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 \"./backend/ElectronHost\";\r\n"]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { BrowserWindow, BrowserWindowConstructorOptions } from "electron";
|
|
2
2
|
import { IpcHandler, NativeHostOpts } from "@itwin/core-backend";
|
|
3
|
-
import {
|
|
4
|
-
import { ElectronAuthorizationBackend } from "./ElectronAuthorizationBackend";
|
|
3
|
+
import { RpcConfiguration, RpcInterfaceDefinition } from "@itwin/core-common";
|
|
5
4
|
/**
|
|
6
5
|
* Options for [[ElectronHost.startup]]
|
|
7
6
|
* @beta
|
|
@@ -21,11 +20,6 @@ export interface ElectronHostOptions {
|
|
|
21
20
|
rpcInterfaces?: RpcInterfaceDefinition[];
|
|
22
21
|
/** list of [IpcHandler]($common) classes to register */
|
|
23
22
|
ipcHandlers?: (typeof IpcHandler)[];
|
|
24
|
-
/** if present, [[NativeHost.authorizationClient]] will be set to an instance of NativeAppAuthorizationBackend and will be initialized. */
|
|
25
|
-
authConfig?: NativeAppAuthorizationConfiguration;
|
|
26
|
-
/** if true, do not attempt to initialize AuthorizationClient on startup */
|
|
27
|
-
noInitializeAuthClient?: boolean;
|
|
28
|
-
applicationName?: never;
|
|
29
23
|
}
|
|
30
24
|
/** @beta */
|
|
31
25
|
export interface ElectronHostOpts extends NativeHostOpts {
|
|
@@ -63,8 +57,6 @@ export declare class ElectronHost {
|
|
|
63
57
|
static get ipcMain(): Electron.IpcMain;
|
|
64
58
|
static get app(): Electron.App;
|
|
65
59
|
static get electron(): typeof Electron;
|
|
66
|
-
/** @internal */
|
|
67
|
-
static get authorization(): ElectronAuthorizationBackend;
|
|
68
60
|
private constructor();
|
|
69
61
|
/**
|
|
70
62
|
* Converts an "electron://frontend/" URL to an absolute file path.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronHost.d.ts","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ElectronHost.d.ts","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAC;AAI1E,OAAO,EAAE,UAAU,EAAuB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAA8D,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAwB1I;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2IAA2I;IAC3I,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,aAAa,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACzC,wDAAwD;IACxD,WAAW,CAAC,EAAE,CAAC,OAAO,UAAU,CAAC,EAAE,CAAC;CACrC;AAED,YAAY;AACZ,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC;AAED,YAAY;AACZ,MAAM,WAAW,yBAA0B,SAAQ,+BAA+B;IAChF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,aAAa,CAAC,EAAE,CAAC,SAAS,GAAG,QAAQ,GAAG,aAAa,GAAG,sBAAsB,CAAC,CAAC;CACjF;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAc;IACjC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAU;IAC3C,OAAO,CAAC,MAAM,CAAC,SAAS,CAAkB;IAC1C,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA0B;IAC1D,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAgB;IAC3C,OAAc,gBAAgB,EAAE,MAAM,CAAC;IACvC,OAAc,WAAW,EAAE,MAAM,CAAC;IAClC,OAAc,WAAW,EAAE,MAAM,CAAC;IAClC,OAAc,SAAS,EAAE,gBAAgB,CAAC;IAC1C,WAAkB,OAAO,qBAAqC;IAC9D,WAAkB,GAAG,iBAAiC;IACtD,WAAkB,QAAQ,oBAA6B;IAEvD,OAAO;IAEP;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAmB/B,OAAO,CAAC,MAAM,CAAC,WAAW;IAqD1B,qDAAqD;IACrD,WAAkB,UAAU,8BAA+B;IAE3D,0FAA0F;WAC5E,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS;IAK9F,wFAAwF;WAC1E,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS;IAIhF;;;OAGG;WACiB,cAAc,CAAC,aAAa,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsC5F,WAAkB,OAAO,YAAsC;IAE/D;;;;;;OAMG;WACiB,OAAO,CAAC,IAAI,CAAC,EAAE,gBAAgB;CA4BpD"}
|
|
@@ -11,7 +11,6 @@ const core_bentley_1 = require("@itwin/core-bentley");
|
|
|
11
11
|
const core_backend_1 = require("@itwin/core-backend");
|
|
12
12
|
const core_common_1 = require("@itwin/core-common");
|
|
13
13
|
const ElectronRpcManager_1 = require("../common/ElectronRpcManager");
|
|
14
|
-
const ElectronAuthorizationBackend_1 = require("./ElectronAuthorizationBackend");
|
|
15
14
|
// cSpell:ignore signin devserver webcontents copyfile unmaximize eopt
|
|
16
15
|
class ElectronIpc {
|
|
17
16
|
addListener(channel, listener) {
|
|
@@ -41,8 +40,6 @@ class ElectronHost {
|
|
|
41
40
|
static get ipcMain() { return this._electron.ipcMain; }
|
|
42
41
|
static get app() { return this._electron.app; }
|
|
43
42
|
static get electron() { return this._electron; }
|
|
44
|
-
/** @internal */
|
|
45
|
-
static get authorization() { return core_backend_1.IModelHost.authorizationClient; }
|
|
46
43
|
/**
|
|
47
44
|
* Converts an "electron://frontend/" URL to an absolute file path.
|
|
48
45
|
*
|
|
@@ -173,7 +170,7 @@ class ElectronHost {
|
|
|
173
170
|
* @note This method must only be called from the backend of an Electron app (i.e. when [ProcessDetector.isElectronAppBackend]($bentley) is `true`).
|
|
174
171
|
*/
|
|
175
172
|
static async startup(opts) {
|
|
176
|
-
var _a, _b, _c, _d, _f, _g, _h, _j
|
|
173
|
+
var _a, _b, _c, _d, _f, _g, _h, _j;
|
|
177
174
|
if (!core_bentley_1.ProcessDetector.isElectronAppBackend)
|
|
178
175
|
throw new Error("Not running under Electron");
|
|
179
176
|
if (!this.isValid) {
|
|
@@ -198,11 +195,6 @@ class ElectronHost {
|
|
|
198
195
|
ElectronAppHandler.register();
|
|
199
196
|
(_j = (_h = opts.electronHost) === null || _h === void 0 ? void 0 : _h.ipcHandlers) === null || _j === void 0 ? void 0 : _j.forEach((ipc) => ipc.register());
|
|
200
197
|
}
|
|
201
|
-
const authorizationBackend = new ElectronAuthorizationBackend_1.ElectronAuthorizationBackend((_k = opts.electronHost) === null || _k === void 0 ? void 0 : _k.authConfig);
|
|
202
|
-
const connectivityStatus = core_backend_1.NativeHost.checkInternetConnectivity();
|
|
203
|
-
if (((_l = opts.electronHost) === null || _l === void 0 ? void 0 : _l.authConfig) && true !== ((_m = opts.electronHost) === null || _m === void 0 ? void 0 : _m.noInitializeAuthClient) && connectivityStatus === core_common_1.InternetConnectivityStatus.Online)
|
|
204
|
-
await authorizationBackend.initialize((_o = opts.electronHost) === null || _o === void 0 ? void 0 : _o.authConfig);
|
|
205
|
-
core_backend_1.IModelHost.authorizationClient = authorizationBackend;
|
|
206
198
|
}
|
|
207
199
|
}
|
|
208
200
|
exports.ElectronHost = ElectronHost;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronHost.js","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAQ/F,yBAAyB;AACzB,6BAA6B;AAC7B,sDAAgF;AAChF,sDAAkG;AAClG,oDAA2M;AAC3M,qEAA4F;AAC5F,iFAA8E;AAE9E,sEAAsE;AAEtE,MAAM,WAAW;IACR,WAAW,CAAC,OAAe,EAAE,QAAqB;QACvD,YAAY,CAAC,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACpD,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtE,CAAC;IACM,cAAc,CAAC,OAAe,EAAE,QAAqB;QAC1D,YAAY,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IACM,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;;QACzC,MAAM,MAAM,GAAG,MAAA,YAAY,CAAC,UAAU,mCAAI,YAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC;QACjG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAC7C,CAAC;IACM,MAAM,CAAC,OAAe,EAAE,QAAoD;QACjF,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,qDAAqD;QA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Y,0CAAE,UAAU,CAAC,CAAC;QAC7F,MAAM,kBAAkB,GAAG,yBAAU,CAAC,yBAAyB,EAAE,CAAC;QAClE,IAAI,CAAA,MAAA,IAAI,CAAC,YAAY,0CAAE,UAAU,KAAI,IAAI,MAAK,MAAA,IAAI,CAAC,YAAY,0CAAE,sBAAsB,CAAA,IAAI,kBAAkB,KAAK,wCAA0B,CAAC,MAAM;YACjJ,MAAM,oBAAoB,CAAC,UAAU,CAAC,MAAA,IAAI,CAAC,YAAY,0CAAE,UAAU,CAAC,CAAC;QAEvE,yBAAU,CAAC,mBAAmB,GAAG,oBAAoB,CAAC;IACxD,CAAC;;AArMH,oCAsMC;AAlMgB,8BAAiB,GAAG,sBAAsB,CAAC;AAoM5D,MAAM,kBAAmB,SAAQ,yBAAU;IACzC,IAAW,WAAW,KAAK,OAAO,eAAe,CAAC,CAAC,CAAC;IAC7C,KAAK,CAAC,YAAY,CAAC,MAAc,EAAE,MAAc,EAAE,GAAG,IAAS;QACpE,MAAM,cAAc,GAAI,YAAY,CAAC,QAAgB,CAAC,MAAM,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,OAAO,IAAI,KAAK,UAAU;YAC5B,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,gBAAgB,EAAE,UAAU,MAAM,uBAAuB,MAAM,EAAE,CAAC,CAAC;QAExG,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,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\n// Note: only import types! Does not create a `require(\"electron\")` in JavaScript after transpiling. That's important so this file can\r\n// be imported by apps that sometimes use Electron and sometimes not. Call to `ElectronBackend.initialize`\r\n// will do the necessary `require(\"electron\")`\r\n// IMPORTANT: Do not call or construct any of these imports. Otherwise, a require(\"electron\") call will be emitted at top level.\r\n// Instead, use `ElectronHost.electron.<type>`\r\nimport { BrowserWindow, BrowserWindowConstructorOptions } from \"electron\";\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport { BeDuration, IModelStatus, ProcessDetector } from \"@itwin/core-bentley\";\r\nimport { IModelHost, IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\r\nimport { IModelError, InternetConnectivityStatus, IpcListener, IpcSocketBackend, NativeAppAuthorizationConfiguration, RemoveFunction, RpcConfiguration, RpcInterfaceDefinition } from \"@itwin/core-common\";\r\nimport { ElectronRpcConfiguration, ElectronRpcManager } from \"../common/ElectronRpcManager\";\r\nimport { ElectronAuthorizationBackend } from \"./ElectronAuthorizationBackend\";\r\n\r\n// cSpell:ignore signin devserver webcontents copyfile unmaximize eopt\r\n\r\nclass ElectronIpc implements IpcSocketBackend {\r\n public addListener(channel: string, listener: IpcListener): RemoveFunction {\r\n ElectronHost.ipcMain.addListener(channel, listener);\r\n return () => ElectronHost.ipcMain.removeListener(channel, listener);\r\n }\r\n public removeListener(channel: string, listener: IpcListener) {\r\n ElectronHost.ipcMain.removeListener(channel, listener);\r\n }\r\n public send(channel: string, ...args: any[]): void {\r\n const window = ElectronHost.mainWindow ?? ElectronHost.electron.BrowserWindow.getAllWindows()[0];\r\n window?.webContents.send(channel, ...args);\r\n }\r\n public handle(channel: string, listener: (evt: any, ...args: any[]) => Promise<any>): RemoveFunction {\r\n ElectronHost.ipcMain.removeHandler(channel); // make sure there's not already a handler registered\r\n ElectronHost.ipcMain.handle(channel, listener);\r\n return () => ElectronHost.ipcMain.removeHandler(channel);\r\n }\r\n}\r\n\r\n/**\r\n * Options for [[ElectronHost.startup]]\r\n * @beta\r\n */\r\nexport interface ElectronHostOptions {\r\n /** the path to find web resources */\r\n webResourcesPath?: string;\r\n /** filename for the app's icon, relative to [[webResourcesPath]] */\r\n iconName?: string;\r\n /** name of frontend url to open. */\r\n frontendURL?: string;\r\n /** use a development server rather than the \"electron\" protocol for loading frontend (see https://www.electronjs.org/docs/api/protocol) */\r\n developmentServer?: boolean;\r\n /** port number for development server. Default is 3000 */\r\n frontendPort?: number;\r\n /** list of RPC interface definitions to register */\r\n rpcInterfaces?: RpcInterfaceDefinition[];\r\n /** list of [IpcHandler]($common) classes to register */\r\n ipcHandlers?: (typeof IpcHandler)[];\r\n /** if present, [[NativeHost.authorizationClient]] will be set to an instance of NativeAppAuthorizationBackend and will be initialized. */\r\n authConfig?: NativeAppAuthorizationConfiguration;\r\n /** if true, do not attempt to initialize AuthorizationClient on startup */\r\n noInitializeAuthClient?: boolean;\r\n applicationName?: never; // this should be supplied in NativeHostOpts\r\n}\r\n\r\n/** @beta */\r\nexport interface ElectronHostOpts extends NativeHostOpts {\r\n electronHost?: ElectronHostOptions;\r\n}\r\n\r\n/** @beta */\r\nexport interface ElectronHostWindowOptions extends BrowserWindowConstructorOptions {\r\n storeWindowName?: string;\r\n /** The style of window title bar. Default is `default`. */\r\n titleBarStyle?: (\"default\" | \"hidden\" | \"hiddenInset\" | \"customButtonsOnHover\");\r\n}\r\n\r\n/** the size and position of a window as stored in the settings file.\r\n * @beta\r\n */\r\nexport interface WindowSizeAndPositionProps {\r\n width: number;\r\n height: number;\r\n x: number;\r\n y: number;\r\n}\r\n\r\n/**\r\n * The backend for Electron-based desktop applications\r\n * @beta\r\n */\r\nexport class ElectronHost {\r\n private static _ipc: ElectronIpc;\r\n private static _developmentServer: boolean;\r\n private static _electron: typeof Electron;\r\n private static _electronFrontend = \"electron://frontend/\";\r\n private static _mainWindow?: BrowserWindow;\r\n public static webResourcesPath: string;\r\n public static appIconPath: string;\r\n public static frontendURL: string;\r\n public static rpcConfig: RpcConfiguration;\r\n public static get ipcMain() { return this._electron.ipcMain; }\r\n public static get app() { return this._electron.app; }\r\n public static get electron() { return this._electron; }\r\n\r\n /** @internal */\r\n public static get authorization() { return IModelHost.authorizationClient as ElectronAuthorizationBackend; }\r\n\r\n private constructor() { }\r\n\r\n /**\r\n * Converts an \"electron://frontend/\" URL to an absolute file path.\r\n *\r\n * We use this protocol in production builds because our frontend must be built with absolute URLs,\r\n * however, since we're loading everything directly from the install directory, we cannot know the\r\n * absolute path at build time.\r\n */\r\n private static parseElectronUrl(requestedUrl: string): string {\r\n // Note that the \"frontend/\" path is arbitrary - this is just so we can handle *some* relative URLs...\r\n let assetPath = requestedUrl.substr(this._electronFrontend.length);\r\n if (assetPath.length === 0)\r\n assetPath = \"index.html\";\r\n assetPath = path.normalize(`${this.webResourcesPath}/${assetPath}`);\r\n // File protocols don't follow symlinks, so we need to resolve this to a real path.\r\n // However, if the file doesn't exist, it's fine to return an invalid path here - the request will just fail with net::ERR_FILE_NOT_FOUND\r\n try {\r\n assetPath = fs.realpathSync(assetPath);\r\n } catch (error) {\r\n // eslint-disable-next-line no-console\r\n // console.warn(`WARNING: Frontend requested \"${requestedUrl}\", but ${assetPath} does not exist`);\r\n }\r\n if (!assetPath.startsWith(this.webResourcesPath))\r\n throw new Error(`Access to files outside installation directory (${this.webResourcesPath}) is prohibited`);\r\n return assetPath;\r\n }\r\n\r\n private static _openWindow(options?: ElectronHostWindowOptions) {\r\n const opts: BrowserWindowConstructorOptions = {\r\n ...options,\r\n autoHideMenuBar: true,\r\n icon: this.appIconPath,\r\n webPreferences: {\r\n ...options?.webPreferences,\r\n\r\n // These web preference variables should not be overriden by the ElectronHostWindowOptions\r\n preload: require.resolve(/* webpack: copyfile */\"./ElectronPreload.js\"),\r\n experimentalFeatures: false,\r\n nodeIntegration: false,\r\n contextIsolation: true,\r\n sandbox: true,\r\n nativeWindowOpen: true,\r\n nodeIntegrationInWorker: false,\r\n nodeIntegrationInSubFrames: false,\r\n },\r\n };\r\n\r\n this._mainWindow = new (this.electron.BrowserWindow)(opts);\r\n ElectronRpcConfiguration.targetWindowId = this._mainWindow.id;\r\n this._mainWindow.on(\"closed\", () => this._mainWindow = undefined);\r\n this._mainWindow.loadURL(this.frontendURL); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n\r\n /** Monitors and saves main window size, position and maximized state */\r\n if (options?.storeWindowName) {\r\n const mainWindow = this._mainWindow;\r\n const name = options.storeWindowName;\r\n const saveWindowPosition = () => {\r\n const resolution = mainWindow.getSize();\r\n const position = mainWindow.getPosition();\r\n const pos: WindowSizeAndPositionProps = {\r\n width: resolution[0],\r\n height: resolution[1],\r\n x: position[0],\r\n y: position[1],\r\n };\r\n NativeHost.settingsStore.setData(`windowPos-${name}`, JSON.stringify(pos));\r\n };\r\n const saveMaximized = (maximized: boolean) => {\r\n if (!maximized)\r\n saveWindowPosition();\r\n NativeHost.settingsStore.setData(`windowMaximized-${name}`, maximized);\r\n };\r\n\r\n mainWindow.on(\"resized\", () => saveWindowPosition());\r\n mainWindow.on(\"moved\", () => saveWindowPosition());\r\n mainWindow.on(\"maximize\", () => saveMaximized(true));\r\n mainWindow.on(\"unmaximize\", () => saveMaximized(false));\r\n }\r\n }\r\n\r\n /** The \"main\" BrowserWindow for this application. */\r\n public static get mainWindow() { return this._mainWindow; }\r\n\r\n /** Gets window size and position for a window, by name, from settings file, if present */\r\n public static getWindowSizeSetting(windowName: string): WindowSizeAndPositionProps | undefined {\r\n const saved = NativeHost.settingsStore.getString(`windowPos-${windowName}`);\r\n return saved ? JSON.parse(saved) as WindowSizeAndPositionProps : undefined;\r\n }\r\n\r\n /** Gets \"window maximized\" flag for a window, by name, from settings file if present */\r\n public static getWindowMaximizedSetting(windowName: string): boolean | undefined {\r\n return NativeHost.settingsStore.getBoolean(`windowMaximized-${windowName}`);\r\n }\r\n\r\n /**\r\n * Open the main Window when the app is ready.\r\n * @param windowOptions Options for constructing the main BrowserWindow. See: https://electronjs.org/docs/api/browser-window#new-browserwindowoptions\r\n */\r\n public static async openMainWindow(windowOptions?: ElectronHostWindowOptions): Promise<void> {\r\n const app = this.app;\r\n // quit the application when all windows are closed (unless we're running on MacOS)\r\n app.on(\"window-all-closed\", () => {\r\n if (process.platform !== \"darwin\")\r\n app.quit();\r\n });\r\n\r\n // re-open the main window if it was closed and the app is re-activated (this is the normal MacOS behavior)\r\n app.on(\"activate\", () => {\r\n if (!this._mainWindow)\r\n this._openWindow(windowOptions);\r\n });\r\n\r\n if (this._developmentServer) {\r\n // Occasionally, the electron backend may start before the webpack devserver has even started.\r\n // If this happens, we'll just retry and keep reloading the page.\r\n app.on(\"web-contents-created\", (_e, webcontents) => {\r\n webcontents.on(\"did-fail-load\", async (_event, errorCode, _errorDescription, _validatedURL, isMainFrame) => {\r\n // errorCode -102 is CONNECTION_REFUSED - see https://cs.chromium.org/chromium/src/net/base/net_error_list.h\r\n if (isMainFrame && errorCode === -102) {\r\n await BeDuration.wait(100);\r\n webcontents.reload();\r\n }\r\n });\r\n });\r\n }\r\n\r\n await app.whenReady();\r\n\r\n if (!this._developmentServer) {\r\n // handle any \"electron://\" requests and redirect them to \"file://\" URLs\r\n this.electron.protocol.registerFileProtocol(\"electron\", (request, callback) => callback(this.parseElectronUrl(request.url))); // eslint-disable-line @typescript-eslint/no-var-requires\r\n }\r\n\r\n this._openWindow(windowOptions);\r\n }\r\n\r\n public static get isValid() { return this._ipc !== undefined; }\r\n\r\n /**\r\n * Initialize the backend of an Electron app.\r\n * This method configures the backend for all of the inter-process communication (RPC and IPC) for an\r\n * Electron app. It should be called from your Electron main function.\r\n * @param opts Options that control aspects of your backend.\r\n * @note This method must only be called from the backend of an Electron app (i.e. when [ProcessDetector.isElectronAppBackend]($bentley) is `true`).\r\n */\r\n public static async startup(opts?: ElectronHostOpts) {\r\n if (!ProcessDetector.isElectronAppBackend)\r\n throw new Error(\"Not running under Electron\");\r\n\r\n if (!this.isValid) {\r\n this._electron = require(\"electron\");\r\n this._ipc = new ElectronIpc();\r\n const app = this.app;\r\n if (!app.isReady())\r\n this.electron.protocol.registerSchemesAsPrivileged([{ scheme: \"electron\", privileges: { standard: true, secure: true } }]);\r\n const eopt = opts?.electronHost;\r\n this._developmentServer = eopt?.developmentServer ?? false;\r\n const frontendPort = eopt?.frontendPort ?? 3000;\r\n this.webResourcesPath = eopt?.webResourcesPath ?? \"\";\r\n this.frontendURL = eopt?.frontendURL ?? (this._developmentServer ? `http://localhost:${frontendPort}` : `${this._electronFrontend}index.html`);\r\n this.appIconPath = path.join(this.webResourcesPath, eopt?.iconName ?? \"appicon.ico\");\r\n this.rpcConfig = ElectronRpcManager.initializeBackend(this._ipc, eopt?.rpcInterfaces);\r\n }\r\n\r\n opts = opts ?? {};\r\n opts.ipcHost = opts.ipcHost ?? {};\r\n opts.ipcHost.socket = this._ipc;\r\n await NativeHost.startup(opts);\r\n if (IpcHost.isValid) {\r\n ElectronAppHandler.register();\r\n opts.electronHost?.ipcHandlers?.forEach((ipc) => ipc.register());\r\n }\r\n\r\n const authorizationBackend = new ElectronAuthorizationBackend(opts.electronHost?.authConfig);\r\n const connectivityStatus = NativeHost.checkInternetConnectivity();\r\n if (opts.electronHost?.authConfig && true !== opts.electronHost?.noInitializeAuthClient && connectivityStatus === InternetConnectivityStatus.Online)\r\n await authorizationBackend.initialize(opts.electronHost?.authConfig);\r\n\r\n IModelHost.authorizationClient = authorizationBackend;\r\n }\r\n}\r\n\r\nclass ElectronAppHandler extends IpcHandler {\r\n public get channelName() { return \"electron-safe\"; }\r\n public async callElectron(member: string, method: string, ...args: any) {\r\n const electronMember = (ElectronHost.electron as any)[member];\r\n const func = electronMember[method];\r\n if (typeof func !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${method} not found electron.${member}`);\r\n\r\n return func.call(electronMember, ...args);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ElectronHost.js","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAS/F,yBAAyB;AACzB,6BAA6B;AAC7B,sDAAgF;AAChF,sDAAsF;AACtF,oDAA0I;AAC1I,qEAA4F;AAE5F,sEAAsE;AAEtE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AkB,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,aAAa,CAAC,CAAC;SACvF;QAED,IAAI,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,EAAE,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,MAAA,IAAI,CAAC,OAAO,mCAAI,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;QAChC,MAAM,yBAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,sBAAO,CAAC,OAAO,EAAE;YACnB,kBAAkB,CAAC,QAAQ,EAAE,CAAC;YAC9B,MAAA,MAAA,IAAI,CAAC,YAAY,0CAAE,WAAW,0CAAE,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;SAClE;IACH,CAAC;;AA3LH,oCA4LC;AAxLgB,8BAAiB,GAAG,sBAAsB,CAAC;AA0L5D,MAAM,kBAAmB,SAAQ,yBAAU;IACzC,IAAW,WAAW,KAAK,OAAO,eAAe,CAAC,CAAC,CAAC;IAC7C,KAAK,CAAC,YAAY,CAAC,MAAc,EAAE,MAAc,EAAE,GAAG,IAAS;QACpE,MAAM,cAAc,GAAI,YAAY,CAAC,QAAgB,CAAC,MAAM,CAAC,CAAC;QAC9D,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,OAAO,IAAI,KAAK,UAAU;YAC5B,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,gBAAgB,EAAE,UAAU,MAAM,uBAAuB,MAAM,EAAE,CAAC,CAAC;QAExG,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,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\n// Note: only import types! Does not create a `require(\"electron\")` in JavaScript after transpiling. That's important so this file can\r\n// be imported by apps that sometimes use Electron and sometimes not. Call to `ElectronBackend.initialize`\r\n// will do the necessary `require(\"electron\")`\r\n// IMPORTANT: Do not call or construct any of these imports. Otherwise, a require(\"electron\") call will be emitted at top level.\r\n// Instead, use `ElectronHost.electron.<type>`\r\n\r\nimport { BrowserWindow, BrowserWindowConstructorOptions } from \"electron\";\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport { BeDuration, IModelStatus, ProcessDetector } from \"@itwin/core-bentley\";\r\nimport { IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\r\nimport { IModelError, IpcListener, IpcSocketBackend, RemoveFunction, RpcConfiguration, RpcInterfaceDefinition } from \"@itwin/core-common\";\r\nimport { ElectronRpcConfiguration, ElectronRpcManager } from \"../common/ElectronRpcManager\";\r\n\r\n// cSpell:ignore signin devserver webcontents copyfile unmaximize eopt\r\n\r\nclass ElectronIpc implements IpcSocketBackend {\r\n public addListener(channel: string, listener: IpcListener): RemoveFunction {\r\n ElectronHost.ipcMain.addListener(channel, listener);\r\n return () => ElectronHost.ipcMain.removeListener(channel, listener);\r\n }\r\n public removeListener(channel: string, listener: IpcListener) {\r\n ElectronHost.ipcMain.removeListener(channel, listener);\r\n }\r\n public send(channel: string, ...args: any[]): void {\r\n const window = ElectronHost.mainWindow ?? ElectronHost.electron.BrowserWindow.getAllWindows()[0];\r\n window?.webContents.send(channel, ...args);\r\n }\r\n public handle(channel: string, listener: (evt: any, ...args: any[]) => Promise<any>): RemoveFunction {\r\n ElectronHost.ipcMain.removeHandler(channel); // make sure there's not already a handler registered\r\n ElectronHost.ipcMain.handle(channel, listener);\r\n return () => ElectronHost.ipcMain.removeHandler(channel);\r\n }\r\n}\r\n\r\n/**\r\n * Options for [[ElectronHost.startup]]\r\n * @beta\r\n */\r\nexport interface ElectronHostOptions {\r\n /** the path to find web resources */\r\n webResourcesPath?: string;\r\n /** filename for the app's icon, relative to [[webResourcesPath]] */\r\n iconName?: string;\r\n /** name of frontend url to open. */\r\n frontendURL?: string;\r\n /** use a development server rather than the \"electron\" protocol for loading frontend (see https://www.electronjs.org/docs/api/protocol) */\r\n developmentServer?: boolean;\r\n /** port number for development server. Default is 3000 */\r\n frontendPort?: number;\r\n /** list of RPC interface definitions to register */\r\n rpcInterfaces?: RpcInterfaceDefinition[];\r\n /** list of [IpcHandler]($common) classes to register */\r\n ipcHandlers?: (typeof IpcHandler)[];\r\n}\r\n\r\n/** @beta */\r\nexport interface ElectronHostOpts extends NativeHostOpts {\r\n electronHost?: ElectronHostOptions;\r\n}\r\n\r\n/** @beta */\r\nexport interface ElectronHostWindowOptions extends BrowserWindowConstructorOptions {\r\n storeWindowName?: string;\r\n /** The style of window title bar. Default is `default`. */\r\n titleBarStyle?: (\"default\" | \"hidden\" | \"hiddenInset\" | \"customButtonsOnHover\");\r\n}\r\n\r\n/** the size and position of a window as stored in the settings file.\r\n * @beta\r\n */\r\nexport interface WindowSizeAndPositionProps {\r\n width: number;\r\n height: number;\r\n x: number;\r\n y: number;\r\n}\r\n\r\n/**\r\n * The backend for Electron-based desktop applications\r\n * @beta\r\n */\r\nexport class ElectronHost {\r\n private static _ipc: ElectronIpc;\r\n private static _developmentServer: boolean;\r\n private static _electron: typeof Electron;\r\n private static _electronFrontend = \"electron://frontend/\";\r\n private static _mainWindow?: BrowserWindow;\r\n public static webResourcesPath: string;\r\n public static appIconPath: string;\r\n public static frontendURL: string;\r\n public static rpcConfig: RpcConfiguration;\r\n public static get ipcMain() { return this._electron.ipcMain; }\r\n public static get app() { return this._electron.app; }\r\n public static get electron() { return this._electron; }\r\n\r\n private constructor() { }\r\n\r\n /**\r\n * Converts an \"electron://frontend/\" URL to an absolute file path.\r\n *\r\n * We use this protocol in production builds because our frontend must be built with absolute URLs,\r\n * however, since we're loading everything directly from the install directory, we cannot know the\r\n * absolute path at build time.\r\n */\r\n private static parseElectronUrl(requestedUrl: string): string {\r\n // Note that the \"frontend/\" path is arbitrary - this is just so we can handle *some* relative URLs...\r\n let assetPath = requestedUrl.substr(this._electronFrontend.length);\r\n if (assetPath.length === 0)\r\n assetPath = \"index.html\";\r\n assetPath = path.normalize(`${this.webResourcesPath}/${assetPath}`);\r\n // File protocols don't follow symlinks, so we need to resolve this to a real path.\r\n // However, if the file doesn't exist, it's fine to return an invalid path here - the request will just fail with net::ERR_FILE_NOT_FOUND\r\n try {\r\n assetPath = fs.realpathSync(assetPath);\r\n } catch (error) {\r\n // eslint-disable-next-line no-console\r\n // console.warn(`WARNING: Frontend requested \"${requestedUrl}\", but ${assetPath} does not exist`);\r\n }\r\n if (!assetPath.startsWith(this.webResourcesPath))\r\n throw new Error(`Access to files outside installation directory (${this.webResourcesPath}) is prohibited`);\r\n return assetPath;\r\n }\r\n\r\n private static _openWindow(options?: ElectronHostWindowOptions) {\r\n const opts: BrowserWindowConstructorOptions = {\r\n ...options,\r\n autoHideMenuBar: true,\r\n icon: this.appIconPath,\r\n webPreferences: {\r\n ...options?.webPreferences,\r\n\r\n // These web preference variables should not be overriden by the ElectronHostWindowOptions\r\n preload: require.resolve(/* webpack: copyfile */\"./ElectronPreload.js\"),\r\n experimentalFeatures: false,\r\n nodeIntegration: false,\r\n contextIsolation: true,\r\n sandbox: true,\r\n nativeWindowOpen: true,\r\n nodeIntegrationInWorker: false,\r\n nodeIntegrationInSubFrames: false,\r\n },\r\n };\r\n\r\n this._mainWindow = new (this.electron.BrowserWindow)(opts);\r\n ElectronRpcConfiguration.targetWindowId = this._mainWindow.id;\r\n this._mainWindow.on(\"closed\", () => this._mainWindow = undefined);\r\n this._mainWindow.loadURL(this.frontendURL); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n\r\n /** Monitors and saves main window size, position and maximized state */\r\n if (options?.storeWindowName) {\r\n const mainWindow = this._mainWindow;\r\n const name = options.storeWindowName;\r\n const saveWindowPosition = () => {\r\n const resolution = mainWindow.getSize();\r\n const position = mainWindow.getPosition();\r\n const pos: WindowSizeAndPositionProps = {\r\n width: resolution[0],\r\n height: resolution[1],\r\n x: position[0],\r\n y: position[1],\r\n };\r\n NativeHost.settingsStore.setData(`windowPos-${name}`, JSON.stringify(pos));\r\n };\r\n const saveMaximized = (maximized: boolean) => {\r\n if (!maximized)\r\n saveWindowPosition();\r\n NativeHost.settingsStore.setData(`windowMaximized-${name}`, maximized);\r\n };\r\n\r\n mainWindow.on(\"resized\", () => saveWindowPosition());\r\n mainWindow.on(\"moved\", () => saveWindowPosition());\r\n mainWindow.on(\"maximize\", () => saveMaximized(true));\r\n mainWindow.on(\"unmaximize\", () => saveMaximized(false));\r\n }\r\n }\r\n\r\n /** The \"main\" BrowserWindow for this application. */\r\n public static get mainWindow() { return this._mainWindow; }\r\n\r\n /** Gets window size and position for a window, by name, from settings file, if present */\r\n public static getWindowSizeSetting(windowName: string): WindowSizeAndPositionProps | undefined {\r\n const saved = NativeHost.settingsStore.getString(`windowPos-${windowName}`);\r\n return saved ? JSON.parse(saved) as WindowSizeAndPositionProps : undefined;\r\n }\r\n\r\n /** Gets \"window maximized\" flag for a window, by name, from settings file if present */\r\n public static getWindowMaximizedSetting(windowName: string): boolean | undefined {\r\n return NativeHost.settingsStore.getBoolean(`windowMaximized-${windowName}`);\r\n }\r\n\r\n /**\r\n * Open the main Window when the app is ready.\r\n * @param windowOptions Options for constructing the main BrowserWindow. See: https://electronjs.org/docs/api/browser-window#new-browserwindowoptions\r\n */\r\n public static async openMainWindow(windowOptions?: ElectronHostWindowOptions): Promise<void> {\r\n const app = this.app;\r\n // quit the application when all windows are closed (unless we're running on MacOS)\r\n app.on(\"window-all-closed\", () => {\r\n if (process.platform !== \"darwin\")\r\n app.quit();\r\n });\r\n\r\n // re-open the main window if it was closed and the app is re-activated (this is the normal MacOS behavior)\r\n app.on(\"activate\", () => {\r\n if (!this._mainWindow)\r\n this._openWindow(windowOptions);\r\n });\r\n\r\n if (this._developmentServer) {\r\n // Occasionally, the electron backend may start before the webpack devserver has even started.\r\n // If this happens, we'll just retry and keep reloading the page.\r\n app.on(\"web-contents-created\", (_e, webcontents) => {\r\n webcontents.on(\"did-fail-load\", async (_event, errorCode, _errorDescription, _validatedURL, isMainFrame) => {\r\n // errorCode -102 is CONNECTION_REFUSED - see https://cs.chromium.org/chromium/src/net/base/net_error_list.h\r\n if (isMainFrame && errorCode === -102) {\r\n await BeDuration.wait(100);\r\n webcontents.reload();\r\n }\r\n });\r\n });\r\n }\r\n\r\n await app.whenReady();\r\n\r\n if (!this._developmentServer) {\r\n // handle any \"electron://\" requests and redirect them to \"file://\" URLs\r\n this.electron.protocol.registerFileProtocol(\"electron\", (request, callback) => callback(this.parseElectronUrl(request.url))); // eslint-disable-line @typescript-eslint/no-var-requires\r\n }\r\n\r\n this._openWindow(windowOptions);\r\n }\r\n\r\n public static get isValid() { return this._ipc !== undefined; }\r\n\r\n /**\r\n * Initialize the backend of an Electron app.\r\n * This method configures the backend for all of the inter-process communication (RPC and IPC) for an\r\n * Electron app. It should be called from your Electron main function.\r\n * @param opts Options that control aspects of your backend.\r\n * @note This method must only be called from the backend of an Electron app (i.e. when [ProcessDetector.isElectronAppBackend]($bentley) is `true`).\r\n */\r\n public static async startup(opts?: ElectronHostOpts) {\r\n if (!ProcessDetector.isElectronAppBackend)\r\n throw new Error(\"Not running under Electron\");\r\n\r\n if (!this.isValid) {\r\n this._electron = require(\"electron\");\r\n this._ipc = new ElectronIpc();\r\n const app = this.app;\r\n if (!app.isReady())\r\n this.electron.protocol.registerSchemesAsPrivileged([{ scheme: \"electron\", privileges: { standard: true, secure: true } }]);\r\n const eopt = opts?.electronHost;\r\n this._developmentServer = eopt?.developmentServer ?? false;\r\n const frontendPort = eopt?.frontendPort ?? 3000;\r\n this.webResourcesPath = eopt?.webResourcesPath ?? \"\";\r\n this.frontendURL = eopt?.frontendURL ?? (this._developmentServer ? `http://localhost:${frontendPort}` : `${this._electronFrontend}index.html`);\r\n this.appIconPath = path.join(this.webResourcesPath, eopt?.iconName ?? \"appicon.ico\");\r\n this.rpcConfig = ElectronRpcManager.initializeBackend(this._ipc, eopt?.rpcInterfaces);\r\n }\r\n\r\n opts = opts ?? {};\r\n opts.ipcHost = opts.ipcHost ?? {};\r\n opts.ipcHost.socket = this._ipc;\r\n await NativeHost.startup(opts);\r\n if (IpcHost.isValid) {\r\n ElectronAppHandler.register();\r\n opts.electronHost?.ipcHandlers?.forEach((ipc) => ipc.register());\r\n }\r\n }\r\n}\r\n\r\nclass ElectronAppHandler extends IpcHandler {\r\n public get channelName() { return \"electron-safe\"; }\r\n public async callElectron(member: string, method: string, ...args: any) {\r\n const electronMember = (ElectronHost.electron as any)[member];\r\n const func = electronMember[method];\r\n if (typeof func !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${method} not found electron.${member}`);\r\n\r\n return func.call(electronMember, ...args);\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-electron",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "iTwin.js ElectronHost and ElectronApp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/
|
|
11
|
+
"url": "https://github.com/iTwin/itwinjs-core/tree/master/core/core-electron"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
14
|
"Bentley",
|
|
@@ -20,23 +20,21 @@
|
|
|
20
20
|
"url": "http://www.bentley.com"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@itwin/core-
|
|
24
|
-
"@itwin/core-
|
|
25
|
-
"@itwin/core-common": "^3.0.
|
|
26
|
-
"@itwin/core-frontend": "^3.0.
|
|
27
|
-
"@
|
|
28
|
-
"@itwin/presentation-common": "^3.0.0-extension.0",
|
|
23
|
+
"@itwin/core-backend": "^3.0.1",
|
|
24
|
+
"@itwin/core-bentley": "^3.0.1",
|
|
25
|
+
"@itwin/core-common": "^3.0.1",
|
|
26
|
+
"@itwin/core-frontend": "^3.0.1",
|
|
27
|
+
"@itwin/presentation-common": "^3.0.1",
|
|
29
28
|
"electron": "^14.0.0"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
|
32
|
-
"@itwin/
|
|
33
|
-
"@itwin/
|
|
34
|
-
"@itwin/
|
|
35
|
-
"@itwin/core-
|
|
36
|
-
"@itwin/core-
|
|
37
|
-
"@itwin/
|
|
38
|
-
"@
|
|
39
|
-
"@itwin/presentation-common": "3.0.0-extension.0",
|
|
31
|
+
"@itwin/build-tools": "3.0.1",
|
|
32
|
+
"@itwin/core-backend": "3.0.1",
|
|
33
|
+
"@itwin/core-bentley": "3.0.1",
|
|
34
|
+
"@itwin/core-common": "3.0.1",
|
|
35
|
+
"@itwin/core-frontend": "3.0.1",
|
|
36
|
+
"@itwin/eslint-plugin": "3.0.1",
|
|
37
|
+
"@itwin/presentation-common": "3.0.1",
|
|
40
38
|
"@types/node": "14.14.31",
|
|
41
39
|
"electron": "^14.0.0",
|
|
42
40
|
"eslint": "^7.11.0",
|
|
@@ -64,5 +62,6 @@
|
|
|
64
62
|
"lint": "eslint -f visualstudio \"./src/**/*.ts\" 1>&2",
|
|
65
63
|
"test": "",
|
|
66
64
|
"cover": ""
|
|
67
|
-
}
|
|
65
|
+
},
|
|
66
|
+
"readme": "# @itwin/core-electron\r\n\r\nCopyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.\r\n\r\n## Description\r\n\r\nThe __@itwin/core-electron__ package contains the electron utilities to write an iTwin.js application based on Electron.\r\n\r\n## Documentation\r\n\r\nSee the [iTwin.js](https://www.itwinjs.org) documentation for more information.\r\n"
|
|
68
67
|
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/** @packageDocumentation
|
|
2
|
-
* @module Authentication
|
|
3
|
-
*/
|
|
4
|
-
import { AccessToken } from "@itwin/core-bentley";
|
|
5
|
-
import { NativeAppAuthorizationBackend } from "@itwin/core-backend";
|
|
6
|
-
import { NativeAppAuthorizationConfiguration } from "@itwin/core-common";
|
|
7
|
-
import { ElectronTokenStore } from "./ElectronTokenStore";
|
|
8
|
-
/**
|
|
9
|
-
* Utility to generate OIDC/OAuth tokens for Desktop Applications
|
|
10
|
-
* @beta
|
|
11
|
-
*/
|
|
12
|
-
export declare class ElectronAuthorizationBackend extends NativeAppAuthorizationBackend {
|
|
13
|
-
static defaultRedirectUri: string;
|
|
14
|
-
private _configuration;
|
|
15
|
-
private _tokenResponse;
|
|
16
|
-
private _tokenStore?;
|
|
17
|
-
private _expiresAt?;
|
|
18
|
-
get tokenStore(): ElectronTokenStore;
|
|
19
|
-
constructor(config?: NativeAppAuthorizationConfiguration);
|
|
20
|
-
get redirectUri(): string;
|
|
21
|
-
/**
|
|
22
|
-
* Used to initialize the client - must be awaited before any other methods are called.
|
|
23
|
-
* The call attempts a silent sign-if possible.
|
|
24
|
-
*/
|
|
25
|
-
initialize(config?: NativeAppAuthorizationConfiguration): Promise<void>;
|
|
26
|
-
refreshToken(): Promise<AccessToken>;
|
|
27
|
-
/** Loads the access token from the store, and refreshes it if necessary and possible
|
|
28
|
-
* @return AccessToken if it's possible to get a valid access token, and undefined otherwise.
|
|
29
|
-
*/
|
|
30
|
-
private loadAccessToken;
|
|
31
|
-
/**
|
|
32
|
-
* Sign-in completely.
|
|
33
|
-
* This is a wrapper around [[signIn]] - the only difference is that the promise resolves
|
|
34
|
-
* with the access token after sign in is complete and successful.
|
|
35
|
-
*/
|
|
36
|
-
signInComplete(): Promise<AccessToken>;
|
|
37
|
-
/**
|
|
38
|
-
* Start the sign-in process
|
|
39
|
-
* - calls the onAccessTokenChanged() call back after the authorization completes
|
|
40
|
-
* or if there is an error.
|
|
41
|
-
* - will attempt in order:
|
|
42
|
-
* (i) load any existing authorized user from storage,
|
|
43
|
-
* (ii) an interactive signin that requires user input.
|
|
44
|
-
*/
|
|
45
|
-
signIn(): Promise<void>;
|
|
46
|
-
private _onAuthorizationResponse;
|
|
47
|
-
/**
|
|
48
|
-
* Start the sign-out process
|
|
49
|
-
* - calls the onAccessTokenChanged() call back after the authorization completes
|
|
50
|
-
* or if there is an error.
|
|
51
|
-
* - redirects application to the postSignoutRedirectUri specified in the configuration when the sign out is
|
|
52
|
-
* complete
|
|
53
|
-
*/
|
|
54
|
-
signOut(): Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* Sign out completely
|
|
57
|
-
* This is a wrapper around [[signOut]] - the only difference is that the promise resolves
|
|
58
|
-
* after the sign out is complete.
|
|
59
|
-
*/
|
|
60
|
-
signOutComplete(): Promise<void>;
|
|
61
|
-
private clearTokenResponse;
|
|
62
|
-
private setTokenResponse;
|
|
63
|
-
private get _hasExpired();
|
|
64
|
-
getAccessToken(): Promise<AccessToken>;
|
|
65
|
-
private refreshAccessToken;
|
|
66
|
-
/** Swap the authorization code for a refresh token and access token */
|
|
67
|
-
private swapAuthorizationCodeForTokens;
|
|
68
|
-
private makeRefreshAccessTokenRequest;
|
|
69
|
-
private makeRevokeTokenRequest;
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=ElectronAuthorizationBackend.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronAuthorizationBackend.d.ts","sourceRoot":"","sources":["../../../src/backend/ElectronAuthorizationBackend.ts"],"names":[],"mappings":"AAMA;;GAEG;AAKH,OAAO,EAAE,WAAW,EAA4C,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,6BAA6B,EAAc,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,mCAAmC,EAAE,MAAM,oBAAoB,CAAC;AASzE,OA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