Skip to content

Commit

Permalink
Add support for fdc3 open with instanceId (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnman authored Feb 12, 2024
1 parent 544f3c7 commit 6fb1a93
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 19 deletions.
1 change: 1 addition & 0 deletions how-to/workspace-platform-starter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fixed an issue where the order of entries within dock would change when toggling between light and dark theme.
- Improved performance when switching themes
- Fixed an issue where the order of Workspace component entries within dock may change when toggling between light and dark theme.
- FDC3 2.0 Open improvement - You can now specify instance id if you wish to open an existing instance of an app and optionally pass it context.

## v16.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,43 +574,73 @@ export function interopOverride(
* @returns The application identifier.
*/
public async fdc3HandleOpen(
fdc3OpenOptions: { app: PlatformApp | string; context: OpenFin.Context },
fdc3OpenOptions: { app: (PlatformApp & AppIdentifier) | string; context: OpenFin.Context },
clientIdentity: OpenFin.ClientIdentity
): Promise<AppIdentifier> {
if (isEmpty(fdc3OpenOptions?.app)) {
logger.error("A request to fdc3.open did not pass an fdc3OpenOptions object");
throw new Error(ResolveError.NoAppsFound);
}

const requestedId = isString(fdc3OpenOptions.app)
? fdc3OpenOptions.app
: fdc3OpenOptions.app.appId ?? fdc3OpenOptions.app.name;
const openAppIntent: OpenFin.Intent = {
context: fdc3OpenOptions.context,
name: "OpenApp",
metadata: {
target: { appId: requestedId }
}
};
logger.info(
`A request to Open has been sent to the platform by uuid: ${clientIdentity?.uuid}, name: ${clientIdentity?.name}, endpointId: ${clientIdentity.endpointId} with passed context:`,
fdc3OpenOptions.context
);
try {
const isOpenByIntent = this._openOptions?.openStrategy === "intent";
let appId: string | undefined;
let requestedId: string;
let instanceId: string | undefined;
let platformIdentities: PlatformAppIdentifier[] | undefined;
let focusApp = false;
let appId: string | undefined;

if (isString(fdc3OpenOptions.app)) {
requestedId = fdc3OpenOptions.app;
} else {
requestedId = fdc3OpenOptions.app.appId ?? fdc3OpenOptions.app.name;
instanceId = fdc3OpenOptions.app.instanceId;
}

const requestedApp = await getApp(requestedId);
if (isEmpty(requestedApp)) {
throw new Error(OpenError.AppNotFound);
}

if (!isEmpty(instanceId)) {
// an instance of an application was selected now look up the uuid and name
const allConnectedClients = await this.getAllClientInfo();
const clientInfo = allConnectedClients.find(
(connectedClient) => connectedClient.endpointId === instanceId
);
if (!isEmpty(clientInfo)) {
logger.info(`App Id: ${requestedId} and instance Id: ${instanceId} was provided and found.`);
// the connected instance is available
platformIdentities = [
{
uuid: clientInfo.uuid,
name: clientInfo.name,
appId: requestedId,
instanceId
}
];
} else {
throw new Error(ResolveError.TargetInstanceUnavailable);
}
}

const isOpenByIntent = this._openOptions?.openStrategy === "intent";

if (isOpenByIntent) {
const openAppIntent: OpenFin.Intent = {
context: fdc3OpenOptions.context,
name: "OpenApp",
metadata: {
target: { appId: requestedId }
}
};
const result = await this.launchAppWithIntent(
requestedApp,
openAppIntent,
undefined,
instanceId,
clientIdentity
);
if (isString(result.source)) {
Expand All @@ -620,13 +650,18 @@ export function interopOverride(
instanceId = result.source.instanceId;
}
} else {
let launchPreference: LaunchPreference | undefined;
const bounds = await getWindowPositionUsingStrategy(this._windowPositionOptions, clientIdentity);
if (!isEmpty(bounds)) {
launchPreference = { bounds };
if (isEmpty(platformIdentities)) {
let launchPreference: LaunchPreference | undefined;
const options = this._windowPositionOptions;
const bounds = await getWindowPositionUsingStrategy(options, clientIdentity);
if (!isEmpty(bounds)) {
launchPreference = { bounds };
}
platformIdentities = await launch(requestedApp, launchPreference);
} else {
focusApp = true;
}

const platformIdentities = await launch(requestedApp, launchPreference);
if (!isEmpty(platformIdentities) && platformIdentities?.length > 0) {
appId = platformIdentities[0].appId;
const openTimeout: number | undefined = this._openOptions?.connectionTimeout;
Expand Down Expand Up @@ -685,6 +720,9 @@ export function interopOverride(
}

if (!isEmpty(appId)) {
if (focusApp && !isEmpty(platformIdentities)) {
await bringToFront(requestedApp, platformIdentities);
}
return { appId, instanceId };
}

Expand Down

0 comments on commit 6fb1a93

Please sign in to comment.