Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for desktop and iOS applications. #1032

Merged
merged 21 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d5eb453
Querying for cached briefcases needs to
ramanujam-raman-zz Mar 24, 2021
5c52333
Change logs.
ramanujam-raman-zz Mar 24, 2021
2756e91
Merge branch 'master' into native-fixes
mergify[bot] Mar 25, 2021
7d2086c
Merge branch 'master' into native-fixes
mergify[bot] Mar 25, 2021
0604c6e
Merge branch 'master' into native-fixes
kabentley Mar 25, 2021
9d05efb
fixes
kabentley Mar 25, 2021
f5cdd78
reverse breaking change. Add rpcInterface to mobileHost
kabentley Mar 25, 2021
015d37c
Merge branch 'master' into native-fixes
mergify[bot] Mar 25, 2021
760ab6c
Merge branch 'master' into native-fixes
mergify[bot] Mar 25, 2021
ac336de
Merge branch 'master' into native-fixes
mergify[bot] Mar 25, 2021
fde9bc8
Merge branch 'master' into native-fixes
mergify[bot] Mar 25, 2021
4cd96a6
Merge branch 'master' into native-fixes
mergify[bot] Mar 25, 2021
bc3dfd8
Merge branch 'master' into native-fixes
mergify[bot] Mar 25, 2021
bbab4f7
Merge branch 'master' into native-fixes
mergify[bot] Mar 25, 2021
fae7746
Merge branch 'master' into native-fixes
mergify[bot] Mar 26, 2021
04888fe
Merge branch 'master' into native-fixes
mergify[bot] Mar 26, 2021
15925c8
Merge branch 'master' into native-fixes
mergify[bot] Mar 26, 2021
87d6e6f
Fixed iOSHost.startup() and setup ui-test-app to use
ramanujam-raman-zz Mar 26, 2021
6fe7a74
Setup default RPC interfaces in mobile and electron
ramanujam-raman-zz Mar 26, 2021
05e17f4
Merge branch 'master' into native-fixes
mergify[bot] Mar 26, 2021
d25a80d
Merge branch 'master' into native-fixes
mergify[bot] Mar 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/api/imodeljs-common.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4367,6 +4367,7 @@ export interface LocalBriefcaseProps {
changeSetId: GuidString;
contextId: GuidString;
fileName: string;
fileSize: number;
iModelId: GuidString;
}

Expand Down
13 changes: 9 additions & 4 deletions common/api/mobile-manager.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,20 @@ export class IOSApp {
// (undocumented)
static get isValid(): boolean;
// (undocumented)
static startup(opts?: {
iModelApp?: IModelAppOptions;
}): Promise<void>;
static startup(opts?: IOSAppOpts): Promise<void>;
}

// @beta (undocumented)
export type IOSAppOpts = NativeAppOpts;

// @beta (undocumented)
export class IOSHost extends MobileHost {
static startup(opt?: MobileHostOpts): Promise<void>;
static startup(opt?: IOSHostOpts): Promise<void>;
}

// @beta (undocumented)
export type IOSHostOpts = MobileHostOpts;

// @beta (undocumented)
export class MobileApp {
// (undocumented)
Expand Down Expand Up @@ -172,6 +176,7 @@ export interface MobileHostOpts extends NativeHostOpts {
// (undocumented)
mobileHost?: {
device?: MobileDevice;
rpcInterfaces?: RpcInterfaceDefinition[];
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
5 changes: 4 additions & 1 deletion core/backend/src/BriefcaseManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions core/backend/src/NativeHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @module NativeApp
*/

import * as path from "path";
import { join } from "path";
import { BeEvent, ClientRequestContext, Config, GuidString, SessionProps } from "@bentley/bentleyjs-core";
import {
BriefcaseProps, InternetConnectivityStatus, LocalBriefcaseProps, NativeAppAuthorizationConfiguration, nativeAppChannel, NativeAppFunctions,
Expand All @@ -33,8 +33,10 @@ export abstract class NativeAppAuthorizationBackend extends ImsAuthorizationClie
return undefined !== this._accessToken && !this._accessToken.isExpired(this._expireSafety);
}
public setAccessToken(token?: AccessToken) {
if (token === this._accessToken)
return;
this._accessToken = token;
NativeHost.onUserStateChanged.raiseEvent(this._accessToken);
NativeHost.onUserStateChanged.raiseEvent(token);
}
public async getAccessToken(): Promise<AccessToken> {
if (!this.isAuthorized)
Expand Down Expand Up @@ -166,6 +168,7 @@ class NativeAppHandler extends IpcHandler implements NativeAppFunctions {
/** @beta */
export interface NativeHostOpts extends IpcHostOpts {
nativeHost?: {
/** Application named. Used to name settings file */
applicationName?: string;
};
}
Expand All @@ -191,9 +194,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;
}

Expand Down
3 changes: 3 additions & 0 deletions core/common/src/BriefcaseTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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.
Expand Down
4 changes: 3 additions & 1 deletion core/electron-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand All @@ -62,4 +64,4 @@
],
"extends": "plugin:@bentley/imodeljs-recommended"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<AccessToken> {
const accessToken = await this.createAccessTokenFromResponse(tokenResponse);
this._tokenResponse = tokenResponse;
await this.tokenStore.save(this._tokenResponse);
this.setAccessToken(accessToken);
return accessToken;
}

Expand Down
11 changes: 9 additions & 2 deletions core/electron-manager/src/common/ElectronRpcManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion core/mobile-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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",
Expand All @@ -74,4 +76,4 @@
],
"extends": "plugin:@bentley/imodeljs-recommended"
}
}
}
16 changes: 15 additions & 1 deletion core/mobile-manager/src/backend/MobileHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

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 { 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";
import { setupMobileRpc } from "./MobileRpcServer";

Expand Down Expand Up @@ -77,6 +79,9 @@ class MobileAppHandler extends IpcHandler implements MobileAppFunctions {
export interface MobileHostOpts extends NativeHostOpts {
mobileHost?: {
device?: MobileDevice;
/** list of RPC interface definitions to register */
rpcInterfaces?: RpcInterfaceDefinition[];

};
}

Expand Down Expand Up @@ -146,5 +151,14 @@ export class MobileHost {
if (IpcHost.isValid)
MobileAppHandler.register();
IModelHost.authorizationClient = new MobileAuthorizationBackend();

const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? [
IModelReadRpcInterface,
IModelTileRpcInterface,
SnapshotIModelRpcInterface,
PresentationRpcInterface,
];

MobileRpcManager.initializeImpl(rpcInterfaces);
}
}
7 changes: 5 additions & 2 deletions core/mobile-manager/src/backend/iOSHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
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<void> {
public static async startup(opt?: IOSHostOpts): Promise<void> {
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
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 } });
}
}
7 changes: 5 additions & 2 deletions core/mobile-manager/src/frontend/IOSApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions test-apps/display-test-app/src/backend/Backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ export const initializeDtaBackend = async (electronHost?: ElectronHostOptions) =
nativeHost: {
applicationName: "display-test-app",
},
mobileHost: {
rpcInterfaces: electronHost?.rpcInterfaces,
},
};

/** register the implementation of our RPCs. */
Expand Down
Loading