-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from nkolba/handlers
Handlers Refactor
- Loading branch information
Showing
35 changed files
with
2,502 additions
and
1,784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Chrome 98 | ||
Chrome 106 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getRuntime } from '../../index'; | ||
import { resolveIntent } from './resolveIntent'; | ||
|
||
export const FDC3_TOPICS = { | ||
RESOLVE_INTENT: 'fdc3:resolveIntent', | ||
}; | ||
|
||
export const register = () => { | ||
const runtime = getRuntime(); | ||
|
||
runtime.addHandler(FDC3_TOPICS.RESOLVE_INTENT, resolveIntent); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { FDC3App } from '../types/FDC3Data'; | ||
import { Context, TargetApp } from '@finos/fdc3'; | ||
import { RuntimeMessage } from './runtimeMessage'; | ||
|
||
export interface FDC3Message extends RuntimeMessage { | ||
name?: string; | ||
intent?: string; | ||
selected?: FDC3App; | ||
context?: Context; | ||
} | ||
|
||
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; | ||
selectedIntent?: string; | ||
selected?: FDC3App; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { getRuntime } from '../../index'; | ||
import { RuntimeMessage } from '../runtimeMessage'; | ||
|
||
export const hideChannelWindow = async (message: RuntimeMessage) => { | ||
const runtime = getRuntime(); | ||
//bring selected browserview to front | ||
const workspace = runtime?.getWorkspace(message.source); | ||
workspace?.hideChannelWindow(); | ||
}; | ||
|
||
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; | ||
if (sourceWS) { | ||
sourceWS.showChannelWindow(mouseX, mouseY); | ||
} | ||
}; | ||
|
||
export const joinChannel = async (message: RuntimeMessage) => { | ||
console.log('joinChannel', message); | ||
const runtime = getRuntime(); | ||
const sourceWS = runtime.getWorkspace(message.source); | ||
if (sourceWS) { | ||
sourceWS.setChannel(message.data.channel); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { getRuntime } from '../../index'; | ||
import { RuntimeMessage } from '../runtimeMessage'; | ||
import { WebContents } from 'electron'; | ||
import utils from '../../utils'; | ||
import fetch from 'electron-fetch'; | ||
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(); | ||
|
||
//request can come frome 2 types of (priviledged) sources: the workspace UI and views | ||
//if the sourceType is View. We need to check that the view is a 'system' view and can access the directory | ||
//through this API. Today, this is only the 'home' view. | ||
let wContents: WebContents | undefined = undefined; | ||
|
||
if (message.data.sourceType && message.data.sourceType === 'view') { | ||
//ensure this is a view that has permissions for this api | ||
const sourceView = runtime.getView(message.source); | ||
if (sourceView && sourceView.isSystemView() && sourceView.content) { | ||
wContents = sourceView.content.webContents; | ||
} | ||
} else { | ||
const sourceWS = runtime.getWorkspace(message.source); | ||
if (sourceWS && sourceWS.window) { | ||
wContents = sourceWS.window.webContents; | ||
} | ||
} | ||
|
||
if (wContents) { | ||
wContents.send( | ||
`${RUNTIME_TOPICS.FETCH_FROM_DIRECTORY}-${message.data.query}`, | ||
{ | ||
data: result, | ||
}, | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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'; | ||
import { pickChannel, joinChannel } from './channelPicker'; | ||
import { loadSearchResults } from './search'; | ||
import { resolveIntent } from '../fdc3/resolveIntent'; | ||
|
||
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); | ||
runtime.addHandler(RUNTIME_TOPICS.RES_RESOLVE_INTENT, resolveIntent); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { getRuntime } from '../../index'; | ||
import { RuntimeMessage } from '../runtimeMessage'; | ||
|
||
export const hideSearchResults = async (message: RuntimeMessage) => { | ||
const runtime = getRuntime(); | ||
//bring selected browserview to front | ||
const workspace = runtime?.getWorkspace(message.source); | ||
workspace?.hideSearchResults(); | ||
}; | ||
|
||
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); | ||
}; |
Oops, something went wrong.