@itwin/core-electron 3.6.0-dev.7 → 4.0.0-dev.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 CHANGED
@@ -1,6 +1,31 @@
1
1
  # Change Log - @itwin/core-electron
2
2
 
3
- This log was last generated on Wed, 07 Dec 2022 19:12:36 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 26 Jan 2023 22:53:27 GMT and should not be manually modified.
4
+
5
+ ## 3.5.5
6
+ Thu, 26 Jan 2023 22:53:27 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 3.5.4
11
+ Wed, 18 Jan 2023 15:27:15 GMT
12
+
13
+ _Version update only_
14
+
15
+ ## 3.5.3
16
+ Fri, 13 Jan 2023 17:23:07 GMT
17
+
18
+ _Version update only_
19
+
20
+ ## 3.5.2
21
+ Wed, 11 Jan 2023 16:46:30 GMT
22
+
23
+ _Version update only_
24
+
25
+ ## 3.5.1
26
+ Thu, 15 Dec 2022 16:38:28 GMT
27
+
28
+ _Version update only_
4
29
 
5
30
  ## 3.5.0
6
31
  Wed, 07 Dec 2022 19:12:36 GMT
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MIT License
2
2
 
3
- Copyright © 2017-2022 Bentley Systems, Incorporated. All rights reserved.
3
+ Copyright © 2017-2023 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
 
@@ -46,6 +46,8 @@ export interface WindowSizeAndPositionProps {
46
46
  * @beta
47
47
  */
48
48
  export declare class ElectronHost {
49
+ private static readonly _deprecatedSizeAndPosStoreKey;
50
+ private static readonly _sizeAndPosStoreKey;
49
51
  private static _ipc;
50
52
  private static _developmentServer;
51
53
  private static _electron;
@@ -70,8 +72,19 @@ export declare class ElectronHost {
70
72
  private static _openWindow;
71
73
  /** The "main" BrowserWindow for this application. */
72
74
  static get mainWindow(): BrowserWindow | undefined;
73
- /** Gets window size and position for a window, by name, from settings file, if present */
75
+ /**
76
+ * Gets window size and position for a window, by name, from settings file, if present.
77
+ * @note Size and position values in the settings file will be updated differently depending on platform.
78
+ * On Linux values are only updated on window "unmaximize".
79
+ * On Windows and MacOS values are also updated on window manual resize or move.
80
+ * To get consistent behavior across different platforms, use [[ElectronHost.getWindowSizeAndPositionSetting]].
81
+ * @deprecated in 3.6. Use [[ElectronHost.getWindowSizeAndPositionSetting]].
82
+ */
74
83
  static getWindowSizeSetting(windowName: string): WindowSizeAndPositionProps | undefined;
84
+ /**
85
+ * Gets window size and position for a window, by name, from settings file, if present.
86
+ */
87
+ static getWindowSizeAndPositionSetting(windowName: string): WindowSizeAndPositionProps | undefined;
75
88
  /** Gets "window maximized" flag for a window, by name, from settings file if present */
76
89
  static getWindowMaximizedSetting(windowName: string): boolean | undefined;
77
90
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronHost.d.ts","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAC;AAC/E,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;AAyB1I;;;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,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BAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS;IAK9F;;OAEG;WACW,+BAA+B,CAAC,UAAU,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS;IAKzG,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;CAmCpD"}
@@ -68,22 +68,23 @@ class ElectronHost {
68
68
  return assetPath;
69
69
  }
70
70
  static _openWindow(options) {
71
+ const webPreferences = {
72
+ ...options === null || options === void 0 ? void 0 : options.webPreferences,
73
+ // These web preference variables should not be overriden by the ElectronHostWindowOptions
74
+ preload: require.resolve(/* webpack: copyfile */ "./ElectronPreload.js"),
75
+ experimentalFeatures: false,
76
+ nodeIntegration: false,
77
+ contextIsolation: true,
78
+ sandbox: true,
79
+ nativeWindowOpen: true,
80
+ nodeIntegrationInWorker: false,
81
+ nodeIntegrationInSubFrames: false,
82
+ };
71
83
  const opts = {
72
84
  ...options,
73
85
  autoHideMenuBar: true,
74
86
  icon: this.appIconPath,
75
- webPreferences: {
76
- ...options === null || options === void 0 ? void 0 : options.webPreferences,
77
- // These web preference variables should not be overriden by the ElectronHostWindowOptions
78
- preload: require.resolve(/* webpack: copyfile */ "./ElectronPreload.js"),
79
- experimentalFeatures: false,
80
- nodeIntegration: false,
81
- contextIsolation: true,
82
- sandbox: true,
83
- nativeWindowOpen: true,
84
- nodeIntegrationInWorker: false,
85
- nodeIntegrationInSubFrames: false,
86
- },
87
+ webPreferences,
87
88
  };
88
89
  this._mainWindow = new (this.electron.BrowserWindow)(opts);
89
90
  ElectronRpcManager_1.ElectronRpcConfiguration.targetWindowId = this._mainWindow.id;
@@ -93,34 +94,45 @@ class ElectronHost {
93
94
  if (options === null || options === void 0 ? void 0 : options.storeWindowName) {
94
95
  const mainWindow = this._mainWindow;
95
96
  const name = options.storeWindowName;
96
- const saveWindowPosition = () => {
97
- const resolution = mainWindow.getSize();
98
- const position = mainWindow.getPosition();
99
- const pos = {
100
- width: resolution[0],
101
- height: resolution[1],
102
- x: position[0],
103
- y: position[1],
104
- };
105
- core_backend_1.NativeHost.settingsStore.setData(`windowPos-${name}`, JSON.stringify(pos));
97
+ const saveWindowPosition = (key) => {
98
+ const bounds = mainWindow.getBounds();
99
+ core_backend_1.NativeHost.settingsStore.setData(`${key}-${name}`, JSON.stringify(bounds));
106
100
  };
107
101
  const saveMaximized = (maximized) => {
108
102
  if (!maximized)
109
- saveWindowPosition();
103
+ saveWindowPosition(this._deprecatedSizeAndPosStoreKey);
110
104
  core_backend_1.NativeHost.settingsStore.setData(`windowMaximized-${name}`, maximized);
111
105
  };
112
- mainWindow.on("resized", () => saveWindowPosition());
113
- mainWindow.on("moved", () => saveWindowPosition());
114
106
  mainWindow.on("maximize", () => saveMaximized(true));
115
107
  mainWindow.on("unmaximize", () => saveMaximized(false));
116
108
  saveMaximized(mainWindow.isMaximized());
109
+ mainWindow.on("resized", () => saveWindowPosition(this._deprecatedSizeAndPosStoreKey));
110
+ mainWindow.on("moved", () => saveWindowPosition(this._deprecatedSizeAndPosStoreKey));
111
+ const debouncedSaveWindowSizeAndPos = debounce(() => saveWindowPosition(this._sizeAndPosStoreKey));
112
+ mainWindow.on("resize", () => debouncedSaveWindowSizeAndPos());
113
+ mainWindow.on("move", () => debouncedSaveWindowSizeAndPos());
114
+ saveWindowPosition(this._sizeAndPosStoreKey);
117
115
  }
118
116
  }
119
117
  /** The "main" BrowserWindow for this application. */
120
118
  static get mainWindow() { return this._mainWindow; }
121
- /** Gets window size and position for a window, by name, from settings file, if present */
119
+ /**
120
+ * Gets window size and position for a window, by name, from settings file, if present.
121
+ * @note Size and position values in the settings file will be updated differently depending on platform.
122
+ * On Linux values are only updated on window "unmaximize".
123
+ * On Windows and MacOS values are also updated on window manual resize or move.
124
+ * To get consistent behavior across different platforms, use [[ElectronHost.getWindowSizeAndPositionSetting]].
125
+ * @deprecated in 3.6. Use [[ElectronHost.getWindowSizeAndPositionSetting]].
126
+ */
122
127
  static getWindowSizeSetting(windowName) {
123
- const saved = core_backend_1.NativeHost.settingsStore.getString(`windowPos-${windowName}`);
128
+ const saved = core_backend_1.NativeHost.settingsStore.getString(`${this._deprecatedSizeAndPosStoreKey}-${windowName}`);
129
+ return saved ? JSON.parse(saved) : undefined;
130
+ }
131
+ /**
132
+ * Gets window size and position for a window, by name, from settings file, if present.
133
+ */
134
+ static getWindowSizeAndPositionSetting(windowName) {
135
+ const saved = core_backend_1.NativeHost.settingsStore.getString(`${this._sizeAndPosStoreKey}-${windowName}`);
124
136
  return saved ? JSON.parse(saved) : undefined;
125
137
  }
126
138
  /** Gets "window maximized" flag for a window, by name, from settings file if present */
@@ -207,6 +219,8 @@ class ElectronHost {
207
219
  }
208
220
  }
209
221
  exports.ElectronHost = ElectronHost;
222
+ ElectronHost._deprecatedSizeAndPosStoreKey = "windowPos";
223
+ ElectronHost._sizeAndPosStoreKey = "windowSizeAndPos";
210
224
  ElectronHost._electronFrontend = "electron://frontend/";
211
225
  class ElectronDialogHandler extends core_backend_1.IpcHandler {
212
226
  get channelName() { return ElectronIpcInterface_1.dialogChannel; }
@@ -218,4 +232,13 @@ class ElectronDialogHandler extends core_backend_1.IpcHandler {
218
232
  return dialogMethod.call(dialog, ...args);
219
233
  }
220
234
  }
235
+ function debounce(func, ms = 200) {
236
+ let timeout;
237
+ return function (...args) {
238
+ clearTimeout(timeout);
239
+ timeout = setTimeout(() => {
240
+ func.apply(this, args);
241
+ }, ms);
242
+ };
243
+ }
221
244
  //# sourceMappingURL=ElectronHost.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronHost.js","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings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CAAC,2BAAY,CAAC,gBAAgB,EAAE,gCAAgC,CAAC,CAAC;QAEzF,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,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* from electron so this file can be imported by apps that sometimes use Electron and sometimes not.\r\nimport type { BrowserWindow, BrowserWindowConstructorOptions } 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 { 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 { dialogChannel, DialogModuleMethod } 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(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 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 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.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 (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 saveMaximized(mainWindow.isMaximized());\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([{\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 dialogChannel; }\r\n public async callDialog(method: DialogModuleMethod, ...args: any) {\r\n const dialog = ElectronHost.electron.dialog;\r\n const dialogMethod = dialog[method] as Function;\r\n if (typeof dialogMethod !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `illegal electron dialog method`);\r\n\r\n return dialogMethod.call(dialog, ...args);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ElectronHost.js","sourceRoot":"","sources":["../../../src/backend/ElectronHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAM/F,yBAAyB;AACzB,6BAA6B;AAC7B,sDAAgF;AAChF,sDAAsF;AACtF,oDAA0I;AAC1I,qEAA4F;AAC5F,yEAAmF;AAEnF,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,CA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,OAAO,oCAAa,CAAC,CAAC,CAAC;IAC3C,KAAK,CAAC,UAAU,CAAC,MAA0B,EAAE,GAAG,IAAS;QAC9D,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAa,CAAC;QAChD,IAAI,OAAO,YAAY,KAAK,UAAU;YACpC,MAAM,IAAI,yBAAW,CAAC,2BAAY,CAAC,gBAAgB,EAAE,gCAAgC,CAAC,CAAC;QAEzF,OAAO,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,IAAc,EAAE,KAAa,GAAG;IAChD,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// 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 { 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 { dialogChannel, DialogModuleMethod } 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(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 readonly _deprecatedSizeAndPosStoreKey = \"windowPos\";\r\n private static readonly _sizeAndPosStoreKey = \"windowSizeAndPos\";\r\n\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 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.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 (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 webPreferences: WebPreferences & { nativeWindowOpen: true } = { // nativeWindowOpen was removed starting Electron 18\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 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 name = options.storeWindowName;\r\n const saveWindowPosition = (key: string) => {\r\n const bounds: WindowSizeAndPositionProps = mainWindow.getBounds();\r\n NativeHost.settingsStore.setData(`${key}-${name}`, JSON.stringify(bounds));\r\n };\r\n const saveMaximized = (maximized: boolean) => {\r\n if (!maximized)\r\n saveWindowPosition(this._deprecatedSizeAndPosStoreKey);\r\n NativeHost.settingsStore.setData(`windowMaximized-${name}`, 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 mainWindow.on(\"resized\", () => saveWindowPosition(this._deprecatedSizeAndPosStoreKey));\r\n mainWindow.on(\"moved\", () => saveWindowPosition(this._deprecatedSizeAndPosStoreKey));\r\n\r\n const debouncedSaveWindowSizeAndPos = debounce(() => saveWindowPosition(this._sizeAndPosStoreKey));\r\n mainWindow.on(\"resize\", () => debouncedSaveWindowSizeAndPos());\r\n mainWindow.on(\"move\", () => debouncedSaveWindowSizeAndPos());\r\n saveWindowPosition(this._sizeAndPosStoreKey);\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 * @note Size and position values in the settings file will be updated differently depending on platform.\r\n * On Linux values are only updated on window \"unmaximize\".\r\n * On Windows and MacOS values are also updated on window manual resize or move.\r\n * To get consistent behavior across different platforms, use [[ElectronHost.getWindowSizeAndPositionSetting]].\r\n * @deprecated in 3.6. Use [[ElectronHost.getWindowSizeAndPositionSetting]].\r\n */\r\n public static getWindowSizeSetting(windowName: string): WindowSizeAndPositionProps | undefined {\r\n const saved = NativeHost.settingsStore.getString(`${this._deprecatedSizeAndPosStoreKey}-${windowName}`);\r\n return saved ? JSON.parse(saved) as WindowSizeAndPositionProps : undefined;\r\n }\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(`${this._sizeAndPosStoreKey}-${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([{\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 dialogChannel; }\r\n public async callDialog(method: DialogModuleMethod, ...args: any) {\r\n const dialog = ElectronHost.electron.dialog;\r\n const dialogMethod = dialog[method] as Function;\r\n if (typeof dialogMethod !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `illegal electron dialog method`);\r\n\r\n return dialogMethod.call(dialog, ...args);\r\n }\r\n}\r\n\r\nfunction debounce(func: Function, 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":"ElectronPush.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronPush.ts"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CAAC,CAAE,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,IAAI,CAAsB;IAClC,OAAO,CAAC,KAAK,CAAc;gBAER,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,mBAAmB;IAK3E,IAAI,CAAC,WAAW,EAAE,GAAG;CAKnC"}
@@ -9,6 +9,7 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.ElectronPushConnection = exports.ElectronPushTransport = void 0;
11
11
  const core_common_1 = require("@itwin/core-common");
12
+ /* eslint-disable deprecation/deprecation */
12
13
  const PUSH = "__push__";
13
14
  /** @internal */
14
15
  class ElectronPushTransport extends core_common_1.RpcPushTransport {
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronPush.js","sourceRoot":"","sources":["../../../src/common/ElectronPush.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAA+H;AAG/H,MAAM,IAAI,GAAG,UAAU,CAAC;AAExB,gBAAgB;AAChB,MAAa,qBAAsB,SAAQ,8BAAgB;IAMzD,YAAmB,GAAyB;QAC1C,KAAK,EAAE,CAAC;QALF,UAAK,GAAW,CAAC,CAAC,CAAC;QAMzB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IALD,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAOjC,OAAO,CAAC,QAA+B;QAC5C,IAAI,QAAQ,CAAC,aAAa,KAAK,IAAI,EAAE;YACnC,OAAO,KAAK,CAAC;SACd;QAED,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC;QAE7B,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,MAAM,WAAW,GAAG,2BAAa,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnF,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;SAC1C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAzBD,sDAyBC;AAED,gBAAgB;AAChB,MAAa,sBAA0B,SAAQ,+BAAoB;IAIjE,YAAmB,OAA0B,EAAE,MAAe,EAAE,GAAwB;QACtF,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAHjB,UAAK,GAAW,CAAC,CAAC,CAAC;QAIzB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,WAAgB;QAChC,MAAM,MAAM,GAAG,MAAM,2BAAa,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC9E,MAAM,WAAW,GAA0B,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9I,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;CACF;AAdD,wDAcC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { RpcMarshaling, RpcPushChannel, RpcPushConnection, RpcPushTransport, RpcRequestFulfillment } from \"@itwin/core-common\";\r\nimport { BackendIpcTransport, FrontendIpcTransport } from \"./ElectronIpcTransport\";\r\n\r\nconst PUSH = \"__push__\";\r\n\r\n/** @internal */\r\nexport class ElectronPushTransport extends RpcPushTransport {\r\n private _ipc: FrontendIpcTransport;\r\n private _last: number = -1;\r\n\r\n public get last() { return this._last; }\r\n\r\n public constructor(ipc: FrontendIpcTransport) {\r\n super();\r\n this._ipc = ipc;\r\n }\r\n\r\n public consume(response: RpcRequestFulfillment): boolean {\r\n if (response.interfaceName !== PUSH) {\r\n return false;\r\n }\r\n\r\n this._last = response.status;\r\n\r\n if (this.onMessage) {\r\n const messageData = RpcMarshaling.deserialize(this._ipc.protocol, response.result);\r\n this.onMessage(response.id, messageData);\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class ElectronPushConnection<T> extends RpcPushConnection<T> {\r\n private _ipc: BackendIpcTransport;\r\n private _next: number = -1;\r\n\r\n public constructor(channel: RpcPushChannel<T>, client: unknown, ipc: BackendIpcTransport) {\r\n super(channel, client);\r\n this._ipc = ipc;\r\n }\r\n\r\n public async send(messageData: any) {\r\n const result = await RpcMarshaling.serialize(this._ipc.protocol, messageData);\r\n const fulfillment: RpcRequestFulfillment = { result, rawResult: messageData, interfaceName: PUSH, id: this.channel.id, status: ++this._next };\r\n this._ipc.sendResponse(fulfillment, undefined);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ElectronPush.js","sourceRoot":"","sources":["../../../src/common/ElectronPush.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAA+H;AAG/H,4CAA4C;AAE5C,MAAM,IAAI,GAAG,UAAU,CAAC;AAExB,gBAAgB;AAChB,MAAa,qBAAsB,SAAQ,8BAAgB;IAMzD,YAAmB,GAAyB;QAC1C,KAAK,EAAE,CAAC;QALF,UAAK,GAAW,CAAC,CAAC,CAAC;QAMzB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IALD,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAOjC,OAAO,CAAC,QAA+B;QAC5C,IAAI,QAAQ,CAAC,aAAa,KAAK,IAAI,EAAE;YACnC,OAAO,KAAK,CAAC;SACd;QAED,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC;QAE7B,IAAI,IAAI,CAAC,SAAS,EAAE;YAClB,MAAM,WAAW,GAAG,2BAAa,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnF,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;SAC1C;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAzBD,sDAyBC;AAED,gBAAgB;AAChB,MAAa,sBAA0B,SAAQ,+BAAoB;IAIjE,YAAmB,OAA0B,EAAE,MAAe,EAAE,GAAwB;QACtF,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAHjB,UAAK,GAAW,CAAC,CAAC,CAAC;QAIzB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,WAAgB;QAChC,MAAM,MAAM,GAAG,MAAM,2BAAa,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC9E,MAAM,WAAW,GAA0B,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9I,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;CACF;AAdD,wDAcC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { RpcMarshaling, RpcPushChannel, RpcPushConnection, RpcPushTransport, RpcRequestFulfillment } from \"@itwin/core-common\";\r\nimport { BackendIpcTransport, FrontendIpcTransport } from \"./ElectronIpcTransport\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\nconst PUSH = \"__push__\";\r\n\r\n/** @internal */\r\nexport class ElectronPushTransport extends RpcPushTransport {\r\n private _ipc: FrontendIpcTransport;\r\n private _last: number = -1;\r\n\r\n public get last() { return this._last; }\r\n\r\n public constructor(ipc: FrontendIpcTransport) {\r\n super();\r\n this._ipc = ipc;\r\n }\r\n\r\n public consume(response: RpcRequestFulfillment): boolean {\r\n if (response.interfaceName !== PUSH) {\r\n return false;\r\n }\r\n\r\n this._last = response.status;\r\n\r\n if (this.onMessage) {\r\n const messageData = RpcMarshaling.deserialize(this._ipc.protocol, response.result);\r\n this.onMessage(response.id, messageData);\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class ElectronPushConnection<T> extends RpcPushConnection<T> {\r\n private _ipc: BackendIpcTransport;\r\n private _next: number = -1;\r\n\r\n public constructor(channel: RpcPushChannel<T>, client: unknown, ipc: BackendIpcTransport) {\r\n super(channel, client);\r\n this._ipc = ipc;\r\n }\r\n\r\n public async send(messageData: any) {\r\n const result = await RpcMarshaling.serialize(this._ipc.protocol, messageData);\r\n const fulfillment: RpcRequestFulfillment = { result, rawResult: messageData, interfaceName: PUSH, id: this.channel.id, status: ++this._next };\r\n this._ipc.sendResponse(fulfillment, undefined);\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronRpcManager.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronRpcManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAA6D,gBAAgB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,UAAU,EAA2C,MAAM,oBAAoB,CAAC;AAEnO,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;GAEG;AACH,8BA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AM,CAAC,qBAAqB;IAsBpC,wEAAwE;WAC1D,iBAAiB;IAI/B,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAOlC"}
@@ -11,6 +11,7 @@ exports.ElectronRpcManager = exports.ElectronRpcConfiguration = void 0;
11
11
  const core_common_1 = require("@itwin/core-common");
12
12
  const presentation_common_1 = require("@itwin/presentation-common");
13
13
  const ElectronRpcProtocol_1 = require("./ElectronRpcProtocol");
14
+ /* eslint-disable deprecation/deprecation */
14
15
  /** RPC interface configuration for an Electron-based application.
15
16
  * @internal
16
17
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronRpcManager.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAAmO;AACnO,oEAAsE;AACtE,+DAA4D;AAE5D;;GAEG;AACH,MAAsB,wBAAyB,SAAQ,8BAAgB;CAMtE;AAND,4DAMC;AAED;;GAEG;AACH,MAAa,kBAAmB,SAAQ,wBAAU;IAChD,yEAAyE;IAClE,MAAM,CAAC,kBAAkB,CAAC,WAA8B,EAAE,UAAqC;QACpG,OAAO,kBAAkB,CAAC,qBAAqB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAC3E,CAAC;IAED,wEAAwE;IACjE,MAAM,CAAC,iBAAiB,CAAC,UAA4B,EAAE,UAAqC;QACjG,OAAO,kBAAkB,CAAC,qBAAqB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC1E,CAAC;IAEO,MAAM,CAAC,qBAAqB,CAAC,SAAoB,EAAE,IAA+B;QACxF,MAAM,UAAU,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI;YACzB,oCAAsB;YACtB,oCAAsB;YACtB,wCAA0B;YAC1B,8CAAwB;SACzB,CAAC;QACF,MAAM,MAAM,GAAG,KAAM,SAAQ,wBAAwB;YAAtC;;gBACN,eAAU,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC;gBAC9B,aAAQ,GAAwB,IAAI,yCAAmB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAClF,CAAC;SAAA,CAAC;QAEF,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE;YAC5B,8BAAgB,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC;SAC5C;QAED,MAAM,QAAQ,GAAG,8BAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACjD,8BAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAEhD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,wEAAwE;IACjE,MAAM,CAAC,iBAAiB;QAC7B,OAAO,kBAAkB,CAAC,kBAAkB,EAAE,CAAC;IACjD,CAAC;IAEO,MAAM,CAAC,kBAAkB;QAC/B,MAAM,WAAW,GAAG,yBAAW,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAE3D,KAAK,MAAM,CAAC,EAAE,YAAY,CAAC,IAAI,WAAW,EAAE;YAC1C,wBAAU,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;SAC7C;IACH,CAAC;CACF;AA7CD,gDA6CC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { IModelReadRpcInterface, IModelTileRpcInterface, IpcSocket, IpcSocketBackend, IpcSocketFrontend, RpcConfiguration, RpcInterfaceDefinition, RpcManager, RpcRegistry, SnapshotIModelRpcInterface } from \"@itwin/core-common\";\r\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol\";\r\n\r\n/** RPC interface configuration for an Electron-based application.\r\n * @internal\r\n */\r\nexport abstract class ElectronRpcConfiguration extends RpcConfiguration {\r\n\r\n public static targetWindowId?: number;\r\n\r\n /** The protocol of the configuration. */\r\n public abstract override protocol: ElectronRpcProtocol;\r\n}\r\n\r\n/** Coordinates usage of RPC interfaces for an Electron-based application.\r\n * @internal\r\n */\r\nexport class ElectronRpcManager extends RpcManager {\r\n /** Initializes ElectronRpcManager for the frontend of an application. */\r\n public static initializeFrontend(ipcFrontend: IpcSocketFrontend, interfaces?: RpcInterfaceDefinition[]): ElectronRpcConfiguration {\r\n return ElectronRpcManager.performInitialization(ipcFrontend, interfaces);\r\n }\r\n\r\n /** Initializes ElectronRpcManager for the backend of an application. */\r\n public static initializeBackend(ipcBackend: IpcSocketBackend, interfaces?: RpcInterfaceDefinition[]): ElectronRpcConfiguration {\r\n return ElectronRpcManager.performInitialization(ipcBackend, interfaces);\r\n }\r\n\r\n private static performInitialization(ipcSocket: IpcSocket, rpcs?: RpcInterfaceDefinition[]): ElectronRpcConfiguration {\r\n const interfaces = rpcs ?? [\r\n IModelReadRpcInterface,\r\n IModelTileRpcInterface,\r\n SnapshotIModelRpcInterface,\r\n PresentationRpcInterface,\r\n ];\r\n const config = class extends ElectronRpcConfiguration {\r\n public interfaces = () => interfaces;\r\n public protocol: ElectronRpcProtocol = new ElectronRpcProtocol(this, ipcSocket);\r\n };\r\n\r\n for (const def of interfaces) {\r\n RpcConfiguration.assign(def, () => config);\r\n }\r\n\r\n const instance = RpcConfiguration.obtain(config);\r\n RpcConfiguration.initializeInterfaces(instance);\r\n\r\n return instance;\r\n }\r\n\r\n /** Terminates ElectronRpcManager for the frontend of an application. */\r\n public static terminateFrontend() {\r\n return ElectronRpcManager.performTermination();\r\n }\r\n\r\n private static performTermination() {\r\n const definitions = RpcRegistry.instance.definitionClasses;\r\n\r\n for (const [, interfaceDef] of definitions) {\r\n RpcManager.terminateInterface(interfaceDef);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ElectronRpcManager.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcManager.ts"],"names":[],"mappings":";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B,OAAO,kBAAkB,CAAC,kBAAkB,EAAE,CAAC;IACjD,CAAC;IAEO,MAAM,CAAC,kBAAkB;QAC/B,MAAM,WAAW,GAAG,yBAAW,CAAC,QAAQ,CAAC,iBAAiB,CAAC;QAE3D,KAAK,MAAM,CAAC,EAAE,YAAY,CAAC,IAAI,WAAW,EAAE;YAC1C,wBAAU,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC;SAC7C;IACH,CAAC;CACF;AA7CD,gDA6CC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { IModelReadRpcInterface, IModelTileRpcInterface, IpcSocket, IpcSocketBackend, IpcSocketFrontend, RpcConfiguration, RpcInterfaceDefinition, RpcManager, RpcRegistry, SnapshotIModelRpcInterface } from \"@itwin/core-common\";\r\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** RPC interface configuration for an Electron-based application.\r\n * @internal\r\n */\r\nexport abstract class ElectronRpcConfiguration extends RpcConfiguration {\r\n\r\n public static targetWindowId?: number;\r\n\r\n /** The protocol of the configuration. */\r\n public abstract override protocol: ElectronRpcProtocol;\r\n}\r\n\r\n/** Coordinates usage of RPC interfaces for an Electron-based application.\r\n * @internal\r\n */\r\nexport class ElectronRpcManager extends RpcManager {\r\n /** Initializes ElectronRpcManager for the frontend of an application. */\r\n public static initializeFrontend(ipcFrontend: IpcSocketFrontend, interfaces?: RpcInterfaceDefinition[]): ElectronRpcConfiguration {\r\n return ElectronRpcManager.performInitialization(ipcFrontend, interfaces);\r\n }\r\n\r\n /** Initializes ElectronRpcManager for the backend of an application. */\r\n public static initializeBackend(ipcBackend: IpcSocketBackend, interfaces?: RpcInterfaceDefinition[]): ElectronRpcConfiguration {\r\n return ElectronRpcManager.performInitialization(ipcBackend, interfaces);\r\n }\r\n\r\n private static performInitialization(ipcSocket: IpcSocket, rpcs?: RpcInterfaceDefinition[]): ElectronRpcConfiguration {\r\n const interfaces = rpcs ?? [\r\n IModelReadRpcInterface,\r\n IModelTileRpcInterface,\r\n SnapshotIModelRpcInterface,\r\n PresentationRpcInterface,\r\n ];\r\n const config = class extends ElectronRpcConfiguration {\r\n public interfaces = () => interfaces;\r\n public protocol: ElectronRpcProtocol = new ElectronRpcProtocol(this, ipcSocket);\r\n };\r\n\r\n for (const def of interfaces) {\r\n RpcConfiguration.assign(def, () => config);\r\n }\r\n\r\n const instance = RpcConfiguration.obtain(config);\r\n RpcConfiguration.initializeInterfaces(instance);\r\n\r\n return instance;\r\n }\r\n\r\n /** Terminates ElectronRpcManager for the frontend of an application. */\r\n public static terminateFrontend() {\r\n return ElectronRpcManager.performTermination();\r\n }\r\n\r\n private static performTermination() {\r\n const definitions = RpcRegistry.instance.definitionClasses;\r\n\r\n for (const [, interfaceDef] of definitions) {\r\n RpcManager.terminateInterface(interfaceDef);\r\n }\r\n }\r\n}\r\n"]}
@@ -6,7 +6,7 @@ import { ElectronIpcTransport, IpcTransportMessage } from "./ElectronIpcTranspor
6
6
  import { ElectronRpcConfiguration } from "./ElectronRpcManager";
7
7
  import { ElectronRpcRequest } from "./ElectronRpcRequest";
8
8
  /** RPC interface protocol for an Electron-based application.
9
- * @beta
9
+ * @internal
10
10
  */
11
11
  export declare class ElectronRpcProtocol extends RpcProtocol {
12
12
  static instances: Map<string, ElectronRpcProtocol>;
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronRpcProtocol.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronRpcProtocol.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAe,SAAS,EAAE,YAAY,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;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WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/G,OAAO,EAAE,oBAAoB,EAAiB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,WAAW;IAClD,OAAc,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAa;IAC/D,SAAS,EAAE,SAAS,CAAC;IAE5B,+CAA+C;IAC/C,SAAgB,WAAW,4BAAsB;IAEjD,8DAA8D;IAC9C,sBAAsB,SAAoB;IAE1D,gBAAgB;IACT,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAa;IAE7D,gBAAgB;IAChB,SAAgB,SAAS,EAAE,oBAAoB,CAAC,mBAAmB,EAAE,mBAAmB,CAAC,CAAC;IAE1F,uCAAuC;gBACpB,aAAa,EAAE,wBAAwB,EAAE,SAAS,EAAE,SAAS;IAMhF,gBAAgB;IACA,sBAAsB,CAAC,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAIvG,gBAAgB;IACA,oBAAoB,CAAC,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAInG,gBAAgB;IACA,qBAAqB,CAAC,UAAU,EAAE,sBAAsB,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAItG,gBAAgB;IACA,mBAAmB,CAAC,UAAU,EAAE,sBAAsB,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;IAIlG,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,cAAc;CAGvB"}
@@ -12,8 +12,9 @@ const core_bentley_1 = require("@itwin/core-bentley");
12
12
  const core_common_1 = require("@itwin/core-common");
13
13
  const ElectronIpcTransport_1 = require("./ElectronIpcTransport");
14
14
  const ElectronRpcRequest_1 = require("./ElectronRpcRequest");
15
+ /* eslint-disable deprecation/deprecation */
15
16
  /** RPC interface protocol for an Electron-based application.
16
- * @beta
17
+ * @internal
17
18
  */
18
19
  class ElectronRpcProtocol extends core_common_1.RpcProtocol {
19
20
  /** Constructs an Electron protocol. */
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronRpcProtocol.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcProtocol.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,oDAA+G;AAC/G,iEAAkG;AAElG,6DAA0D;AAE1D;;GAEG;AACH,MAAa,mBAAoB,SAAQ,yBAAW;IAgBlD,uCAAuC;IACvC,YAAmB,aAAuC,EAAE,SAAoB;QAC9E,KAAK,CAAC,aAAa,CAAC,CAAC;QAdvB,+CAA+C;QAC/B,gBAAW,GAAG,uCAAkB,CAAC;QAEjD,8DAA8D;QAC9C,2BAAsB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;QAE1D,gBAAgB;QACT,aAAQ,GAAoC,IAAI,GAAG,EAAE,CAAC;QAQ3D,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAA,oCAAa,EAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,gBAAgB;IACA,sBAAsB,CAAC,UAAkC,EAAE,OAAqB;QAC9F,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB;IACA,oBAAoB,CAAC,UAAkC,EAAE,KAAmB;QAC1F,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,gBAAgB;IACA,qBAAqB,CAAC,UAAkC,EAAE,OAAqB;QAC7F,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAED,gBAAgB;IACA,mBAAmB,CAAC,UAAkC,EAAE,KAAmB;QACzF,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAClC,CAAC;IAEO,iBAAiB,CAAC,UAAkC;QAC1D,IAAI,mBAAmB,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC;YAC7D,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,kBAAkB,UAAU,CAAC,aAAa,2CAA2C,CAAC,CAAC;QAEpI,mBAAmB,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC;IAEO,cAAc,CAAC,UAAkC;QACvD,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,CAAC;;AApDH,kDAqDC;AApDe,6BAAS,GAAqC,IAAI,GAAG,EAAE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError, IpcSocket, RpcInterface, RpcInterfaceDefinition, RpcProtocol } from \"@itwin/core-common\";\r\nimport { ElectronIpcTransport, initializeIpc, IpcTransportMessage } from \"./ElectronIpcTransport\";\r\nimport { ElectronRpcConfiguration } from \"./ElectronRpcManager\";\r\nimport { ElectronRpcRequest } from \"./ElectronRpcRequest\";\r\n\r\n/** RPC interface protocol for an Electron-based application.\r\n * @beta\r\n */\r\nexport class ElectronRpcProtocol extends RpcProtocol {\r\n public static instances: Map<string, ElectronRpcProtocol> = new Map();\r\n public ipcSocket: IpcSocket;\r\n\r\n /** The RPC request class for this protocol. */\r\n public readonly requestType = ElectronRpcRequest;\r\n\r\n /** Specifies where to break large binary request payloads. */\r\n public override transferChunkThreshold = 48 * 1024 * 1024;\r\n\r\n /** @internal */\r\n public requests: Map<string, ElectronRpcRequest> = new Map();\r\n\r\n /** @internal */\r\n public readonly transport: ElectronIpcTransport<IpcTransportMessage, IpcTransportMessage>;\r\n\r\n /** Constructs an Electron protocol. */\r\n public constructor(configuration: ElectronRpcConfiguration, ipcSocket: IpcSocket) {\r\n super(configuration);\r\n this.ipcSocket = ipcSocket;\r\n this.transport = initializeIpc(this);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcClientInitialized(definition: RpcInterfaceDefinition, _client: RpcInterface): void {\r\n this.registerInterface(definition);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcImplInitialized(definition: RpcInterfaceDefinition, _impl: RpcInterface): void {\r\n this.registerInterface(definition);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcClientTerminated(definition: RpcInterfaceDefinition, _client: RpcInterface): void {\r\n this.purgeInterface(definition);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcImplTerminated(definition: RpcInterfaceDefinition, _impl: RpcInterface): void {\r\n this.purgeInterface(definition);\r\n }\r\n\r\n private registerInterface(definition: RpcInterfaceDefinition) {\r\n if (ElectronRpcProtocol.instances.has(definition.interfaceName))\r\n throw new IModelError(BentleyStatus.ERROR, `RPC interface \"${definition.interfaceName}\"\" is already associated with a protocol.`);\r\n\r\n ElectronRpcProtocol.instances.set(definition.interfaceName, this);\r\n }\r\n\r\n private purgeInterface(definition: RpcInterfaceDefinition) {\r\n ElectronRpcProtocol.instances.delete(definition.interfaceName);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ElectronRpcProtocol.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcProtocol.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,oDAA+G;AAC/G,iEAAkG;AAElG,6DAA0D;AAE1D,4CAA4C;AAE5C;;GAEG;AACH,MAAa,mBAAoB,SAAQ,yBAAW;IAgBlD,uCAAuC;IACvC,YAAmB,aAAuC,EAAE,SAAoB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H,kDAqDC;AApDe,6BAAS,GAAqC,IAAI,GAAG,EAAE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError, IpcSocket, RpcInterface, RpcInterfaceDefinition, RpcProtocol } from \"@itwin/core-common\";\r\nimport { ElectronIpcTransport, initializeIpc, IpcTransportMessage } from \"./ElectronIpcTransport\";\r\nimport { ElectronRpcConfiguration } from \"./ElectronRpcManager\";\r\nimport { ElectronRpcRequest } from \"./ElectronRpcRequest\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** RPC interface protocol for an Electron-based application.\r\n * @internal\r\n */\r\nexport class ElectronRpcProtocol extends RpcProtocol {\r\n public static instances: Map<string, ElectronRpcProtocol> = new Map();\r\n public ipcSocket: IpcSocket;\r\n\r\n /** The RPC request class for this protocol. */\r\n public readonly requestType = ElectronRpcRequest;\r\n\r\n /** Specifies where to break large binary request payloads. */\r\n public override transferChunkThreshold = 48 * 1024 * 1024;\r\n\r\n /** @internal */\r\n public requests: Map<string, ElectronRpcRequest> = new Map();\r\n\r\n /** @internal */\r\n public readonly transport: ElectronIpcTransport<IpcTransportMessage, IpcTransportMessage>;\r\n\r\n /** Constructs an Electron protocol. */\r\n public constructor(configuration: ElectronRpcConfiguration, ipcSocket: IpcSocket) {\r\n super(configuration);\r\n this.ipcSocket = ipcSocket;\r\n this.transport = initializeIpc(this);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcClientInitialized(definition: RpcInterfaceDefinition, _client: RpcInterface): void {\r\n this.registerInterface(definition);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcImplInitialized(definition: RpcInterfaceDefinition, _impl: RpcInterface): void {\r\n this.registerInterface(definition);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcClientTerminated(definition: RpcInterfaceDefinition, _client: RpcInterface): void {\r\n this.purgeInterface(definition);\r\n }\r\n\r\n /** @internal */\r\n public override onRpcImplTerminated(definition: RpcInterfaceDefinition, _impl: RpcInterface): void {\r\n this.purgeInterface(definition);\r\n }\r\n\r\n private registerInterface(definition: RpcInterfaceDefinition) {\r\n if (ElectronRpcProtocol.instances.has(definition.interfaceName))\r\n throw new IModelError(BentleyStatus.ERROR, `RPC interface \"${definition.interfaceName}\"\" is already associated with a protocol.`);\r\n\r\n ElectronRpcProtocol.instances.set(definition.interfaceName, this);\r\n }\r\n\r\n private purgeInterface(definition: RpcInterfaceDefinition) {\r\n ElectronRpcProtocol.instances.delete(definition.interfaceName);\r\n }\r\n}\r\n"]}
@@ -1,6 +1,6 @@
1
1
  import { RpcRequest, RpcRequestFulfillment } from "@itwin/core-common";
2
2
  import { ElectronRpcProtocol } from "./ElectronRpcProtocol";
3
- /** @beta */
3
+ /** @internal */
4
4
  export declare class ElectronRpcRequest extends RpcRequest {
5
5
  private _res;
6
6
  private _fulfillment;
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronRpcRequest.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronRpcRequest.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,UAAU,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,YAAY;AACZ,qBAAa,kBAAmB,SAAQ,UAAU;IAChD,OAAO,CAAC,IAAI,CAA4C;IACxD,OAAO,CAAC,YAAY,CAAgD;IAEpE,0DAA0D;IAC1D,SAAyB,QAAQ,EAAE,mBAAmB,CAA6C;IAEnG,yBAAyB;cACT,IAAI;IAcpB,yBAAyB;cACT,IAAI;IASpB,kCAAkC;IAClC,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAIxD,gBAAgB;IACT,cAAc,CAAC,WAAW,EAAE,qBAAqB;IAKxD,gBAAgB;IACA,OAAO;CAIxB"}
1
+ {"version":3,"file":"ElectronRpcRequest.d.ts","sourceRoot":"","sources":["../../../src/common/ElectronRpcRequest.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,UAAU,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAI5D,gBAAgB;AAChB,qBAAa,kBAAmB,SAAQ,UAAU;IAChD,OAAO,CAAC,IAAI,CAA4C;IACxD,OAAO,CAAC,YAAY,CAAgD;IAEpE,0DAA0D;IAC1D,SAAyB,QAAQ,EAAE,mBAAmB,CAA6C;IAEnG,yBAAyB;cACT,IAAI;IAcpB,yBAAyB;cACT,IAAI;IASpB,kCAAkC;IAClC,SAAS,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAIxD,gBAAgB;IACT,cAAc,CAAC,WAAW,EAAE,qBAAqB;IAKxD,gBAAgB;IACA,OAAO;CAIxB"}
@@ -6,7 +6,8 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.ElectronRpcRequest = void 0;
8
8
  const core_common_1 = require("@itwin/core-common");
9
- /** @beta */
9
+ /* eslint-disable deprecation/deprecation */
10
+ /** @internal */
10
11
  class ElectronRpcRequest extends core_common_1.RpcRequest {
11
12
  constructor() {
12
13
  super(...arguments);
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronRpcRequest.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcRequest.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,oDAAyF;AAGzF,YAAY;AACZ,MAAa,kBAAmB,SAAQ,wBAAU;IAAlD;;QACU,SAAI,GAA4B,GAAG,EAAE,CAAC,SAAS,CAAC;QAChD,iBAAY,GAAsC,SAAS,CAAC;QAEpE,0DAA0D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AAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF;AAhDD,gDAgDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { RpcProtocolEvent, RpcRequest, RpcRequestFulfillment } from \"@itwin/core-common\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol\";\r\n\r\n/** @beta */\r\nexport class ElectronRpcRequest extends RpcRequest {\r\n private _res: (value: number) => void = () => undefined;\r\n private _fulfillment: RpcRequestFulfillment | undefined = undefined;\r\n\r\n /** Convenience access to the protocol of this request. */\r\n public override readonly protocol: ElectronRpcProtocol = this.client.configuration.protocol as any;\r\n\r\n /** Sends the request. */\r\n protected async send() {\r\n try {\r\n this.protocol.requests.set(this.id, this);\r\n const request = await this.protocol.serialize(this);\r\n this.protocol.transport.sendRequest(request);\r\n } catch (e) {\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.ConnectionErrorReceived, this);\r\n }\r\n\r\n return new Promise<number>((resolve) => {\r\n this._res = resolve;\r\n });\r\n }\r\n\r\n /** Loads the request. */\r\n protected async load() {\r\n const fulfillment = this._fulfillment;\r\n if (!fulfillment) {\r\n throw new Error(\"No request fulfillment available.\");\r\n }\r\n\r\n return fulfillment.result;\r\n }\r\n\r\n /** Sets request header values. */\r\n protected setHeader(_name: string, _value: string): void {\r\n // No implementation\r\n }\r\n\r\n /** @internal */\r\n public notifyResponse(fulfillment: RpcRequestFulfillment) {\r\n this._fulfillment = fulfillment;\r\n this._res(fulfillment.status);\r\n }\r\n\r\n /** @internal */\r\n public override dispose() {\r\n this.protocol.requests.delete(this.id);\r\n super.dispose();\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ElectronRpcRequest.js","sourceRoot":"","sources":["../../../src/common/ElectronRpcRequest.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,oD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AI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAED,gBAAgB;IACA,OAAO;QACrB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACvC,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;CACF;AAhDD,gDAgDC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { RpcProtocolEvent, RpcRequest, RpcRequestFulfillment } from \"@itwin/core-common\";\r\nimport { ElectronRpcProtocol } from \"./ElectronRpcProtocol\";\r\n\r\n/* eslint-disable deprecation/deprecation */\r\n\r\n/** @internal */\r\nexport class ElectronRpcRequest extends RpcRequest {\r\n private _res: (value: number) => void = () => undefined;\r\n private _fulfillment: RpcRequestFulfillment | undefined = undefined;\r\n\r\n /** Convenience access to the protocol of this request. */\r\n public override readonly protocol: ElectronRpcProtocol = this.client.configuration.protocol as any;\r\n\r\n /** Sends the request. */\r\n protected async send() {\r\n try {\r\n this.protocol.requests.set(this.id, this);\r\n const request = await this.protocol.serialize(this);\r\n this.protocol.transport.sendRequest(request);\r\n } catch (e) {\r\n this.protocol.events.raiseEvent(RpcProtocolEvent.ConnectionErrorReceived, this);\r\n }\r\n\r\n return new Promise<number>((resolve) => {\r\n this._res = resolve;\r\n });\r\n }\r\n\r\n /** Loads the request. */\r\n protected async load() {\r\n const fulfillment = this._fulfillment;\r\n if (!fulfillment) {\r\n throw new Error(\"No request fulfillment available.\");\r\n }\r\n\r\n return fulfillment.result;\r\n }\r\n\r\n /** Sets request header values. */\r\n protected setHeader(_name: string, _value: string): void {\r\n // No implementation\r\n }\r\n\r\n /** @internal */\r\n public notifyResponse(fulfillment: RpcRequestFulfillment) {\r\n this._fulfillment = fulfillment;\r\n this._res(fulfillment.status);\r\n }\r\n\r\n /** @internal */\r\n public override dispose() {\r\n this.protocol.requests.delete(this.id);\r\n super.dispose();\r\n }\r\n}\r\n"]}
@@ -27,7 +27,7 @@ export declare class ElectronApp {
27
27
  * Call an asynchronous method in the [Electron.Dialog](https://www.electronjs.org/docs/api/dialog) interface from a previously initialized ElectronFrontend.
28
28
  * @param methodName the name of the method to call
29
29
  * @param args arguments to method
30
- * @deprecated use [[dialogIpc]]
30
+ * @deprecated in 3.x. use [[dialogIpc]]
31
31
  */
32
32
  static callDialog<T extends DialogModuleMethod>(methodName: T, ...args: Parameters<Electron.Dialog[T]>): Promise<PromiseReturnType<Electron.Dialog[T]>>;
33
33
  /** Proxy object for calling methods of `Electron.Dialog` */
@@ -64,7 +64,7 @@ class ElectronApp {
64
64
  * Call an asynchronous method in the [Electron.Dialog](https://www.electronjs.org/docs/api/dialog) interface from a previously initialized ElectronFrontend.
65
65
  * @param methodName the name of the method to call
66
66
  * @param args arguments to method
67
- * @deprecated use [[dialogIpc]]
67
+ * @deprecated in 3.x. use [[dialogIpc]]
68
68
  */
69
69
  static async callDialog(methodName, ...args) {
70
70
  return core_frontend_1.IpcApp.callIpcChannel(ElectronIpcInterface_1.dialogChannel, "callDialog", methodName, ...args);
@@ -1 +1 @@
1
- {"version":3,"file":"ElectronApp.js","sourceRoot":"","sources":["../../../src/frontend/ElectronApp.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAyE;AAEzE,wDAAwE;AAExE,yEAAmF;AACnF,qEAAkE;AASlE;;GAEG;AACH,MAAM,WAAW;IAef;;QACE,sJAAsJ;QACtJ,iGAAiG;QACjG,8DAA8D;QAC9D,IAAI,CAAC,IAAI,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,OAAO,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC;IAChE,CAAC;IAlBM,WAAW,CAAC,WAAmB,EAAE,QAAqB;QAC3D,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,Q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AM,yBAAS,CAAC,QAAQ,EAAE,CAAC;QAC3B,uCAAkB,CAAC,iBAAiB,EAAE,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,UAAU,CAA+B,UAAa,EAAE,GAAG,IAAoC;QACjH,OAAO,sBAAM,CAAC,cAAc,CAAC,oCAAa,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,IAAI,CAA0C,CAAC;IAC1H,CAAC;;AAjCH,kCAqCC;AAFC,4DAA4D;AAC9C,qBAAS,GAAG,sBAAM,CAAC,oBAAoB,CAAkB,oCAAa,EAAE,YAAY,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { ProcessDetector, PromiseReturnType } from \"@itwin/core-bentley\";\r\nimport { IpcListener, IpcSocketFrontend } from \"@itwin/core-common\";\r\nimport { IpcApp, NativeApp, NativeAppOpts } from \"@itwin/core-frontend\";\r\nimport type { IpcRenderer } from \"electron\";\r\nimport { dialogChannel, DialogModuleMethod } from \"../common/ElectronIpcInterface\";\r\nimport { ElectronRpcManager } from \"../common/ElectronRpcManager\";\r\nimport type { ITwinElectronApi } from \"../common/ITwinElectronApi\";\r\n\r\ndeclare global {\r\n interface Window {\r\n itwinjs: ITwinElectronApi;\r\n }\r\n}\r\n\r\n/**\r\n * Frontend Ipc support for Electron apps.\r\n */\r\nclass ElectronIpc implements IpcSocketFrontend {\r\n private _api: ITwinElectronApi | IpcRenderer;\r\n public addListener(channelName: string, listener: IpcListener) {\r\n this._api.addListener(channelName, listener);\r\n return () => this._api.removeListener(channelName, listener);\r\n }\r\n public removeListener(channelName: string, listener: IpcListener) {\r\n this._api.removeListener(channelName, listener);\r\n }\r\n public send(channel: string, ...data: any[]) {\r\n this._api.send(channel, ...data);\r\n }\r\n public async invoke(channel: string, ...args: any[]) {\r\n return this._api.invoke(channel, ...args);\r\n }\r\n constructor() {\r\n // use the methods on window.itwinjs exposed by ElectronPreload.ts, or ipcRenderer directly if running with nodeIntegration=true (**only** for tests).\r\n // Note that `require(\"electron\")` doesn't work with nodeIntegration=false - that's what it stops\r\n // eslint-disable-next-line @typescript-eslint/no-var-requires\r\n this._api = window.itwinjs ?? require(\"electron\").ipcRenderer;\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport type ElectronAppOpts = NativeAppOpts;\r\n\r\n/**\r\n * Frontend of an Electron App.\r\n * @beta\r\n */\r\nexport class ElectronApp {\r\n private static _ipc?: ElectronIpc;\r\n public static get isValid(): boolean { return undefined !== this._ipc; }\r\n\r\n /**\r\n * Start the frontend of an Electron application.\r\n * @param opts Options for your ElectronApp\r\n * @note This method must only be called from the frontend of an Electron app (i.e. when [ProcessDetector.isElectronAppFrontend]($bentley) is `true`).\r\n */\r\n public static async startup(opts?: ElectronAppOpts) {\r\n if (!ProcessDetector.isElectronAppFrontend)\r\n throw new Error(\"Not running under Electron\");\r\n if (!this.isValid) {\r\n this._ipc = new ElectronIpc();\r\n ElectronRpcManager.initializeFrontend(this._ipc, opts?.iModelApp?.rpcInterfaces);\r\n }\r\n await NativeApp.startup(this._ipc!, opts);\r\n }\r\n\r\n public static async shutdown() {\r\n this._ipc = undefined;\r\n await NativeApp.shutdown();\r\n ElectronRpcManager.terminateFrontend();\r\n }\r\n\r\n /**\r\n * Call an asynchronous method in the [Electron.Dialog](https://www.electronjs.org/docs/api/dialog) interface from a previously initialized ElectronFrontend.\r\n * @param methodName the name of the method to call\r\n * @param args arguments to method\r\n * @deprecated use [[dialogIpc]]\r\n */\r\n public static async callDialog<T extends DialogModuleMethod>(methodName: T, ...args: Parameters<Electron.Dialog[T]>) {\r\n return IpcApp.callIpcChannel(dialogChannel, \"callDialog\", methodName, ...args) as PromiseReturnType<Electron.Dialog[T]>;\r\n }\r\n\r\n /** Proxy object for calling methods of `Electron.Dialog` */\r\n public static dialogIpc = IpcApp.makeIpcFunctionProxy<Electron.Dialog>(dialogChannel, \"callDialog\");\r\n}\r\n"]}
1
+ {"version":3,"file":"ElectronApp.js","sourceRoot":"","sources":["../../../src/frontend/ElectronApp.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F,sDAAyE;AAEzE,wDAAwE;AAExE,yEAAmF;AACnF,qEAAkE;AASlE;;GAEG;AACH,MAAM,WAAW;IAef;;QACE,sJAAsJ;QACtJ,iGAAiG;QACjG,8DAA8D;QAC9D,IAAI,CAAC,IAAI,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,OAAO,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC;IAChE,CAAC;IAlBM,WAAW,CAAC,WAAmB,EAAE,QAAqB;QAC3D,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAC7C,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC;IACM,cAAc,CAAC,WAAmB,EAAE,QAAqB;QAC9D,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAClD,CAAC;IACM,IAAI,CAAC,OAAe,EAAE,GAAG,IAAW;QACzC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACnC,CAAC;IACM,KAAK,CAAC,MAAM,CAAC,OAAe,EAAE,GAAG,IAAW;QACjD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC;CAOF;AAKD;;;GAGG;AACH,MAAa,WAAW;IAEf,MAAM,KAAK,OAAO,KAAc,OAAO,SAAS,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAExE;;;;OAIG;IACI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAsB;;QAChD,IAAI,CAAC,8BAAe,CAAC,qBAAqB;YACxC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,IAAI,CAAC,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,uCAAkB,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,SAAS,0CAAE,aAAa,CAAC,CAAC;SAClF;QACD,MAAM,yBAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAK,EAAE,IAAI,CAAC,CAAC;IAC5C,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,QAAQ;QAC1B,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACtB,MAAM,yBAAS,CAAC,QAAQ,EAAE,CAAC;QAC3B,uCAAkB,CAAC,iBAAiB,EAAE,CAAC;IACzC,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,UAAU,CAA+B,UAAa,EAAE,GAAG,IAAoC;QACjH,OAAO,sBAAM,CAAC,cAAc,CAAC,oCAAa,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,IAAI,CAA0C,CAAC;IAC1H,CAAC;;AAjCH,kCAqCC;AAFC,4DAA4D;AAC9C,qBAAS,GAAG,sBAAM,CAAC,oBAAoB,CAAkB,oCAAa,EAAE,YAAY,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { ProcessDetector, PromiseReturnType } from \"@itwin/core-bentley\";\r\nimport { IpcListener, IpcSocketFrontend } from \"@itwin/core-common\";\r\nimport { IpcApp, NativeApp, NativeAppOpts } from \"@itwin/core-frontend\";\r\nimport type { IpcRenderer } from \"electron\";\r\nimport { dialogChannel, DialogModuleMethod } from \"../common/ElectronIpcInterface\";\r\nimport { ElectronRpcManager } from \"../common/ElectronRpcManager\";\r\nimport type { ITwinElectronApi } from \"../common/ITwinElectronApi\";\r\n\r\ndeclare global {\r\n interface Window {\r\n itwinjs: ITwinElectronApi;\r\n }\r\n}\r\n\r\n/**\r\n * Frontend Ipc support for Electron apps.\r\n */\r\nclass ElectronIpc implements IpcSocketFrontend {\r\n private _api: ITwinElectronApi | IpcRenderer;\r\n public addListener(channelName: string, listener: IpcListener) {\r\n this._api.addListener(channelName, listener);\r\n return () => this._api.removeListener(channelName, listener);\r\n }\r\n public removeListener(channelName: string, listener: IpcListener) {\r\n this._api.removeListener(channelName, listener);\r\n }\r\n public send(channel: string, ...data: any[]) {\r\n this._api.send(channel, ...data);\r\n }\r\n public async invoke(channel: string, ...args: any[]) {\r\n return this._api.invoke(channel, ...args);\r\n }\r\n constructor() {\r\n // use the methods on window.itwinjs exposed by ElectronPreload.ts, or ipcRenderer directly if running with nodeIntegration=true (**only** for tests).\r\n // Note that `require(\"electron\")` doesn't work with nodeIntegration=false - that's what it stops\r\n // eslint-disable-next-line @typescript-eslint/no-var-requires\r\n this._api = window.itwinjs ?? require(\"electron\").ipcRenderer;\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport type ElectronAppOpts = NativeAppOpts;\r\n\r\n/**\r\n * Frontend of an Electron App.\r\n * @beta\r\n */\r\nexport class ElectronApp {\r\n private static _ipc?: ElectronIpc;\r\n public static get isValid(): boolean { return undefined !== this._ipc; }\r\n\r\n /**\r\n * Start the frontend of an Electron application.\r\n * @param opts Options for your ElectronApp\r\n * @note This method must only be called from the frontend of an Electron app (i.e. when [ProcessDetector.isElectronAppFrontend]($bentley) is `true`).\r\n */\r\n public static async startup(opts?: ElectronAppOpts) {\r\n if (!ProcessDetector.isElectronAppFrontend)\r\n throw new Error(\"Not running under Electron\");\r\n if (!this.isValid) {\r\n this._ipc = new ElectronIpc();\r\n ElectronRpcManager.initializeFrontend(this._ipc, opts?.iModelApp?.rpcInterfaces);\r\n }\r\n await NativeApp.startup(this._ipc!, opts);\r\n }\r\n\r\n public static async shutdown() {\r\n this._ipc = undefined;\r\n await NativeApp.shutdown();\r\n ElectronRpcManager.terminateFrontend();\r\n }\r\n\r\n /**\r\n * Call an asynchronous method in the [Electron.Dialog](https://www.electronjs.org/docs/api/dialog) interface from a previously initialized ElectronFrontend.\r\n * @param methodName the name of the method to call\r\n * @param args arguments to method\r\n * @deprecated in 3.x. use [[dialogIpc]]\r\n */\r\n public static async callDialog<T extends DialogModuleMethod>(methodName: T, ...args: Parameters<Electron.Dialog[T]>) {\r\n return IpcApp.callIpcChannel(dialogChannel, \"callDialog\", methodName, ...args) as PromiseReturnType<Electron.Dialog[T]>;\r\n }\r\n\r\n /** Proxy object for calling methods of `Electron.Dialog` */\r\n public static dialogIpc = IpcApp.makeIpcFunctionProxy<Electron.Dialog>(dialogChannel, \"callDialog\");\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-electron",
3
- "version": "3.6.0-dev.7",
3
+ "version": "4.0.0-dev.1",
4
4
  "description": "iTwin.js ElectronHost and ElectronApp",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -20,27 +20,27 @@
20
20
  "url": "http://www.bentley.com"
21
21
  },
22
22
  "peerDependencies": {
23
- "@itwin/core-backend": "^3.6.0-dev.7",
24
- "@itwin/core-bentley": "^3.6.0-dev.7",
25
- "@itwin/core-common": "^3.6.0-dev.7",
26
- "@itwin/core-frontend": "^3.6.0-dev.7",
27
- "@itwin/presentation-common": "^3.6.0-dev.7",
28
- "electron": ">=14.0.0 <18.0.0"
23
+ "@itwin/core-backend": "^4.0.0-dev.1",
24
+ "@itwin/core-bentley": "^4.0.0-dev.1",
25
+ "@itwin/core-common": "^4.0.0-dev.1",
26
+ "@itwin/core-frontend": "^4.0.0-dev.1",
27
+ "@itwin/presentation-common": "^4.0.0-dev.1",
28
+ "electron": ">=14.0.0 <18.0.0 || >=22.0.0 <23.0.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@itwin/build-tools": "3.6.0-dev.7",
32
- "@itwin/certa": "3.6.0-dev.7",
33
- "@itwin/core-backend": "3.6.0-dev.7",
34
- "@itwin/core-bentley": "3.6.0-dev.7",
35
- "@itwin/core-common": "3.6.0-dev.7",
36
- "@itwin/core-frontend": "3.6.0-dev.7",
37
- "@itwin/eslint-plugin": "3.6.0-dev.7",
38
- "@itwin/presentation-common": "3.6.0-dev.7",
31
+ "@itwin/build-tools": "4.0.0-dev.1",
32
+ "@itwin/certa": "4.0.0-dev.1",
33
+ "@itwin/core-backend": "4.0.0-dev.1",
34
+ "@itwin/core-bentley": "4.0.0-dev.1",
35
+ "@itwin/core-common": "4.0.0-dev.1",
36
+ "@itwin/core-frontend": "4.0.0-dev.1",
37
+ "@itwin/eslint-plugin": "4.0.0-dev.1",
38
+ "@itwin/presentation-common": "4.0.0-dev.1",
39
39
  "@types/chai": "4.3.1",
40
40
  "@types/mocha": "^8.2.2",
41
41
  "@types/node": "18.11.5",
42
42
  "chai": "^4.1.2",
43
- "electron": "^17.0.0",
43
+ "electron": "^22.0.0",
44
44
  "eslint": "^7.11.0",
45
45
  "mocha": "^10.0.0",
46
46
  "rimraf": "^3.0.2",