-
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.
- Loading branch information
Showing
18 changed files
with
6,601 additions
and
5,577 deletions.
There are no files selected for viewing
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
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,27 @@ | ||
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(); | ||
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) => { | ||
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,40 @@ | ||
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 './index'; | ||
|
||
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,31 @@ | ||
import { getRuntime } from '../../index'; | ||
import { | ||
tabSelected, | ||
tabDragStart, | ||
newTab, | ||
tearOutTab, | ||
closeTab, | ||
} from './tabs'; | ||
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', | ||
}; | ||
|
||
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.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); | ||
}; |
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,16 @@ | ||
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 | ||
const workspace = runtime?.getWorkspace(message.source); | ||
workspace?.loadSearchResults(message.data.results); | ||
}; |
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,166 @@ | ||
import { getRuntime } from '../../index'; | ||
import { RuntimeMessage } from '../runtimeMessage'; | ||
import { RUNTIME_TOPICS } from './index'; | ||
import { Point, screen } from 'electron'; | ||
import { Workspace } from '../../workspace'; | ||
|
||
export const tabSelected = async (message: RuntimeMessage) => { | ||
const runtime = getRuntime(); | ||
//bring selected browserview to front | ||
const workspace = runtime?.getWorkspace(message.source); | ||
if (workspace) { | ||
workspace.setSelectedTab(message.data.selected); | ||
} | ||
return; | ||
}; | ||
|
||
export const tabDragStart = async (message: RuntimeMessage) => { | ||
const runtime = getRuntime(); | ||
|
||
const workspace = runtime.getWorkspace(message.source); | ||
if (workspace) { | ||
runtime.draggedTab = { | ||
tabId: message.data?.selected, | ||
source: message.source, | ||
}; | ||
} | ||
return; | ||
}; | ||
|
||
export const newTab = async (message: RuntimeMessage) => { | ||
const runtime = getRuntime(); | ||
//bring selected browserview to front | ||
const workspace = runtime.getWorkspace(message.source); | ||
if (workspace) { | ||
workspace.createView(); | ||
} | ||
return; | ||
}; | ||
|
||
export const dropTab = async (message: RuntimeMessage) => { | ||
const runtime = getRuntime(); | ||
|
||
if (runtime.draggedTab) { | ||
console.log( | ||
'dragged tab', | ||
runtime.draggedTab.tabId, | ||
runtime.draggedTab.source, | ||
); | ||
} | ||
let tabId: string | undefined; | ||
let source: string | undefined; | ||
if (runtime.draggedTab) { | ||
tabId = runtime.draggedTab.tabId; | ||
source = runtime.draggedTab.source; | ||
runtime.draggedTab = null; | ||
} | ||
//to do: handle droppng on an existing workspace | ||
//get cursor position | ||
const p: Point = screen.getCursorScreenPoint(); | ||
// const targetWS = resolveWorkspaceFromPoint(p); | ||
let targetWS: Workspace | undefined; | ||
//add to existing? | ||
if (message.data.frameTarget) { | ||
targetWS = runtime.getWorkspace(message.source); | ||
} | ||
if (targetWS && tabId && source) { | ||
const oldWorkspace = runtime.getWorkspace(source); | ||
const draggedView = runtime.getView(tabId); | ||
//workspace | ||
if (oldWorkspace && draggedView) { | ||
//send event to UI to visually remove the tab | ||
console.log('calling remove tab'); | ||
await oldWorkspace.removeTab(draggedView.id); | ||
await targetWS.addTab(draggedView.id); | ||
} | ||
} else if (tabId) { | ||
//make a new workspace and window | ||
const workspace = runtime.createWorkspace({ | ||
x: p.x, | ||
y: p.y, | ||
onInit: () => { | ||
console.log('workspace created', workspace.id); | ||
return new Promise((resolve) => { | ||
if (tabId) { | ||
const oldWorkspace = runtime.getWorkspace(message.source); | ||
const draggedView = runtime.getView(tabId); | ||
//workspace | ||
if (oldWorkspace && draggedView) { | ||
//send event to UI to visually remove the tab | ||
if (oldWorkspace.window) { | ||
console.log('removing tab - sending message to client'); | ||
oldWorkspace.window.webContents.send( | ||
RUNTIME_TOPICS.REMOVE_TAB, | ||
{ | ||
tabId: tabId, | ||
}, | ||
); | ||
} | ||
oldWorkspace.removeTab(tabId).then(() => { | ||
if (tabId) { | ||
workspace.addTab(tabId); | ||
} | ||
}); | ||
} | ||
} | ||
resolve(); | ||
}); | ||
}, | ||
}); | ||
runtime.draggedTab = null; | ||
} | ||
return; | ||
}; | ||
|
||
export const closeTab = async (message: RuntimeMessage) => { | ||
const runtime = getRuntime(); | ||
//bring selected browserview to front | ||
const workspace = runtime.getWorkspace(message.source); | ||
if (workspace) { | ||
workspace.closeTab(message.data.tabId); | ||
} | ||
return; | ||
}; | ||
|
||
export const tearOutTab = async (message: RuntimeMessage) => { | ||
const runtime = getRuntime(); | ||
const tabId: string | undefined = message.data.tabId; | ||
|
||
//to do: handle droppng on an existing workspace | ||
//get cursor position | ||
const p: Point = screen.getCursorScreenPoint(); | ||
if (tabId) { | ||
//make a new workspace and window | ||
const workspace = runtime.createWorkspace({ | ||
x: p.x, | ||
y: p.y, | ||
onInit: () => { | ||
return new Promise((resolve) => { | ||
if (tabId) { | ||
const oldWorkspace = runtime.getWorkspace(message.source); | ||
const draggedView = runtime.getView(tabId); | ||
//workspace | ||
if (oldWorkspace && draggedView) { | ||
//send event to UI to visually remove the tab | ||
if (oldWorkspace.window) { | ||
console.log('removing tab - sending message to client'); | ||
oldWorkspace.window.webContents.send( | ||
RUNTIME_TOPICS.REMOVE_TAB, | ||
{ | ||
tabId: tabId, | ||
}, | ||
); | ||
} | ||
oldWorkspace.removeTab(tabId, true).then(() => { | ||
if (tabId) { | ||
workspace.addTab(tabId); | ||
} | ||
}); | ||
} | ||
} | ||
resolve(); | ||
}); | ||
}, | ||
}); | ||
} | ||
}; |
Oops, something went wrong.