openfin-adapter
Advanced tools
Comparing version 17.55.11 to 17.55.12
{ | ||
"name": "openfin-adapter", | ||
"version": "17.55.11", | ||
"version": "17.55.12", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "main": "./src/main.js", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable no-console */ | ||
/* eslint-disable class-methods-use-this, no-undef */ | ||
@@ -47,3 +48,4 @@ /* global localStorage */ | ||
'parent', | ||
'target' | ||
'target', | ||
'updateStateIfExists' | ||
]; | ||
@@ -239,6 +241,12 @@ // Remove internal/non used values | ||
// ************* UTILS ************** | ||
const windowExists = async (winName) => { | ||
const application = fin.Application.getCurrentSync(); | ||
const childWindows = await application.getChildWindows(); | ||
return childWindows.some((win) => win.identity.name === winName); | ||
const createOrWrapView = async (convertedOpts, target) => { | ||
const allViews = await app.getViews(); | ||
let view = allViews.find((v) => v.identity.name === convertedOpts.name); | ||
if (!view) { | ||
view = await fin.View.create({ ...convertedOpts, target }); | ||
if (!fin.__internal_.childViews) { | ||
view.navigate(convertedOpts.url); | ||
} | ||
} | ||
return view; | ||
}; | ||
@@ -275,42 +283,11 @@ // MAKE ME REAL OR KILL ME | ||
// const closeWindow = identity => fin.Window.wrapSync(identity).close(); | ||
const resolveWhenLayoutReady = (win) => new Promise((res) => win.on('layout-ready', () => res())); | ||
const resolveWhenLayoutReady = (win) => new Promise((res) => win.on('layout-ready', () => res(win))); | ||
async function openSnapshot(snapshot) { | ||
const currentWindowNames = (await fin.Application.getCurrentSync().getChildWindows()).map((win) => win.identity.name); | ||
const creationPromises = snapshot.windows.map(async (windowOptions) => { | ||
const { uuid } = fin.me; | ||
const win = fin.Window.wrapSync({ uuid, name: windowOptions.name }); | ||
const resolveCondition = windowOptions.layout ? resolveWhenLayoutReady(win) : undefined; | ||
if (currentWindowNames.includes(windowOptions.name)) { | ||
if (windowOptions.layout) { | ||
await platformProvider.replaceLayout({ opts: windowOptions, target: win.identity }, fin.me.identity); | ||
} | ||
platformProvider.setWindowContext({ | ||
target: win.identity, | ||
entityType: EntityType_1.default.WINDOW, | ||
context: windowOptions.customContext | ||
}, fin.me.identity); | ||
if (windowOptions.state === 'minimized') { | ||
win.minimize(); | ||
} | ||
else if (windowOptions.state === 'maximized') { | ||
win.maximize(); | ||
} | ||
const x = windowOptions.x || windowOptions.defaultLeft; | ||
const y = windowOptions.y || windowOptions.defaultTop; | ||
const width = windowOptions.width || windowOptions.defaultWidth; | ||
const height = windowOptions.height || windowOptions.defaultHeight; | ||
if (width && height) { | ||
win.resizeTo(width, height, 'top-left'); | ||
} | ||
if (x && y) { | ||
win.moveTo(x, y); | ||
} | ||
return resolveCondition; | ||
if (windowOptions.updateStateIfExists === undefined) { | ||
windowOptions.updateStateIfExists = true; | ||
} | ||
const pooledViewMap = await view_pool_1.getPooledViewObject(); | ||
if (windowOptions.layout) { | ||
windowOptions.layout.content = (await mapLayoutContentItems(windowOptions.layout.content, async (contentItem) => modifyContentItemName(contentItem, !pooledViewMap[contentItem.componentState.name]))); | ||
} | ||
await platformProvider.createWindow(windowOptions, fin.me.identity); | ||
return resolveCondition; | ||
return platformProvider | ||
.createWindow(windowOptions, fin.me.identity) | ||
.catch((e) => console.error(e)); | ||
}); | ||
@@ -389,11 +366,64 @@ await Promise.all(creationPromises); | ||
const { reason = Platform_1.WindowCreationReason.APICall, ...windowOptions } = options; | ||
const currentWindowNames = (await app.getChildWindows()).map((win) => win.identity.name); | ||
const { uuid } = fin.me; | ||
if (windowOptions.name && currentWindowNames.includes(windowOptions.name)) { | ||
if (!windowOptions.updateStateIfExists) { | ||
throw new Error(`Trying to create a Window in ${uuid} Platform with name already in use - ${windowOptions.name}`); | ||
} | ||
const win = fin.Window.wrapSync({ uuid, name: windowOptions.name }); | ||
const resolveCondition = windowOptions.layout ? resolveWhenLayoutReady(win) : win; | ||
if (windowOptions.layout) { | ||
platformProvider.replaceLayout({ opts: windowOptions, target: win.identity }, fin.me.identity); | ||
} | ||
platformProvider.setWindowContext({ | ||
target: win.identity, | ||
entityType: EntityType_1.default.WINDOW, | ||
context: windowOptions.customContext | ||
}, fin.me.identity); | ||
if (windowOptions.state === 'minimized') { | ||
win.minimize(); | ||
} | ||
else if (windowOptions.state === 'maximized') { | ||
win.maximize(); | ||
} | ||
const x = windowOptions.x || windowOptions.defaultLeft; | ||
const y = windowOptions.y || windowOptions.defaultTop; | ||
const width = windowOptions.width || windowOptions.defaultWidth; | ||
const height = windowOptions.height || windowOptions.defaultHeight; | ||
if (width && height) { | ||
win.resizeTo(width, height, 'top-left'); | ||
} | ||
if (x && y) { | ||
win.moveTo(x, y); | ||
} | ||
return resolveCondition; | ||
} | ||
const pooledViewMap = await view_pool_1.getPooledViewObject(); | ||
if (windowOptions.layout) { | ||
windowOptions.layout.content = await mapLayoutContentItems(windowOptions.layout.content, async (contentItem) => modifyContentItemName(contentItem, !pooledViewMap[contentItem.componentState.name] && | ||
reason !== Platform_1.WindowCreationReason.Tearout && | ||
// In the CreateViewWithoutTarget case, we have already generated a name for the view. | ||
// Generating a new one will mess up listeners created as part of view creation. | ||
reason !== Platform_1.WindowCreationReason.CreateViewWithoutTarget)); | ||
const convertedOpts = await convertWindowOptions(windowOptions); | ||
if (convertedOpts.layout) { | ||
convertedOpts.layout.content = await mapLayoutContentItems(convertedOpts.layout.content, async (contentItem) => { | ||
const newOpts = modifyContentItemName(contentItem, | ||
// The name does not need to be generated for a tearout or if it matches a pooled view (i.e. use existing view) | ||
!pooledViewMap[contentItem.componentState.name] && | ||
reason !== Platform_1.WindowCreationReason.Tearout && | ||
// In the CreateViewWithoutTarget case, we have already generated a name for the view. | ||
// Generating a new one will mess up listeners created as part of view creation. | ||
reason !== Platform_1.WindowCreationReason.CreateViewWithoutTarget); | ||
return newOpts; | ||
}); | ||
const win = fin.Window.wrapSync({ uuid, name: convertedOpts.name }); | ||
const layoutResolved = resolveWhenLayoutReady(win); | ||
fin.Window.create(convertedOpts); | ||
// using this `map` function just to iterate recursively over the content and dropping return value on floor | ||
mapLayoutContentItems(convertedOpts.layout.content, async (contentItem) => { | ||
// create the view attached to the provider, later to be stolen by the window | ||
this.createView({ | ||
opts: contentItem.componentState, | ||
target: fin.me.identity | ||
}, callerIdentity || fin.me.identity); | ||
return contentItem; | ||
}); | ||
return layoutResolved; | ||
} | ||
return fin.Window.create(await convertWindowOptions(windowOptions)); | ||
return fin.Window.create(convertedOpts); | ||
} | ||
@@ -453,3 +483,5 @@ /** | ||
const client = provider.connections.find((c) => c.name === win.identity.name); | ||
const layoutPromise = provider.dispatch(client, 'get-frame-snapshot'); | ||
const layoutPromise = client | ||
? provider.dispatch(client, 'get-frame-snapshot') | ||
: Promise.resolve(); | ||
const [bounds, state, winOptions, layout, { url, title }] = await Promise.all([ | ||
@@ -608,3 +640,3 @@ windowBoundsPromise, | ||
/** | ||
* Creates a new view and attaches it to a specified target window. | ||
* Creates a new view and attaches it to a specified target window, or creates a new window for it if no target window is provided. | ||
* @param { CreateViewPayload } payload Creation options for the new view. | ||
@@ -619,18 +651,12 @@ * @param { Identity } callerIdentity Identity of the entity that called | ||
const { uuid } = fin.me.identity; | ||
const convertedOpts = await convertViewOptions(opts); | ||
if (target) { | ||
// will move from another layout window if already exists | ||
// will create or attach the BV but we should document just create | ||
const viewOptions = await convertViewOptions(opts); | ||
const viewPromise = createOrWrapView(convertedOpts, target); | ||
if (target.name === fin.me.name) { | ||
return fin.View.create({ ...viewOptions, target }).then((view) => { | ||
// With the flag views have loaded the initial url | ||
if (!fin.__internal_.childViews) { | ||
view.navigate(viewOptions.url); | ||
} | ||
return view; | ||
}); | ||
// this is likely a "pooled" or "detached" view | ||
return viewPromise; | ||
} | ||
return provider.dispatch(target, 'add-view', viewOptions); | ||
return provider.dispatch(target, 'add-view', convertedOpts); | ||
} | ||
const layout = utils_1.generateLayoutContent(opts); | ||
const layout = utils_1.generateLayoutContent(convertedOpts); | ||
const options = { | ||
@@ -642,6 +668,6 @@ uuid, | ||
return new Promise((res) => { | ||
const view = fin.View.wrapSync({ uuid, name: opts.name }); | ||
// View could already exist, target-changed fires on creation so will capture either case | ||
view.once('target-changed', () => res(view)); | ||
this.createWindow(options, fin.me.identity); | ||
const wrappedView = fin.View.wrapSync({ uuid, name: convertedOpts.name }); | ||
wrappedView.once('target-changed', () => res(wrappedView)); | ||
this.createWindow(options, callerIdentity || fin.me.identity); | ||
}); | ||
@@ -665,10 +691,23 @@ } | ||
const newOptions = { ...opts, layout: modifiedLayout }; | ||
if (!newOptions.layout.content) { | ||
throw new Error(`Layout has incorrect shape, needs content property: ${JSON.stringify(newOptions.layout)}.`); | ||
} | ||
// we only want to generate a random name if: (1) the view has no name (2) the view has a generated name | ||
// AND (3) doesn't exist in the current window or in the view pool | ||
const windowViews = await fin.Window.wrapSync(target).getCurrentViews(); | ||
const pooledViews = await fin.Window.getCurrentSync().getCurrentViews(); | ||
const ofWin = fin.Window.wrapSync(target); | ||
const windowViews = await ofWin.getCurrentViews(); | ||
const pooledViews = await ofWin.getCurrentViews(); | ||
const viewNamesMap = [...windowViews, ...pooledViews].reduce((carry, view) => ({ ...carry, [view.identity.name]: true }), {}); | ||
const modifiedRootContentItem = await mapLayoutContentItems(newOptions.layout.content, async (contentItem) => modifyContentItemName(contentItem, !viewNamesMap[contentItem.componentState.name])); | ||
const modifiedRootContentItem = await mapLayoutContentItems(newOptions.layout.content, async (contentItem) => { | ||
if (!viewNamesMap[contentItem.componentState.name]) { | ||
const newContentItem = modifyContentItemName(contentItem, true); | ||
this.createView({ opts: newContentItem.componentState, target }, callerIdentity || fin.me.identity); | ||
return newContentItem; | ||
} | ||
return modifyContentItemName(contentItem, false); | ||
}); | ||
newOptions.layout.content = modifiedRootContentItem; | ||
return provider.dispatch(target, 'replace-layout', newOptions); | ||
const layoutReady = resolveWhenLayoutReady(ofWin); | ||
await provider.dispatch(target, 'replace-layout', newOptions); | ||
await layoutReady; | ||
} | ||
@@ -818,3 +857,2 @@ /** | ||
provider.onError((action, error, identity) => { | ||
// eslint-disable-next-line no-console | ||
console.error(`Error on action ${action} sent by ${JSON.stringify(identity)}: ${JSON.stringify(errors_1.errorToPOJO(error))}`); | ||
@@ -821,0 +859,0 @@ throw error; |
@@ -34,2 +34,5 @@ "use strict"; | ||
const app = this.fin.Application.getCurrentSync(); | ||
const attachView = () => this.ofView.attach(this.windowIdentity); | ||
const boundAttachView = attachView.bind(this); | ||
this.ofView.once('created', boundAttachView); | ||
const allViews = await app.getViews(); | ||
@@ -39,13 +42,7 @@ const view = allViews.find((v) => v.identity.name === this.ofView.identity.name); | ||
// this will move an existing view to this window | ||
this.ofView.removeListener('created', boundAttachView); | ||
await this.ofView.attach(this.windowIdentity); | ||
} | ||
else { | ||
await this.fin.View.create(this.options); | ||
// With the flag views have loaded the initial url | ||
if (!this.fin.__internal_.childViews) { | ||
this.ofView.navigate(this.options.url); | ||
} | ||
} | ||
} | ||
} | ||
exports.ResizableView = ResizableView; |
@@ -221,2 +221,5 @@ "use strict"; | ||
updatedTitle = state.title || url.hostname || state.url || state.name; | ||
if (updatedTitle === null || updatedTitle === void 0 ? void 0 : updatedTitle.includes('internal-generated')) { | ||
updatedTitle = url.hostname || state.url || state.name; | ||
} | ||
} | ||
@@ -223,0 +226,0 @@ container.setTitle(updatedTitle); |
@@ -26,2 +26,3 @@ import { DownloadPreloadOption } from '../system/download-preload'; | ||
frame?: boolean; | ||
height?: Readonly<number>; | ||
hideOnClose?: boolean; | ||
@@ -53,2 +54,5 @@ hotkeys?: Hotkey[]; | ||
waitForPageLoad?: boolean; | ||
width?: Readonly<number>; | ||
x?: Readonly<number>; | ||
y?: Readonly<number>; | ||
} | ||
@@ -55,0 +59,0 @@ export interface CustomRequestHeaders { |
@@ -22,2 +22,3 @@ import type { ApplicationOption } from '../api/application/applicationOption'; | ||
export interface PlatformWindowCreationOptions extends Partial<WindowOption> { | ||
updateStateIfExists?: boolean; | ||
reason?: WindowCreationReason; | ||
@@ -24,0 +25,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3983755
18110