Skip to content

Commit

Permalink
Refactor containers to use factory method for creating the message bus (
Browse files Browse the repository at this point in the history
  • Loading branch information
bingenito authored Jul 23, 2018
1 parent 8323b4f commit dffbf31
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Default/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class DefaultContainer extends WebContainerBase {
super(win);
this.hostType = "Default";

this.ipc = new DefaultMessageBus(this);
this.ipc = this.createMessageBus();

// Create a global windows object for tracking all windows and add the current global window for current
if (this.globalWindow && !(DefaultContainer.windowsPropertyKey in this.globalWindow)) {
Expand All @@ -203,6 +203,10 @@ export class DefaultContainer extends WebContainerBase {
this.screen = new DefaultDisplayManager(this.globalWindow);
}

protected createMessageBus() : MessageBus {
return new DefaultMessageBus(this);
}

public getMainWindow(): ContainerWindow {
if (!this.mainWindow) {
this.mainWindow = new DefaultContainerWindow(this.globalWindow);
Expand Down
6 changes: 5 additions & 1 deletion src/Electron/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export class ElectronContainer extends WebContainerBase {
this.menu = this.electron.Menu;

this.internalIpc = ipc || ((this.isRemote) ? require("electron").ipcRenderer : this.electron.ipcMain);
this.ipc = new ElectronMessageBus(this.internalIpc, this.browserWindow);
this.ipc = this.createMessageBus();

if (!this.isRemote || (options && typeof options.isRemote !== "undefined" && !options.isRemote)) {
this.windowManager = new ElectronWindowManager(this.app, this.internalIpc, this.browserWindow);
Expand All @@ -303,6 +303,10 @@ export class ElectronContainer extends WebContainerBase {
this.screen = new ElectronDisplayManager(this.electron);
}

protected createMessageBus() : MessageBus {
return new ElectronMessageBus(this.internalIpc, this.browserWindow);
}

protected registerNotificationsApi() {
if (typeof this.globalWindow !== "undefined" && this.globalWindow) {
// Define owningContainer for closure to inner class
Expand Down
6 changes: 5 additions & 1 deletion src/OpenFin/openfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export class OpenFinContainer extends WebContainerBase {
this.desktop.Application.getCurrent().registerUser(options.userName, options.appName);
}

this.ipc = new OpenFinMessageBus(this.desktop.InterApplicationBus, (<any>this.desktop.Application.getCurrent()).uuid);
this.ipc = this.createMessageBus();

let replaceNotificationApi = OpenFinContainer.replaceNotificationApi;
if (options && typeof options.replaceNotificationApi !== "undefined") {
Expand All @@ -366,6 +366,10 @@ export class OpenFinContainer extends WebContainerBase {
this.screen = new OpenFinDisplayManager(this.desktop);
}

protected createMessageBus() : MessageBus {
return new OpenFinMessageBus(this.desktop.InterApplicationBus, (<any>this.desktop.Application.getCurrent()).uuid);
}

protected registerNotificationsApi() {
if (typeof this.globalWindow !== "undefined" && this.globalWindow) {
// Define owningContainer for closure to inner class
Expand Down
3 changes: 3 additions & 0 deletions src/desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Container } from "./container";
import { ContainerNotification } from "./notification";
import { ObjectTransform } from "./propertymapping";
import { ContainerWindow, WindowStateTracking, GroupWindowManager, SnapAssistWindowManager } from "./window";
import { MessageBusSubscription, MessageBusOptions } from "./ipc";
import * as Default from "./Default/default";
import * as Electron from "./Electron/electron";
import * as OpenFin from "./OpenFin/openfin";
Expand All @@ -21,4 +22,6 @@ export default class Desktop { //tslint:disable-line
static get WindowStateTracking(): typeof WindowStateTracking { return WindowStateTracking; }
static get GroupWindowManager(): typeof GroupWindowManager { return GroupWindowManager; }
static get SnapAssistWindowManager(): typeof SnapAssistWindowManager { return SnapAssistWindowManager; }
static get MessageBusSubscription(): typeof MessageBusSubscription { return MessageBusSubscription; }
static get MessageBusOptions(): typeof MessageBusOptions { return MessageBusOptions; }
}

0 comments on commit dffbf31

Please sign in to comment.