Skip to content

Commit

Permalink
added support for raiseIntentForContext, fixed some resolver issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolba committed Mar 30, 2022
1 parent 1d80712 commit a0cedee
Show file tree
Hide file tree
Showing 10 changed files with 562 additions and 141 deletions.
63 changes: 46 additions & 17 deletions packages/main/src/IntentResolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { View } from './view';
import { getRuntime } from './index';
import { BrowserWindow } from 'electron';
import { FDC3App, ResolverDetail } from './types/FDC3Data';
import { FDC3App, IntentInstance, ResolverDetail } from './types/FDC3Data';
import { Context } from '@finos/fdc3';
import utils from './utils';
import { join } from 'path';
Expand All @@ -12,18 +12,24 @@ const RESOLVER_PRELOAD = join(
'../../preload/dist/intentResolver/index.cjs',
);

const devTools = false;

export class IntentResolver {
window: BrowserWindow;

view: View | null = null;

id: string;

intent: string;
intent: string | undefined;

context: Context | null;

constructor(view: View, detail: ResolverDetail, options?: Array<FDC3App>) {
constructor(
view: View,
detail: ResolverDetail,
options?: Array<FDC3App> | Array<IntentInstance>,
) {
this.id = utils.guid();

this.intent = detail.intent;
Expand All @@ -35,31 +41,34 @@ export class IntentResolver {
width: 400,
frame: false,
hasShadow: true,
resizable: false,
webPreferences: {
preload: RESOLVER_PRELOAD,
webSecurity: true,
nodeIntegration: true,
contextIsolation: false,
devTools: true,
devTools: devTools,
},
});

//TO DO: refactor bounds and positioning for multi-screen
const vBounds = view.content.getBounds();
console.log('Resolver vBounds', JSON.stringify(vBounds));
const x =
vBounds && vBounds.width ? vBounds.x + (vBounds.width + 200) / 2 : 0;
const y = vBounds && vBounds.height ? (vBounds.y + vBounds.height) / 2 : 0;
console.log('opening intentResolver @', x, y, vBounds);
this.window.setBounds({
x: x,
y: y,
x: Math.round(x),
y: Math.round(y),
height: 400,
width: 400,
});

//add resolution listener
getRuntime().getResolvers().set(this.id, this);
getRuntime().setResolver(this);

//to do: position resolver in relation to view

const RESOLVER_CONTENT =
import.meta.env.DEV &&
import.meta.env.VITE_DEV_SERVER_INTENTS_URL !== undefined
Expand All @@ -69,15 +78,32 @@ export class IntentResolver {
'file://' + __dirname,
).toString();
// and load the index.html of the app.
console.log('resolver content', RESOLVER_CONTENT);

if (RESOLVER_CONTENT) {
this.window.loadURL(RESOLVER_CONTENT as string).then(() => {
// this.window.webContents.openDevTools();
this.window.webContents.send(TOPICS.WINDOW_START, {
if (devTools) {
this.window.webContents.openDevTools();
}
console.log('resolver Window loaded');

const startObject = {
id: this.id,
intent: this.intent,
intent: this.intent || '',
context: this.context,
options: options,
});
};

console.log(
'startObject',
this.id,
this.intent,
JSON.stringify(this.context),
);

console.log('startObject options', JSON.stringify(options));

this.window.webContents.send(TOPICS.WINDOW_START, startObject);

console.log(
'intent resolver create',
Expand All @@ -89,14 +115,17 @@ export class IntentResolver {

this.window.focus();

this.window.on('blur', () => {
this.window.destroy();
});
//dev tools will automatically blur and close the resolver
if (!devTools) {
this.window.on('blur', () => {
this.window.destroy();
});
}
}
}

close() {
this.window.close();
getRuntime().getResolvers().delete(this.id);
this.window.destroy();
getRuntime().dropResolver();
}
}
1 change: 1 addition & 0 deletions packages/main/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ export enum TOPICS {
FDC3_GET_CURRENT_CHANNEL = 'FDC3:getCurrentChannel',
FDC3_GET_APP_INSTANCE = 'FDC3:getAppInstance',
FDC3_RAISE_INTENT = 'FDC3:raiseIntent',
FDC3_RAISE_INTENT_FOR_CONTEXT = 'FDC3:raiseIntentForContext',
}
Loading

0 comments on commit a0cedee

Please sign in to comment.