Skip to content

Commit

Permalink
linting and fix for name/target support in getIntentsForContext
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolba committed Nov 4, 2022
1 parent 5947765 commit f427030
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
41 changes: 24 additions & 17 deletions packages/main/src/handlers/fdc3/1.2/raiseIntent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,44 @@ export const raiseIntentForContext = async (message: RuntimeMessage) => {

const r: Array<FDC3App> = [];

const context =
const context: string =
message.data?.context && message.data?.context?.type
? message.data.context.type
: '';
/**
* To Do: Support additional AppMetadata searching (other than name)
*/
const target: TargetApp | undefined =
(message.data && message.data.target) || undefined;
const name: string | undefined = target
? typeof target === 'string'
? target
: (target as AppMetadata).name
: '';

const intentListeners = runtime.getIntentListenersByContext(context);

if (intentListeners) {
// let keys = Object.keys(intentListeners);
intentListeners.forEach((listeners: Array<View>) => {
let addListener = true;
//look up the details of the window and directory metadata in the "connected" store
listeners.forEach((view: View) => {
if (name && name !== view.directoryData?.name) {
addListener = false;
}
//de-dupe
if (
!r.find((item) => {
r.find((item) => {
return (
item.details.instanceId && item.details.instanceId === view.id
);
})
) {
addListener = false;
}

if (addListener) {
const title = view.getTitle();
const details: FDC3AppDetail = {
instanceId: view.id,
Expand All @@ -396,24 +414,13 @@ export const raiseIntentForContext = async (message: RuntimeMessage) => {
});
}

/**
* To Do: Support additional AppMetadata searching (other than name)
*/
const target: TargetApp | undefined =
(message.data && message.data.target) || undefined;
const name: string | undefined = target
? typeof target === 'string'
? target
: (target as AppMetadata).name
: '';

const data = getRuntime()
.getDirectory()
.retrieveByIntentAndContextType(name, context.type);
const data = getRuntime().getDirectory().retrieveByContextType(context);

if (data) {
data.forEach((entry: DirectoryApp) => {
r.push({ type: 'directory', details: { directoryData: entry } });
if (!name || (name && entry.name === name)) {
r.push({ type: 'directory', details: { directoryData: entry } });
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class View {

initiated = false;

fdc3Version: '2.0' | '1.2' = '2.0';
fdc3Version: '2.0' | '1.2' = '1.2';

private type: 'system' | 'app' = 'app';

Expand Down
4 changes: 2 additions & 2 deletions packages/preload/exposedInMainWorld.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface Window {
readonly fdc3: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/api/DesktopAgent").DesktopAgent;
readonly sail: { isConnected: () => boolean; isReady: () => void; joinChannel: (channel: string) => void; leaveChannel: () => void; hideWindow: () => void; resolveIntent: (data: any) => void; versions: NodeJS.ProcessVersions; getApps: () => Promise<unknown>; tabs: { select: (selectedId: string) => void; tearOut: (tabId: string) => void; new: () => void; drop: (frameTarget: boolean) => void; dragStart: (selected: string) => void; close: (tabId: string) => void; }; menu: { openTools: (clientX: number, clientY: number) => void; openChannelPicker: (mouseX: number, mouseY: number) => void; }; search: { hideResultsWindow: () => void; searchDirectory: (query: string) => void; selectResult: (selection: string) => void; }; };
readonly fdc3: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/fdc3-1.2/dist/api/DesktopAgent").DesktopAgent;
readonly sail: { isConnected: () => boolean; isReady: () => void; joinChannel: (channel: string) => void; leaveChannel: () => void; hideWindow: () => void; resolveIntent: (data: { selectedIntent: any; selected: { details: any; }; }) => void; versions: NodeJS.ProcessVersions; getApps: () => Promise<unknown>; tabs: { select: (selectedId: string) => void; tearOut: (tabId: string) => void; new: () => void; drop: (frameTarget: boolean) => void; dragStart: (selected: string) => void; close: (tabId: string) => void; }; menu: { openTools: (clientX: number, clientY: number) => void; openChannelPicker: (mouseX: number, mouseY: number) => void; }; search: { hideResultsWindow: () => void; searchDirectory: (query: string) => void; selectResult: (selection: string) => void; }; };
}
11 changes: 10 additions & 1 deletion packages/preload/src/fdc3-1.2/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ interface FDC3ReturnListener {
listener: { (msg: FDC3Message): void };
}

//backwards compatability support for fdc3 namespaced intents
const stripNS = (intent: string): string => {
if (intent.startsWith('fdc3.')) {
intent = intent.substring(5);
}
return intent;
};

//flag to indicate the background script is ready for fdc3!
let instanceId = '';

Expand Down Expand Up @@ -342,7 +350,7 @@ export const createAPI = (): DesktopAgent => {
app?: TargetApp,
): Promise<IntentResolution> => {
return await sendMessage(FDC3_1_2_TOPICS.RAISE_INTENT, {
intent: intent,
intent: stripNS(intent),
context: context,
target: app,
});
Expand Down Expand Up @@ -381,6 +389,7 @@ export const createAPI = (): DesktopAgent => {

addIntentListener: (intent: string, listener: ContextHandler): Listener => {
const listenerId: string = guid();
intent = stripNS(intent);
if (!_intentListeners.has(intent)) {
_intentListeners.set(intent, new Map());
}
Expand Down
2 changes: 1 addition & 1 deletion packages/preload/src/systemView/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { connect, createAPI } from '../fdc3-2.0/api';
import { connect, createAPI } from '../fdc3-1.2/api';
import { contextBridge } from 'electron';
import { api } from '../system/api';
connect();
Expand Down

0 comments on commit f427030

Please sign in to comment.