Skip to content

Commit

Permalink
fixes for intentResolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolba committed Sep 30, 2022
1 parent 3b7c5bf commit 73f8959
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 189 deletions.
2 changes: 1 addition & 1 deletion packages/main/src/IntentResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class IntentResolver {
preload: RESOLVER_PRELOAD,
webSecurity: true,
nodeIntegration: true,
contextIsolation: false,
contextIsolation: true,
devTools: devTools,
},
});
Expand Down
2 changes: 2 additions & 0 deletions packages/main/src/handlers/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { openToolsMenu } from './toolbar';
import { fetchFromDirectory } from './directory';
import { pickChannel, joinChannel } from './channelPicker';
import { loadSearchResults } from './search';
import { resolveIntent } from '../fdc3/resolveIntent';

export const register = () => {
const runtime = getRuntime();
Expand All @@ -28,4 +29,5 @@ export const register = () => {
runtime.addHandler(RUNTIME_TOPICS.OPEN_CHANNEL_PICKER, pickChannel);
runtime.addHandler(RUNTIME_TOPICS.JOIN_WORKSPACE_TO_CHANNEL, joinChannel);
runtime.addHandler(RUNTIME_TOPICS.SEARCH_LOAD_RESULTS, loadSearchResults);
runtime.addHandler(RUNTIME_TOPICS.RES_RESOLVE_INTENT, resolveIntent);
};
47 changes: 47 additions & 0 deletions packages/main/src/handlers/runtime/resolveIntent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { getRuntime } from '../../index';
import { RuntimeMessage } from '../runtimeMessage';
import { DirectoryApp } from '../../types/FDC3Data';
import { TOPICS } from '../../constants';

export const resolveIntent = async (message: RuntimeMessage) => {
const runtime = getRuntime();

//TODO: autojoin the new app to the channel which the 'open' call is sourced from

if (!message.data.selected.instanceId) {
const data: DirectoryApp = message.data.selected?.directoryData;

//launch window
const runtime = getRuntime();
if (runtime) {
const win = runtime.createWorkspace();
const view = win.createView(data.start_url, {
directoryData: data as DirectoryApp,
});

//set pending intent and context
view.setPendingIntent(
message.data.intent,
message.data.context,
message.data.id,
);
}
} else {
const view = runtime.getView(message.data.selected?.instanceId);
//send new intent
if (view && view.parent) {
view.content.webContents.send(TOPICS.FDC3_INTENT, {
topic: 'intent',
data: { intent: message.data.intent, context: message.data.context },
source: message.data.id,
});
view.parent.setSelectedTab(view.id);
}
}

//close the resolver
const resolver = runtime.getResolver();
if (resolver) {
resolver.close();
}
};
1 change: 1 addition & 0 deletions packages/main/src/handlers/runtime/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export const RUNTIME_TOPICS = {
SEARCH: 'runtime:search',
SEARCH_LOAD_RESULTS: 'runtime:loadSearchResults',
RES_LOAD_RESULTS: 'runtime:loadResolverResults',
RES_RESOLVE_INTENT: 'runtime:resolveIntent',
};
1 change: 1 addition & 0 deletions packages/preload/exposedInMainWorld.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ interface Window {
readonly versions: NodeJS.ProcessVersions;
readonly agentFrame: { isConnected: () => boolean; selectTab: (selectedId: string) => void; tearOutTab: (tabId: string) => void; openToolsMenu: (clientX: number, clientY: number) => void; isReady: () => void; newTab: () => void; openChannelPicker: (mouseX: number, mouseY: number) => void; hideResultsWindow: () => void; searchDirectory: (query: string) => void; dropTab: (frameTarget: boolean) => void; tabDragStart: (selected: string) => void; closeTab: (tabId: string) => void; };
readonly home: { getApps: () => Promise<unknown>; };
readonly agentResolver: { resolveIntent: (data: any) => void; };
readonly agentSearch: { selectResult: (selection: string) => void; };
readonly fdc3: { getInfo(): import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/api/ImplementationMetadata").ImplementationMetadata; open: (app: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").TargetApp, context?: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<FDC3Result>; broadcast: (context: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => void; raiseIntent: (intent: string, context: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context, app?: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").TargetApp) => Promise<FDC3Result>; raiseIntentForContext(context: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context, app?: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").TargetApp): Promise<FDC3Result>; addContextListener: (contextType: string | import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").ContextHandler, handler?: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").ContextHandler) => FDC3Listener; addIntentListener: (intent: string, listener: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").ContextHandler) => FDC3Listener; findIntent: (intent: string, context: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<FDC3Result>; findIntentsByContext: (context: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<FDC3Result>; getSystemChannels: () => Promise<FDC3Result>; getOrCreateChannel: (channelId: string) => Promise<FDC3Result>; joinChannel: (channel: string) => Promise<FDC3Result>; leaveCurrentChannel: () => Promise<FDC3Result>; getCurrentChannel: () => Promise<FDC3Result>; };
}
30 changes: 16 additions & 14 deletions packages/preload/src/intentResolver/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import { ipcRenderer } from 'electron';
import { ipcRenderer, contextBridge } from 'electron';
import { Context } from '@finos/fdc3';
import { FDC3MessageData } from '../../../main/src/types/FDC3Message';
import { TOPICS } from '../../../main/src/constants';
import { RUNTIME_TOPICS } from '../../../main/src/handlers/runtime/topics';

let id: string | undefined = undefined;
let intent: string | undefined = undefined;
let context: Context | undefined = undefined;

ipcRenderer.on(TOPICS.WINDOW_START, (event, args) => {
ipcRenderer.on(RUNTIME_TOPICS.WINDOW_START, (event, args) => {
console.log(event.type);
id = args.id;
intent = args.intent;
context = args.context;

document.dispatchEvent(
new CustomEvent(TOPICS.RES_LOAD_INTENT_RESULTS, { detail: args }),
new CustomEvent(RUNTIME_TOPICS.RES_LOAD_RESULTS, { detail: args }),
);
});

const resolveIntent = (data: FDC3MessageData) => {
ipcRenderer.send(TOPICS.RES_RESOLVE_INTENT, {
method: 'resolveIntent',
const resolveIntent = (data: any) => {
ipcRenderer.send(RUNTIME_TOPICS.RES_RESOLVE_INTENT, {
id: id,
intent: data.selectedIntent || intent,
selected: data.selected && data.selected.details,
context: context,
data: {
intent: data.selectedIntent || intent,
selected: data.selected && data.selected.details,
context: context,
},
});
};

document.addEventListener(TOPICS.RES_RESOLVE_INTENT, ((event: CustomEvent) => {
resolveIntent(event.detail);
}) as EventListener);
const api = {
resolveIntent,
};

contextBridge.exposeInMainWorld('agentResolver', api);
Loading

0 comments on commit 73f8959

Please sign in to comment.