Skip to content

Commit

Permalink
Provide access to username/appname OpenFin registerUser override for …
Browse files Browse the repository at this point in the history
…licensing api (#142)

Fixes #141
  • Loading branch information
bingenito authored Apr 4, 2018
1 parent 2cd8b98 commit 074daf1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/OpenFin/openfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MessageBus, MessageBusSubscription, MessageBusOptions } from "../ipc";

ContainerRegistry.registerContainer("OpenFin", {
condition: () => typeof window !== "undefined" && "fin" in window && "desktop" in fin,
create: () => new OpenFinContainer()
create: (options) => new OpenFinContainer(null, null, options)
});

const windowEventMap = {
Expand Down Expand Up @@ -298,11 +298,15 @@ export class OpenFinContainer extends WebContainerBase {
</html>`;
/* tslint:enable */

public constructor(desktop?: fin.OpenFinDesktop, win?: Window) {
public constructor(desktop?: fin.OpenFinDesktop, win?: Window, options?: any) {
super(win);
this.desktop = desktop || fin.desktop;
this.hostType = "OpenFin";

if (options && options.userName && options.appName) {
this.desktop.Application.getCurrent().registerUser(options.userName, options.appName);
}

this.ipc = new OpenFinMessageBus(this.desktop.InterApplicationBus, (<any>this.desktop.Application.getCurrent()).uuid);
this.registerNotificationsApi();
}
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/OpenFin/openfin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,40 @@ describe("OpenFinContainer", () => {
expect(container.hostType).toEqual("OpenFin");
});

describe("ctor options", () => {
describe("registerUser", () => {
let desktop;
let app;

beforeEach(() => {
desktop = jasmine.createSpyObj("desktop", ["Application"]);
app = jasmine.createSpyObj("application", ["getCurrent", "registerUser"]);
Object.defineProperty(desktop, "Application", { value: app });
app.getCurrent.and.returnValue(app);
});

it("options userName and appName to registerUser", () => {
const container = new OpenFinContainer(desktop, null, { userName: "user", appName: "app" });
expect(app.registerUser).toHaveBeenCalledWith("user", "app");
});

it("options missing userName does not invoke registerUser", () => {
const container = new OpenFinContainer(desktop, null, { appName: "app" });
expect(app.registerUser).toHaveBeenCalledTimes(0);
});

it("options missing userName does not invoke registerUser", () => {
const container = new OpenFinContainer(desktop, null, { userName: "user" });
expect(app.registerUser).toHaveBeenCalledTimes(0);
});

it("options missing userName and appName does not invoke registerUser", () => {
const container = new OpenFinContainer(desktop, null, {});
expect(app.registerUser).toHaveBeenCalledTimes(0);
});
});
});

it("getMainWindow returns wrapped inner window", () => {
const win: OpenFinContainerWindow = container.getMainWindow();
expect(win).toBeDefined();
Expand Down

0 comments on commit 074daf1

Please sign in to comment.