@itwin/core-electron 4.0.0-dev.6 → 4.0.0-dev.60
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 +22 -7
- package/lib/cjs/ElectronBackend.d.ts +1 -1
- package/lib/cjs/ElectronBackend.js +21 -17
- package/lib/cjs/ElectronBackend.js.map +1 -1
- package/lib/cjs/ElectronFrontend.d.ts +1 -1
- package/lib/cjs/ElectronFrontend.js +21 -17
- package/lib/cjs/ElectronFrontend.js.map +1 -1
- package/lib/cjs/__DOC_ONLY__.d.ts +3 -3
- package/lib/cjs/__DOC_ONLY__.js +26 -22
- package/lib/cjs/__DOC_ONLY__.js.map +1 -1
- package/lib/cjs/backend/ElectronHost.d.ts +104 -104
- package/lib/cjs/backend/ElectronHost.d.ts.map +1 -1
- package/lib/cjs/backend/ElectronHost.js +240 -243
- package/lib/cjs/backend/ElectronHost.js.map +1 -1
- package/lib/cjs/backend/ElectronPreload.d.ts +1 -1
- package/lib/cjs/backend/ElectronPreload.js +39 -39
- package/lib/cjs/common/ElectronIpcInterface.d.ts +7 -7
- package/lib/cjs/common/ElectronIpcInterface.d.ts.map +1 -1
- package/lib/cjs/common/ElectronIpcInterface.js +5 -5
- package/lib/cjs/common/ElectronIpcTransport.d.ts +44 -44
- package/lib/cjs/common/ElectronIpcTransport.js +186 -186
- package/lib/cjs/common/ElectronIpcTransport.js.map +1 -1
- package/lib/cjs/common/ElectronManagerLoggerCategory.d.ts +10 -10
- package/lib/cjs/common/ElectronManagerLoggerCategory.js +18 -18
- package/lib/cjs/common/ElectronPush.d.ts +20 -20
- package/lib/cjs/common/ElectronPush.js +48 -48
- package/lib/cjs/common/ElectronPush.js.map +1 -1
- package/lib/cjs/common/ElectronRpcManager.d.ts +26 -26
- package/lib/cjs/common/ElectronRpcManager.js +65 -65
- package/lib/cjs/common/ElectronRpcManager.js.map +1 -1
- package/lib/cjs/common/ElectronRpcProtocol.d.ts +34 -34
- package/lib/cjs/common/ElectronRpcProtocol.js +58 -58
- package/lib/cjs/common/ElectronRpcProtocol.js.map +1 -1
- package/lib/cjs/common/ElectronRpcRequest.d.ts +19 -19
- package/lib/cjs/common/ElectronRpcRequest.js +56 -56
- package/lib/cjs/common/ITwinElectronApi.d.ts +10 -10
- package/lib/cjs/common/ITwinElectronApi.d.ts.map +1 -1
- package/lib/cjs/common/ITwinElectronApi.js +6 -6
- package/lib/cjs/frontend/ElectronApp.d.ts +35 -35
- package/lib/cjs/frontend/ElectronApp.d.ts.map +1 -1
- package/lib/cjs/frontend/ElectronApp.js +73 -75
- package/lib/cjs/frontend/ElectronApp.js.map +1 -1
- package/package.json +23 -24
|
@@ -1,244 +1,241 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.ElectronHost = void 0;
|
|
8
|
-
const fs = require("fs");
|
|
9
|
-
const path = require("path");
|
|
10
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
11
|
-
const core_backend_1 = require("@itwin/core-backend");
|
|
12
|
-
const core_common_1 = require("@itwin/core-common");
|
|
13
|
-
const ElectronRpcManager_1 = require("../common/ElectronRpcManager");
|
|
14
|
-
const ElectronIpcInterface_1 = require("../common/ElectronIpcInterface");
|
|
15
|
-
// cSpell:ignore signin devserver webcontents copyfile unmaximize eopt
|
|
16
|
-
class ElectronIpc {
|
|
17
|
-
addListener(channel, listener) {
|
|
18
|
-
ElectronHost.ipcMain.addListener(channel, listener);
|
|
19
|
-
return () => ElectronHost.ipcMain.removeListener(channel, listener);
|
|
20
|
-
}
|
|
21
|
-
removeListener(channel, listener) {
|
|
22
|
-
ElectronHost.ipcMain.removeListener(channel, listener);
|
|
23
|
-
}
|
|
24
|
-
send(channel, ...args) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
ElectronHost.ipcMain.
|
|
31
|
-
ElectronHost.ipcMain.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
static get
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this._mainWindow
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
mainWindow.
|
|
107
|
-
mainWindow.on("
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
mainWindow.on("
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
this.
|
|
205
|
-
|
|
206
|
-
this.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
exports.ElectronHost = ElectronHost;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}, ms);
|
|
242
|
-
};
|
|
243
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ElectronHost = void 0;
|
|
8
|
+
const fs = require("fs");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
11
|
+
const core_backend_1 = require("@itwin/core-backend");
|
|
12
|
+
const core_common_1 = require("@itwin/core-common");
|
|
13
|
+
const ElectronRpcManager_1 = require("../common/ElectronRpcManager");
|
|
14
|
+
const ElectronIpcInterface_1 = require("../common/ElectronIpcInterface");
|
|
15
|
+
// cSpell:ignore signin devserver webcontents copyfile unmaximize eopt
|
|
16
|
+
class ElectronIpc {
|
|
17
|
+
addListener(channel, listener) {
|
|
18
|
+
ElectronHost.ipcMain.addListener(channel, listener);
|
|
19
|
+
return () => ElectronHost.ipcMain.removeListener(channel, listener);
|
|
20
|
+
}
|
|
21
|
+
removeListener(channel, listener) {
|
|
22
|
+
ElectronHost.ipcMain.removeListener(channel, listener);
|
|
23
|
+
}
|
|
24
|
+
send(channel, ...args) {
|
|
25
|
+
const window = ElectronHost.mainWindow ?? ElectronHost.electron.BrowserWindow.getAllWindows()[0];
|
|
26
|
+
window?.webContents.send(channel, ...args);
|
|
27
|
+
}
|
|
28
|
+
handle(channel, listener) {
|
|
29
|
+
ElectronHost.ipcMain.removeHandler(channel); // make sure there's not already a handler registered
|
|
30
|
+
ElectronHost.ipcMain.handle(channel, listener);
|
|
31
|
+
return () => ElectronHost.ipcMain.removeHandler(channel);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The backend for Electron-based desktop applications
|
|
36
|
+
* @beta
|
|
37
|
+
*/
|
|
38
|
+
class ElectronHost {
|
|
39
|
+
static get ipcMain() { return this._electron?.ipcMain; }
|
|
40
|
+
static get app() { return this._electron?.app; }
|
|
41
|
+
static get electron() { return this._electron; }
|
|
42
|
+
constructor() { }
|
|
43
|
+
/**
|
|
44
|
+
* Converts an "electron://frontend/" URL to an absolute file path.
|
|
45
|
+
*
|
|
46
|
+
* We use this protocol in production builds because our frontend must be built with absolute URLs,
|
|
47
|
+
* however, since we're loading everything directly from the install directory, we cannot know the
|
|
48
|
+
* absolute path at build time.
|
|
49
|
+
*/
|
|
50
|
+
static parseElectronUrl(requestedUrl) {
|
|
51
|
+
// Note that the "frontend/" path is arbitrary - this is just so we can handle *some* relative URLs...
|
|
52
|
+
let assetPath = requestedUrl.substring(this._electronFrontend.length);
|
|
53
|
+
if (assetPath.length === 0)
|
|
54
|
+
assetPath = "index.html";
|
|
55
|
+
assetPath = path.normalize(`${this.webResourcesPath}/${assetPath}`);
|
|
56
|
+
// File protocols don't follow symlinks, so we need to resolve this to a real path.
|
|
57
|
+
// 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
|
|
58
|
+
try {
|
|
59
|
+
assetPath = fs.realpathSync(assetPath);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// eslint-disable-next-line no-console
|
|
63
|
+
// console.warn(`WARNING: Frontend requested "${requestedUrl}", but ${assetPath} does not exist`);
|
|
64
|
+
}
|
|
65
|
+
if (!assetPath.startsWith(this.webResourcesPath))
|
|
66
|
+
throw new Error(`Access to files outside installation directory (${this.webResourcesPath}) is prohibited`);
|
|
67
|
+
return assetPath;
|
|
68
|
+
}
|
|
69
|
+
static _openWindow(options) {
|
|
70
|
+
const webPreferences = {
|
|
71
|
+
...options?.webPreferences,
|
|
72
|
+
// These web preference variables should not be overriden by the ElectronHostWindowOptions
|
|
73
|
+
preload: require.resolve(/* webpack: copyfile */ "./ElectronPreload.js"),
|
|
74
|
+
experimentalFeatures: false,
|
|
75
|
+
nodeIntegration: false,
|
|
76
|
+
contextIsolation: true,
|
|
77
|
+
sandbox: true,
|
|
78
|
+
nodeIntegrationInWorker: false,
|
|
79
|
+
nodeIntegrationInSubFrames: false,
|
|
80
|
+
};
|
|
81
|
+
const opts = {
|
|
82
|
+
...options,
|
|
83
|
+
autoHideMenuBar: true,
|
|
84
|
+
icon: this.appIconPath,
|
|
85
|
+
webPreferences,
|
|
86
|
+
};
|
|
87
|
+
this._mainWindow = new (this.electron.BrowserWindow)(opts);
|
|
88
|
+
ElectronRpcManager_1.ElectronRpcConfiguration.targetWindowId = this._mainWindow.id;
|
|
89
|
+
this._mainWindow.on("closed", () => this._mainWindow = undefined);
|
|
90
|
+
this._mainWindow.loadURL(this.frontendURL); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
91
|
+
/** Monitors and saves main window size, position and maximized state */
|
|
92
|
+
if (options?.storeWindowName) {
|
|
93
|
+
const mainWindow = this._mainWindow;
|
|
94
|
+
const name = options.storeWindowName;
|
|
95
|
+
const saveWindowPosition = (key) => {
|
|
96
|
+
const bounds = mainWindow.getBounds();
|
|
97
|
+
core_backend_1.NativeHost.settingsStore.setData(`${key}-${name}`, JSON.stringify(bounds));
|
|
98
|
+
};
|
|
99
|
+
const saveMaximized = (maximized) => {
|
|
100
|
+
if (!maximized)
|
|
101
|
+
saveWindowPosition(this._deprecatedSizeAndPosStoreKey);
|
|
102
|
+
core_backend_1.NativeHost.settingsStore.setData(`windowMaximized-${name}`, maximized);
|
|
103
|
+
};
|
|
104
|
+
mainWindow.on("maximize", () => saveMaximized(true));
|
|
105
|
+
mainWindow.on("unmaximize", () => saveMaximized(false));
|
|
106
|
+
saveMaximized(mainWindow.isMaximized());
|
|
107
|
+
mainWindow.on("resized", () => saveWindowPosition(this._deprecatedSizeAndPosStoreKey));
|
|
108
|
+
mainWindow.on("moved", () => saveWindowPosition(this._deprecatedSizeAndPosStoreKey));
|
|
109
|
+
const debouncedSaveWindowSizeAndPos = debounce(() => saveWindowPosition(this._sizeAndPosStoreKey));
|
|
110
|
+
mainWindow.on("resize", () => debouncedSaveWindowSizeAndPos());
|
|
111
|
+
mainWindow.on("move", () => debouncedSaveWindowSizeAndPos());
|
|
112
|
+
saveWindowPosition(this._sizeAndPosStoreKey);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** The "main" BrowserWindow for this application. */
|
|
116
|
+
static get mainWindow() { return this._mainWindow; }
|
|
117
|
+
/**
|
|
118
|
+
* Gets window size and position for a window, by name, from settings file, if present.
|
|
119
|
+
* @note Size and position values in the settings file will be updated differently depending on platform.
|
|
120
|
+
* On Linux values are only updated on window "unmaximize".
|
|
121
|
+
* On Windows and MacOS values are also updated on window manual resize or move.
|
|
122
|
+
* To get consistent behavior across different platforms, use [[ElectronHost.getWindowSizeAndPositionSetting]].
|
|
123
|
+
* @deprecated in 3.6. Use [[ElectronHost.getWindowSizeAndPositionSetting]].
|
|
124
|
+
*/
|
|
125
|
+
static getWindowSizeSetting(windowName) {
|
|
126
|
+
const saved = core_backend_1.NativeHost.settingsStore.getString(`${this._deprecatedSizeAndPosStoreKey}-${windowName}`);
|
|
127
|
+
return saved ? JSON.parse(saved) : undefined;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Gets window size and position for a window, by name, from settings file, if present.
|
|
131
|
+
*/
|
|
132
|
+
static getWindowSizeAndPositionSetting(windowName) {
|
|
133
|
+
const saved = core_backend_1.NativeHost.settingsStore.getString(`${this._sizeAndPosStoreKey}-${windowName}`);
|
|
134
|
+
return saved ? JSON.parse(saved) : undefined;
|
|
135
|
+
}
|
|
136
|
+
/** Gets "window maximized" flag for a window, by name, from settings file if present */
|
|
137
|
+
static getWindowMaximizedSetting(windowName) {
|
|
138
|
+
return core_backend_1.NativeHost.settingsStore.getBoolean(`windowMaximized-${windowName}`);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Open the main Window when the app is ready.
|
|
142
|
+
* @param windowOptions Options for constructing the main BrowserWindow. See: https://electronjs.org/docs/api/browser-window#new-browserwindowoptions
|
|
143
|
+
*/
|
|
144
|
+
static async openMainWindow(windowOptions) {
|
|
145
|
+
const app = this.app;
|
|
146
|
+
// quit the application when all windows are closed (unless we're running on MacOS)
|
|
147
|
+
app.on("window-all-closed", () => {
|
|
148
|
+
if (process.platform !== "darwin")
|
|
149
|
+
app.quit();
|
|
150
|
+
});
|
|
151
|
+
// re-open the main window if it was closed and the app is re-activated (this is the normal MacOS behavior)
|
|
152
|
+
app.on("activate", () => {
|
|
153
|
+
if (!this._mainWindow)
|
|
154
|
+
this._openWindow(windowOptions);
|
|
155
|
+
});
|
|
156
|
+
if (this._developmentServer) {
|
|
157
|
+
// Occasionally, the electron backend may start before the webpack devserver has even started.
|
|
158
|
+
// If this happens, we'll just retry and keep reloading the page.
|
|
159
|
+
app.on("web-contents-created", (_e, webcontents) => {
|
|
160
|
+
webcontents.on("did-fail-load", async (_event, errorCode, _errorDescription, _validatedURL, isMainFrame) => {
|
|
161
|
+
// errorCode -102 is CONNECTION_REFUSED - see https://cs.chromium.org/chromium/src/net/base/net_error_list.h
|
|
162
|
+
if (isMainFrame && errorCode === -102) {
|
|
163
|
+
await core_bentley_1.BeDuration.wait(100);
|
|
164
|
+
webcontents.reload();
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
await app.whenReady();
|
|
170
|
+
if (!this._developmentServer) {
|
|
171
|
+
// handle any "electron://" requests and redirect them to "file://" URLs
|
|
172
|
+
this.electron.protocol.registerFileProtocol("electron", (request, callback) => callback(this.parseElectronUrl(request.url))); // eslint-disable-line @typescript-eslint/no-var-requires
|
|
173
|
+
}
|
|
174
|
+
this._openWindow(windowOptions);
|
|
175
|
+
}
|
|
176
|
+
static get isValid() { return this._ipc !== undefined; }
|
|
177
|
+
/**
|
|
178
|
+
* Initialize the backend of an Electron app.
|
|
179
|
+
* This method configures the backend for all of the inter-process communication (RPC and IPC) for an
|
|
180
|
+
* Electron app. It should be called from your Electron main function.
|
|
181
|
+
* @param opts Options that control aspects of your backend.
|
|
182
|
+
* @note This method must only be called from the backend of an Electron app (i.e. when [ProcessDetector.isElectronAppBackend]($bentley) is `true`).
|
|
183
|
+
*/
|
|
184
|
+
static async startup(opts) {
|
|
185
|
+
if (!core_bentley_1.ProcessDetector.isElectronAppBackend)
|
|
186
|
+
throw new Error("Not running under Electron");
|
|
187
|
+
if (!this.isValid) {
|
|
188
|
+
this._electron = require("electron");
|
|
189
|
+
this._ipc = new ElectronIpc();
|
|
190
|
+
const app = this.app;
|
|
191
|
+
if (!app.isReady())
|
|
192
|
+
this.electron.protocol.registerSchemesAsPrivileged([{
|
|
193
|
+
scheme: "electron",
|
|
194
|
+
privileges: {
|
|
195
|
+
standard: true,
|
|
196
|
+
secure: true,
|
|
197
|
+
supportFetchAPI: true,
|
|
198
|
+
},
|
|
199
|
+
}]);
|
|
200
|
+
const eopt = opts?.electronHost;
|
|
201
|
+
this._developmentServer = eopt?.developmentServer ?? false;
|
|
202
|
+
const frontendPort = eopt?.frontendPort ?? 3000;
|
|
203
|
+
this.webResourcesPath = eopt?.webResourcesPath ?? "";
|
|
204
|
+
this.frontendURL = eopt?.frontendURL ?? (this._developmentServer ? `http://localhost:${frontendPort}` : `${this._electronFrontend}index.html`);
|
|
205
|
+
this.appIconPath = path.join(this.webResourcesPath, eopt?.iconName ?? "appicon.ico");
|
|
206
|
+
this.rpcConfig = ElectronRpcManager_1.ElectronRpcManager.initializeBackend(this._ipc, eopt?.rpcInterfaces);
|
|
207
|
+
}
|
|
208
|
+
opts = opts ?? {};
|
|
209
|
+
opts.ipcHost = opts.ipcHost ?? {};
|
|
210
|
+
opts.ipcHost.socket = this._ipc;
|
|
211
|
+
await core_backend_1.NativeHost.startup(opts);
|
|
212
|
+
if (core_backend_1.IpcHost.isValid) {
|
|
213
|
+
ElectronDialogHandler.register();
|
|
214
|
+
opts.electronHost?.ipcHandlers?.forEach((ipc) => ipc.register());
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
ElectronHost._deprecatedSizeAndPosStoreKey = "windowPos";
|
|
219
|
+
ElectronHost._sizeAndPosStoreKey = "windowSizeAndPos";
|
|
220
|
+
ElectronHost._electronFrontend = "electron://frontend/";
|
|
221
|
+
exports.ElectronHost = ElectronHost;
|
|
222
|
+
class ElectronDialogHandler extends core_backend_1.IpcHandler {
|
|
223
|
+
get channelName() { return ElectronIpcInterface_1.dialogChannel; }
|
|
224
|
+
async callDialog(method, ...args) {
|
|
225
|
+
const dialog = ElectronHost.electron.dialog;
|
|
226
|
+
const dialogMethod = dialog[method];
|
|
227
|
+
if (typeof dialogMethod !== "function")
|
|
228
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.FunctionNotFound, `illegal electron dialog method`);
|
|
229
|
+
return dialogMethod.call(dialog, ...args);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function debounce(func, ms = 200) {
|
|
233
|
+
let timeout;
|
|
234
|
+
return function (...args) {
|
|
235
|
+
clearTimeout(timeout);
|
|
236
|
+
timeout = setTimeout(() => {
|
|
237
|
+
func.apply(this, args);
|
|
238
|
+
}, ms);
|
|
239
|
+
};
|
|
240
|
+
}
|
|
244
241
|
//# sourceMappingURL=ElectronHost.js.map
|