Skip to content

Commit

Permalink
more linting and refactoring of types. All but 9 lint warnings elminated
Browse files Browse the repository at this point in the history
  • Loading branch information
nkolba committed Mar 31, 2022
1 parent 8394b2c commit 6b3014f
Show file tree
Hide file tree
Showing 21 changed files with 302 additions and 242 deletions.
155 changes: 95 additions & 60 deletions packages/main/src/listeners/fdc3Listeners.ts

Large diffs are not rendered by default.

19 changes: 17 additions & 2 deletions packages/main/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { RuntimeListener } from './listeners/listener';
import { FDC3Listener } from './types/FDC3Listener';
import { Context, IntentMetadata } from '@finos/fdc3';
import { DirectoryApp, FDC3App, IntentInstance, ResolverDetail} from './types/FDC3Data';
import {
DirectoryApp,
FDC3App,
IntentInstance,
ResolverDetail,
} from './types/FDC3Data';
import { channels } from './system-channels';
import { View } from './view';
import { Workspace } from './workspace';
Expand Down Expand Up @@ -218,7 +223,17 @@ export class Runtime {
return workspace;
}

fetchFromDirectory(query: string): Promise<DirectoryApp | Array<DirectoryApp> | IntentMetadata | Array<IntentMetadata> | Context | Array<Context> | void> {
fetchFromDirectory(
query: string,
): Promise<
| DirectoryApp
| Array<DirectoryApp>
| IntentMetadata
| Array<IntentMetadata>
| Context
| Array<Context>
| void
> {
return new Promise((resolve, reject) => {
utils.getDirectoryUrl().then((directoryUrl) => {
const url = `${directoryUrl}${query}`;
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/system-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* metadata for the system channels
*/

import type { Channel } from './types/FDC3Data';
import type { ChannelData } from './types/FDC3Data';

export const channels: Array<Channel> = [
export const channels: Array<ChannelData> = [
{
id: 'red',
type: 'system',
Expand Down
8 changes: 7 additions & 1 deletion packages/main/src/types/FDC3Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface FDC3EventDetail {
channelId?: string; //resolve w/channel
instanceId?: string; //identifier for the app instance
contextType?: string;
data?: object | Array<object> | null;
data?: FDC3ResponseData | null;
name?: string;
context?: Context;
target?: TargetApp;
Expand All @@ -38,6 +38,12 @@ export interface FDC3EventDetail {
viewId?: string;
}

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

/**
* EventEnum
* enum of all fdc3 event topics that can originate from the API layer
Expand Down
8 changes: 4 additions & 4 deletions packages/main/src/types/FDC3Listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*/
export interface FDC3Listener {
//the id of the owner of the listener
viewId: string| undefined;
viewId: string | undefined;
//the id of the app that has set the listener (in the case of direct messaging)
source?: string| undefined;
contextType?: string| undefined;
intent?: string| undefined;
source?: string | undefined;
contextType?: string | undefined;
intent?: string | undefined;
channel?: string | undefined;
isChannel?: boolean;
listenerId: string;
Expand Down
34 changes: 18 additions & 16 deletions packages/main/src/types/FDC3Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ export interface FDC3Message {
source: string;
name?: string | null;
intent?: string | null;
data?: FDC3MessageData | null;
data?: FDC3MessageData | null;
tabId?: number;
selected?: FDC3App | null;
context?: Context | null;
}

export interface FDC3MessageData {
id? : string;
eventId? : string;
context? : Context;
name? : string;
intent? : string;
source? : string; //the viewId (internal instance identifier) of the sender of the message
channel? : string; //name of source/related channel
contextType? : string;
instanceId? : string;
ts? : number; //timestamp (for pending contexts/intents)
target? : TargetApp;
channelId? : string; //to do : refactor with channel prop
type? : string;
restoreOnly? : boolean;
}
id?: string;
eventId?: string;
context?: Context;
name?: string;
intent?: string;
source?: string; //the viewId (internal instance identifier) of the sender of the message
channel?: string; //name of source/related channel
contextType?: string;
instanceId?: string;
ts?: number; //timestamp (for pending contexts/intents)
target?: TargetApp;
channelId?: string; //to do : refactor with channel prop
type?: string;
restoreOnly?: boolean;
selectedIntent?: string;
selected?: FDC3App;
}
4 changes: 2 additions & 2 deletions packages/main/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { channels } from './system-channels';
import { ConnectedApp, Channel } from './types/FDC3Data';
import { ConnectedApp, ChannelData } from './types/FDC3Data';
import { FDC3EventDetail } from './types/FDC3Event';
import { DirectoryPort } from '../../../directory/src/config';

Expand Down Expand Up @@ -69,7 +69,7 @@ const ChannelError = {
//connected end points / apps
const connected: Map<string, ConnectedApp> = new Map();

const getSystemChannels = (): Array<Channel> => {
const getSystemChannels = (): Array<ChannelData> => {
return channels;
};

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 @@ -82,8 +82,9 @@ export class View {
this.content.setBackgroundColor('#fff');

this.content.webContents.on('ipc-message', (event, channel) => {
console.log('ipc-message', event.type);
console.log('ipc-message', event.type, channel);
if (channel === TOPICS.FDC3_INITIATE && !this.initiated) {
console.log('fdc3 initiating!');
initView(config);
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class Workspace {
// 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.openDevTools();
console.log('workspace created', this.id);
const runtime = getRuntime();
if (runtime) {
Expand Down
2 changes: 1 addition & 1 deletion packages/preload/exposedInMainWorld.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ interface Window {
readonly versions: NodeJS.ProcessVersions;
readonly workspace: { isConnected: () => boolean; };
readonly home: { getApps: () => Promise<unknown>; };
readonly fdc3: { getInfo(): import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/ImplementationMetadata").ImplementationMetadata; open: (app: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").TargetApp, context?: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<any>; broadcast: (context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => void; raiseIntent: (intent: string, context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context, app?: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").TargetApp) => Promise<any>; raiseIntentForContext(context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context, app?: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").TargetApp): Promise<any>; addContextListener: (contextType: any, handler?: any) => Listener; addIntentListener: (intent: string, listener: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").ContextHandler) => Listener; findIntent: (intent: string, context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<any>; findIntentsByContext: (context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<any>; getSystemChannels: () => Promise<any>; getOrCreateChannel: (channelId: string) => Promise<any>; joinChannel: (channel: string) => Promise<void>; leaveCurrentChannel: () => Promise<any>; getCurrentChannel: () => Promise<any>; getAppInstance: (instanceId: string) => Promise<import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/packages/main/src/types/AppInstance").AppInstance>; };
readonly fdc3: { getInfo(): import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/ImplementationMetadata").ImplementationMetadata; open: (app: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").TargetApp, context?: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<any>; broadcast: (context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => void; raiseIntent: (intent: string, context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context, app?: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").TargetApp) => Promise<any>; raiseIntentForContext(context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context, app?: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").TargetApp): Promise<any>; addContextListener: (contextType: string | import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").ContextHandler, handler?: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").ContextHandler) => Listener; addIntentListener: (intent: string, listener: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").ContextHandler) => Listener; findIntent: (intent: string, context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<any>; findIntentsByContext: (context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<any>; getSystemChannels: () => Promise<any>; getOrCreateChannel: (channelId: string) => Promise<any>; joinChannel: (channel: string) => Promise<void>; leaveCurrentChannel: () => Promise<any>; getCurrentChannel: () => Promise<any>; };
}
79 changes: 36 additions & 43 deletions packages/preload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,29 @@ ipcRenderer.on(TOPICS.CHANNEL_SELECTED, async (event, args) => {
);
});

(document as any).addEventListener(
TOPICS.JOIN_CHANNEL,
(event: CustomEvent) => {
ipcRenderer.send(TOPICS.JOIN_WORKSPACE_TO_CHANNEL, {
source: id,
data: event.detail,
});
},
);
document.addEventListener(TOPICS.JOIN_CHANNEL, ((event: CustomEvent) => {
ipcRenderer.send(TOPICS.JOIN_WORKSPACE_TO_CHANNEL, {
source: id,
data: event.detail,
});
}) as EventListener);

(document as any).addEventListener(TOPICS.SELECT_TAB, (event: CustomEvent) => {
document.addEventListener(TOPICS.SELECT_TAB, ((event: CustomEvent) => {
ipcRenderer.send(TOPICS.SELECT_TAB, {
source: id,
selected: event.detail.selected,
});
});
}) as EventListener);

(document as any).addEventListener(TOPICS.CLOSE_TAB, (event: CustomEvent) => {
document.addEventListener(TOPICS.CLOSE_TAB, ((event: CustomEvent) => {
ipcRenderer.send(TOPICS.CLOSE_TAB, { source: id, tabId: event.detail.tabId });
});
}) as EventListener);

(document as any).addEventListener(TOPICS.DROP_TAB, (event: CustomEvent) => {
document.addEventListener(TOPICS.DROP_TAB, ((event: CustomEvent) => {
ipcRenderer.send(TOPICS.DROP_TAB, { source: id, tabId: event.detail.tabId });
});
}) as EventListener);

(document as any).addEventListener(TOPICS.SEARCH, (event: CustomEvent) => {
document.addEventListener(TOPICS.SEARCH, ((event: CustomEvent) => {
const query = event.detail.query;
ipcRenderer.once(
`${TOPICS.FETCH_FROM_DIRECTORY}-/apps/search?text=${query}`,
Expand All @@ -106,7 +103,7 @@ ipcRenderer.on(TOPICS.CHANNEL_SELECTED, async (event, args) => {
source: id,
query: `/apps/search?text=${query}`,
});
});
}) as EventListener);

document.addEventListener(TOPICS.HIDE_RESULTS_WINDOW, () => {
ipcRenderer.send(TOPICS.HIDE_WINDOW, {
Expand All @@ -122,16 +119,15 @@ document.addEventListener(TOPICS.NEW_TAB_CLICK, () => {
ipcRenderer.send(TOPICS.NEW_TAB, { source: id });
});

(document as any).addEventListener(
TOPICS.OPEN_CHANNEL_PICKER_CLICK,
(event: CustomEvent) => {
ipcRenderer.send(TOPICS.RES_PICK_CHANNEL, {
source: id,
mouseX: event.detail.mouseX,
mouseY: event.detail.mouseY,
});
},
);
document.addEventListener(TOPICS.OPEN_CHANNEL_PICKER_CLICK, ((
event: CustomEvent,
) => {
ipcRenderer.send(TOPICS.RES_PICK_CHANNEL, {
source: id,
mouseX: event.detail.mouseX,
mouseY: event.detail.mouseY,
});
}) as EventListener);

document.addEventListener(TOPICS.OPEN_FRAME_TOOLS_CLICK, () => {
ipcRenderer.send(TOPICS.FRAME_DEV_TOOLS, { source: id });
Expand Down Expand Up @@ -159,23 +155,20 @@ const selectTab = (selectedId: string) => {
}
};

(document as any).addEventListener(TOPICS.SELECT_TAB, (event: CustomEvent) => {
document.addEventListener(TOPICS.SELECT_TAB, ((event: CustomEvent) => {
selectTab(event.detail.selected);
});

(document as any).addEventListener(
TOPICS.CHANNEL_SELECTED,
(event: CustomEvent) => {
//highlight the channelPicker button on selection (remove on deselection)
const channelPicker = document.getElementById('channelPicker');
if (channelPicker) {
channelPicker.style.backgroundColor =
event.detail.channel.displayMetadata.color;
channelPicker.style.borderColor =
event.detail.channel.displayMetadata.color2;
}
},
);
}) as EventListener);

document.addEventListener(TOPICS.CHANNEL_SELECTED, ((event: CustomEvent) => {
//highlight the channelPicker button on selection (remove on deselection)
const channelPicker = document.getElementById('channelPicker');
if (channelPicker) {
channelPicker.style.backgroundColor =
event.detail.channel.displayMetadata.color;
channelPicker.style.borderColor =
event.detail.channel.displayMetadata.color2;
}
}) as EventListener);

const api = {
isConnected: (): boolean => {
Expand Down
14 changes: 6 additions & 8 deletions packages/preload/src/intentResolver/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ipcRenderer } from 'electron';
import { Context } from '@finos/fdc3';
import { FDC3MessageData } from '../../../main/src/types/FDC3Message';
import { TOPICS } from '../../../main/src/constants';

let id: string | undefined = undefined;
Expand All @@ -17,19 +18,16 @@ ipcRenderer.on(TOPICS.WINDOW_START, (event, args) => {
);
});

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

(document as any).addEventListener(
TOPICS.RES_RESOLVE_INTENT,
(event: CustomEvent) => {
resolveIntent(event.detail);
},
);
document.addEventListener(TOPICS.RES_RESOLVE_INTENT, ((event: CustomEvent) => {
resolveIntent(event.detail);
}) as EventListener);
29 changes: 13 additions & 16 deletions packages/preload/src/searchResults/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ ipcRenderer.on(TOPICS.RES_LOAD_RESULTS, (event, args) => {
);
});

(document as any).addEventListener(
TOPICS.RESULT_SELECTED,
(event: CustomEvent) => {
const result = event.detail.result;
const selection = result.name;
if (selection) {
ipcRenderer.send(TOPICS.FDC3_OPEN, {
topic: 'open',
source: workspaceId,
data: { name: selection },
});
}
ipcRenderer.send(TOPICS.HIDE_WINDOW, {
document.addEventListener(TOPICS.RESULT_SELECTED, ((event: CustomEvent) => {
const result = event.detail.result;
const selection = result.name;
if (selection) {
ipcRenderer.send(TOPICS.FDC3_OPEN, {
topic: 'open',
source: workspaceId,
target: TARGETS.SEARCH_RESULTS,
data: { name: selection },
});
},
);
}
ipcRenderer.send(TOPICS.HIDE_WINDOW, {
source: workspaceId,
target: TARGETS.SEARCH_RESULTS,
});
}) as EventListener);
Loading

0 comments on commit 6b3014f

Please sign in to comment.