Skip to content

Commit

Permalink
Merge pull request #78 from nkolba/hello-2.0
Browse files Browse the repository at this point in the history
initial commit for 2.0 support
  • Loading branch information
nkolba authored Oct 25, 2022
2 parents c96d414 + 733422d commit 2e1042f
Show file tree
Hide file tree
Showing 30 changed files with 1,655 additions and 800 deletions.
1,379 changes: 715 additions & 664 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"nano-staged": "^0.5.0",
"playwright": "^1.19.2",
"prettier": "^2.5.1",
"rollup-plugin-tsconfig-paths": "^1.4.0",
"simple-git-hooks": "^2.7.0",
"typescript": "^4.5.4",
"vite": "^2.7.10",
Expand All @@ -60,13 +61,15 @@
"dependencies": {
"@emotion/react": "^11.8.1",
"@emotion/styled": "^11.8.1",
"@finos/fdc3": "^1.2.0",
"@finos/fdc3": "2.0.0-beta.2",
"@finos/fdc3-1.2": "@finos/fdc3@1.2.0",
"@fontsource/roboto": "^4.5.3",
"@mui/icons-material": "^5.4.4",
"@mui/material": "^5.4.4",
"electron-fetch": "^1.7.4",
"electron-updater": "^4.6.5",
"fastify": "^3.27.2",
"fdc3-1.2": "npm:@finos/fdc3@^1.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
Expand Down
6 changes: 5 additions & 1 deletion packages/main/src/IntentResolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { View } from './view';
import { getRuntime } from './index';
import { BrowserWindow } from 'electron';
import { FDC3App, IntentInstance, ResolverDetail } from './types/FDC3Data';
import {
FDC3App,
IntentInstance,
ResolverDetail,
} from '/@/handlers/fdc3/1.2/types/FDC3Data';
import { Context } from '@finos/fdc3';
import { join } from 'path';
import { Workspace } from './workspace';
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/handlers/fdc3/1.2/channels.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getRuntime } from '/@/index';
import { RuntimeMessage } from '/@/handlers/runtimeMessage';
import { ChannelData } from '/@/types/FDC3Data';
import { Context, ChannelError } from '@finos/fdc3';
import { ChannelData } from '/@/handlers/fdc3/1.2/types/FDC3Data';
import { Context, ChannelError } from 'fdc3-1.2';
import { systemChannels } from './systemChannels';

export const getSystemChannels = async () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/main/src/handlers/fdc3/1.2/findIntent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getRuntime } from '/@/index';
import { RuntimeMessage } from '/@/handlers/runtimeMessage';
import { DirectoryApp } from '/@/types/FDC3Data';
import { AppIntent, AppMetadata, IntentMetadata } from '@finos/fdc3';
import { DirectoryApp } from '/@/handlers/fdc3/1.2/types/FDC3Data';
import { AppMetadata } from './types/AppMetadata';
import { AppIntent, IntentMetadata } from 'fdc3-1.2';

export const findIntent = async (message: RuntimeMessage) => {
const runtime = getRuntime();
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/handlers/fdc3/1.2/open.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getRuntime } from '/@/index';
import { RuntimeMessage } from '/@/handlers/runtimeMessage';
import { TargetApp, AppMetadata, OpenError } from '@finos/fdc3';
import { DirectoryApp } from '/@/types/FDC3Data';
import { TargetApp, AppMetadata, OpenError } from 'fdc3-1.2';
import { DirectoryApp } from '/@/handlers/fdc3/1.2/types/FDC3Data';

/**
*
Expand Down
10 changes: 3 additions & 7 deletions packages/main/src/handlers/fdc3/1.2/raiseIntent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
AppMetadata,
IntentResolution,
IntentMetadata,
} from '@finos/fdc3';
} from 'fdc3-1.2';
import { getRuntime } from '/@/index';
import { View } from '/@/view';
import fetch from 'electron-fetch';
Expand All @@ -14,7 +14,7 @@ import {
FDC3App,
IntentInstance,
FDC3AppDetail,
} from '/@/types/FDC3Data';
} from '/@/handlers/fdc3/1.2/types/FDC3Data';
import utils from '/@/utils';
import { FDC3_TOPICS } from './topics';
import { ipcMain } from 'electron';
Expand Down Expand Up @@ -414,10 +414,6 @@ export const raiseIntentForContext = async (message: RuntimeMessage) => {
intentListeners.forEach((listeners: Array<View>) => {
//look up the details of the window and directory metadata in the "connected" store
listeners.forEach((view: View) => {
// const connect : FDC3AppDetail= utils.getConnected(listener.appId);
//connect.intent = intent;
//decorate with the intent

//de-dupe
if (
!r.find((item) => {
Expand All @@ -443,7 +439,7 @@ export const raiseIntentForContext = async (message: RuntimeMessage) => {
*/
const target: TargetApp | undefined =
(message.data && message.data.target) || undefined;
const name: string = target
const name: string | undefined = target
? typeof target === 'string'
? target
: (target as AppMetadata).name
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/handlers/fdc3/1.2/systemChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* metadata for the system channels
*/

import type { ChannelData } from '/@/types/FDC3Data';
import type { ChannelData } from '/@/handlers/fdc3/1.2/types/FDC3Data';

export const systemChannels: Array<ChannelData> = [
{
Expand Down
60 changes: 60 additions & 0 deletions packages/main/src/handlers/fdc3/1.2/types/AppInstance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { WebContents } from 'electron';
import { DirectoryApp } from './FDC3Data';

/**
* represents an app instance when resolving intents
* can either represent a directory item or a connected instance
*/
export interface AppInstance {
details: AppDetails;
type: string;
}

/**
* the connection and metadata details of a app
*/
export interface AppDetails {
directoryData: DirectoryApp;
content: WebContents;
}

export enum InstanceTypeEnum {
Window = 'window',
Directory = 'directory',
}

/**
* SPDX-License-Identifier: Apache-2.0
* Copyright 2020 FINOS FDC3 contributors - see NOTICE file
*/

import { Context, ContextHandler, Listener } from '@finos/fdc3';

/**
* An interface that relates an instance of an app to other apps
*/
export interface fdc3AppInstance {
readonly instanceId: string;
readonly status: 'ready' | 'loading' | 'unregistered';

/**
* Adds a listener for incoming contexts whenever a broadcast happens from this instance.
*/
addContextListener(handler: ContextHandler): Listener;

/**
* Adds a listener for incoming contexts of the specified context type whenever a broadcast happens from this instance.
*/
addContextListener(contextType: string, handler: ContextHandler): Listener;

/**
* Sends the given context to this app instance.
* The context will be recieved on the applicable contextListener for the instance.
*/
broadcast(context: Context): void;

/**
*
*/
onStatusChanged(handler: (newVal: string, oldVal: string) => void): void;
}
33 changes: 33 additions & 0 deletions packages/main/src/handlers/fdc3/1.2/types/AppMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* SPDX-License-Identifier: Apache-2.0
* Copyright 2019 FINOS FDC3 contributors - see NOTICE file
*/

/**
* App definition as provided by the application directory
*/
export interface AppMetadata {
/** The unique app name that can be used with the open and raiseIntent calls. */
readonly name: string;

/** The unique application identifier located within a specific application directory instance. An example of an appId might be 'app@sub.root' */
readonly appId?: string;

/** The Version of the application. */
readonly version?: string;

/** A more user-friendly application title that can be used to render UI elements */
readonly title?: string;

/** A tooltip for the application that can be used to render UI elements */
readonly tooltip?: string;

/** A longer, multi-paragraph description for the application that could include markup */
readonly description?: string;

/** A list of icon URLs for the application that can be used to render UI elements */
readonly icons?: Array<string>;

/** A list of image URLs for the application that can be used to render UI elements */
readonly images?: Array<string>;
}
89 changes: 89 additions & 0 deletions packages/main/src/handlers/fdc3/1.2/types/FDC3Data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Context, DisplayMetadata, IntentMetadata } from 'fdc3-1.2';

/**
* represenation of an FDC3 App - whether it is running (connected) or not (directory only)
*/
export interface FDC3App {
type: string;
details: FDC3AppDetail;
}

/**
* A collection of apps associated with an intent
*/
export interface IntentInstance {
intent: IntentMetadata;
apps: Array<FDC3App>;
}

export interface FDC3AppDetail {
instanceId?: string;
title?: string;
directoryData?: DirectoryApp;
}

export interface ResolverDetail {
intent?: string;
context?: Context;
}

/**
* Data structure representing an App Directory item
*/
export interface DirectoryApp {
name: string;
title: string;
start_url: string;
manifest: string;
manifest_type: string;
description: string;
icons: Array<DirectoryIcon>;
images: Array<DirectoryImage>;
appId: string;
intents: Array<DirectoryIntent>;
}

export interface DirectoryIcon {
icon: string;
}

export interface DirectoryImage {
url: string;
}

export interface DirectoryIntent {
name: string;
display_name: string;
contexts: Array<string>;
}

/**
* representation of channel data
*/
export interface ChannelData {
id: string;
type: 'app' | 'system';
displayMetadata?: ChannelMetadata;
}

export class ChannelMetadata implements DisplayMetadata {
/**
* A user-readable name for this channel, e.g: `"Red"`
*/
name?: string;

/**
* The color that should be associated within this channel when displaying this channel in a UI, e.g: `0xFF0000`.
*/
color?: string;

/**
* A URL of an image that can be used to display this channel
*/
glyph?: string;

/**
* alternate / secondary color to use in conjunction with 'color' when creating UIs
*/
color2?: string;
}
74 changes: 74 additions & 0 deletions packages/main/src/handlers/fdc3/1.2/types/FDC3Event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Context, TargetApp } from 'fdc3-1.2';

/**
* Custom DOM event used by the FDC3 API
*/

export class FDC3Event extends Event {
detail: FDC3EventDetail = {};
ts = 0;

constructor(type: string, init?: CustomEventInit) {
super(type, init);
}
}

/**
* Event Detail structure
*/
export interface FDC3EventDetail {
/**
*
*/
id?: string; //resolve with listenerId
ts?: number;
listenerId?: string;
eventId?: string; //resolve with listenerId & eventId
intent?: string;
channel?: string;
channelId?: string; //resolve w/channel
instanceId?: string; //identifier for the app instance
contextType?: string;
data?: FDC3ResponseData | null;
name?: string;
context?: Context;
target?: TargetApp;
source?: string;
/* identifier of the browserView the event originated from */
viewId?: string;
error?: string;
}

export interface FDC3ResponseData {
context?: Context;
intent?: string;
listenerId?: string;
}

/**
* EventEnum
* enum of all fdc3 event topics that can originate from the API layer
*/
export enum FDC3EventEnum {
Broadcast = 'broadcast',
Open = 'open',
RaiseIntent = 'raiseIntent',
AddContextListener = 'addContextListener',
AddIntentListener = 'addIntentListener',
FindIntent = 'findIntent',
FindIntentsByContext = 'findIntentsByContext',
GetCurrentContext = 'getCurrentContext',
GetSystemChannels = 'getSystemChannels',
GetOrCreateChannel = 'getOrCreateChannel',
GetCurrentChannel = 'getCurrentChannel',
JoinChannel = 'joinChannel',
DropContextListener = 'dropContextListener',
DropIntentListener = 'dropIntentListener',
IntentComplete = 'intentComplete',
}

/*export {
FDC3Event,
FDC3EventDetail,
FDC3EventEnum
};*/
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FDC3App } from '../types/FDC3Data';
import { Context, TargetApp } from '@finos/fdc3';
import { RuntimeMessage } from './runtimeMessage';
import { FDC3App } from '/@/handlers/fdc3/1.2/types/FDC3Data';
import { Context, TargetApp } from 'fdc3-1.2';
import { RuntimeMessage } from '../../../runtimeMessage';

export interface FDC3Message extends RuntimeMessage {
name?: string;
Expand All @@ -27,3 +27,8 @@ export interface FDC3MessageData {
selectedIntent?: string;
selected?: FDC3App;
}

export interface FDC3Response {
error?: string;
data: any;
}
Loading

0 comments on commit 2e1042f

Please sign in to comment.