Skip to content

Commit

Permalink
initial refactoring of non-fdc3 handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolba committed Sep 30, 2022
2 parents 2958383 + 34f8b7f commit 4004334
Show file tree
Hide file tree
Showing 28 changed files with 1,526 additions and 901 deletions.
1,242 changes: 896 additions & 346 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"update-versions": "node scripts/update-electron-vendors.js"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^14.1.0",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@types/node": "^17.0.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/IntentResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { BrowserWindow } from 'electron';
import { FDC3App, IntentInstance, ResolverDetail } from './types/FDC3Data';
import { Context } from '@finos/fdc3';
import { join } from 'path';
import { TOPICS } from './constants';
import { Workspace } from './workspace';
import { randomUUID } from 'crypto';
import { RUNTIME_TOPICS } from './handlers/runtime/topics';

const RESOLVER_PRELOAD = join(
__dirname,
Expand Down Expand Up @@ -108,7 +108,7 @@ export class IntentResolver {

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

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

console.log(
'intent resolver create',
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const DEFAULT_WINDOW_HEIGHT = 600;
export const DEFAULT_WINDOW_WIDTH = 800;
export const TOOLBAR_HEIGHT = 100;
export const TOOLBAR_HEIGHT = 140;

export enum TARGETS {
SEARCH_RESULTS = 'searchResults',
Expand Down
2 changes: 2 additions & 0 deletions packages/main/src/handlers/runtime/channelPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const hideChannelWindow = async (message: RuntimeMessage) => {

export const pickChannel = async (message: RuntimeMessage) => {
const runtime = getRuntime();
console.log('pickChannel', message.source, message.data);
const sourceWS = runtime.getWorkspace(message.source);
const mouseX: number = message.data.mouseX || 0;
const mouseY: number = message.data.mouseY || 0;
Expand All @@ -19,6 +20,7 @@ export const pickChannel = async (message: RuntimeMessage) => {
};

export const joinChannel = async (message: RuntimeMessage) => {
console.log('joinChannel', message);
const runtime = getRuntime();
const sourceWS = runtime.getWorkspace(message.source);
if (sourceWS) {
Expand Down
3 changes: 2 additions & 1 deletion packages/main/src/handlers/runtime/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { RuntimeMessage } from '../runtimeMessage';
import { WebContents } from 'electron';
import utils from '../../utils';
import fetch from 'electron-fetch';
import { RUNTIME_TOPICS } from './index';
import { RUNTIME_TOPICS } from './topics';

export const fetchFromDirectory = async (message: RuntimeMessage) => {
const runtime = getRuntime();
const directoryUrl = await utils.getDirectoryUrl();

const response = await fetch(`${directoryUrl}${message.data.query}`);
const result = await response.json();

Expand Down
22 changes: 11 additions & 11 deletions packages/main/src/handlers/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import { getRuntime } from '../../index';
import { RUNTIME_TOPICS } from './topics';

import {
tabSelected,
tabDragStart,
newTab,
tearOutTab,
closeTab,
dropTab,
} from './tabs';
import { openToolsMenu } from './toolbar';
import { fetchFromDirectory } from './directory';

export const RUNTIME_TOPICS = {
TAB_SELECTED: 'runtime:tabSelected',
TAB_DRAG_START: 'runtime:tabDragStart',
NEW_TAB: 'runtime:newTab',
DROP_TAB: 'runtime:dropTab',
TEAR_OUT_TAB: 'runtime:tearOutTab',
CLOSE_TAB: 'runtime:closeTab',
REMOVE_TAB: 'runtime:removeTab',
FETCH_FROM_DIRECTORY: 'runtime:fetchFromDirectory',
};
import { pickChannel, joinChannel } from './channelPicker';
import { loadSearchResults } from './search';

export const register = () => {
const runtime = getRuntime();

runtime.addHandler(RUNTIME_TOPICS.TAB_SELECTED, tabSelected);
runtime.addHandler(RUNTIME_TOPICS.TAB_DRAG_START, tabDragStart);
runtime.addHandler(RUNTIME_TOPICS.DROP_TAB, dropTab);
runtime.addHandler(RUNTIME_TOPICS.NEW_TAB, newTab);
runtime.addHandler(RUNTIME_TOPICS.TEAR_OUT_TAB, tearOutTab);
runtime.addHandler(RUNTIME_TOPICS.CLOSE_TAB, closeTab);
runtime.addHandler(RUNTIME_TOPICS.FETCH_FROM_DIRECTORY, fetchFromDirectory);
runtime.addHandler(RUNTIME_TOPICS.OPEN_TOOLS_MENU, openToolsMenu);
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);
};
1 change: 1 addition & 0 deletions packages/main/src/handlers/runtime/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const hideSearchResults = async (message: RuntimeMessage) => {
export const loadSearchResults = async (message: RuntimeMessage) => {
const runtime = getRuntime();
//bring selected browserview to front
console.log('loadSearchResults', message.data.results);
const workspace = runtime?.getWorkspace(message.source);
workspace?.loadSearchResults(message.data.results);
};
2 changes: 1 addition & 1 deletion packages/main/src/handlers/runtime/tabs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getRuntime } from '../../index';
import { RuntimeMessage } from '../runtimeMessage';
import { RUNTIME_TOPICS } from './index';
import { RUNTIME_TOPICS } from './topics';
import { Point, screen } from 'electron';
import { Workspace } from '../../workspace';

Expand Down
22 changes: 22 additions & 0 deletions packages/main/src/handlers/runtime/topics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const RUNTIME_TOPICS = {
TAB_SELECTED: 'runtime:tabSelected',
TAB_DRAG_START: 'runtime:tabDragStart',
NEW_TAB: 'runtime:newTab',
ADD_TAB: 'runtime:addTab',
DROP_TAB: 'runtime:dropTab',
SELECT_TAB: 'runtime:selectTab',
TEAR_OUT_TAB: 'runtime:tearOutTab',
CLOSE_TAB: 'runtime:closeTab',
REMOVE_TAB: 'runtime:removeTab',
FETCH_FROM_DIRECTORY: 'runtime:fetchFromDirectory',
OPEN_TOOLS_MENU: 'runtime:openToolsMenu',
WINDOW_START: 'runtime:windowStart',
OPEN_CHANNEL_PICKER: 'runtime:openChannelPicker',
JOIN_WORKSPACE_TO_CHANNEL: 'runtime:joinWorkspaceToChannel',
CHANNEL_SELECTED: 'runtime:channelSelected',
HIDE_WINDOW: 'runtime:hideWindow',
HIDE_RESULTS_WINDOW: 'runtime:hideResultsWindow',
SEARCH: 'runtime:search',
SEARCH_LOAD_RESULTS: 'runtime:loadSearchResults',
RES_LOAD_RESULTS: 'runtime:loadResolverResults',
};
4 changes: 2 additions & 2 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ app
/**
* Install Vue.js or some other devtools in development mode only
*/
if (import.meta.env.DEV) {
/*if (import.meta.env.DEV) {
app
.whenReady()
.then(() => import('electron-devtools-installer'))
Expand All @@ -131,7 +131,7 @@ if (import.meta.env.DEV) {
}),
)
.catch((e) => console.error('Failed install extension:', e));
}
}*/

/**
* Check new app version in production mode only
Expand Down
8 changes: 4 additions & 4 deletions packages/main/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ export class Runtime {
*/
addHandler(
name: string,
handler: (args: RuntimeMessage) => Promise<any>,
handler: (args: RuntimeMessage) => Promise<unknown>,
once?: boolean,
) {
const theHandler = async (event: IpcMainEvent, args: any) => {
const theHandler = async (event: IpcMainEvent, args: RuntimeMessage) => {
try {
const r = await handler.call(undefined, args as RuntimeMessage);
const r = await handler.call(undefined, args);

if (event.ports && args.data?.eventId) {
event.ports[0].postMessage({
topic: args.data.eventId,
topic: (args as RuntimeMessage).data.eventId,
data: r,
});
}
Expand Down
3 changes: 2 additions & 1 deletion packages/main/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class View {
devTools: true,
contextIsolation: true,
webSecurity: true,
nodeIntegration: false,
nodeIntegration: true,
},
});
//set bgcolor so view doesn't bleed through to hidden tabs
Expand All @@ -98,6 +98,7 @@ export class View {

if (url) {
this.content.webContents.loadURL(url).then(() => {
// this.content.webContents.openDevTools();
// initView(config);
});

Expand Down
33 changes: 18 additions & 15 deletions packages/main/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
TOPICS,
} from './constants';
import { randomUUID } from 'crypto';
import { RUNTIME_TOPICS } from './handlers/runtime/topics';

const CHANNEL_PICKER_PRELOAD = join(
__dirname,
Expand All @@ -33,8 +34,8 @@ const SEARCH_RESULTS_PRELOAD = join(
'../../preload/dist/searchResults/index.cjs',
);

const CHANNEL_WINDOW_WIDTH = 130;
const CHANNEL_WINDOW_HEIGHT = 90;
const CHANNEL_WINDOW_WIDTH = 140;
const CHANNEL_WINDOW_HEIGHT = 100;

export class Workspace {
constructor(config?: WorkspaceConfig) {
Expand All @@ -46,7 +47,8 @@ export class Workspace {
width: DEFAULT_WINDOW_WIDTH,
webPreferences: {
webviewTag: false, // The webview tag is not recommended. Consider alternatives like iframe or Electron's BrowserView. https://www.electronjs.org/docs/latest/api/webview-tag#warning
preload: join(__dirname, '../../preload/dist/index.cjs'),
preload: join(__dirname, '../../preload/dist/frame/index.cjs'),
nodeIntegration: true,
},
});

Expand All @@ -72,8 +74,10 @@ export class Workspace {
this.window.loadURL(MAIN_WINDOW_CONTENT).then(() => {
// this.window.loadFile('src/windows/workspace/frame.html').then(() => {
if (this.window) {
this.window.webContents.send(TOPICS.WORKSPACE_START, { id: this.id });
this.window.webContents.openDevTools();
this.window.webContents.send(RUNTIME_TOPICS.WINDOW_START, {
id: this.id,
});
// this.window.webContents.openDevTools();
console.log('workspace created', this.id);
const runtime = getRuntime();
if (runtime) {
Expand Down Expand Up @@ -352,7 +356,7 @@ export class Workspace {
webPreferences: {
webSecurity: true,
nodeIntegration: true,
contextIsolation: false,
contextIsolation: true,
preload: SEARCH_RESULTS_PRELOAD,
devTools: true,
},
Expand All @@ -371,7 +375,7 @@ export class Workspace {
this.resultsWindow.loadURL(SEARCH_RESULTS_CONTENT as string).then(
() => {
if (this.resultsWindow) {
this.resultsWindow.webContents.send(TOPICS.WINDOW_START, {
this.resultsWindow.webContents.send(RUNTIME_TOPICS.WINDOW_START, {
workspaceId: this.id,
});
console.log('results window created', this.resultsId);
Expand All @@ -388,7 +392,6 @@ export class Workspace {
}

createChannelWindow(): Promise<void> {
console.log('creatChannelWIndow');
return new Promise((resolve, reject) => {
this.channelWindow = new BrowserWindow({
height: CHANNEL_WINDOW_HEIGHT,
Expand All @@ -400,7 +403,7 @@ export class Workspace {
webPreferences: {
webSecurity: true,
nodeIntegration: true,
contextIsolation: false,
contextIsolation: true,
preload: CHANNEL_PICKER_PRELOAD,
devTools: true,
},
Expand All @@ -419,7 +422,7 @@ export class Workspace {
this.channelWindow.loadURL(CHANNEL_PICKER_CONTENT as string).then(
() => {
if (this.channelWindow) {
this.channelWindow.webContents.send(TOPICS.WINDOW_START, {
this.channelWindow.webContents.send(RUNTIME_TOPICS.WINDOW_START, {
workspaceId: this.id,
});
console.log('channel window created', this.id);
Expand Down Expand Up @@ -472,7 +475,7 @@ export class Workspace {
this.resultsWindow.setPosition(winPos[0] + 9, winPos[1] + 70);

this.resultsWindow.showInactive();
this.resultsWindow.webContents.send(TOPICS.RES_LOAD_RESULTS, {
this.resultsWindow.webContents.send(RUNTIME_TOPICS.SEARCH_LOAD_RESULTS, {
results: results,
});
// this.resultsWindow.webContents.openDevTools();
Expand Down Expand Up @@ -523,7 +526,7 @@ export class Workspace {
view.size();
this.setSelectedTab(view.id);
if (this.window) {
this.window.webContents.send(TOPICS.ADD_TAB, {
this.window.webContents.send(RUNTIME_TOPICS.ADD_TAB, {
viewId: view.id,
title: view.getTitle(),
});
Expand Down Expand Up @@ -551,7 +554,7 @@ export class Workspace {
return new Promise((resolve, reject) => {
if (this.window) {
console.log('adding tab', view.id, view.getTitle());
this.window.webContents.send(TOPICS.ADD_TAB, {
this.window.webContents.send(RUNTIME_TOPICS.ADD_TAB, {
viewId: view.id,
title: view.getTitle(),
});
Expand Down Expand Up @@ -602,12 +605,12 @@ export class Workspace {
}
});
if (this.channelWindow) {
this.channelWindow.webContents.send(TOPICS.CHANNEL_SELECTED, {
this.channelWindow.webContents.send(RUNTIME_TOPICS.CHANNEL_SELECTED, {
channel: channel,
});
}
if (this.window) {
this.window.webContents.send(TOPICS.CHANNEL_SELECTED, {
this.window.webContents.send(RUNTIME_TOPICS.CHANNEL_SELECTED, {
channel: channel,
});
}
Expand Down
4 changes: 3 additions & 1 deletion packages/preload/exposedInMainWorld.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
interface Window {
readonly agentChannelPicker: { joinChannel: (channel: string) => void; hideWindow: () => void; leaveChannel: () => void; };
readonly versions: NodeJS.ProcessVersions;
readonly workspace: { isConnected: () => boolean; };
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; addTab: (viewId: string, title: string) => void; tabDragStart: (selected: string) => void; closeTab: (tabId: string) => void; };
readonly home: { getApps: () => Promise<unknown>; };
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>; };
}
Loading

0 comments on commit 4004334

Please sign in to comment.