Skip to content

Commit

Permalink
Merge pull request #33 from nkolba/fix-channel-selection
Browse files Browse the repository at this point in the history
fixed behavior of joinViewToChannel so that it will ensure the channe…
  • Loading branch information
nkolba authored Apr 29, 2022
2 parents f89a094 + f5bfb25 commit 1a8d470
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 33 deletions.
75 changes: 43 additions & 32 deletions packages/main/src/listeners/fdc3Listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,45 +670,56 @@ export const joinViewToChannel = (
//if there is a context...
const contexts = runtime.getContexts();
const channelContext = contexts.get(channel);
if (channelContext) {
const ctx = channelContext.length > 0 ? channelContext[0] : null;
let contextSent = false;

if (ctx && (restoreOnly === undefined || !restoreOnly)) {
// send to individual listenerIds

view.listeners.forEach((l) => {
//if this is not an intent listener, and not set for a specific channel, and not set for a non-matching context type - send the context to the listener
if (!l.intent) {
if (
(!l.channel ||
l.channel === 'default' ||
(l.channel && l.channel === channel)) &&
(!l.contextType ||
(l.contextType && l.contextType === ctx.type))
) {
view.content.webContents.send(TOPICS.FDC3_CONTEXT, {
topic: 'context',
listenerIds: [l.listenerId],
data: { context: ctx, listenerId: l.listenerId },
source: view.id,
});
contextSent = true;
//ensure the channel state for the view's workspace is updated
if (view.parent) {
const sourceWS = runtime.getWorkspace(view.parent.id);
//setChannel will result in calling joinViewToChannel again,
//so we are going to no op if that is the case
//which would mean that 'joinChannel' has been called programtically from the fdc3 api
if (sourceWS && sourceWS.channel !== channel) {
sourceWS.setChannel(channel);
} else {
if (channelContext) {
const ctx = channelContext.length > 0 ? channelContext[0] : null;
let contextSent = false;

if (ctx && (restoreOnly === undefined || !restoreOnly)) {
// send to individual listenerIds

view.listeners.forEach((l) => {
//if this is not an intent listener, and not set for a specific channel, and not set for a non-matching context type - send the context to the listener
if (!l.intent) {
if (
(!l.channel ||
l.channel === 'default' ||
(l.channel && l.channel === channel)) &&
(!l.contextType ||
(l.contextType && l.contextType === ctx.type))
) {
view.content.webContents.send(TOPICS.FDC3_CONTEXT, {
topic: 'context',
listenerIds: [l.listenerId],
data: { context: ctx, listenerId: l.listenerId },
source: view.id,
});
contextSent = true;
}
}
});
if (!contextSent) {
//note: the source for this context is the view itself - since this was the result of being joined to the channel (not context being broadcast from another view)
console.log(
'setPendingContext',
channelContext && channelContext[0],
);
view.setPendingContext(channelContext && channelContext[0]);
}
}
});
if (!contextSent) {
//note: the source for this context is the view itself - since this was the result of being joined to the channel (not context being broadcast from another view)
console.log(
'setPendingContext',
channelContext && channelContext[0],
);
view.setPendingContext(channelContext && channelContext[0]);
}
}
}
}

resolve();
} catch (err) {
reject(err);
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<FDC3Result>; 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<FDC3Result>; 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<FDC3Result>; 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<FDC3Result>; findIntentsByContext: (context: import("/Users/nicholaskolba/connectifi/agent/electron-fdc3/node_modules/@finos/fdc3/dist/context/ContextTypes").Context) => Promise<FDC3Result>; getSystemChannels: () => Promise<FDC3Result>; getOrCreateChannel: (channelId: string) => Promise<FDC3Result>; joinChannel: (channel: string) => Promise<void>; leaveCurrentChannel: () => Promise<FDC3Result>; getCurrentChannel: () => Promise<FDC3Result>; };
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) => Listener; addIntentListener: (intent: string, listener: import("/Users/nicholaskolba/connectifi/electron-fdc3/node_modules/@finos/fdc3/dist/api/Types").ContextHandler) => Listener; 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<void>; leaveCurrentChannel: () => Promise<FDC3Result>; getCurrentChannel: () => Promise<FDC3Result>; };
}

0 comments on commit 1a8d470

Please sign in to comment.