@itwin/core-electron 5.13.0-dev.9 → 5.13.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 +45 -1
- package/lib/cjs/backend/ElectronHost.d.ts.map +1 -1
- package/lib/cjs/backend/ElectronHost.js +8 -5
- package/lib/cjs/backend/ElectronHost.js.map +1 -1
- package/lib/cjs/common/ElectronIpcTransport.d.ts.map +1 -1
- package/lib/cjs/common/ElectronIpcTransport.js +3 -0
- package/lib/cjs/common/ElectronIpcTransport.js.map +1 -1
- package/package.json +11 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
# Change Log - @itwin/core-electron
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 08 Sep 2026 18:43:29 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 5.13.1
|
|
6
|
+
Tue, 08 Sep 2026 18:43:29 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 5.13.0
|
|
11
|
+
Thu, 03 Sep 2026 18:49:56 GMT
|
|
12
|
+
|
|
13
|
+
### Updates
|
|
14
|
+
|
|
15
|
+
- Removed unused 'open' dependency
|
|
16
|
+
- Remove unused '@openid/appauth' and 'username' dependencies
|
|
17
|
+
- Improve Electron window state persistence and RPC shutdown reliability.
|
|
18
|
+
|
|
19
|
+
## 5.12.5
|
|
20
|
+
Tue, 25 Aug 2026 21:22:08 GMT
|
|
21
|
+
|
|
22
|
+
_Version update only_
|
|
23
|
+
|
|
24
|
+
## 5.12.4
|
|
25
|
+
Tue, 18 Aug 2026 15:45:35 GMT
|
|
26
|
+
|
|
27
|
+
_Version update only_
|
|
28
|
+
|
|
29
|
+
## 5.12.3
|
|
30
|
+
Mon, 17 Aug 2026 11:29:39 GMT
|
|
31
|
+
|
|
32
|
+
_Version update only_
|
|
33
|
+
|
|
34
|
+
## 5.12.2
|
|
35
|
+
Mon, 10 Aug 2026 20:38:45 GMT
|
|
36
|
+
|
|
37
|
+
_Version update only_
|
|
38
|
+
|
|
39
|
+
## 5.12.1
|
|
40
|
+
Mon, 10 Aug 2026 19:07:26 GMT
|
|
41
|
+
|
|
42
|
+
_Version update only_
|
|
4
43
|
|
|
5
44
|
## 5.12.0
|
|
6
45
|
Mon, 03 Aug 2026 12:25:49 GMT
|
|
@@ -9,6 +48,11 @@ Mon, 03 Aug 2026 12:25:49 GMT
|
|
|
9
48
|
|
|
10
49
|
- Add support for Electron 43
|
|
11
50
|
|
|
51
|
+
## 5.11.4
|
|
52
|
+
Tue, 25 Aug 2026 19:54:22 GMT
|
|
53
|
+
|
|
54
|
+
_Version update only_
|
|
55
|
+
|
|
12
56
|
## 5.11.3
|
|
13
57
|
Wed, 15 Jul 2026 19:40:44 GMT
|
|
14
58
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronHost.d.ts","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings":"AAKA;;GAEG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA+B,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/F,OAAO,KAAK,KAAK,cAAc,MAAM,UAAU,CAAC;AAKhD,OAAO,EAAE,UAAU,EAAuB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACtF,OAAO,EAA8D,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AA4B1I;;;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,M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yB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsC5F,WAAkB,OAAO,YAAsC;IAE/D;;;;;;OAMG;WACiB,OAAO,CAAC,IAAI,CAAC,EAAE,gBAAgB;CAmCpD"}
|
|
@@ -107,13 +107,16 @@ class ElectronHost {
|
|
|
107
107
|
const saveMaximized = (maximized) => {
|
|
108
108
|
core_backend_1.NativeHost.settingsStore.setData(`windowMaximized-${windowName}`, maximized);
|
|
109
109
|
};
|
|
110
|
+
const saveWindowState = () => {
|
|
111
|
+
saveWindowPosition();
|
|
112
|
+
saveMaximized(mainWindow.isMaximized());
|
|
113
|
+
};
|
|
110
114
|
mainWindow.on("maximize", () => saveMaximized(true));
|
|
111
115
|
mainWindow.on("unmaximize", () => saveMaximized(false));
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
mainWindow.on("
|
|
115
|
-
|
|
116
|
-
saveWindowPosition();
|
|
116
|
+
const debouncedSaveWindowState = debounce(() => saveWindowState());
|
|
117
|
+
mainWindow.on("resize", () => debouncedSaveWindowState());
|
|
118
|
+
mainWindow.on("move", () => debouncedSaveWindowState());
|
|
119
|
+
saveWindowState();
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
/** The "main" BrowserWindow for this application. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronHost.js","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAU/F,yBAAyB;AACzB,6BAA6B;AAC7B,sDAAgG;AAChG,sDAAsF;AACtF,oDAA0I;AAC1I,qEAA4F;AAC5F,yEAAoE;AAEpE,sEAAsE;AAEtE,MAAM,WAAW;IACR,WAAW,CAChB,OAAe,EACf,QAA4C;QAE5C,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,CA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AI,CAAC,IAAI,CAAC;QAChC,MAAM,yBAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,sBAAO,CAAC,OAAO,EAAE,CAAC;YACpB,qBAAqB,CAAC,QAAQ,EAAE,CAAC;YACjC,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;;AA/LH,oCAgMC;AAED,MAAM,qBAAsB,SAAQ,yBAAU;IAC5C,IAAW,WAAW,KAAK,OAAO,yCAAkB,CAAC,aAAa,CAAC,CAAC,CAAC;IAC9D,KAAK,CAAC,UAAU,CAAC,MAAuC,EAAE,GAAG,IAAS;QAC3E,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,IAAI,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,UAAU;YACtC,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,gBAAgB,EAAE,gCAAgC,CAAC,CAAC;QAEzF,OAAQ,MAAM,CAAC,MAAM,CAA6B,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC3E,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,IAA6B,EAAE,KAAa,GAAG;IAC/D,IAAI,OAAuB,CAAC;IAC5B,OAAO,UAAqB,GAAG,IAAW;QACxC,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC,CAAC;AACJ,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 Main\r\n */\r\n\r\n// Note: only import *types* from electron so this file can be imported by apps that sometimes use Electron and sometimes not.\r\nimport type { BrowserWindow, BrowserWindowConstructorOptions, WebPreferences } from \"electron\";\r\nimport type * as ElectronModule from \"electron\";\r\n\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport { AsyncMethodsOf, 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\nimport { electronIpcStrings } from \"../common/ElectronIpcInterface\";\r\n\r\n// cSpell:ignore signin devserver webcontents copyfile unmaximize eopt\r\n\r\nclass ElectronIpc implements IpcSocketBackend {\r\n public addListener(\r\n channel: string,\r\n listener: (evt: any, ...args: any[]) => void, // There is mismatch between IPC Event and Electron.IpcMainEvent. Defining `evt` as any as a temporary fix\r\n ): 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]($backend) 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 /** Name used to construct key for saving window size, position and maximize status to the settings store */\r\n storeWindowName?: string;\r\n /** The style of window title bar. Default is `default`. */\r\n titleBarStyle?: (\"default\" | \"hidden\" | \"hiddenInset\" | \"customButtonsOnHover\");\r\n /** Web page settings */\r\n webPreferences?: Omit<WebPreferences, \"preload\" | \"experimentalFeatures\" | \"nodeIntegration\" | \"contextIsolation\" | \"sandbox\" | \"nodeIntegrationInWorker\" | \"nodeIntegrationInSubFrames\">;\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 ElectronModule;\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 \"file://{absolute file path}\" URL.\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 transformElectronUrlToFileUrl(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.substring(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 {\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 `file://${assetPath}`;\r\n }\r\n\r\n private static _openWindow(options?: ElectronHostWindowOptions) {\r\n const webPreferences: 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 nodeIntegrationInWorker: false,\r\n nodeIntegrationInSubFrames: false,\r\n };\r\n\r\n const opts: BrowserWindowConstructorOptions = {\r\n ...options,\r\n autoHideMenuBar: true,\r\n icon: this.appIconPath,\r\n webPreferences,\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 windowName = options.storeWindowName;\r\n const saveWindowPosition = () => {\r\n const bounds: WindowSizeAndPositionProps = mainWindow.getBounds();\r\n NativeHost.settingsStore.setData(`windowSizeAndPos-${windowName}`, JSON.stringify(bounds));\r\n };\r\n const saveMaximized = (maximized: boolean) => {\r\n NativeHost.settingsStore.setData(`windowMaximized-${windowName}`, maximized);\r\n };\r\n\r\n mainWindow.on(\"maximize\", () => saveMaximized(true));\r\n mainWindow.on(\"unmaximize\", () => saveMaximized(false));\r\n saveMaximized(mainWindow.isMaximized());\r\n\r\n const debouncedSaveWindowSizeAndPos = debounce(() => saveWindowPosition());\r\n mainWindow.on(\"resize\", () => debouncedSaveWindowSizeAndPos());\r\n mainWindow.on(\"move\", () => debouncedSaveWindowSizeAndPos());\r\n saveWindowPosition();\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 /**\r\n * Gets window size and position for a window, by name, from settings file, if present.\r\n */\r\n public static getWindowSizeAndPositionSetting(windowName: string): WindowSizeAndPositionProps | undefined {\r\n const saved = NativeHost.settingsStore.getString(`windowSizeAndPos-${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.handle(\"electron\", async (request) => ElectronHost.electron.net.fetch(this.transformElectronUrlToFileUrl(request.url)));\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\"); // eslint-disable-line @typescript-eslint/no-require-imports\r\n this._ipc = new ElectronIpc();\r\n const app = this.app;\r\n if (!app.isReady())\r\n this.electron.protocol.registerSchemesAsPrivileged([{\r\n scheme: \"electron\",\r\n privileges: {\r\n standard: true,\r\n secure: true,\r\n supportFetchAPI: true,\r\n },\r\n }]);\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 ElectronDialogHandler.register();\r\n opts.electronHost?.ipcHandlers?.forEach((ipc) => ipc.register());\r\n }\r\n }\r\n}\r\n\r\nclass ElectronDialogHandler extends IpcHandler {\r\n public get channelName() { return electronIpcStrings.dialogChannel; }\r\n public async callDialog(method: AsyncMethodsOf<Electron.Dialog>, ...args: any) {\r\n const dialog = ElectronHost.electron.dialog;\r\n if (typeof dialog[method] !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `illegal electron dialog method`);\r\n\r\n return (dialog[method] as (...args: any[]) => any).call(dialog, ...args);\r\n }\r\n}\r\n\r\nfunction debounce(func: (...args: any[]) => any, ms: number = 200) {\r\n let timeout: NodeJS.Timeout;\r\n return function (this: any, ...args: any[]) {\r\n clearTimeout(timeout);\r\n timeout = setTimeout(() => {\r\n func.apply(this, args);\r\n }, ms);\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ElectronHost.js","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAU/F,yBAAyB;AACzB,6BAA6B;AA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AAI,OAAuB,CAAC;IAC5B,OAAO,UAAqB,GAAG,IAAW;QACxC,YAAY,CAAC,OAAO,CAAC,CAAC;QACtB,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC,CAAC;AACJ,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 Main\r\n */\r\n\r\n// Note: only import *types* from electron so this file can be imported by apps that sometimes use Electron and sometimes not.\r\nimport type { BrowserWindow, BrowserWindowConstructorOptions, WebPreferences } from \"electron\";\r\nimport type * as ElectronModule from \"electron\";\r\n\r\nimport * as fs from \"fs\";\r\nimport * as path from \"path\";\r\nimport { AsyncMethodsOf, 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\nimport { electronIpcStrings } from \"../common/ElectronIpcInterface\";\r\n\r\n// cSpell:ignore signin devserver webcontents copyfile unmaximize eopt\r\n\r\nclass ElectronIpc implements IpcSocketBackend {\r\n public addListener(\r\n channel: string,\r\n listener: (evt: any, ...args: any[]) => void, // There is mismatch between IPC Event and Electron.IpcMainEvent. Defining `evt` as any as a temporary fix\r\n ): 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]($backend) 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 /** Name used to construct key for saving window size, position and maximize status to the settings store */\r\n storeWindowName?: string;\r\n /** The style of window title bar. Default is `default`. */\r\n titleBarStyle?: (\"default\" | \"hidden\" | \"hiddenInset\" | \"customButtonsOnHover\");\r\n /** Web page settings */\r\n webPreferences?: Omit<WebPreferences, \"preload\" | \"experimentalFeatures\" | \"nodeIntegration\" | \"contextIsolation\" | \"sandbox\" | \"nodeIntegrationInWorker\" | \"nodeIntegrationInSubFrames\">;\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 ElectronModule;\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 \"file://{absolute file path}\" URL.\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 transformElectronUrlToFileUrl(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.substring(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 {\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 `file://${assetPath}`;\r\n }\r\n\r\n private static _openWindow(options?: ElectronHostWindowOptions) {\r\n const webPreferences: 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 nodeIntegrationInWorker: false,\r\n nodeIntegrationInSubFrames: false,\r\n };\r\n\r\n const opts: BrowserWindowConstructorOptions = {\r\n ...options,\r\n autoHideMenuBar: true,\r\n icon: this.appIconPath,\r\n webPreferences,\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 windowName = options.storeWindowName;\r\n const saveWindowPosition = () => {\r\n const bounds: WindowSizeAndPositionProps = mainWindow.getBounds();\r\n NativeHost.settingsStore.setData(`windowSizeAndPos-${windowName}`, JSON.stringify(bounds));\r\n };\r\n const saveMaximized = (maximized: boolean) => {\r\n NativeHost.settingsStore.setData(`windowMaximized-${windowName}`, maximized);\r\n };\r\n const saveWindowState = () => {\r\n saveWindowPosition();\r\n saveMaximized(mainWindow.isMaximized());\r\n };\r\n\r\n mainWindow.on(\"maximize\", () => saveMaximized(true));\r\n mainWindow.on(\"unmaximize\", () => saveMaximized(false));\r\n\r\n const debouncedSaveWindowState = debounce(() => saveWindowState());\r\n mainWindow.on(\"resize\", () => debouncedSaveWindowState());\r\n mainWindow.on(\"move\", () => debouncedSaveWindowState());\r\n saveWindowState();\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 /**\r\n * Gets window size and position for a window, by name, from settings file, if present.\r\n */\r\n public static getWindowSizeAndPositionSetting(windowName: string): WindowSizeAndPositionProps | undefined {\r\n const saved = NativeHost.settingsStore.getString(`windowSizeAndPos-${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.handle(\"electron\", async (request) => ElectronHost.electron.net.fetch(this.transformElectronUrlToFileUrl(request.url)));\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\"); // eslint-disable-line @typescript-eslint/no-require-imports\r\n this._ipc = new ElectronIpc();\r\n const app = this.app;\r\n if (!app.isReady())\r\n this.electron.protocol.registerSchemesAsPrivileged([{\r\n scheme: \"electron\",\r\n privileges: {\r\n standard: true,\r\n secure: true,\r\n supportFetchAPI: true,\r\n },\r\n }]);\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 ElectronDialogHandler.register();\r\n opts.electronHost?.ipcHandlers?.forEach((ipc) => ipc.register());\r\n }\r\n }\r\n}\r\n\r\nclass ElectronDialogHandler extends IpcHandler {\r\n public get channelName() { return electronIpcStrings.dialogChannel; }\r\n public async callDialog(method: AsyncMethodsOf<Electron.Dialog>, ...args: any) {\r\n const dialog = ElectronHost.electron.dialog;\r\n if (typeof dialog[method] !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `illegal electron dialog method`);\r\n\r\n return (dialog[method] as (...args: any[]) => any).call(dialog, ...args);\r\n }\r\n}\r\n\r\nfunction debounce(func: (...args: any[]) => any, ms: number = 200) {\r\n let timeout: NodeJS.Timeout;\r\n return function (this: any, ...args: any[]) {\r\n clearTimeout(timeout);\r\n timeout = setTimeout(() => {\r\n func.apply(this, args);\r\n }, ms);\r\n };\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronIpcTransport.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronIpcTransport.ts"],"names":[],"mappings":"AAMA,OAAO,EACyD,qBAAqB,EAAE,kBAAkB,EAAE,oBAAoB,EAC9H,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"ElectronIpcTransport.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronIpcTransport.ts"],"names":[],"mappings":"AAMA,OAAO,EACyD,qBAAqB,EAAE,kBAAkB,EAAE,oBAAoB,EAC9H,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAO5D,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAAG,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAAC,MAAM,CAAC,EAAE,kBAAkB,CAAA;CAAE;AAEjH,gBAAgB;AAChB,8BAAsB,oBAAoB,CAAC,GAAG,SAAS,mBAAmB,GAAG,mBAAmB,EAAE,IAAI,SAAS,mBAAmB,GAAG,mBAAmB;IACtJ,OAAO,CAAC,SAAS,CAAqE;IACtF,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,SAAS,CAAC,SAAS,EAAE,mBAAmB,CAAC;IAEzC,IAAW,QAAQ,wBAA6B;IAEzC,WAAW,CAAC,OAAO,EAAE,oBAAoB;gBAK7B,QAAQ,EAAE,mBAAmB;IAQhD,SAAS,CAAC,SAAS;IAEnB,OAAO,CAAC,iBAAiB;IAwBzB,OAAO,CAAC,oBAAoB;IAyB5B,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,KAAK;IAeb,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAI7D,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI;IAE7D,gBAAgB;IACT,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG;IAK3C,SAAS,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM;IAUzB,OAAO;CAGf;AAED,gBAAgB;AAChB,qBAAa,oBAAqB,SAAQ,oBAAoB,CAAC,qBAAqB,CAAC;IACnF,OAAO,CAAC,cAAc,CAAC,CAAwB;cAE5B,SAAS;cAMZ,cAAc,CAAC,EAAE,EAAE,MAAM;CAe1C;AAED,gBAAgB;AAChB,qBAAa,mBAAoB,SAAQ,oBAAoB,CAAC,oBAAoB,EAAE,qBAAqB,CAAC;IACxG,OAAO,CAAC,cAAc,CAAM;cAET,SAAS;cAKZ,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG;cAiBhC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;IAWtE,OAAO,CAAC,qBAAqB;CAW9B;AAID,gBAAgB;AAChB,wBAAgB,aAAa,CAAC,QAAQ,EAAE,mBAAmB,kEAU1D"}
|
|
@@ -129,6 +129,9 @@ class FrontendIpcTransport extends ElectronIpcTransport {
|
|
|
129
129
|
}
|
|
130
130
|
const protocol = this._protocol;
|
|
131
131
|
const request = protocol.requests.get(message.id);
|
|
132
|
+
// A response may arrive after shutdown has removed the request.
|
|
133
|
+
if (!request)
|
|
134
|
+
return;
|
|
132
135
|
request.notifyResponse(message);
|
|
133
136
|
}
|
|
134
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ElectronIpcTransport.js","sourceRoot":"","sources":["../../../src/common/ElectronIpcTransport.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AA6N/F,sCAUC;AArOD,sDAAmF;AACnF,oDAE4B;AAC5B,iDAA+E;AAC/E,6DAAgE;AAIhE,MAAM,eAAe,GAAG,IAAA,0BAAY,EAAC,aAAa,CAAC,CAAC;AACpD,MAAM,YAAY,GAAG,IAAA,0BAAY,EAAC,UAAU,CAAC,CAAC;AAO9C,gBAAgB;AAChB,MAAsB,oBAAoB;IAChC,SAAS,CAAqE;IAC9E,gBAAgB,GAAmB,EAAE,CAAC;IACpC,SAAS,CAAsB;IAEzC,IAAW,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAEzC,WAAW,CAAC,OAA6B;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,YAAmB,QAA6B;QAC9C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;IACnB,CAAC;IAES,SAAS,KAAK,CAAC;IAEjB,iBAAiB;QACvB,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,YAAY,EAAE,KAAK,EAAE,GAAQ,EAAE,KAAqB,EAAE,EAAE;YACjH,IAAI,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,C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ACT,CAAC;QAED,IAAI,CAAC,CAAC,8FAA8F;YAClG,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC,CAAC,4DAA4D;QACvH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,0BAA0B,EAAE,GAAG,EAAE,CAAC,2BAAY,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;QAChH,CAAC;IACH,CAAC;CACF;AA/CD,kDA+CC;AAED,IAAI,SAA2C,CAAC;AAEhD,gBAAgB;AAChB,SAAgB,aAAa,CAAC,QAA6B;IACzD,IAAI,SAAS,IAAI,SAAS,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjD,SAAS,CAAC,OAAO,EAAE,CAAC;QACpB,SAAS,GAAG,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,SAAS,KAAK,SAAS;QACzB,SAAS,GAAG,8BAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAE7H,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { BentleyError, BentleyStatus, ProcessDetector } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelError, iTwinChannel, RpcPushChannel, RpcPushConnection, RpcRequestFulfillment, RpcSerializedValue, SerializedRpcRequest,\r\n} from \"@itwin/core-common\";\r\nimport { ElectronPushConnection, ElectronPushTransport } from \"./ElectronPush\";\r\nimport { ElectronRpcConfiguration } from \"./ElectronRpcManager\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol\";\r\nimport { ElectronRpcRequest } from \"./ElectronRpcRequest\";\r\n\r\nconst OBJECTS_CHANNEL = iTwinChannel(\"rpc.objects\");\r\nconst DATA_CHANNEL = iTwinChannel(\"rpc.data\");\r\n\r\ninterface PartialPayload { id: string, index: number, data: Uint8Array }\r\n\r\n/** @internal */\r\nexport interface IpcTransportMessage { id: string, parameters?: RpcSerializedValue, result?: RpcSerializedValue }\r\n\r\n/** @internal */\r\nexport abstract class ElectronIpcTransport<TIn extends IpcTransportMessage = IpcTransportMessage, TOut extends IpcTransportMessage = IpcTransportMessage> {\r\n private _partials: Map<string, { message: TIn, received: number } | PartialPayload[]>;\r\n private _removeListeners: VoidFunction[] = [];\r\n protected _protocol: ElectronRpcProtocol;\r\n\r\n public get protocol() { return this._protocol; }\r\n\r\n public sendRequest(request: SerializedRpcRequest) {\r\n const value = this._extractValue(request);\r\n this._send(request, value);\r\n }\r\n\r\n public constructor(protocol: ElectronRpcProtocol) {\r\n this._protocol = protocol;\r\n this._partials = new Map();\r\n this._setupDataChannel();\r\n this._setupObjectsChannel();\r\n this.setupPush();\r\n }\r\n\r\n protected setupPush() { }\r\n\r\n private _setupDataChannel() {\r\n const removeListener = this.protocol.ipcSocket.addListener(DATA_CHANNEL, async (evt: any, chunk: PartialPayload) => {\r\n let pending = this._partials.get(chunk.id);\r\n if (!pending) {\r\n pending = [];\r\n this._partials.set(chunk.id, pending);\r\n }\r\n\r\n if (Array.isArray(pending)) {\r\n pending.push(chunk);\r\n } else {\r\n ++pending.received;\r\n\r\n const value = this._extractValue(pending.message);\r\n value.data[chunk.index] = chunk.data;\r\n\r\n if (pending.received === (value.chunks || 0)) {\r\n this.handleComplete(pending.message.id, evt);\r\n }\r\n }\r\n });\r\n this._removeListeners.push(removeListener);\r\n }\r\n\r\n private _setupObjectsChannel() {\r\n const removeListener = this.protocol.ipcSocket.addListener(OBJECTS_CHANNEL, async (evt: any, message: TIn) => {\r\n const pending = this._partials.get(message.id);\r\n if (pending && !Array.isArray(pending)) {\r\n throw new IModelError(BentleyStatus.ERROR, `Message already received for id \"${message.id}\".`);\r\n }\r\n\r\n const partial = { message, received: 0 };\r\n this._partials.set(message.id, partial);\r\n const value = this._extractValue(partial.message);\r\n\r\n if (pending && Array.isArray(pending)) {\r\n for (const chunk of pending) {\r\n ++partial.received;\r\n value.data[chunk.index] = chunk.data;\r\n }\r\n }\r\n\r\n if (partial.received === (value.chunks || 0)) {\r\n this.handleComplete(message.id, evt);\r\n }\r\n });\r\n this._removeListeners.push(removeListener);\r\n }\r\n\r\n private _extractValue(t: IpcTransportMessage): RpcSerializedValue {\r\n if (t.parameters) {\r\n return t.parameters;\r\n }\r\n\r\n if (t.result) {\r\n return t.result;\r\n }\r\n\r\n throw new IModelError(BentleyStatus.ERROR, \"Unknown value type.\");\r\n }\r\n\r\n private _send(message: IpcTransportMessage, value: RpcSerializedValue, evt?: any) {\r\n const chunks = value.data;\r\n if (chunks.length) {\r\n value.chunks = chunks.length;\r\n value.data = [];\r\n }\r\n\r\n this.performSend(OBJECTS_CHANNEL, message, evt);\r\n\r\n for (let index = 0; index !== chunks.length; ++index) {\r\n const chunk: PartialPayload = { id: message.id, index, data: chunks[index] };\r\n this.performSend(DATA_CHANNEL, chunk, evt);\r\n }\r\n }\r\n\r\n protected performSend(channel: string, message: any, evt: any) {\r\n (evt ? evt.sender : this.protocol.ipcSocket).send(channel, message);\r\n }\r\n\r\n protected abstract handleComplete(id: string, evt: any): void;\r\n\r\n /** @internal */\r\n public sendResponse(message: TOut, evt: any) {\r\n const value = this._extractValue(message);\r\n this._send(message, value, evt);\r\n }\r\n\r\n protected loadMessage(id: string) {\r\n const partial = this._partials.get(id);\r\n if (!partial || Array.isArray(partial)) {\r\n throw new IModelError(BentleyStatus.ERROR, `Incomplete transmission for id \"${id}\".`);\r\n }\r\n\r\n this._partials.delete(id);\r\n return partial.message;\r\n }\r\n\r\n public cleanup() {\r\n this._removeListeners.forEach((removeListener) => removeListener());\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class FrontendIpcTransport extends ElectronIpcTransport<RpcRequestFulfillment> {\r\n private _pushTransport?: ElectronPushTransport;\r\n\r\n protected override setupPush() {\r\n const pushTransport = new ElectronPushTransport(this);\r\n this._pushTransport = pushTransport;\r\n RpcPushChannel.setup(pushTransport);\r\n }\r\n\r\n protected async handleComplete(id: string) {\r\n const message = this.loadMessage(id);\r\n\r\n if (this._pushTransport && this._pushTransport.consume(message)) {\r\n return;\r\n }\r\n\r\n const protocol = this._protocol;\r\n const request = protocol.requests.get(message.id) as ElectronRpcRequest;\r\n request.notifyResponse(message);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class BackendIpcTransport extends ElectronIpcTransport<SerializedRpcRequest, RpcRequestFulfillment> {\r\n private _browserWindow: any;\r\n\r\n protected override setupPush() {\r\n RpcPushConnection.for = (channel, client) => new ElectronPushConnection(channel, client, this);\r\n RpcPushChannel.enabled = true;\r\n }\r\n\r\n protected async handleComplete(id: string, evt: any) {\r\n const message = this.loadMessage(id);\r\n\r\n let response: RpcRequestFulfillment;\r\n try {\r\n const protocol = this._protocol;\r\n response = await protocol.fulfill(message);\r\n } catch (err) {\r\n response = await RpcRequestFulfillment.forUnknownError(message, err);\r\n }\r\n\r\n const raw = response.rawResult;\r\n response.rawResult = undefined; // Otherwise, it will be serialized in IPC layer and large responses will then crash the app\r\n this.sendResponse(response, evt);\r\n response.rawResult = raw;\r\n }\r\n\r\n protected override performSend(channel: string, message: any, evt: any) {\r\n if (evt) {\r\n return super.performSend(channel, message, evt);\r\n }\r\n\r\n this._requireBrowserWindow();\r\n const target = ElectronRpcConfiguration.targetWindowId;\r\n const windows = target ? [this._browserWindow.fromId(target)] : this._browserWindow.getAllWindows();\r\n windows.forEach((window: any) => window.webContents.send(channel, message));\r\n }\r\n\r\n private _requireBrowserWindow() {\r\n if (this._browserWindow) {\r\n return;\r\n }\r\n\r\n try { // Wrapping require in a try/catch signals to webpack that this is only an optional dependency\r\n this._browserWindow = require(\"electron\").BrowserWindow; // eslint-disable-line @typescript-eslint/no-require-imports\r\n } catch (err) {\r\n throw new IModelError(BentleyStatus.ERROR, `Error requiring electron`, () => BentleyError.getErrorProps(err));\r\n }\r\n }\r\n}\r\n\r\nlet transport: ElectronIpcTransport | undefined;\r\n\r\n/** @internal */\r\nexport function initializeIpc(protocol: ElectronRpcProtocol) {\r\n if (transport && transport.protocol !== protocol) {\r\n transport.cleanup();\r\n transport = undefined;\r\n }\r\n\r\n if (undefined === transport)\r\n transport = ProcessDetector.isElectronAppFrontend ? new FrontendIpcTransport(protocol) : new BackendIpcTransport(protocol);\r\n\r\n return transport;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"ElectronIpcTransport.js","sourceRoot":"","sources":["../../../src/common/ElectronIpcTransport.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAgO/F,sCAUC;AAxOD,sDAAmF;AACnF,oDAE4B;AAC5B,iDAA+E;AAC/E,6DAAgE;AAGhE,MAAM,eAAe,GAAG,IAAA,0BAAY,EAAC,aAAa,CAAC,CAAC;AACpD,MAAM,YAAY,GAAG,IAAA,0BAAY,EAAC,UAAU,CAAC,CAAC;AAO9C,gBAAgB;AAChB,MAAsB,oBAAoB;IAChC,SAAS,CAAqE;IAC9E,gBAAgB,GAAmB,EAAE,CAAC;IACpC,SAAS,CAAsB;IAEzC,IAAW,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAEzC,WAAW,CAAC,OAA6B;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,YAAmB,QAA6B;QAC9C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,oBAA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GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAC;QACpG,OAAO,CAAC,OAAO,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9E,CAAC;IAEO,qBAAqB;QAC3B,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,CAAC,8FAA8F;YAClG,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,aAAa,CAAC,CAAC,4DAA4D;QACvH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,0BAA0B,EAAE,GAAG,EAAE,CAAC,2BAAY,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;QAChH,CAAC;IACH,CAAC;CACF;AA/CD,kDA+CC;AAED,IAAI,SAA2C,CAAC;AAEhD,gBAAgB;AAChB,SAAgB,aAAa,CAAC,QAA6B;IACzD,IAAI,SAAS,IAAI,SAAS,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACjD,SAAS,CAAC,OAAO,EAAE,CAAC;QACpB,SAAS,GAAG,SAAS,CAAC;IACxB,CAAC;IAED,IAAI,SAAS,KAAK,SAAS;QACzB,SAAS,GAAG,8BAAe,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAE7H,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { BentleyError, BentleyStatus, ProcessDetector } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelError, iTwinChannel, RpcPushChannel, RpcPushConnection, RpcRequestFulfillment, RpcSerializedValue, SerializedRpcRequest,\r\n} from \"@itwin/core-common\";\r\nimport { ElectronPushConnection, ElectronPushTransport } from \"./ElectronPush\";\r\nimport { ElectronRpcConfiguration } from \"./ElectronRpcManager\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol\";\r\n\r\nconst OBJECTS_CHANNEL = iTwinChannel(\"rpc.objects\");\r\nconst DATA_CHANNEL = iTwinChannel(\"rpc.data\");\r\n\r\ninterface PartialPayload { id: string, index: number, data: Uint8Array }\r\n\r\n/** @internal */\r\nexport interface IpcTransportMessage { id: string, parameters?: RpcSerializedValue, result?: RpcSerializedValue }\r\n\r\n/** @internal */\r\nexport abstract class ElectronIpcTransport<TIn extends IpcTransportMessage = IpcTransportMessage, TOut extends IpcTransportMessage = IpcTransportMessage> {\r\n private _partials: Map<string, { message: TIn, received: number } | PartialPayload[]>;\r\n private _removeListeners: VoidFunction[] = [];\r\n protected _protocol: ElectronRpcProtocol;\r\n\r\n public get protocol() { return this._protocol; }\r\n\r\n public sendRequest(request: SerializedRpcRequest) {\r\n const value = this._extractValue(request);\r\n this._send(request, value);\r\n }\r\n\r\n public constructor(protocol: ElectronRpcProtocol) {\r\n this._protocol = protocol;\r\n this._partials = new Map();\r\n this._setupDataChannel();\r\n this._setupObjectsChannel();\r\n this.setupPush();\r\n }\r\n\r\n protected setupPush() { }\r\n\r\n private _setupDataChannel() {\r\n const removeListener = this.protocol.ipcSocket.addListener(DATA_CHANNEL, async (evt: any, chunk: PartialPayload) => {\r\n let pending = this._partials.get(chunk.id);\r\n if (!pending) {\r\n pending = [];\r\n this._partials.set(chunk.id, pending);\r\n }\r\n\r\n if (Array.isArray(pending)) {\r\n pending.push(chunk);\r\n } else {\r\n ++pending.received;\r\n\r\n const value = this._extractValue(pending.message);\r\n value.data[chunk.index] = chunk.data;\r\n\r\n if (pending.received === (value.chunks || 0)) {\r\n this.handleComplete(pending.message.id, evt);\r\n }\r\n }\r\n });\r\n this._removeListeners.push(removeListener);\r\n }\r\n\r\n private _setupObjectsChannel() {\r\n const removeListener = this.protocol.ipcSocket.addListener(OBJECTS_CHANNEL, async (evt: any, message: TIn) => {\r\n const pending = this._partials.get(message.id);\r\n if (pending && !Array.isArray(pending)) {\r\n throw new IModelError(BentleyStatus.ERROR, `Message already received for id \"${message.id}\".`);\r\n }\r\n\r\n const partial = { message, received: 0 };\r\n this._partials.set(message.id, partial);\r\n const value = this._extractValue(partial.message);\r\n\r\n if (pending && Array.isArray(pending)) {\r\n for (const chunk of pending) {\r\n ++partial.received;\r\n value.data[chunk.index] = chunk.data;\r\n }\r\n }\r\n\r\n if (partial.received === (value.chunks || 0)) {\r\n this.handleComplete(message.id, evt);\r\n }\r\n });\r\n this._removeListeners.push(removeListener);\r\n }\r\n\r\n private _extractValue(t: IpcTransportMessage): RpcSerializedValue {\r\n if (t.parameters) {\r\n return t.parameters;\r\n }\r\n\r\n if (t.result) {\r\n return t.result;\r\n }\r\n\r\n throw new IModelError(BentleyStatus.ERROR, \"Unknown value type.\");\r\n }\r\n\r\n private _send(message: IpcTransportMessage, value: RpcSerializedValue, evt?: any) {\r\n const chunks = value.data;\r\n if (chunks.length) {\r\n value.chunks = chunks.length;\r\n value.data = [];\r\n }\r\n\r\n this.performSend(OBJECTS_CHANNEL, message, evt);\r\n\r\n for (let index = 0; index !== chunks.length; ++index) {\r\n const chunk: PartialPayload = { id: message.id, index, data: chunks[index] };\r\n this.performSend(DATA_CHANNEL, chunk, evt);\r\n }\r\n }\r\n\r\n protected performSend(channel: string, message: any, evt: any) {\r\n (evt ? evt.sender : this.protocol.ipcSocket).send(channel, message);\r\n }\r\n\r\n protected abstract handleComplete(id: string, evt: any): void;\r\n\r\n /** @internal */\r\n public sendResponse(message: TOut, evt: any) {\r\n const value = this._extractValue(message);\r\n this._send(message, value, evt);\r\n }\r\n\r\n protected loadMessage(id: string) {\r\n const partial = this._partials.get(id);\r\n if (!partial || Array.isArray(partial)) {\r\n throw new IModelError(BentleyStatus.ERROR, `Incomplete transmission for id \"${id}\".`);\r\n }\r\n\r\n this._partials.delete(id);\r\n return partial.message;\r\n }\r\n\r\n public cleanup() {\r\n this._removeListeners.forEach((removeListener) => removeListener());\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class FrontendIpcTransport extends ElectronIpcTransport<RpcRequestFulfillment> {\r\n private _pushTransport?: ElectronPushTransport;\r\n\r\n protected override setupPush() {\r\n const pushTransport = new ElectronPushTransport(this);\r\n this._pushTransport = pushTransport;\r\n RpcPushChannel.setup(pushTransport);\r\n }\r\n\r\n protected async handleComplete(id: string) {\r\n const message = this.loadMessage(id);\r\n\r\n if (this._pushTransport && this._pushTransport.consume(message)) {\r\n return;\r\n }\r\n\r\n const protocol = this._protocol;\r\n const request = protocol.requests.get(message.id);\r\n // A response may arrive after shutdown has removed the request.\r\n if (!request)\r\n return;\r\n\r\n request.notifyResponse(message);\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class BackendIpcTransport extends ElectronIpcTransport<SerializedRpcRequest, RpcRequestFulfillment> {\r\n private _browserWindow: any;\r\n\r\n protected override setupPush() {\r\n RpcPushConnection.for = (channel, client) => new ElectronPushConnection(channel, client, this);\r\n RpcPushChannel.enabled = true;\r\n }\r\n\r\n protected async handleComplete(id: string, evt: any) {\r\n const message = this.loadMessage(id);\r\n\r\n let response: RpcRequestFulfillment;\r\n try {\r\n const protocol = this._protocol;\r\n response = await protocol.fulfill(message);\r\n } catch (err) {\r\n response = await RpcRequestFulfillment.forUnknownError(message, err);\r\n }\r\n\r\n const raw = response.rawResult;\r\n response.rawResult = undefined; // Otherwise, it will be serialized in IPC layer and large responses will then crash the app\r\n this.sendResponse(response, evt);\r\n response.rawResult = raw;\r\n }\r\n\r\n protected override performSend(channel: string, message: any, evt: any) {\r\n if (evt) {\r\n return super.performSend(channel, message, evt);\r\n }\r\n\r\n this._requireBrowserWindow();\r\n const target = ElectronRpcConfiguration.targetWindowId;\r\n const windows = target ? [this._browserWindow.fromId(target)] : this._browserWindow.getAllWindows();\r\n windows.forEach((window: any) => window.webContents.send(channel, message));\r\n }\r\n\r\n private _requireBrowserWindow() {\r\n if (this._browserWindow) {\r\n return;\r\n }\r\n\r\n try { // Wrapping require in a try/catch signals to webpack that this is only an optional dependency\r\n this._browserWindow = require(\"electron\").BrowserWindow; // eslint-disable-line @typescript-eslint/no-require-imports\r\n } catch (err) {\r\n throw new IModelError(BentleyStatus.ERROR, `Error requiring electron`, () => BentleyError.getErrorProps(err));\r\n }\r\n }\r\n}\r\n\r\nlet transport: ElectronIpcTransport | undefined;\r\n\r\n/** @internal */\r\nexport function initializeIpc(protocol: ElectronRpcProtocol) {\r\n if (transport && transport.protocol !== protocol) {\r\n transport.cleanup();\r\n transport = undefined;\r\n }\r\n\r\n if (undefined === transport)\r\n transport = ProcessDetector.isElectronAppFrontend ? new FrontendIpcTransport(protocol) : new BackendIpcTransport(protocol);\r\n\r\n return transport;\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-electron",
|
|
3
|
-
"version": "5.13.
|
|
3
|
+
"version": "5.13.1",
|
|
4
4
|
"description": "iTwin.js ElectronHost and ElectronApp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"electron": ">=35.0.0 <44.0.0",
|
|
22
|
-
"@itwin/core-backend": "5.13.
|
|
23
|
-
"@itwin/core-
|
|
24
|
-
"@itwin/core-
|
|
25
|
-
"@itwin/core-
|
|
22
|
+
"@itwin/core-backend": "5.13.1",
|
|
23
|
+
"@itwin/core-frontend": "5.13.1",
|
|
24
|
+
"@itwin/core-bentley": "5.13.1",
|
|
25
|
+
"@itwin/core-common": "5.13.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@itwin/eslint-plugin": "^6.0.0",
|
|
@@ -40,16 +40,12 @@
|
|
|
40
40
|
"typescript": "~5.6.2",
|
|
41
41
|
"webpack": "^5.97.1",
|
|
42
42
|
"webpack-cli": "^5.0.1",
|
|
43
|
-
"@itwin/
|
|
44
|
-
"@itwin/
|
|
45
|
-
"@itwin/core-
|
|
46
|
-
"@itwin/core-
|
|
47
|
-
"@itwin/core-
|
|
48
|
-
"@itwin/core-
|
|
49
|
-
},
|
|
50
|
-
"dependencies": {
|
|
51
|
-
"@openid/appauth": "^1.3.2",
|
|
52
|
-
"username": "^7.0.0"
|
|
43
|
+
"@itwin/build-tools": "5.13.1",
|
|
44
|
+
"@itwin/certa": "5.13.1",
|
|
45
|
+
"@itwin/core-frontend": "5.13.1",
|
|
46
|
+
"@itwin/core-backend": "5.13.1",
|
|
47
|
+
"@itwin/core-bentley": "5.13.1",
|
|
48
|
+
"@itwin/core-common": "5.13.1"
|
|
53
49
|
},
|
|
54
50
|
"scripts": {
|
|
55
51
|
"build": "npm run -s build:cjs && npm run -s webpack:test && npm run -s copy:test-assets",
|