From d5eb453570a4291ec205dd78059e203af26e51ce Mon Sep 17 00:00:00 2001 From: "Ramanujam.Raman" <32458710+ramanujam-raman@users.noreply.github.com> Date: Wed, 24 Mar 2021 19:47:44 -0400 Subject: [PATCH 1/6] Querying for cached briefcases needs to include fileSize. DesktopAuthorization must call onuserStateChanged when token is set (signIn/refreshed), unset (signOut). Refined arguments to IOSHost.startup() Moved rpcInterfaces as an option to NativeHost instead of ElectronHost so that all native applications (iOS, Android and Desktops) can use it. --- common/api/electron-manager.api.md | 2 -- common/api/imodeljs-backend.api.md | 11 ++++++++++- common/api/imodeljs-common.api.md | 1 + common/api/mobile-manager.api.md | 12 ++++++++---- .../api/summary/imodeljs-backend.exports.csv | 3 ++- core/backend/src/BriefcaseManager.ts | 5 ++++- core/backend/src/NativeHost.ts | 19 ++++++++++++++++--- core/common/src/BriefcaseTypes.ts | 3 +++ .../backend/ElectronAuthorizationBackend.ts | 4 +++- .../src/backend/ElectronHost.ts | 6 ++---- core/mobile-manager/src/backend/MobileHost.ts | 4 ++++ core/mobile-manager/src/backend/iOSHost.ts | 5 ++++- core/mobile-manager/src/frontend/IOSApp.ts | 7 +++++-- .../app/src/backend/RobotWorldRpcImpl.ts | 2 +- full-stack-tests/core/src/backend/backend.ts | 2 +- .../native-app/src/backend/backend.ts | 2 +- .../rpc/src/backend/CommonBackendSetup.ts | 2 +- .../src/backend/backend.ts | 2 +- .../display-test-app/src/backend/Backend.ts | 12 ++++++++---- .../src/backend/DtaElectronMain.ts | 7 +++---- .../src/backend/electron/ElectronMain.ts | 8 ++++++-- .../src/backend/electron/ElectronMain.ts | 12 ++++++++---- 22 files changed, 92 insertions(+), 39 deletions(-) diff --git a/common/api/electron-manager.api.md b/common/api/electron-manager.api.md index 2bb3422a2d31..f5e8fe7ae313 100644 --- a/common/api/electron-manager.api.md +++ b/common/api/electron-manager.api.md @@ -12,7 +12,6 @@ import { NativeAppOpts } from '@bentley/imodeljs-frontend'; import { NativeHostOpts } from '@bentley/imodeljs-backend'; import { PromiseReturnType } from '@bentley/imodeljs-frontend'; import { RpcConfiguration } from '@bentley/imodeljs-common'; -import { RpcInterfaceDefinition } from '@bentley/imodeljs-common'; // @beta export class ElectronApp { @@ -59,7 +58,6 @@ export interface ElectronHostOptions { frontendURL?: string; iconName?: string; ipcHandlers?: (typeof IpcHandler)[]; - rpcInterfaces?: RpcInterfaceDefinition[]; webResourcesPath?: string; } diff --git a/common/api/imodeljs-backend.api.md b/common/api/imodeljs-backend.api.md index b198e1f0ebaa..497b8ff51b64 100644 --- a/common/api/imodeljs-backend.api.md +++ b/common/api/imodeljs-backend.api.md @@ -162,6 +162,7 @@ import { RenderMaterialProps } from '@bentley/imodeljs-common'; import { RenderSchedule } from '@bentley/imodeljs-common'; import { RepositoryLinkProps } from '@bentley/imodeljs-common'; import { RequestNewBriefcaseProps } from '@bentley/imodeljs-common'; +import { RpcInterfaceDefinition } from '@bentley/imodeljs-common'; import { Schema as Schema_2 } from '@bentley/ecschema-metadata'; import { SchemaState } from '@bentley/imodeljs-common'; import { SectionDrawingLocationProps } from '@bentley/imodeljs-common'; @@ -3458,8 +3459,16 @@ export class NativeHost { static startup(opt?: NativeHostOpts): Promise; } +// @beta +export interface NativeHostOptions { + rpcInterfaces?: RpcInterfaceDefinition[]; +} + // @beta (undocumented) -export type NativeHostOpts = IpcHostOpts; +export interface NativeHostOpts extends IpcHostOpts { + // (undocumented) + nativeHost?: NativeHostOptions; +} export { NativeLoggerCategory } diff --git a/common/api/imodeljs-common.api.md b/common/api/imodeljs-common.api.md index 63a5ed716128..0a1b0d7e70ad 100644 --- a/common/api/imodeljs-common.api.md +++ b/common/api/imodeljs-common.api.md @@ -4365,6 +4365,7 @@ export interface LocalBriefcaseProps { changeSetId: GuidString; contextId: GuidString; fileName: string; + fileSize: number; iModelId: GuidString; } diff --git a/common/api/mobile-manager.api.md b/common/api/mobile-manager.api.md index 40012e636a77..fc557f3bd021 100644 --- a/common/api/mobile-manager.api.md +++ b/common/api/mobile-manager.api.md @@ -74,16 +74,20 @@ export class IOSApp { // (undocumented) static get isValid(): boolean; // (undocumented) - static startup(opts?: { - iModelApp?: IModelAppOptions; - }): Promise; + static startup(opts?: IOSAppOpts): Promise; } +// @beta (undocumented) +export type IOSAppOpts = NativeAppOpts; + // @beta (undocumented) export class IOSHost extends MobileHost { - static startup(opt?: MobileHostOpts): Promise; + static startup(opt?: IOSHostOpts): Promise; } +// @beta (undocumented) +export type IOSHostOpts = MobileHostOpts; + // @beta (undocumented) export class MobileApp { // (undocumented) diff --git a/common/api/summary/imodeljs-backend.exports.csv b/common/api/summary/imodeljs-backend.exports.csv index 474bebbc6ac2..6927b9f7e52a 100644 --- a/common/api/summary/imodeljs-backend.exports.csv +++ b/common/api/summary/imodeljs-backend.exports.csv @@ -226,7 +226,8 @@ public;Model public;ModelSelector internal;class NativeAppAuthorizationBackend beta;NativeHost -beta;NativeHostOpts = IpcHostOpts +beta;NativeHostOptions +beta;NativeHostOpts public;OrthographicViewDefinition public;class PhysicalElement public;PhysicalElementAssemblesElements diff --git a/core/backend/src/BriefcaseManager.ts b/core/backend/src/BriefcaseManager.ts index 97ee7a5a657c..0c0f5bf1dec9 100644 --- a/core/backend/src/BriefcaseManager.ts +++ b/core/backend/src/BriefcaseManager.ts @@ -155,8 +155,9 @@ export class BriefcaseManager { if (briefcaseName.endsWith(".bim")) { try { const fileName = path.join(bcPath, briefcaseName); + const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0; const db = IModelDb.openDgnDb({ path: fileName }, OpenMode.Readonly); - briefcaseList.push({ fileName, contextId: db.queryProjectGuid(), iModelId: db.getDbGuid(), briefcaseId: db.getBriefcaseId(), changeSetId: db.getParentChangeSetId() }); + briefcaseList.push({ fileName, contextId: db.queryProjectGuid(), iModelId: db.getDbGuid(), briefcaseId: db.getBriefcaseId(), changeSetId: db.getParentChangeSetId(), fileSize }); db.closeIModel(); } catch (_err) { } @@ -249,12 +250,14 @@ export class BriefcaseManager { }; await CheckpointManager.downloadCheckpoint(args); + const fileSize = IModelJsFs.lstatSync(fileName)?.size ?? 0; const response: LocalBriefcaseProps = { fileName, briefcaseId, iModelId: request.iModelId, contextId: request.contextId, changeSetId: args.checkpoint.changeSetId, + fileSize, }; // now open the downloaded checkpoint and reset its BriefcaseId diff --git a/core/backend/src/NativeHost.ts b/core/backend/src/NativeHost.ts index a72886c1d2f6..1870007f4aeb 100644 --- a/core/backend/src/NativeHost.ts +++ b/core/backend/src/NativeHost.ts @@ -6,13 +6,13 @@ * @module NativeApp */ -import * as path from "path"; import { BeEvent, ClientRequestContext, Config, GuidString, SessionProps } from "@bentley/bentleyjs-core"; import { BriefcaseProps, InternetConnectivityStatus, LocalBriefcaseProps, NativeAppAuthorizationConfiguration, nativeAppChannel, NativeAppFunctions, - NativeAppNotifications, nativeAppNotify, OverriddenBy, RequestNewBriefcaseProps, StorageValue, + NativeAppNotifications, nativeAppNotify, OverriddenBy, RequestNewBriefcaseProps, RpcInterfaceDefinition, StorageValue, } from "@bentley/imodeljs-common"; import { AccessToken, AccessTokenProps, ImsAuthorizationClient, RequestGlobalOptions } from "@bentley/itwin-client"; +import * as path from "path"; import { BriefcaseManager } from "./BriefcaseManager"; import { Downloads } from "./CheckpointManager"; import { IModelHost } from "./IModelHost"; @@ -33,6 +33,8 @@ export abstract class NativeAppAuthorizationBackend extends ImsAuthorizationClie return undefined !== this._accessToken && !this._accessToken.isExpired(this._expireSafety); } public setAccessToken(token?: AccessToken) { + if (this._accessToken === token) + return; this._accessToken = token; NativeHost.onUserStateChanged.raiseEvent(this._accessToken); } @@ -165,8 +167,19 @@ class NativeAppHandler extends IpcHandler implements NativeAppFunctions { } } +/** + * Options for [[NativeHost.startup]] + * @beta + */ +export interface NativeHostOptions { + /** list of RPC interface definitions to register */ + rpcInterfaces?: RpcInterfaceDefinition[]; +} + /** @beta */ -export type NativeHostOpts = IpcHostOpts; +export interface NativeHostOpts extends IpcHostOpts { + nativeHost?: NativeHostOptions; +} /** * Used by desktop/mobile native applications diff --git a/core/common/src/BriefcaseTypes.ts b/core/common/src/BriefcaseTypes.ts index f2de28c201e0..24e33eb8169b 100644 --- a/core/common/src/BriefcaseTypes.ts +++ b/core/common/src/BriefcaseTypes.ts @@ -116,6 +116,9 @@ export interface LocalBriefcaseProps { /** The current changeSetId. */ changeSetId: GuidString; + + /** Size of the briefcase file in bytes */ + fileSize: number; } /** Properties for downloading a briefcase to a local file, from iModelHub. diff --git a/core/electron-manager/src/backend/ElectronAuthorizationBackend.ts b/core/electron-manager/src/backend/ElectronAuthorizationBackend.ts index 2d045df69ba3..ceb19df34447 100644 --- a/core/electron-manager/src/backend/ElectronAuthorizationBackend.ts +++ b/core/electron-manager/src/backend/ElectronAuthorizationBackend.ts @@ -133,7 +133,7 @@ export class ElectronAuthorizationBackend extends NativeAppAuthorizationBackend if (!tokenResponse) await this.clearTokenResponse(); else - this.setAccessToken(await this.setTokenResponse(tokenResponse)); + await this.setTokenResponse(tokenResponse); }); // Start the signin @@ -204,12 +204,14 @@ export class ElectronAuthorizationBackend extends NativeAppAuthorizationBackend private async clearTokenResponse() { this._tokenResponse = undefined; await this.tokenStore.delete(); + this.setAccessToken(undefined); } private async setTokenResponse(tokenResponse: TokenResponse): Promise { const accessToken = await this.createAccessTokenFromResponse(tokenResponse); this._tokenResponse = tokenResponse; await this.tokenStore.save(this._tokenResponse); + this.setAccessToken(accessToken); return accessToken; } diff --git a/core/electron-manager/src/backend/ElectronHost.ts b/core/electron-manager/src/backend/ElectronHost.ts index d0bb4a9c0640..e9f7ad086cb8 100644 --- a/core/electron-manager/src/backend/ElectronHost.ts +++ b/core/electron-manager/src/backend/ElectronHost.ts @@ -13,7 +13,7 @@ import * as fs from "fs"; import * as path from "path"; import { BeDuration, IModelStatus, ProcessDetector } from "@bentley/bentleyjs-core"; import { IModelHost, IpcHandler, IpcHost, NativeHost, NativeHostOpts } from "@bentley/imodeljs-backend"; -import { IModelError, IpcListener, IpcSocketBackend, RemoveFunction, RpcConfiguration, RpcInterfaceDefinition } from "@bentley/imodeljs-common"; +import { IModelError, IpcListener, IpcSocketBackend, RemoveFunction, RpcConfiguration } from "@bentley/imodeljs-common"; import { ElectronRpcConfiguration, ElectronRpcManager } from "../common/ElectronRpcManager"; import { ElectronAuthorizationBackend } from "./ElectronAuthorizationBackend"; @@ -53,8 +53,6 @@ export interface ElectronHostOptions { developmentServer?: boolean; /** port number for development server. Default is 3000 */ frontendPort?: number; - /** list of RPC interface definitions to register */ - rpcInterfaces?: RpcInterfaceDefinition[]; /** list of [IpcHandler]($common) classes to register */ ipcHandlers?: (typeof IpcHandler)[]; } @@ -205,7 +203,7 @@ export class ElectronHost { this.webResourcesPath = eopt?.webResourcesPath ?? ""; this.frontendURL = eopt?.frontendURL ?? (this._developmentServer ? `http://localhost:${frontendPort}` : `${this._electronFrontend}index.html`); this.appIconPath = path.join(this.webResourcesPath, eopt?.iconName ?? "appicon.ico"); - this.rpcConfig = ElectronRpcManager.initializeBackend(this._ipc, eopt?.rpcInterfaces); + this.rpcConfig = ElectronRpcManager.initializeBackend(this._ipc, opts?.nativeHost?.rpcInterfaces); } opts = opts ?? {}; opts.ipcHost = opts.ipcHost ?? {}; diff --git a/core/mobile-manager/src/backend/MobileHost.ts b/core/mobile-manager/src/backend/MobileHost.ts index 777d20cb14ac..12ef52f7d364 100644 --- a/core/mobile-manager/src/backend/MobileHost.ts +++ b/core/mobile-manager/src/backend/MobileHost.ts @@ -8,6 +8,7 @@ import { IModelHost, IpcHandler, IpcHost, NativeHost, NativeHostOpts } from "@be import { NativeAppAuthorizationConfiguration } from "@bentley/imodeljs-common"; import { CancelRequest, DownloadFailed, ProgressCallback, UserCancelledError } from "@bentley/itwin-client"; import { BatteryState, DeviceEvents, mobileAppChannel, MobileAppFunctions, Orientation } from "../common/MobileAppProps"; +import { MobileRpcManager } from "../common/MobileRpcManager"; import { MobileAuthorizationBackend } from "../MobileBackend"; import { setupMobileRpc } from "./MobileRpcServer"; @@ -146,5 +147,8 @@ export class MobileHost { if (IpcHost.isValid) MobileAppHandler.register(); IModelHost.authorizationClient = new MobileAuthorizationBackend(); + + const rpcInterfaces = opt?.nativeHost?.rpcInterfaces ?? []; + MobileRpcManager.initializeImpl(rpcInterfaces); } } diff --git a/core/mobile-manager/src/backend/iOSHost.ts b/core/mobile-manager/src/backend/iOSHost.ts index 4f7196b24572..0e4a40582106 100644 --- a/core/mobile-manager/src/backend/iOSHost.ts +++ b/core/mobile-manager/src/backend/iOSHost.ts @@ -6,12 +6,15 @@ import { IpcWebSocketBackend } from "@bentley/imodeljs-common"; import { MobileDevice, MobileHost, MobileHostOpts } from "./MobileHost"; +/** @beta */ +export type IOSHostOpts = MobileHostOpts; + /** @beta */ export class IOSHost extends MobileHost { /** * Start the backend of an IOS app. */ - public static async startup(opt?: MobileHostOpts): Promise { + public static async startup(opt?: IOSHostOpts): Promise { const device = opt?.mobileHost?.device ?? new (MobileDevice as any)(); // The abstract functions of MobileDevice are implemented at runtime in native code. (global as any).__iTwinJsNativeBridge = device; // for native side diff --git a/core/mobile-manager/src/frontend/IOSApp.ts b/core/mobile-manager/src/frontend/IOSApp.ts index 5161810c86ac..68da9a2dc96c 100644 --- a/core/mobile-manager/src/frontend/IOSApp.ts +++ b/core/mobile-manager/src/frontend/IOSApp.ts @@ -3,15 +3,18 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { IModelAppOptions } from "@bentley/imodeljs-frontend"; +import { NativeAppOpts } from "@bentley/imodeljs-frontend"; import { MobileApp } from "./MobileApp"; +/** @beta */ +export type IOSAppOpts = NativeAppOpts; + /** @beta */ export class IOSApp { private static _isValid = false; public static get isValid() { return this._isValid; } - public static async startup(opts?: { iModelApp?: IModelAppOptions }) { + public static async startup(opts?: IOSAppOpts) { if (!this._isValid) { this._isValid = true; } diff --git a/example-code/app/src/backend/RobotWorldRpcImpl.ts b/example-code/app/src/backend/RobotWorldRpcImpl.ts index 4e06d9cbcd8d..f54f7453f31b 100644 --- a/example-code/app/src/backend/RobotWorldRpcImpl.ts +++ b/example-code/app/src/backend/RobotWorldRpcImpl.ts @@ -60,7 +60,7 @@ export function initializeRpcImplBentleyCloud(interfaces: RpcInterfaceDefinition import { ElectronHost } from "@bentley/electron-manager/lib/ElectronBackend"; export async function initializeForElectron(rpcInterfaces: RpcInterfaceDefinition[]) { - await ElectronHost.startup({ electronHost: { rpcInterfaces } }); + await ElectronHost.startup({ nativeHost: { rpcInterfaces } }); } // __PUBLISH_EXTRACT_END__ diff --git a/full-stack-tests/core/src/backend/backend.ts b/full-stack-tests/core/src/backend/backend.ts index 3617ac9909dc..12f07b96200f 100644 --- a/full-stack-tests/core/src/backend/backend.ts +++ b/full-stack-tests/core/src/backend/backend.ts @@ -36,7 +36,7 @@ async function init() { iModelHost.concurrentQuery.pollInterval = 5; iModelHost.imodelClient = new IModelHubClient(new AzureFileHandler()); if (ProcessDetector.isElectronAppBackend) { - await ElectronHost.startup({ electronHost: { rpcInterfaces }, iModelHost }); + await ElectronHost.startup({ nativeHost: { rpcInterfaces }, iModelHost }); EditCommandAdmin.registerModule(testCommands); EditCommandAdmin.register(BasicManipulationCommand); } else { diff --git a/full-stack-tests/native-app/src/backend/backend.ts b/full-stack-tests/native-app/src/backend/backend.ts index 12dcc46285d3..684b50c531c9 100644 --- a/full-stack-tests/native-app/src/backend/backend.ts +++ b/full-stack-tests/native-app/src/backend/backend.ts @@ -52,6 +52,6 @@ async function init() { iModelHost.concurrentQuery.concurrent = 2; iModelHost.concurrentQuery.pollInterval = 5; iModelHost.cacheDir = path.join(__dirname, "out"); - await ElectronHost.startup({ electronHost: { rpcInterfaces }, iModelHost }); + await ElectronHost.startup({ nativeHost: { rpcInterfaces }, iModelHost }); } module.exports = init(); diff --git a/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts b/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts index d64272d4a5c8..683518e34466 100644 --- a/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts +++ b/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts @@ -16,7 +16,7 @@ export async function commonSetup(): Promise { // Start the backend if (ProcessDetector.isElectronAppBackend) - await ElectronHost.startup({ electronHost: { rpcInterfaces } }); + await ElectronHost.startup({ nativeHost: { rpcInterfaces } }); else await IModelHost.startup(); diff --git a/test-apps/display-performance-test-app/src/backend/backend.ts b/test-apps/display-performance-test-app/src/backend/backend.ts index 272ccc3c3783..6100fa5f7315 100644 --- a/test-apps/display-performance-test-app/src/backend/backend.ts +++ b/test-apps/display-performance-test-app/src/backend/backend.ts @@ -17,7 +17,7 @@ export async function initializeBackend() { if (ProcessDetector.isElectronAppBackend) { const rpcInterfaces = [DisplayPerfRpcInterface, IModelTileRpcInterface, SnapshotIModelRpcInterface, IModelReadRpcInterface]; - await ElectronHost.startup({ electronHost: { webResourcesPath: path.join(__dirname, "..", "..", "build"), rpcInterfaces } }); + await ElectronHost.startup({ electronHost: { webResourcesPath: path.join(__dirname, "..", "..", "build") }, nativeHost: { rpcInterfaces } }); } else await IModelHost.startup(); } diff --git a/test-apps/display-test-app/src/backend/Backend.ts b/test-apps/display-test-app/src/backend/Backend.ts index a044386cd391..d41b8bf9ac80 100644 --- a/test-apps/display-test-app/src/backend/Backend.ts +++ b/test-apps/display-test-app/src/backend/Backend.ts @@ -9,7 +9,7 @@ import { Logger, LogLevel, ProcessDetector } from "@bentley/bentleyjs-core"; import { loadEnv } from "@bentley/config-loader"; import { ElectronHost, ElectronHostOptions } from "@bentley/electron-manager/lib/ElectronBackend"; import { IModelBankClient } from "@bentley/imodelhub-client"; -import { IModelHost, IModelHostConfiguration, LocalhostIpcHost } from "@bentley/imodeljs-backend"; +import { IModelHost, IModelHostConfiguration, LocalhostIpcHost, NativeHostOptions } from "@bentley/imodeljs-backend"; import { IModelReadRpcInterface, IModelTileRpcInterface, IModelWriteRpcInterface, RpcInterfaceDefinition, RpcManager, SnapshotIModelRpcInterface, @@ -246,15 +246,19 @@ export const initializeDtaBackend = async (electronHost?: ElectronHostOptions) = logLevel = Logger.parseLogLevel(logLevelEnv); } + const nativeHost: NativeHostOptions = { + rpcInterfaces: getRpcInterfaces(), + }; + /** register the implementation of our RPCs. */ RpcManager.registerImpl(DtaRpcInterface, DisplayTestAppRpc); if (ProcessDetector.isElectronAppBackend) { - await ElectronHost.startup({ electronHost, iModelHost }); + await ElectronHost.startup({ electronHost, iModelHost, nativeHost }); EditCommandAdmin.register(BasicManipulationCommand); } else if (ProcessDetector.isIOSAppBackend) { - await IOSHost.startup({ iModelHost }); + await IOSHost.startup({ iModelHost, nativeHost }); } else if (ProcessDetector.isAndroidAppBackend) { - await AndroidHost.startup({ iModelHost }); + await AndroidHost.startup({ iModelHost, nativeHost }); } else { await LocalhostIpcHost.startup({ iModelHost }); } diff --git a/test-apps/display-test-app/src/backend/DtaElectronMain.ts b/test-apps/display-test-app/src/backend/DtaElectronMain.ts index 4e35f14306f1..694544450473 100644 --- a/test-apps/display-test-app/src/backend/DtaElectronMain.ts +++ b/test-apps/display-test-app/src/backend/DtaElectronMain.ts @@ -6,7 +6,7 @@ import * as path from "path"; import { assert } from "@bentley/bentleyjs-core"; import { ElectronHost, ElectronHostOptions } from "@bentley/electron-manager/lib/ElectronBackend"; import { dtaChannel, DtaIpcInterface } from "../common/DtaIpcInterface"; -import { getRpcInterfaces, initializeDtaBackend } from "./Backend"; +import { initializeDtaBackend } from "./Backend"; import { IpcHandler } from "@bentley/imodeljs-backend"; const getWindowSize = () => { @@ -42,15 +42,14 @@ class DtaHandler extends IpcHandler implements DtaIpcInterface { * that starts from the file "index.ts". That launches the iModel.js frontend (IModelApp). */ const dtaElectronMain = async () => { - const opts: ElectronHostOptions = { + const electronHost: ElectronHostOptions = { webResourcesPath: path.join(__dirname, "..", "..", "build"), iconName: "display-test-app.ico", - rpcInterfaces: getRpcInterfaces(), ipcHandlers: [DtaHandler], developmentServer: process.env.NODE_ENV === "development", }; - await initializeDtaBackend(opts); + await initializeDtaBackend(electronHost); const autoOpenDevTools = (undefined === process.env.SVT_NO_DEV_TOOLS); const maximizeWindow = (undefined === process.env.SVT_NO_MAXIMIZE_WINDOW); diff --git a/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts b/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts index 879554ca48e2..d3968c3fbd09 100644 --- a/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts +++ b/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts @@ -5,6 +5,7 @@ import * as path from "path"; import { ElectronHost, ElectronHostOptions } from "@bentley/electron-manager/lib/ElectronBackend"; import { RpcInterfaceDefinition } from "@bentley/imodeljs-common"; +import { NativeHostOptions } from "@bentley/imodeljs-backend"; /** * Initializes Electron backend @@ -16,11 +17,14 @@ export default async function initialize(rpcInterfaces: RpcInterfaceDefinition[] const electronHost: ElectronHostOptions = { webResourcesPath: path.join(__dirname, "..", "..", "..", "build"), - rpcInterfaces, developmentServer: process.env.NODE_ENV === "development", }; - await ElectronHost.startup({ electronHost }); + const nativeHost: NativeHostOptions = { + rpcInterfaces, + }; + + await ElectronHost.startup({ electronHost, nativeHost }); await ElectronHost.openMainWindow(); // __PUBLISH_EXTRACT_END__ diff --git a/test-apps/ui-test-app/src/backend/electron/ElectronMain.ts b/test-apps/ui-test-app/src/backend/electron/ElectronMain.ts index a330fb0379a8..3e4326843811 100644 --- a/test-apps/ui-test-app/src/backend/electron/ElectronMain.ts +++ b/test-apps/ui-test-app/src/backend/electron/ElectronMain.ts @@ -2,11 +2,12 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import * as path from "path"; import { assert } from "@bentley/bentleyjs-core"; import { ElectronHost, ElectronHostOptions } from "@bentley/electron-manager/lib/ElectronBackend"; -import { getSupportedRpcs } from "../../common/rpcs"; +import { NativeHostOptions } from "@bentley/imodeljs-backend"; import { BasicManipulationCommand, EditCommandAdmin } from "@bentley/imodeljs-editor-backend"; +import * as path from "path"; +import { getSupportedRpcs } from "../../common/rpcs"; /** * Initializes Electron backend @@ -17,11 +18,14 @@ const maximizeWindow = (undefined === process.env.SVT_NO_MAXIMIZE_WINDOW); export async function initializeElectron() { const electronHost: ElectronHostOptions = { webResourcesPath: path.join(__dirname, "..", "..", "..", "build"), - rpcInterfaces: getSupportedRpcs(), developmentServer: process.env.NODE_ENV === "development", }; - await ElectronHost.startup({ electronHost }); + const nativeHost: NativeHostOptions = { + rpcInterfaces: getSupportedRpcs(), + }; + + await ElectronHost.startup({ electronHost, nativeHost }); EditCommandAdmin.register(BasicManipulationCommand); // Handle custom keyboard shortcuts From 5c52333108f6820849243a11ecbf4faee07b17b7 Mon Sep 17 00:00:00 2001 From: "Ramanujam.Raman" <32458710+ramanujam-raman@users.noreply.github.com> Date: Wed, 24 Mar 2021 19:50:02 -0400 Subject: [PATCH 2/6] Change logs. --- .../native-fixes_2021-03-24-23-49.json | 11 +++++++++++ .../native-fixes_2021-03-24-23-49.json | 11 +++++++++++ .../native-fixes_2021-03-24-23-49.json | 11 +++++++++++ .../mobile-manager/native-fixes_2021-03-24-23-49.json | 11 +++++++++++ 4 files changed, 44 insertions(+) create mode 100644 common/changes/@bentley/electron-manager/native-fixes_2021-03-24-23-49.json create mode 100644 common/changes/@bentley/imodeljs-backend/native-fixes_2021-03-24-23-49.json create mode 100644 common/changes/@bentley/imodeljs-common/native-fixes_2021-03-24-23-49.json create mode 100644 common/changes/@bentley/mobile-manager/native-fixes_2021-03-24-23-49.json diff --git a/common/changes/@bentley/electron-manager/native-fixes_2021-03-24-23-49.json b/common/changes/@bentley/electron-manager/native-fixes_2021-03-24-23-49.json new file mode 100644 index 000000000000..0b73cdb1421c --- /dev/null +++ b/common/changes/@bentley/electron-manager/native-fixes_2021-03-24-23-49.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/electron-manager", + "comment": "Fixes to desktop and iOS apps. ", + "type": "none" + } + ], + "packageName": "@bentley/electron-manager", + "email": "32458710+ramanujam-raman@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/imodeljs-backend/native-fixes_2021-03-24-23-49.json b/common/changes/@bentley/imodeljs-backend/native-fixes_2021-03-24-23-49.json new file mode 100644 index 000000000000..92c774a49be1 --- /dev/null +++ b/common/changes/@bentley/imodeljs-backend/native-fixes_2021-03-24-23-49.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/imodeljs-backend", + "comment": "Fixes to desktop and iOS apps.", + "type": "none" + } + ], + "packageName": "@bentley/imodeljs-backend", + "email": "32458710+ramanujam-raman@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/imodeljs-common/native-fixes_2021-03-24-23-49.json b/common/changes/@bentley/imodeljs-common/native-fixes_2021-03-24-23-49.json new file mode 100644 index 000000000000..83f513ae0b1b --- /dev/null +++ b/common/changes/@bentley/imodeljs-common/native-fixes_2021-03-24-23-49.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/imodeljs-common", + "comment": "Fixes to desktop and iOS apps.", + "type": "none" + } + ], + "packageName": "@bentley/imodeljs-common", + "email": "32458710+ramanujam-raman@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/changes/@bentley/mobile-manager/native-fixes_2021-03-24-23-49.json b/common/changes/@bentley/mobile-manager/native-fixes_2021-03-24-23-49.json new file mode 100644 index 000000000000..9717062131e2 --- /dev/null +++ b/common/changes/@bentley/mobile-manager/native-fixes_2021-03-24-23-49.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@bentley/mobile-manager", + "comment": "Fixes to desktop and iOS apps.", + "type": "none" + } + ], + "packageName": "@bentley/mobile-manager", + "email": "32458710+ramanujam-raman@users.noreply.github.com" +} \ No newline at end of file From 9d05efb6e9cba485463a66de40be0d9d62155b7b Mon Sep 17 00:00:00 2001 From: Keith Bentley <33296803+kabentley@users.noreply.github.com> Date: Thu, 25 Mar 2021 06:59:47 -0400 Subject: [PATCH 3/6] fixes --- core/backend/src/NativeHost.ts | 23 ++++++------------- .../src/backend/electron/ElectronMain.ts | 22 +++++++++--------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/core/backend/src/NativeHost.ts b/core/backend/src/NativeHost.ts index f5db9d47c0e8..5e410e4552a7 100644 --- a/core/backend/src/NativeHost.ts +++ b/core/backend/src/NativeHost.ts @@ -6,13 +6,13 @@ * @module NativeApp */ +import { join } from "path"; import { BeEvent, ClientRequestContext, Config, GuidString, SessionProps } from "@bentley/bentleyjs-core"; import { BriefcaseProps, InternetConnectivityStatus, LocalBriefcaseProps, NativeAppAuthorizationConfiguration, nativeAppChannel, NativeAppFunctions, NativeAppNotifications, nativeAppNotify, OverriddenBy, RequestNewBriefcaseProps, RpcInterfaceDefinition, StorageValue, } from "@bentley/imodeljs-common"; import { AccessToken, AccessTokenProps, ImsAuthorizationClient, RequestGlobalOptions } from "@bentley/itwin-client"; -import * as path from "path"; import { BriefcaseManager } from "./BriefcaseManager"; import { Downloads } from "./CheckpointManager"; import { IModelHost } from "./IModelHost"; @@ -35,7 +35,7 @@ export abstract class NativeAppAuthorizationBackend extends ImsAuthorizationClie public setAccessToken(token?: AccessToken) { const wasToken = this._accessToken !== undefined; this._accessToken = token; - if (wasToken !== (token === undefined)) + if (wasToken !== (token === undefined)) // only send event if token goes from undefined to defined or vice versa NativeHost.onUserStateChanged.raiseEvent(token); } public async getAccessToken(): Promise { @@ -166,23 +166,15 @@ class NativeAppHandler extends IpcHandler implements NativeAppFunctions { } /** - * Options for [[NativeHost.startup]] * @beta */ -export interface NativeHostOptions { - /** list of RPC interface definitions to register */ - rpcInterfaces?: RpcInterfaceDefinition[]; -} - -/** @beta */ export interface NativeHostOpts extends IpcHostOpts { -<<<<<<< HEAD - nativeHost?: NativeHostOptions; -======= nativeHost?: { + /** Application named. Used to name settings file */ applicationName?: string; + /** list of RPC interface definitions to register */ + rpcInterfaces?: RpcInterfaceDefinition[]; }; ->>>>>>> master } /** @@ -206,9 +198,8 @@ export class NativeHost { /** Get the local cache folder for application settings */ public static get appSettingsCacheDir(): string { - if (this._appSettingsCacheDir === undefined) { - this._appSettingsCacheDir = path.join(IModelHost.cacheDir, "appSettings"); - } + if (this._appSettingsCacheDir === undefined) + this._appSettingsCacheDir = join(IModelHost.cacheDir, "appSettings"); return this._appSettingsCacheDir; } diff --git a/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts b/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts index d3968c3fbd09..43c4d758a7a5 100644 --- a/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts +++ b/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts @@ -3,9 +3,8 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import * as path from "path"; -import { ElectronHost, ElectronHostOptions } from "@bentley/electron-manager/lib/ElectronBackend"; +import { ElectronHost } from "@bentley/electron-manager/lib/ElectronBackend"; import { RpcInterfaceDefinition } from "@bentley/imodeljs-common"; -import { NativeHostOptions } from "@bentley/imodeljs-backend"; /** * Initializes Electron backend @@ -15,16 +14,17 @@ export default async function initialize(rpcInterfaces: RpcInterfaceDefinition[] // __PUBLISH_EXTRACT_START__ Presentation.Backend.RpcInterface - const electronHost: ElectronHostOptions = { - webResourcesPath: path.join(__dirname, "..", "..", "..", "build"), - developmentServer: process.env.NODE_ENV === "development", - }; + const opts = { + electronHost: { + webResourcesPath: path.join(__dirname, "..", "..", "..", "build"), + developmentServer: process.env.NODE_ENV === "development", + }, + nativeHost: { + rpcInterfaces, + }, + } - const nativeHost: NativeHostOptions = { - rpcInterfaces, - }; - - await ElectronHost.startup({ electronHost, nativeHost }); + await ElectronHost.startup(opts); await ElectronHost.openMainWindow(); // __PUBLISH_EXTRACT_END__ From f5cdd7857d9fb9a89e9e1c58673f2f8d29fcd988 Mon Sep 17 00:00:00 2001 From: Keith Bentley <33296803+kabentley@users.noreply.github.com> Date: Thu, 25 Mar 2021 08:47:07 -0400 Subject: [PATCH 4/6] reverse breaking change. Add rpcInterface to mobileHost --- common/api/electron-manager.api.md | 2 ++ common/api/imodeljs-backend.api.md | 2 -- common/api/mobile-manager.api.md | 1 + core/backend/src/NativeHost.ts | 14 +++++--------- .../src/backend/ElectronHost.ts | 6 ++++-- core/mobile-manager/src/backend/MobileHost.ts | 7 +++++-- .../app/src/backend/RobotWorldRpcImpl.ts | 2 +- full-stack-tests/core/src/backend/backend.ts | 2 +- .../native-app/src/backend/backend.ts | 2 +- .../rpc/src/backend/CommonBackendSetup.ts | 2 +- .../src/backend/backend.ts | 2 +- .../display-test-app/src/backend/Backend.ts | 4 +++- .../src/backend/DtaElectronMain.ts | 7 ++++--- .../src/backend/electron/ElectronMain.ts | 18 +++++++----------- .../src/backend/electron/ElectronMain.ts | 4 ++-- 15 files changed, 38 insertions(+), 37 deletions(-) diff --git a/common/api/electron-manager.api.md b/common/api/electron-manager.api.md index f6e303879581..8df6c9bb76df 100644 --- a/common/api/electron-manager.api.md +++ b/common/api/electron-manager.api.md @@ -12,6 +12,7 @@ import { NativeAppOpts } from '@bentley/imodeljs-frontend'; import { NativeHostOpts } from '@bentley/imodeljs-backend'; import { PromiseReturnType } from '@bentley/imodeljs-frontend'; import { RpcConfiguration } from '@bentley/imodeljs-common'; +import { RpcInterfaceDefinition } from '@bentley/imodeljs-common'; // @beta export class ElectronApp { @@ -61,6 +62,7 @@ export interface ElectronHostOptions { frontendURL?: string; iconName?: string; ipcHandlers?: (typeof IpcHandler)[]; + rpcInterfaces?: RpcInterfaceDefinition[]; webResourcesPath?: string; } diff --git a/common/api/imodeljs-backend.api.md b/common/api/imodeljs-backend.api.md index 87318727f2a8..20bc94259516 100644 --- a/common/api/imodeljs-backend.api.md +++ b/common/api/imodeljs-backend.api.md @@ -162,7 +162,6 @@ import { RenderMaterialProps } from '@bentley/imodeljs-common'; import { RenderSchedule } from '@bentley/imodeljs-common'; import { RepositoryLinkProps } from '@bentley/imodeljs-common'; import { RequestNewBriefcaseProps } from '@bentley/imodeljs-common'; -import { RpcInterfaceDefinition } from '@bentley/imodeljs-common'; import { Schema as Schema_2 } from '@bentley/ecschema-metadata'; import { SchemaState } from '@bentley/imodeljs-common'; import { SectionDrawingLocationProps } from '@bentley/imodeljs-common'; @@ -3489,7 +3488,6 @@ export interface NativeHostOpts extends IpcHostOpts { // (undocumented) nativeHost?: { applicationName?: string; - rpcInterfaces?: RpcInterfaceDefinition[]; }; } diff --git a/common/api/mobile-manager.api.md b/common/api/mobile-manager.api.md index fc557f3bd021..f95698210529 100644 --- a/common/api/mobile-manager.api.md +++ b/common/api/mobile-manager.api.md @@ -176,6 +176,7 @@ export interface MobileHostOpts extends NativeHostOpts { // (undocumented) mobileHost?: { device?: MobileDevice; + rpcInterfaces?: RpcInterfaceDefinition[]; }; } diff --git a/core/backend/src/NativeHost.ts b/core/backend/src/NativeHost.ts index 5e410e4552a7..3c9e75ed605d 100644 --- a/core/backend/src/NativeHost.ts +++ b/core/backend/src/NativeHost.ts @@ -10,7 +10,7 @@ import { join } from "path"; import { BeEvent, ClientRequestContext, Config, GuidString, SessionProps } from "@bentley/bentleyjs-core"; import { BriefcaseProps, InternetConnectivityStatus, LocalBriefcaseProps, NativeAppAuthorizationConfiguration, nativeAppChannel, NativeAppFunctions, - NativeAppNotifications, nativeAppNotify, OverriddenBy, RequestNewBriefcaseProps, RpcInterfaceDefinition, StorageValue, + NativeAppNotifications, nativeAppNotify, OverriddenBy, RequestNewBriefcaseProps, StorageValue, } from "@bentley/imodeljs-common"; import { AccessToken, AccessTokenProps, ImsAuthorizationClient, RequestGlobalOptions } from "@bentley/itwin-client"; import { BriefcaseManager } from "./BriefcaseManager"; @@ -33,10 +33,10 @@ export abstract class NativeAppAuthorizationBackend extends ImsAuthorizationClie return undefined !== this._accessToken && !this._accessToken.isExpired(this._expireSafety); } public setAccessToken(token?: AccessToken) { - const wasToken = this._accessToken !== undefined; + if (token === this._accessToken) + return; this._accessToken = token; - if (wasToken !== (token === undefined)) // only send event if token goes from undefined to defined or vice versa - NativeHost.onUserStateChanged.raiseEvent(token); + NativeHost.onUserStateChanged.raiseEvent(token); } public async getAccessToken(): Promise { if (!this.isAuthorized) @@ -165,15 +165,11 @@ class NativeAppHandler extends IpcHandler implements NativeAppFunctions { } } -/** - * @beta - */ +/** @beta */ export interface NativeHostOpts extends IpcHostOpts { nativeHost?: { /** Application named. Used to name settings file */ applicationName?: string; - /** list of RPC interface definitions to register */ - rpcInterfaces?: RpcInterfaceDefinition[]; }; } diff --git a/core/electron-manager/src/backend/ElectronHost.ts b/core/electron-manager/src/backend/ElectronHost.ts index 11747c7811e7..7298a7f5a1a7 100644 --- a/core/electron-manager/src/backend/ElectronHost.ts +++ b/core/electron-manager/src/backend/ElectronHost.ts @@ -13,7 +13,7 @@ import * as fs from "fs"; import * as path from "path"; import { BeDuration, IModelStatus, ProcessDetector } from "@bentley/bentleyjs-core"; import { IModelHost, IpcHandler, IpcHost, NativeHost, NativeHostOpts } from "@bentley/imodeljs-backend"; -import { IModelError, IpcListener, IpcSocketBackend, RemoveFunction, RpcConfiguration } from "@bentley/imodeljs-common"; +import { IModelError, IpcListener, IpcSocketBackend, RemoveFunction, RpcConfiguration, RpcInterfaceDefinition } from "@bentley/imodeljs-common"; import { ElectronRpcConfiguration, ElectronRpcManager } from "../common/ElectronRpcManager"; import { ElectronAuthorizationBackend } from "./ElectronAuthorizationBackend"; @@ -53,6 +53,8 @@ export interface ElectronHostOptions { developmentServer?: boolean; /** port number for development server. Default is 3000 */ frontendPort?: number; + /** list of RPC interface definitions to register */ + rpcInterfaces?: RpcInterfaceDefinition[]; /** list of [IpcHandler]($common) classes to register */ ipcHandlers?: (typeof IpcHandler)[]; /** name of application. Used for naming settings file. */ @@ -258,7 +260,7 @@ export class ElectronHost { this.webResourcesPath = eopt?.webResourcesPath ?? ""; this.frontendURL = eopt?.frontendURL ?? (this._developmentServer ? `http://localhost:${frontendPort}` : `${this._electronFrontend}index.html`); this.appIconPath = path.join(this.webResourcesPath, eopt?.iconName ?? "appicon.ico"); - this.rpcConfig = ElectronRpcManager.initializeBackend(this._ipc, opts?.nativeHost?.rpcInterfaces); + this.rpcConfig = ElectronRpcManager.initializeBackend(this._ipc, eopt?.rpcInterfaces); } opts = opts ?? {}; diff --git a/core/mobile-manager/src/backend/MobileHost.ts b/core/mobile-manager/src/backend/MobileHost.ts index 12ef52f7d364..e8cc17721e04 100644 --- a/core/mobile-manager/src/backend/MobileHost.ts +++ b/core/mobile-manager/src/backend/MobileHost.ts @@ -5,7 +5,7 @@ import { BeEvent, BriefcaseStatus, ClientRequestContext, Logger } from "@bentley/bentleyjs-core"; import { IModelHost, IpcHandler, IpcHost, NativeHost, NativeHostOpts } from "@bentley/imodeljs-backend"; -import { NativeAppAuthorizationConfiguration } from "@bentley/imodeljs-common"; +import { NativeAppAuthorizationConfiguration, RpcInterfaceDefinition } from "@bentley/imodeljs-common"; import { CancelRequest, DownloadFailed, ProgressCallback, UserCancelledError } from "@bentley/itwin-client"; import { BatteryState, DeviceEvents, mobileAppChannel, MobileAppFunctions, Orientation } from "../common/MobileAppProps"; import { MobileRpcManager } from "../common/MobileRpcManager"; @@ -78,6 +78,9 @@ class MobileAppHandler extends IpcHandler implements MobileAppFunctions { export interface MobileHostOpts extends NativeHostOpts { mobileHost?: { device?: MobileDevice; + /** list of RPC interface definitions to register */ + rpcInterfaces?: RpcInterfaceDefinition[]; + }; } @@ -148,7 +151,7 @@ export class MobileHost { MobileAppHandler.register(); IModelHost.authorizationClient = new MobileAuthorizationBackend(); - const rpcInterfaces = opt?.nativeHost?.rpcInterfaces ?? []; + const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? []; MobileRpcManager.initializeImpl(rpcInterfaces); } } diff --git a/example-code/app/src/backend/RobotWorldRpcImpl.ts b/example-code/app/src/backend/RobotWorldRpcImpl.ts index f54f7453f31b..4e06d9cbcd8d 100644 --- a/example-code/app/src/backend/RobotWorldRpcImpl.ts +++ b/example-code/app/src/backend/RobotWorldRpcImpl.ts @@ -60,7 +60,7 @@ export function initializeRpcImplBentleyCloud(interfaces: RpcInterfaceDefinition import { ElectronHost } from "@bentley/electron-manager/lib/ElectronBackend"; export async function initializeForElectron(rpcInterfaces: RpcInterfaceDefinition[]) { - await ElectronHost.startup({ nativeHost: { rpcInterfaces } }); + await ElectronHost.startup({ electronHost: { rpcInterfaces } }); } // __PUBLISH_EXTRACT_END__ diff --git a/full-stack-tests/core/src/backend/backend.ts b/full-stack-tests/core/src/backend/backend.ts index 12f07b96200f..3617ac9909dc 100644 --- a/full-stack-tests/core/src/backend/backend.ts +++ b/full-stack-tests/core/src/backend/backend.ts @@ -36,7 +36,7 @@ async function init() { iModelHost.concurrentQuery.pollInterval = 5; iModelHost.imodelClient = new IModelHubClient(new AzureFileHandler()); if (ProcessDetector.isElectronAppBackend) { - await ElectronHost.startup({ nativeHost: { rpcInterfaces }, iModelHost }); + await ElectronHost.startup({ electronHost: { rpcInterfaces }, iModelHost }); EditCommandAdmin.registerModule(testCommands); EditCommandAdmin.register(BasicManipulationCommand); } else { diff --git a/full-stack-tests/native-app/src/backend/backend.ts b/full-stack-tests/native-app/src/backend/backend.ts index 684b50c531c9..12dcc46285d3 100644 --- a/full-stack-tests/native-app/src/backend/backend.ts +++ b/full-stack-tests/native-app/src/backend/backend.ts @@ -52,6 +52,6 @@ async function init() { iModelHost.concurrentQuery.concurrent = 2; iModelHost.concurrentQuery.pollInterval = 5; iModelHost.cacheDir = path.join(__dirname, "out"); - await ElectronHost.startup({ nativeHost: { rpcInterfaces }, iModelHost }); + await ElectronHost.startup({ electronHost: { rpcInterfaces }, iModelHost }); } module.exports = init(); diff --git a/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts b/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts index 683518e34466..d64272d4a5c8 100644 --- a/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts +++ b/full-stack-tests/rpc/src/backend/CommonBackendSetup.ts @@ -16,7 +16,7 @@ export async function commonSetup(): Promise { // Start the backend if (ProcessDetector.isElectronAppBackend) - await ElectronHost.startup({ nativeHost: { rpcInterfaces } }); + await ElectronHost.startup({ electronHost: { rpcInterfaces } }); else await IModelHost.startup(); diff --git a/test-apps/display-performance-test-app/src/backend/backend.ts b/test-apps/display-performance-test-app/src/backend/backend.ts index 6100fa5f7315..272ccc3c3783 100644 --- a/test-apps/display-performance-test-app/src/backend/backend.ts +++ b/test-apps/display-performance-test-app/src/backend/backend.ts @@ -17,7 +17,7 @@ export async function initializeBackend() { if (ProcessDetector.isElectronAppBackend) { const rpcInterfaces = [DisplayPerfRpcInterface, IModelTileRpcInterface, SnapshotIModelRpcInterface, IModelReadRpcInterface]; - await ElectronHost.startup({ electronHost: { webResourcesPath: path.join(__dirname, "..", "..", "build") }, nativeHost: { rpcInterfaces } }); + await ElectronHost.startup({ electronHost: { webResourcesPath: path.join(__dirname, "..", "..", "build"), rpcInterfaces } }); } else await IModelHost.startup(); } diff --git a/test-apps/display-test-app/src/backend/Backend.ts b/test-apps/display-test-app/src/backend/Backend.ts index 02ef97ca63b4..26c8645448a9 100644 --- a/test-apps/display-test-app/src/backend/Backend.ts +++ b/test-apps/display-test-app/src/backend/Backend.ts @@ -250,7 +250,9 @@ export const initializeDtaBackend = async (electronHost?: ElectronHostOptions) = electronHost, nativeHost: { applicationName: "display-test-app", - rpcInterfaces: getRpcInterfaces(), + }, + mobileHost: { + rpcInterfaces: electronHost?.rpcInterfaces, }, }; diff --git a/test-apps/display-test-app/src/backend/DtaElectronMain.ts b/test-apps/display-test-app/src/backend/DtaElectronMain.ts index 666e9917ee1d..27b1cd5d79de 100644 --- a/test-apps/display-test-app/src/backend/DtaElectronMain.ts +++ b/test-apps/display-test-app/src/backend/DtaElectronMain.ts @@ -6,7 +6,7 @@ import * as path from "path"; import { assert } from "@bentley/bentleyjs-core"; import { ElectronHost, ElectronHostOptions } from "@bentley/electron-manager/lib/ElectronBackend"; import { dtaChannel, DtaIpcInterface } from "../common/DtaIpcInterface"; -import { initializeDtaBackend } from "./Backend"; +import { getRpcInterfaces, initializeDtaBackend } from "./Backend"; import { IpcHandler } from "@bentley/imodeljs-backend"; const mainWindowName = "mainWindow"; @@ -43,14 +43,15 @@ class DtaHandler extends IpcHandler implements DtaIpcInterface { * that starts from the file "index.ts". That launches the iModel.js frontend (IModelApp). */ const dtaElectronMain = async () => { - const electronHost: ElectronHostOptions = { + const opts: ElectronHostOptions = { webResourcesPath: path.join(__dirname, "..", "..", "build"), iconName: "display-test-app.ico", + rpcInterfaces: getRpcInterfaces(), ipcHandlers: [DtaHandler], developmentServer: process.env.NODE_ENV === "development", }; - await initializeDtaBackend(electronHost); + await initializeDtaBackend(opts); // Restore previous window size, position and maximized state const sizeAndPosition = getWindowSize(); diff --git a/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts b/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts index 43c4d758a7a5..879554ca48e2 100644 --- a/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts +++ b/test-apps/presentation-test-app/src/backend/electron/ElectronMain.ts @@ -3,7 +3,7 @@ * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ import * as path from "path"; -import { ElectronHost } from "@bentley/electron-manager/lib/ElectronBackend"; +import { ElectronHost, ElectronHostOptions } from "@bentley/electron-manager/lib/ElectronBackend"; import { RpcInterfaceDefinition } from "@bentley/imodeljs-common"; /** @@ -14,17 +14,13 @@ export default async function initialize(rpcInterfaces: RpcInterfaceDefinition[] // __PUBLISH_EXTRACT_START__ Presentation.Backend.RpcInterface - const opts = { - electronHost: { - webResourcesPath: path.join(__dirname, "..", "..", "..", "build"), - developmentServer: process.env.NODE_ENV === "development", - }, - nativeHost: { - rpcInterfaces, - }, - } + const electronHost: ElectronHostOptions = { + webResourcesPath: path.join(__dirname, "..", "..", "..", "build"), + rpcInterfaces, + developmentServer: process.env.NODE_ENV === "development", + }; - await ElectronHost.startup(opts); + await ElectronHost.startup({ electronHost }); await ElectronHost.openMainWindow(); // __PUBLISH_EXTRACT_END__ diff --git a/test-apps/ui-test-app/src/backend/electron/ElectronMain.ts b/test-apps/ui-test-app/src/backend/electron/ElectronMain.ts index 4a1efc2e9b8d..c9a318a47b4f 100644 --- a/test-apps/ui-test-app/src/backend/electron/ElectronMain.ts +++ b/test-apps/ui-test-app/src/backend/electron/ElectronMain.ts @@ -11,17 +11,17 @@ import { getSupportedRpcs } from "../../common/rpcs"; const mainWindowName = "mainWindow"; -/** Initializes Electron backend */ +/** Initializes Electron backend */ export async function initializeElectron() { const opt = { electronHost: { webResourcesPath: join(__dirname, "..", "..", "..", "build"), developmentServer: process.env.NODE_ENV === "development", + rpcInterfaces: getSupportedRpcs(), }, nativeHost: { applicationName: "ui-test-app", - rpcInterfaces: getSupportedRpcs(), }, }; From 87d6e6f66515ebb5ba3a5d2af9beee93799d0a9b Mon Sep 17 00:00:00 2001 From: "Ramanujam.Raman" <32458710+ramanujam-raman@users.noreply.github.com> Date: Fri, 26 Mar 2021 10:16:48 -0400 Subject: [PATCH 5/6] Fixed iOSHost.startup() and setup ui-test-app to use recent changes. --- core/mobile-manager/src/backend/iOSHost.ts | 2 +- .../src/backend/mobile/MobileMain.ts | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/core/mobile-manager/src/backend/iOSHost.ts b/core/mobile-manager/src/backend/iOSHost.ts index 0e4a40582106..5c563a2a977d 100644 --- a/core/mobile-manager/src/backend/iOSHost.ts +++ b/core/mobile-manager/src/backend/iOSHost.ts @@ -19,6 +19,6 @@ export class IOSHost extends MobileHost { // The abstract functions of MobileDevice are implemented at runtime in native code. (global as any).__iTwinJsNativeBridge = device; // for native side const socket = opt?.ipcHost?.socket ?? new IpcWebSocketBackend(); - return MobileHost.startup({ ...opt, mobileHost: { device }, ipcHost: { socket } }); + return MobileHost.startup({ ...opt, mobileHost: { ...opt?.mobileHost, device }, ipcHost: { ...opt?.ipcHost, socket } }); } } diff --git a/test-apps/ui-test-app/src/backend/mobile/MobileMain.ts b/test-apps/ui-test-app/src/backend/mobile/MobileMain.ts index dced0f3e1aee..a1db7f5746f3 100644 --- a/test-apps/ui-test-app/src/backend/mobile/MobileMain.ts +++ b/test-apps/ui-test-app/src/backend/mobile/MobileMain.ts @@ -7,7 +7,7 @@ import * as fs from "fs"; import * as path from "path"; import { Logger, LogLevel, ProcessDetector } from "@bentley/bentleyjs-core"; import { IModelReadRpcInterface, IModelTileRpcInterface, SnapshotIModelRpcInterface } from "@bentley/imodeljs-common"; -import { AndroidHost, IOSHost, MobileRpcManager } from "@bentley/mobile-manager/lib/MobileBackend"; +import { AndroidHost, IOSHost } from "@bentley/mobile-manager/lib/MobileBackend"; import { Presentation } from "@bentley/presentation-backend"; import { PresentationRpcInterface } from "@bentley/presentation-common"; @@ -22,11 +22,18 @@ import { PresentationRpcInterface } from "@bentley/presentation-common"; Logger.initializeToConsole(); Logger.setLevelDefault(LogLevel.Trace); + const rpcInterfaces = [ + IModelReadRpcInterface, + IModelTileRpcInterface, + SnapshotIModelRpcInterface, + PresentationRpcInterface, + ]; + // initialize imodeljs-backend if (ProcessDetector.isIOSAppBackend) - await IOSHost.startup(); + await IOSHost.startup({ mobileHost: { rpcInterfaces } }); else - await AndroidHost.startup(); + await AndroidHost.startup({ mobileHost: { rpcInterfaces } }); // initialize presentation-backend Presentation.initialize({ @@ -37,12 +44,6 @@ import { PresentationRpcInterface } from "@bentley/presentation-common"; updatesPollInterval: 100, }); - MobileRpcManager.initializeImpl([ - IModelReadRpcInterface, - IModelTileRpcInterface, - SnapshotIModelRpcInterface, - PresentationRpcInterface, - ]); } catch (error) { Logger.logError("ui-test-app", error); process.exitCode = 1; From 6fe7a74097bdb8b109dfbec877a129adef795ef3 Mon Sep 17 00:00:00 2001 From: "Ramanujam.Raman" <32458710+ramanujam-raman@users.noreply.github.com> Date: Fri, 26 Mar 2021 10:53:26 -0400 Subject: [PATCH 6/6] Setup default RPC interfaces in mobile and electron hosts. --- core/electron-manager/package.json | 4 +++- .../electron-manager/src/common/ElectronRpcManager.ts | 11 +++++++++-- core/mobile-manager/package.json | 4 +++- core/mobile-manager/src/backend/MobileHost.ts | 11 +++++++++-- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/core/electron-manager/package.json b/core/electron-manager/package.json index 5fedb685c78d..dccc2f89e2d9 100644 --- a/core/electron-manager/package.json +++ b/core/electron-manager/package.json @@ -35,6 +35,7 @@ "@bentley/imodeljs-frontend": "^2.15.0-dev.8", "@bentley/imodeljs-backend": "^2.15.0-dev.8", "@bentley/itwin-client": "^2.15.0-dev.8", + "@bentley/presentation-common": "^2.15.0-dev.8", "electron": "^11.1.0" }, "devDependencies": { @@ -45,6 +46,7 @@ "@bentley/imodeljs-frontend": "2.15.0-dev.8", "@bentley/imodeljs-common": "2.15.0-dev.8", "@bentley/itwin-client": "2.15.0-dev.8", + "@bentley/presentation-common": "2.15.0-dev.8", "@types/node": "10.14.1", "electron": "^11.1.0", "eslint": "^6.8.0", @@ -62,4 +64,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/core/electron-manager/src/common/ElectronRpcManager.ts b/core/electron-manager/src/common/ElectronRpcManager.ts index a263da829097..bc7bca9ed9ba 100644 --- a/core/electron-manager/src/common/ElectronRpcManager.ts +++ b/core/electron-manager/src/common/ElectronRpcManager.ts @@ -6,8 +6,9 @@ * @module RpcInterface */ +import { IModelReadRpcInterface, IModelTileRpcInterface, IModelWriteRpcInterface, IpcSocket, IpcSocketBackend, IpcSocketFrontend, RpcConfiguration, RpcInterfaceDefinition, RpcManager, SnapshotIModelRpcInterface } from "@bentley/imodeljs-common"; +import { PresentationRpcInterface } from "@bentley/presentation-common"; import { ElectronRpcProtocol } from "./ElectronRpcProtocol"; -import { IpcSocket, IpcSocketBackend, IpcSocketFrontend, RpcConfiguration, RpcInterfaceDefinition, RpcManager } from "@bentley/imodeljs-common"; /** RPC interface configuration for an Electron-based application. * @internal @@ -35,7 +36,13 @@ export class ElectronRpcManager extends RpcManager { } private static performInitialization(ipcSocket: IpcSocket, rpcs?: RpcInterfaceDefinition[]): ElectronRpcConfiguration { - const interfaces = rpcs ?? []; + const interfaces = rpcs ?? [ + IModelReadRpcInterface, + IModelTileRpcInterface, + IModelWriteRpcInterface, + SnapshotIModelRpcInterface, + PresentationRpcInterface, + ]; const config = class extends ElectronRpcConfiguration { public interfaces = () => interfaces; public protocol: ElectronRpcProtocol = new ElectronRpcProtocol(this, ipcSocket); diff --git a/core/mobile-manager/package.json b/core/mobile-manager/package.json index b9841c260160..84a7cf24eb4f 100644 --- a/core/mobile-manager/package.json +++ b/core/mobile-manager/package.json @@ -38,6 +38,7 @@ "@bentley/imodeljs-backend": "^2.15.0-dev.8", "@bentley/itwin-client": "^2.15.0-dev.8", "@bentley/imodelhub-client": "^2.15.0-dev.8", + "@bentley/presentation-common": "^2.15.0-dev.8", "ws": "^7.2.0", "js-base64": "^2.4.5" }, @@ -51,6 +52,7 @@ "@bentley/imodeljs-common": "2.15.0-dev.8", "@bentley/itwin-client": "2.15.0-dev.8", "@bentley/imodelhub-client": "2.15.0-dev.8", + "@bentley/presentation-common": "2.15.0-dev.8", "@types/node": "10.14.1", "@types/mocha": "^5.2.5", "@types/chai": "^4.1.4", @@ -74,4 +76,4 @@ ], "extends": "plugin:@bentley/imodeljs-recommended" } -} +} \ No newline at end of file diff --git a/core/mobile-manager/src/backend/MobileHost.ts b/core/mobile-manager/src/backend/MobileHost.ts index e8cc17721e04..989cd440faf5 100644 --- a/core/mobile-manager/src/backend/MobileHost.ts +++ b/core/mobile-manager/src/backend/MobileHost.ts @@ -5,8 +5,9 @@ import { BeEvent, BriefcaseStatus, ClientRequestContext, Logger } from "@bentley/bentleyjs-core"; import { IModelHost, IpcHandler, IpcHost, NativeHost, NativeHostOpts } from "@bentley/imodeljs-backend"; -import { NativeAppAuthorizationConfiguration, RpcInterfaceDefinition } from "@bentley/imodeljs-common"; +import { IModelReadRpcInterface, IModelTileRpcInterface, NativeAppAuthorizationConfiguration, RpcInterfaceDefinition, SnapshotIModelRpcInterface } from "@bentley/imodeljs-common"; import { CancelRequest, DownloadFailed, ProgressCallback, UserCancelledError } from "@bentley/itwin-client"; +import { PresentationRpcInterface } from "@bentley/presentation-common"; import { BatteryState, DeviceEvents, mobileAppChannel, MobileAppFunctions, Orientation } from "../common/MobileAppProps"; import { MobileRpcManager } from "../common/MobileRpcManager"; import { MobileAuthorizationBackend } from "../MobileBackend"; @@ -151,7 +152,13 @@ export class MobileHost { MobileAppHandler.register(); IModelHost.authorizationClient = new MobileAuthorizationBackend(); - const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? []; + const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? [ + IModelReadRpcInterface, + IModelTileRpcInterface, + SnapshotIModelRpcInterface, + PresentationRpcInterface, + ]; + MobileRpcManager.initializeImpl(rpcInterfaces); } }