Skip to content

Commit

Permalink
bumped to electron v20. fixes for breaking changes to preload and som…
Browse files Browse the repository at this point in the history
…e of the Vite configuration with electron upgrade. fixed some rendering issues in the view frame
  • Loading branch information
nkolba committed Sep 21, 2022
1 parent 3e85a75 commit e2bc286
Show file tree
Hide file tree
Showing 12 changed files with 6,201 additions and 3,943 deletions.
9,875 changes: 5,964 additions & 3,911 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@vitejs/plugin-react": "^1.1.3",
"cross-env": "^7.0.3",
"dts-for-context-bridge": "^0.7.1",
"electron": "^17.0.0",
"electron": "^20.0.0",
"electron-builder": "^22.14.5",
"electron-devtools-installer": "^3.2.0",
"eslint": "^8.6.0",
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
4 changes: 2 additions & 2 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,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 @@ -126,7 +126,7 @@ if (import.meta.env.DEV) {
}),
)
.catch((e) => console.error('Failed install extension:', e));
}
}*/

/**
* Check new app version in production mode only
Expand Down
2 changes: 1 addition & 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 Down
7 changes: 3 additions & 4 deletions packages/main/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,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 @@ -45,7 +45,6 @@ export class Workspace {
height: DEFAULT_WINDOW_HEIGHT,
width: DEFAULT_WINDOW_WIDTH,
webPreferences: {
nativeWindowOpen: true,
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'),
},
Expand Down Expand Up @@ -74,7 +73,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
104 changes: 102 additions & 2 deletions packages/preload/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,107 @@
import { ipcRenderer } from 'electron';
import { contextBridge } from 'electron';
import { channels } from '../../main/src/system-channels';
import { TOPICS, TARGETS } from '../../main/src/constants';

/**
* inline these dependencies ahead of refactoring the whole preload
**/

export const channels = [
{
id: 'red',
type: 'system',
displayMetadata: { color: '#da2d2d', color2: '#9d0b0b', name: 'Red' },
},
{
id: 'orange',
type: 'system',
displayMetadata: { color: '#eb8242', color2: '#e25822', name: 'Orange' },
},
{
id: 'yellow',
type: 'system',
displayMetadata: { color: '#f6da63', color2: '#e3c878', name: 'Yellow' },
},
{
id: 'green',
type: 'system',
displayMetadata: { color: '#42b883', color2: '#347474', name: 'Green' },
},
{
id: 'blue',
type: 'system',
displayMetadata: { color: '#1089ff', color2: '#505BDA', name: 'Blue' },
},
{
id: 'purple',
type: 'system',
displayMetadata: { color: '#C355F5', color2: '#AA26DA', name: 'Purple' },
},
];

export enum TARGETS {
SEARCH_RESULTS = 'searchResults',
INTENT_RESOLVER = 'intentResolver',
CHANNEL_PICKER = 'channelPicker',
}

export enum TOPICS {
OPEN_TOOLS_MENU = 'FRAME:openToolsMenu',
FRAME_READY = 'FRAME:ready',
SEARCH = 'WORK:search',
WORKSPACE_INIT = 'WORK:Init',
WORKSPACE_START = 'WORK:Start',
WINDOW_START = 'WIN:start',
WINDOW_SHOW = 'WIN:show',
ADD_TAB = 'WORK:addTab',
NEW_TAB = 'WORK:newTab',
NEW_TAB_CLICK = 'UI:newTab',
OPEN_CHANNEL_PICKER_CLICK = 'UI:openChannelPicker',
SELECT_TAB = 'WORK:selectTab', //tab state changes from event in the main process (i.e. change of focus from new view or intent resolution)
TAB_SELECTED = 'WORK:tabSelected', //tab is selected by user action in the UI
CLOSE_TAB = 'WORK:closeTab',
TAB_DRAG_START = 'WORK:tabDragStart',
TAB_DRAG_END = 'WORK:tabDragEnd',
TEAR_OUT_TAB = 'WORK:tearOutTab',
DROP_TAB = 'WORK:dropTab',
REMOVE_TAB = 'WORK:removeTab', //prune tab without closing the view (when moving tab from one window to another)
JOIN_CHANNEL = 'WORK:joinChannel',
LEAVE_CHANNEL = 'WORK:leaveChannel',
JOIN_WORKSPACE_TO_CHANNEL = 'FDC3:joinWorkspaceToChannel',
CONFIRM_JOIN = 'FDC3:confirmJoin',
PICK_CHANNEL = 'RES:pickChannel',
CHANNEL_SELECTED = 'WORK:channelSelected',
FETCH_FROM_DIRECTORY = 'WIN:fetchFromDirectory',
FRAME_DEV_TOOLS = 'WORK:openFrameDevTools',
TAB_DEV_TOOLS = 'WORK:openTabDevTools',
RES_LOAD_RESULTS = 'RES:loadResults',
RESULT_SELECTED = 'RES:resultSelected',
RES_PICK_CHANNEL = 'RES:pickChannel',
RES_RESOLVE_INTENT = 'RES:resolveIntent',
RES_LOAD_INTENT_RESULTS = 'RES:loadIntentResults',
HIDE_WINDOW = 'WORK:hideWindow',
HIDE_RESULTS_WINDOW = 'UI:hideResultsWindow',
FDC3_START = 'FDC3:start',
FDC3_INITIATE = 'FDC3:initiate',
FDC3_SET_CURRENT_CHANEL = 'FDC3:setCurrentChannel',
FDC3_GET_OR_CREATE_CHANNEL = 'FDC3:getOrCreateChannel',
FDC3_ADD_CONTEXT_LISTENER = 'FDC3:addContextListener',
FDC3_INTENT = 'FDC3:intent',
FDC3_CONTEXT = 'FDC3:context',
FDC3_BROADCAST = 'FDC3:broadcast',
FDC3_OPEN = 'FDC3:open',
FDC3_DROP_CONTEXT_LISTENER = 'FDC3:dropContextListener',
FDC3_GET_CURRENT_CONTEXT = 'FDC3:getCurrentContext',
FDC3_GET_SYSTEM_CHANNELS = 'FDC3:getSystemChannels',
FDC3_LEAVE_CURRENT_CHANNEL = 'FDC3:leaveCurrentChannel',
FDC3_ADD_INTENT_LISTENER = 'FDC3:addIntentListener',
FDC3_JOIN_CHANNEL = 'FDC3:joinChannel',
FDC3_FIND_INTENT = 'FDC3:findIntent',
FDC3_FIND_INTENTS_BY_CONTEXT = 'FDC3:findIntentsByContext',
FDC3_GET_CURRENT_CHANNEL = 'FDC3:getCurrentChannel',
FDC3_GET_APP_INSTANCE = 'FDC3:getAppInstance',
FDC3_RAISE_INTENT = 'FDC3:raiseIntent',
FDC3_RAISE_INTENT_FOR_CONTEXT = 'FDC3:raiseIntentForContext',
}

//flag to indicate the background script is ready for fdc3!
let connected = true;
Expand Down
106 changes: 106 additions & 0 deletions packages/preload/src/lib/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* generates a CustomEvent for FDC3 eventing in the DOM
* @param type
* @param detail
*/
export const fdc3Event = (type: string, detail: unknown): CustomEvent => {
return new CustomEvent(`FDC3:${type}`, { detail: detail });
};

export const channels = [
{
id: 'red',
type: 'system',
displayMetadata: { color: '#da2d2d', color2: '#9d0b0b', name: 'Red' },
},
{
id: 'orange',
type: 'system',
displayMetadata: { color: '#eb8242', color2: '#e25822', name: 'Orange' },
},
{
id: 'yellow',
type: 'system',
displayMetadata: { color: '#f6da63', color2: '#e3c878', name: 'Yellow' },
},
{
id: 'green',
type: 'system',
displayMetadata: { color: '#42b883', color2: '#347474', name: 'Green' },
},
{
id: 'blue',
type: 'system',
displayMetadata: { color: '#1089ff', color2: '#505BDA', name: 'Blue' },
},
{
id: 'purple',
type: 'system',
displayMetadata: { color: '#C355F5', color2: '#AA26DA', name: 'Purple' },
},
];

export enum TARGETS {
SEARCH_RESULTS = 'searchResults',
INTENT_RESOLVER = 'intentResolver',
CHANNEL_PICKER = 'channelPicker',
}

export enum TOPICS {
OPEN_TOOLS_MENU = 'FRAME:openToolsMenu',
FRAME_READY = 'FRAME:ready',
SEARCH = 'WORK:search',
WORKSPACE_INIT = 'WORK:Init',
WORKSPACE_START = 'WORK:Start',
WINDOW_START = 'WIN:start',
WINDOW_SHOW = 'WIN:show',
ADD_TAB = 'WORK:addTab',
NEW_TAB = 'WORK:newTab',
NEW_TAB_CLICK = 'UI:newTab',
OPEN_CHANNEL_PICKER_CLICK = 'UI:openChannelPicker',
SELECT_TAB = 'WORK:selectTab', //tab state changes from event in the main process (i.e. change of focus from new view or intent resolution)
TAB_SELECTED = 'WORK:tabSelected', //tab is selected by user action in the UI
CLOSE_TAB = 'WORK:closeTab',
TAB_DRAG_START = 'WORK:tabDragStart',
TAB_DRAG_END = 'WORK:tabDragEnd',
TEAR_OUT_TAB = 'WORK:tearOutTab',
DROP_TAB = 'WORK:dropTab',
REMOVE_TAB = 'WORK:removeTab', //prune tab without closing the view (when moving tab from one window to another)
JOIN_CHANNEL = 'WORK:joinChannel',
LEAVE_CHANNEL = 'WORK:leaveChannel',
JOIN_WORKSPACE_TO_CHANNEL = 'FDC3:joinWorkspaceToChannel',
CONFIRM_JOIN = 'FDC3:confirmJoin',
PICK_CHANNEL = 'RES:pickChannel',
CHANNEL_SELECTED = 'WORK:channelSelected',
FETCH_FROM_DIRECTORY = 'WIN:fetchFromDirectory',
FRAME_DEV_TOOLS = 'WORK:openFrameDevTools',
TAB_DEV_TOOLS = 'WORK:openTabDevTools',
RES_LOAD_RESULTS = 'RES:loadResults',
RESULT_SELECTED = 'RES:resultSelected',
RES_PICK_CHANNEL = 'RES:pickChannel',
RES_RESOLVE_INTENT = 'RES:resolveIntent',
RES_LOAD_INTENT_RESULTS = 'RES:loadIntentResults',
HIDE_WINDOW = 'WORK:hideWindow',
HIDE_RESULTS_WINDOW = 'UI:hideResultsWindow',
FDC3_START = 'FDC3:start',
FDC3_INITIATE = 'FDC3:initiate',
FDC3_SET_CURRENT_CHANEL = 'FDC3:setCurrentChannel',
FDC3_GET_OR_CREATE_CHANNEL = 'FDC3:getOrCreateChannel',
FDC3_ADD_CONTEXT_LISTENER = 'FDC3:addContextListener',
FDC3_INTENT = 'FDC3:intent',
FDC3_CONTEXT = 'FDC3:context',
FDC3_BROADCAST = 'FDC3:broadcast',
FDC3_OPEN = 'FDC3:open',
FDC3_DROP_CONTEXT_LISTENER = 'FDC3:dropContextListener',
FDC3_GET_CURRENT_CONTEXT = 'FDC3:getCurrentContext',
FDC3_GET_SYSTEM_CHANNELS = 'FDC3:getSystemChannels',
FDC3_LEAVE_CURRENT_CHANNEL = 'FDC3:leaveCurrentChannel',
FDC3_ADD_INTENT_LISTENER = 'FDC3:addIntentListener',
FDC3_JOIN_CHANNEL = 'FDC3:joinChannel',
FDC3_FIND_INTENT = 'FDC3:findIntent',
FDC3_FIND_INTENTS_BY_CONTEXT = 'FDC3:findIntentsByContext',
FDC3_GET_CURRENT_CHANNEL = 'FDC3:getCurrentChannel',
FDC3_GET_APP_INSTANCE = 'FDC3:getAppInstance',
FDC3_RAISE_INTENT = 'FDC3:raiseIntent',
FDC3_RAISE_INTENT_FOR_CONTEXT = 'FDC3:raiseIntentForContext',
}
19 changes: 9 additions & 10 deletions packages/preload/src/view/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { contextBridge } from 'electron';
import utils from '../../../main/src/utils';
import { fdc3Event, TOPICS } from '../lib/lib';
import { Listener } from '@finos/fdc3';
import {
Context,
Expand All @@ -12,7 +12,6 @@ import {
import { FDC3Event, FDC3EventDetail } from '../../../main/src/types/FDC3Event';
import { ChannelData } from '../../../main/src/types/FDC3Data';
import { FDC3EventEnum } from '../../../main/src/types/FDC3Event';
import { TOPICS } from '../../../main/src/constants';

/** generate pseudo-random ids for handlers created on the client */
const guid = (): string => {
Expand Down Expand Up @@ -62,7 +61,7 @@ export function createAPI() {
_contextListeners.delete(this.id);
//notify the background script
document.dispatchEvent(
utils.fdc3Event(FDC3EventEnum.DropContextListener, { id: this.id }),
fdc3Event(FDC3EventEnum.DropContextListener, { id: this.id }),
);
} else if (this.type === 'intent' && this.intent) {
const listeners = _intentListeners.get(this.intent);
Expand All @@ -71,7 +70,7 @@ export function createAPI() {
}
//notify the background script
document.dispatchEvent(
utils.fdc3Event(FDC3EventEnum.DropIntentListener, {
fdc3Event(FDC3EventEnum.DropIntentListener, {
id: this.id,
intent: this.intent,
}),
Expand Down Expand Up @@ -150,7 +149,7 @@ export function createAPI() {
createListenerItem(listenerId, thisListener, thisContextType),
);
document.dispatchEvent(
utils.fdc3Event(FDC3EventEnum.AddContextListener, {
fdc3Event(FDC3EventEnum.AddContextListener, {
id: listenerId,
channel: channel.id,
contextType: thisContextType,
Expand Down Expand Up @@ -189,7 +188,7 @@ export function createAPI() {
detail.eventId = eventId;
detail.ts = ts;
if (config && config.void) {
document.dispatchEvent(utils.fdc3Event(method, detail));
document.dispatchEvent(fdc3Event(method, detail));
return new Promise((resolve) => {
resolve();
});
Expand All @@ -210,7 +209,7 @@ export function createAPI() {
{ once: true },
);

document.dispatchEvent(utils.fdc3Event(method, detail));
document.dispatchEvent(fdc3Event(method, detail));
});
}
};
Expand Down Expand Up @@ -263,7 +262,7 @@ export function createAPI() {
createListenerItem(listenerId, thisListener, thisContextType),
);
document.dispatchEvent(
utils.fdc3Event(FDC3EventEnum.AddContextListener, {
fdc3Event(FDC3EventEnum.AddContextListener, {
id: listenerId,
contextType: thisContextType,
}),
Expand All @@ -280,7 +279,7 @@ export function createAPI() {
if (listeners) {
listeners.set(listenerId, createListenerItem(listenerId, listener));
document.dispatchEvent(
utils.fdc3Event(FDC3EventEnum.AddIntentListener, {
fdc3Event(FDC3EventEnum.AddIntentListener, {
id: listenerId,
intent: intent,
}),
Expand Down Expand Up @@ -411,7 +410,7 @@ export function createAPI() {
}
//emit return event
document.dispatchEvent(
utils.fdc3Event(FDC3EventEnum.IntentComplete, { data: result }),
fdc3Event(FDC3EventEnum.IntentComplete, { data: result }),
);
}
}) as EventListener);
Expand Down
Loading

0 comments on commit e2bc286

Please sign in to comment.