Handles requests to apply a snapshot to the current Platform.
Payload containing the snapshot to be applied, as well as any options.
Optional
identity: Identity_4Identity of the entity that called Platform.Platform#applySnapshot Platform.applySnapshot. Undefined if called internally (e.g. when opening the initial snapshot).
Allows overriding a platform's default snapshot behavior. All calls to Platform#applySnapshot Platform.applySnapshot will pass through the override.
const overrideCallback = (Provider) => {
class Override extends Provider {
async applySnapshot(payload, callerIdentity) {
const { snapshot, options } = payload;
// Perhaps in our platform, we wish to always use the closeExistingWindows option
return super.applySnapshot(
{ snapshot, options: { ...options, closeExistingWindows: true }},
callerIdentity
);
}
return new Override();
}
fin.Platform.init({ overrideCallback });
Applies a workspace to the user's desktop. Makes that workspace the active workspace.
true if the workspace was applied, false if the workspace was not applied.
Closes a view
Specifies the target
view to be closed.
Optional
identity: Identity_4Identity of the entity that called Platform.Platform#closeView Platform.closeView.
Allows overriding a platform's default view closing behavior. All calls to Platform#closeView Platform.closeView will pass through the override.
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async closeView(payload, callerIdentity) {
const { view } = payload;
// Perhaps in our platform, we want to take a snapshot and save it somewhere before closing certain views.
if (view.name === 'my-special-view') {
const snapshot = await fin.Platform.getCurrentSync().getSnapshot();
await saveSnapshot(snapshot);
}
return super.closeView(options, callerIdentity);
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
async function saveSnapshot(snapshot) {
// Save the snapshot in localstorage, send to a server, etc.
}
Closes a Window. By default it will fire any before unload handler set by a View in the Window. This can be disabled by setting skipBeforeUnload in the options object of the payload. This method is called by Platform.Platform#closeWindow Platform.closeWindow.
Object that contains the Window Identity and related options.
This method calls a number of Platform Provider methods:
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async closeWindow(payload, callerIdentity) {
const { windowId: { uuid, name }, options: { skipBeforeUnload } } = payload;
console.log(`${uuid}/${name} is closing and skipBeforeUnload is set to: ${skipBeforeUnload}`);
return super.closeWindow(payload, callerIdentity);
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
Implementation for creating a copy of a page. Called when a page is Saved-As or Duplicated.
Note: The page.layout
and page.panels
property cannot be overridden for 'Save As' operations,
the page.layout
and page.panels
property provided in the return value will be ignored, and the layout and panels of
the original page will remain after 'Save As' is performed.
Implementation for creating a saved page in persistent storage.
the create saved page request.
Implementation for creating a saved workspace in persistent storage.
the create saved workspace request.
Override when you need to add custom functionality when creating a view.
creatin options for the new view
identity of the entity that called createView
Handles requests to create a window in the current platform.
Optional
identity: Identity_4If Platform.Platform#createWindow Platform.createWindow was called, the identity of the caller will be here.
If createWindow
was called as part of applying a snapshot or creating a view without a target window,
identity
will be undefined.
Allows overriding a platform's default window creation behavior. All calls to Platform#createWindow Platform.createWindow will pass through the override.
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async createWindow(options, callerIdentity) {
if (options.reason === 'tearout') {
// Perhaps in our platform, we want tearout windows to have a certain initial context value
const customContext = {
security: 'STOCK',
currentView: 'detailed'
}
return super.createWindow({ ...options, customContext }, callerIdentity);
}
// default behavior for all other creation reasons
return super.createWindow(options, callerIdentity);
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
Handles requests to fetch manifests in the current platform.
Payload containing the manifestUrl to be fetched.
If Platform.Platform#fetchManifest Platform.fetchManifest was called, the identity of the caller will be here.
If fetchManifest
was called internally, callerIdentity
will be the provider's identity.
Allows overriding a platform's default behavior when fetching manifests. Overwriting this call will change how Platform#launchContentManifest Platform.launchContentManifest and fins links fetch manifests. All calls to Platform#fetchManifest Platform.fetchManifest will also pass through the override.
const overrideCallback = (Provider) => {
class Override extends Provider {
async fetchManifest(payload, callerIdentity) {
const { manifestUrl } = payload;
// I want to fetch certain URLs from the platform provider so that renderer-side cookies will be sent
if (manifestUrl === 'https://www.my-internal-manifest.com') {
const manifest = await fetch(manifestUrl);
return manifest.json();
}
// Any requests that might be cross-origin should still be sent from the browser process
return super.fetchManifest(payload);
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
Implementation for getting selected theme scheme.
Gets the current state of windows and their views and returns a snapshot object containing that info.
Undefined unless you've defined a custom getSnapshot
protocol.
Identity of the entity that called Platform.Platform#getSnapshot Platform.getSnapshot.
Snapshot of current platform state.
Allows overriding a platform's default snapshot behavior. All calls to Platform#getSnapshot Platform.getSnapshot will pass through the override.
const overrideCallback = (PlatformProvider) => {
// Extend default behavior
class MyOverride extends PlatformProvider {
async getSnapshot(payload, callerIdentity) {
// Call super to access vanilla platform behavior
const snapshot = await super.getSnapshot();
// Perform any additional logic needed
const modifiedSnapshot = { ...snapshot, answer: 42 }
await saveSnapshotToServer(modifiedSnapshot);
return modifiedSnapshot;
}
}
// Return instance with methods to be consumed by Platform
return new MyOverride();
};
fin.Platform.init({ overrideCallback });
async function saveSnapshotToServer(snapshot) {
// Send a snapshot to the server, store it locally somewhere, etc.
}
Handle the decision of whether a Window or specific View should close when trying to prevent an unload. This is meant to be overridden. Called in PlatformProvider#closeWindow PlatformProvider.closeWindow. Normally you would use this method to show a dialog indicating that there are Views that are trying to prevent an unload. By default it will always return all Views passed into it as meaning to close.
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async getUserDecisionForBeforeUnload(payload, callerIdentity) {
const { windowShouldClose, viewsPreventingUnload, viewsNotPreventingUnload, windowId, closeType } = payload;
// launch dialog and wait for user response
const continueWithClose = await showDialog(viewsPreventingUnload, windowId, closeType);
if (continueWithClose) {
return { windowShouldClose, viewsToClose: [...viewsNotPreventingUnload, ...viewsPreventingUnload] };
} else {
return { windowShouldClose: false, viewsToClose: [] };
}
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
async function showDialog(viewsPreventingUnload, windowId, closeType) {
// Show a dialog and await for user response
}
Gets all the Views attached to a Window that should close along with it. This is meant to be overridable in the case where you want to return other Views that may not be attached to the Window that is closing.
Handles requests to get a window's context. target
may be a window or a view.
If it is a window, that window's customContext
will be returned.
If it is a view, the customContext
of that view's current host window will be returned.
Object containing the requested context
update,
the target
's identity, and the target's entityType
.
Optional
identity: Identity_4Identity of the entity that called Platform.Platform#getWindowContext Platform.getWindowContext.
Undefined when getWindowContext
is called internally
(e.g. when getting a window's context for the purpose of raising a "host-context-changed" event on a reparented view).
The new context.
Allows overriding a platform's default getWindowContext behavior. All calls to Platform#getWindowContext Platform.getWindowContext will pass through the override.
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async getWindowContext(payload, callerIdentity) {
// Perhaps in our platform, we wish to make window context available only to views from a given domain.
const { entityType } = callerIdentity;
if (entityType === 'view') {
const { url } = await fin.View.wrapSync(callerIdentity).getInfo();
if (!url.startsWith('https://my.trusted-domain.com')) {
throw new Error('Only apps from trusted domains may use window context in this platform.');
}
}
return super.getWindowContext(payload, callerIdentity);
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
Experimental
This API is called during the () call. Gets the current state of a particular window and its views and returns an object that can be added to the OpenFin.Snapshot.windows property. Override this function if you wish to mutate each window snapshot during the () call
Implementation for handling Workspace analytics events
the payload received by the provider
Experimental
This method is called to handle errors with view creation and initial navigation during layout creation. Overriding this method enables catching the error and correcting behavior (ie navigating to an error page).
Identity of the view
error thrown during a view creation
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async handleFailedViewCreation(viewIdentity, error) {
const view = fin.View.wrapSync(viewId);
try {
// navigate to an error page
await view.navigate('http://localhost:3000/errorPage.html');
// resolve a success result after redirecting to a error page
return {identity: viewIdentity, success: true};
} catch(e) {
// layout-initialized event will include this view with the error
throw error;
}
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
Implementation for detecting if a page change qualifies as putting the page in an unsaved state.
the page with new changes and the identity of the OF window where the page change occured.
Handles subsequent launch attempts of the current platform. Attempts to launch appManifestUrl passed as userAppConfigArgs. If no appManifestUrl is present will attempt to launch using the requesting manifest snapshot. If no appManifestUrl or snapshot is available nothing will be launched.
Implementation for deciding whether a modal informing about loss of unsaved changes will be displayed when closing a page.
The default implementation returns { shouldShowModal: true }
if the page has unsaved changes (hasUnsavedChanges
page property)
and false
otherwise.
Handles the closing of a Window and/or its Views. Called in PlatformProvider#closeWindow PlatformProvider.closeWindow. The return of PlatformProvider#getUserDecisionForBeforeUnload PlatformProvider.getUserDecisionForBeforeUnload is passed into this method.
Decision object
Called when a window's customContext
is updated. Responsible for raising the host-context-updated
event on that window's child views.
The event payload for the window whose context has changed.
The new context will be contained as payload.diff.customContext.newVal
.
The event that it raised.
Implementation for showing a global context menu given a menu template, handler callback, and screen coordinates. For an example of overriding, see WorkspacePlatformOverrideCallback.
the payload received by the provider call
OF identity of the entity from which the request originated
Implementation for showing a page tab context menu given a menu template, handler callback, and screen coordinates. For an example of overriding, see WorkspacePlatformOverrideCallback.
the payload received by the provider call
OF identity of the entity from which the request originated
Implementation for showing a context menu for save button given a menu template, handler callback, and screen coordinates. For an example of overriding, see WorkspacePlatformOverrideCallback.
the payload received by the provider call
OF identity of the entity from which the request originated
Implementation for showing a view tab context menu given a menu template, handler callback, and screen coordinates. For an example of overriding, see WorkspacePlatformOverrideCallback.
the payload received by the provider call
OF identity of the entity from which the request originated
Called when a snapshot is being applied and some windows in that snapshot would be fully or partially off-screen. Returns an array of windows with modified positions, such that any off-screen windows are positioned in the top left corner of the main monitor.
The snapshot to be applied.
An array of WindowOptions for any windows that would be off-screen.
An array of WindowOptions with their position modified to fit on screen.
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async positionOutOfBoundsWindows(
snapshot, // The snapshot currently being applied
outOfBoundsWindows // An array of options for all windows that would be fully or partially off-screen.
) {
// By default, this function cascades out-of-bounds windows from the top left of the main monitor.
// Perhaps we wish to instead position all such windows on the bottom right.
// First, find the coordinates of the bottom right of the primary monitor
const {
primaryMonitor: {
availableRect: { right, bottom }
}
} = await fin.System.getMonitorInfo();
// Update the coordinates of each out-of-bounds window to be bottom right
const newWindows = snapshot.windows.map((windowOptions) => {
if (outOfBoundsWindows.find(w => w.name === windowOptions.name)) {
// If the window is out of bounds, set a new initial top and left
const { defaultHeight, defaultWidth } = windowOptions;
return {
...windowOptions,
defaultTop: bottom - defaultHeight,
defaultLeft: right - defaultWidth
}
} else {
return windowOptions;
}
})
// Return all windows with desired bounds
return newWindows;
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
Closes the current Platform and all child windows and views.
Undefined unless you have implemented a custom quite protocol.
Identity of the entity that called Platform.Platform#quit Platform.quit.
Allows overriding a platform's default shutdown behavior. All calls to Platform#quit Platform.quit will pass through the override.
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async quit(payload, callerIdentity) {
// Perhaps in our platform, we wish to take a snapshot and save it somewhere before shutting down
const snapshot = await this.getSnapshot();
await saveSnapshot(snapshot);
return super.quit(payload, callerIdentity);
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
async function saveSnapshot(snapshot) {
// Save the snapshot in localstorage, send to a server, etc.
}
Replaces a Platform window's layout with a new layout. Any views that were in the old layout but not the new layout will be destroyed.
Contains the target
window and an opts
object with a layout
property to apply.
Optional
identity: Identity_4Identity of the entity that called PlatformProvider#replaceLayout Platform.replaceLayout.
Undefined if replaceLayout
is called internally (e.g. while applying a snapshot).
Allows overriding a platform's default replaceLayout behavior. All calls to Platform#replaceLayout Platform.replaceLayout will pass through the override.
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async replaceLayout(payload, callerIdentity) {
// Perhaps in our platform, we wish to save an updated snapshot each time a layout is replaced
await super.replaceLayout(payload, callerIdentity);
const updatedSnapshot = await fin.Platform.getCurrentSync().getSnapshot();
await saveSnapshot(updatedSnapshot);
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
async function saveSnapshot(snapshot) {
// Save the snapshot in localstorage, send to a server, etc.
}
Implementation for setting the active page in a browser window. Called when the active page is changed and on browser window creation.
Implementation for setting selected theme scheme.
scheme to be set
Handles requests to set a window's context. target
may be a window or a view.
If it is a window, that window's customContext
will be updated.
If it is a view, the customContext
of that view's current host window will be updated.
Object containing the requested context
update,
the target
's identity, and the target's entityType
.
Optional
identity: Identity_4Identity of the entity that called Platform.Platform#setWindowContext Platform.setWindowContext.
Undefined if setWindowContext
is called internally (e.g. while applying a snapshot).
The new context.
Allows overriding a platform's default setWindowContext behavior. All calls to Platform#setWindowContext Platform.setWindowContext will pass through the override.
const overrideCallback = (PlatformProvider) => {
class Override extends PlatformProvider {
async setWindowContext(payload, callerIdentity) {
// Perhaps in our platform, we wish to only take context updates from windows
// and ignore updates sent from views.
if (payload.entityType === 'view') {
throw new Error('Updating window context from a view is not permitted in this platform.');
}
return super.setWindowContext(payload, callerIdentity);
}
}
return new Override();
}
fin.Platform.init({ overrideCallback });
Implementation for updating a saved page in persistent storage.
the update saved page request.
Implementation for updating a saved workspace in persistent storage.
the update saved workspace request.
Implementation for adding custom default page