Skip to content

Commit

Permalink
Reverting to promise for handler
Browse files Browse the repository at this point in the history
Signed-off-by: 1000TurquoisePogs <[email protected]>
  • Loading branch information
1000TurquoisePogs committed Feb 19, 2019
1 parent 4bf48f2 commit 2a87f2b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ViewportManager implements MVDHosting.ViewportManagerInterface {
private viewports: Map<MVDHosting.ViewportId, Viewport>;
private viewportInstances: Map<MVDHosting.ViewportId, MVDHosting.InstanceId>;
private readonly logger: ZLUX.ComponentLogger = BaseLogger;
private closeHandlers: Map<MVDHosting.ViewportId, Array<MVDHosting.ViewportCloseHandler>>;
private closeHandlers: Map<MVDHosting.ViewportId, Array<() => Promise<any>>>;
constructor() {
this.viewports = new Map();
this.viewportInstances = new Map();
Expand All @@ -42,20 +42,20 @@ export class ViewportManager implements MVDHosting.ViewportManagerInterface {
this.viewportInstances.set(viewportId, instanceId);
}

registerViewportCloseHandler(viewportId: MVDHosting.ViewportId, handler: MVDHosting.ViewportCloseHandler):void {
registerViewportCloseHandler(viewportId: MVDHosting.ViewportId, handler: () => Promise<any>):void {
let handlers = this.closeHandlers.get(viewportId);
if (!handlers) {
handlers = new Array<MVDHosting.ViewportCloseHandler>();
handlers = new Array<() => Promise<any>>();
this.closeHandlers.set(viewportId, handlers);
}
handlers.push(handler);
}

private closeWatcherLoop(pos: number, handlers: Array<MVDHosting.ViewportCloseHandler>, finishedCallback: any, rejectCallback: any): void {
private closeWatcherLoop(pos: number, handlers: Array<() => Promise<any>>, finishedCallback: any, rejectCallback: any): void {
if (pos >= handlers.length) {
finishedCallback();
} else {
handlers[pos].onViewportClosed().then(()=> {
handlers[pos]().then(()=> {
this.closeWatcherLoop(++pos, handlers, finishedCallback, rejectCallback);
}).catch((reason:any)=> {
rejectCallback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export class WindowManagerService implements MVDWindowManagement.WindowManagerSe
return {
resized: events.windowResized,
spawnContextMenu: (xRel, yRel, items) => this.spawnContextMenu(windowId, xRel, yRel, items),
registerCloseHandler: (handler: MVDHosting.ViewportCloseHandler) => this.viewportManager.registerViewportCloseHandler(viewportId, handler)
registerCloseHandler: (handler) => this.viewportManager.registerViewportCloseHandler(viewportId, handler)
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class SimpleWindowManagerService implements MVDWindowManagement.WindowMan
return {
resized: this.windowResized,
spawnContextMenu: (xRel, yRel, items) => this.spawnContextMenu(windowId, xRel, yRel, items),
registerCloseHandler: (handler: MVDHosting.ViewportCloseHandler) => this.viewportManager.registerViewportCloseHandler(viewportId, handler)
registerCloseHandler: (handler: ()=>Promise<any>) => this.viewportManager.registerViewportCloseHandler(viewportId, handler)
};
}

Expand Down
2 changes: 1 addition & 1 deletion virtual-desktop/src/pluginlib/inject-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export interface Angular2PluginWindowEvents {
export interface Angular2PluginViewportEvents {
readonly resized: Subject<{width: number, height: number}>;
readonly spawnContextMenu: (xPos: number, yPos: number, items: ContextMenuItem[]) => void;
readonly registerCloseHandler: (handler: MVDHosting.ViewportCloseHandler) => void;
readonly registerCloseHandler: (handler: () => Promise<any>) => void;
}

export interface Angular2PluginEmbedActions {
Expand Down

0 comments on commit 2a87f2b

Please sign in to comment.