Provides access to the OpenFin representation of the current code context (usually a document
such as a View or Window), as well as to the current Interop
context.
Useful for debugging in the devtools console, where this will intelligently type itself based on the context in which the devtools panel was opened.
Adds a listener to the end of the listeners array for the specified event.
Optional
options: SubscriptionOptionsClose will be prevented from closing when force is false and ‘close-requested’ has been subscribed to for application’s main window.
use Application.quit instead Closes the application and any child windows created by the application.
async function closeApp() {
const app = await fin.Application.getCurrent();
return await app.close();
}
closeApp().then(() => console.log('Application closed')).catch(err => console.log(err));
Retrieves an array of wrapped fin.Windows for each of the application’s child windows.
async function getChildWindows() {
const app = await fin.Application.getCurrent();
return await app.getChildWindows();
}
getChildWindows().then(children => console.log(children)).catch(err => console.log(err));
Gets file auto download location. It's only allowed in the same application. If file auto download location is not set, it will return the default location.
Note: This method is restricted by default and must be enabled via API security settings.
if getting file auto download location on different applications.
const app = await fin.Application.getCurrent();
const fileDownloadDir = await app.getFileDownloadLocation();
Retrieves information about the application.
If the application was not launched from a manifest, the call will return the closest parent application manifest
and manifestUrl
. initialOptions
shows the parameters used when launched programmatically, or the startup_app
options
if launched from manifest. The parentUuid
will be the uuid of the immediate parent (if applicable).
async function getInfo() {
const app = await fin.Application.getCurrent();
return await app.getInfo();
}
getInfo().then(info => console.log(info)).catch(err => console.log(err));
Retrieves the JSON manifest that was used to create the application. Invokes the error callback if the application was not created from a manifest.
async function getManifest() {
const app = await fin.Application.getCurrent();
return await app.getManifest();
}
getManifest().then(manifest => console.log(manifest)).catch(err => console.log(err));
Retrieves UUID of the application that launches this application. Invokes the error callback if the application was created from a manifest.
async function getParentUuid() {
const app = await fin.Application.start({
uuid: 'app-1',
name: 'myApp',
url: 'https://cdn.openfin.co/docs/javascript/stable/tutorial-Application.getParentUuid.html',
autoShow: true
});
return await app.getParentUuid();
}
getParentUuid().then(parentUuid => console.log(parentUuid)).catch(err => console.log(err));
Experimental
Retrieves all process information for entities (windows and views) associated with an application.
const app = await fin.Application.getCurrent();
const processInfo = await app.getProcessInfo();
Retrieves current application's shortcut configuration.
async function getShortcuts() {
const app = await fin.Application.wrap({ uuid: 'testapp' });
return await app.getShortcuts();
}
getShortcuts().then(config => console.log(config)).catch(err => console.log(err));
Retrieves information about the system tray. If the system tray is not set, it will throw an error message.
The only information currently returned is the position and dimensions.
async function getTrayIconInfo() {
const app = await fin.Application.wrap({ uuid: 'testapp' });
return await app.getTrayIconInfo();
}
getTrayIconInfo().then(info => console.log(info)).catch(err => console.log(err));
Returns an instance of the main Window of the application
async function getWindow() {
const app = await fin.Application.start({
uuid: 'app-1',
name: 'myApp',
url: 'https://cdn.openfin.co/docs/javascript/stable/tutorial-Application.getWindow.html',
autoShow: true
});
return await app.getWindow();
}
getWindow().then(win => {
win.showAt(0, 400);
win.flash();
}).catch(err => console.log(err));
Returns the current zoom level of the application.
async function getZoomLevel() {
const app = await fin.Application.getCurrent();
return await app.getZoomLevel();
}
getZoomLevel().then(zoomLevel => console.log(zoomLevel)).catch(err => console.log(err));
Determines if the application is currently running.
async function isAppRunning() {
const app = await fin.Application.getCurrent();
return await app.isRunning();
}
isAppRunning().then(running => console.log(`Current app is running: ${running}`)).catch(err => console.log(err));
Adds a listener to the end of the listeners array for the specified event.
Optional
options: SubscriptionOptionsEvent payloads are documented in the Events namespace.
Adds a one time listener for the event. The listener is invoked only the first time the event is fired, after which it is removed.
Optional
options: SubscriptionOptionsEvent payloads are documented in the Events namespace.
Adds a listener to the beginning of the listeners array for the specified event.
Optional
options: SubscriptionOptionsEvent payloads are documented in the Events namespace.
Adds a one time listener for the event. The listener is invoked only the first time the event is fired, after which it is removed. The listener is added to the beginning of the listeners array.
Optional
options: SubscriptionOptionsEvent payloads are documented in the Events namespace.
Closes the application and any child windows created by the application. Cleans the application from state so it is no longer found in getAllApplications.
Close will be prevented from closing when force is false and ‘close-requested’ has been subscribed to for application’s main window.
async function closeApp() {
const allApps1 = await fin.System.getAllApplications(); //[{uuid: 'app1', isRunning: true}, {uuid: 'app2', isRunning: true}]
const app = await fin.Application.wrap({uuid: 'app2'});
await app.quit();
const allApps2 = await fin.System.getAllApplications(); //[{uuid: 'app1', isRunning: true}]
}
closeApp().then(() => console.log('Application quit')).catch(err => console.log(err));
Manually registers a user with the licensing service. The only data sent by this call is userName and appName.
username to be passed to the RVM.
app name to be passed to the RVM.
async function registerUser() {
const app = await fin.Application.getCurrent();
return await app.registerUser('user', 'myApp');
}
registerUser().then(() => console.log('Successfully registered the user')).catch(err => console.log(err));
Removes all listeners, or those of the specified event.
Optional
eventType: "crashed" | "started" | "closed" | "initialized" | "view-blurred" | "view-certificate-selection-shown" | "view-crashed" | "view-did-change-theme-color" | "view-focused" | "view-navigation-rejected" | "view-url-changed" | "view-did-fail-load" | "view-did-finish-load" | "view-page-favicon-updated" | "view-page-title-updated" | "view-resource-load-failed" | "view-resource-response-received" | "view-child-content-blocked" | "view-child-content-opened-in-browser" | "view-child-view-created" | "view-child-window-created" | "view-file-download-started" | "view-file-download-progress" | "view-file-download-completed" | "view-found-in-page" | "view-certificate-error" | "view-content-blocked" | "view-will-redirect" | "view-created" | "view-destroyed" | "view-hidden" | "view-hotkey" | "view-shown" | "view-target-changed" | "view-host-context-changed" | "connected" | "window-alert-requested" | "window-created" | "window-end-load" | "window-not-responding" | "window-responding" | "window-start-load" | "manifest-changed" | "not-responding" | "responding" | "run-requested" | "tray-icon-clicked" | "file-download-location-changed" | "window-blurred" | "window-certificate-selection-shown" | "window-crashed" | "window-did-change-theme-color" | "window-focused" | "window-navigation-rejected" | "window-url-changed" | "window-did-fail-load" | "window-did-finish-load" | "window-page-favicon-updated" | "window-page-title-updated" | "window-resource-load-failed" | "window-resource-response-received" | "window-child-content-blocked" | "window-child-content-opened-in-browser" | "window-child-view-created" | "window-child-window-created" | "window-file-download-started" | "window-file-download-progress" | "window-file-download-completed" | "window-found-in-page" | "window-certificate-error" | "window-content-blocked" | "window-will-redirect" | "window-view-attached" | "window-view-detached" | "window-auth-requested" | "window-begin-user-bounds-changing" | "window-bounds-changed" | "window-bounds-changing" | "window-context-changed" | "window-closed" | "window-closing" | "window-disabled-movement-bounds-changed" | "window-disabled-movement-bounds-changing" | "window-embedded" | "window-end-user-bounds-changing" | "window-external-process-exited" | "window-external-process-started" | "window-hidden" | "window-hotkey" | "window-initialized" | "window-layout-initialized" | "window-layout-ready" | "window-maximized" | "window-minimized" | "window-options-changed" | "window-performance-report" | "window-preload-scripts-state-changed" | "window-preload-scripts-state-changing" | "window-reloaded" | "window-restored" | "window-show-requested" | "window-shown" | "window-user-movement-disabled" | "window-user-movement-enabled" | "window-will-move" | "window-will-resize" | "window-show-all-downloads" | "window-download-shelf-visibility-changed"Remove a listener from the listener array for the specified event.
Optional
options: SubscriptionOptionsCaution: Calling this method changes the array indices in the listener array behind the listener.
Removes the application’s icon from the tray.
async function removeTrayIcon() {
const app = await fin.Application.getCurrent();
return await app.removeTrayIcon();
}
removeTrayIcon().then(() => console.log('Removed the tray icon.')).catch(err => console.log(err));
Instructs the RVM to schedule one restart of the application.
async function scheduleRestart() {
const app = await fin.Application.getCurrent();
return await app.scheduleRestart();
}
scheduleRestart().then(() => console.log('Application is scheduled to restart')).catch(err => console.log(err));
Sends a message to the RVM to upload the application's logs. On success, an object containing logId is returned.
async function sendLog() {
const app = await fin.Application.getCurrent();
return await app.sendApplicationLog();
}
sendLog().then(info => console.log(info.logId)).catch(err => console.log(err));
Sets a username to correlate with App Log Management.
Username to correlate with App's Log.
async function setAppLogUser() {
const app = await fin.Application.getCurrent();
return await app.setAppLogUsername('username');
}
setAppLogUser().then(() => console.log('Success')).catch(err => console.log(err));
Sets file auto download location. It's only allowed in the same application.
Note: This method is restricted by default and must be enabled via API security settings.
file auto download location
if setting file auto download location on different applications.
const downloadLocation = 'C:\\dev\\temp';
const app = await fin.Application.getCurrent();
try {
await app.setFileDownloadLocation(downloadLocation);
console.log('File download location is set');
} catch(err) {
console.error(err)
}
Sets or removes a custom JumpList for the application. Only applicable in Windows OS. If categories is null the previously set custom JumpList (if any) will be replaced by the standard JumpList for the app (managed by Windows).
Note: If the "name" property is omitted it defaults to "tasks".
An array of JumpList Categories to populate. If null, remove any existing JumpList configuration and set to Windows default.
If categories is null the previously set custom JumpList (if any) will be replaced by the standard JumpList for the app (managed by Windows).
The bottommost item in the jumplist will always be an item pointing to the current app. Its name is taken from the manifest's
shortcut.name
and uses shortcut.company
as a fallback. Clicking that item will launch the app from its current manifest.
Note: If the "name" property is omitted it defaults to "tasks".
Note: Window OS caches jumplists icons, therefore an icon change might only be visible after the cache is removed or the uuid or shortcut.name is changed.
const app = fin.Application.getCurrentSync();
const appName = 'My App';
const jumpListConfig = [ // array of JumpList categories
{
// has no name and no type so `type` is assumed to be "tasks"
items: [ // array of JumpList items
{
type: 'task',
title: `Launch ${appName}`,
description: `Runs ${appName} with the default configuration`,
deepLink: 'fins://path.to/app/manifest.json',
iconPath: 'https://path.to/app/icon.ico',
iconIndex: 0
},
{ type: 'separator' },
{
type: 'task',
title: `Restore ${appName}`,
description: 'Restore to last configuration',
deepLink: 'fins://path.to/app/manifest.json?$$use-last-configuration=true',
iconPath: 'https://path.to/app/icon.ico',
iconIndex: 0
},
]
},
{
name: 'Tools',
items: [ // array of JumpList items
{
type: 'task',
title: 'Tool A',
description: 'Runs Tool A',
deepLink: 'fins://path.to/tool-a/manifest.json',
iconPath: 'https://path.to/tool-a/icon.ico',
iconIndex: 0
},
{
type: 'task',
title: 'Tool B',
description: 'Runs Tool B',
deepLink: 'fins://path.to/tool-b/manifest.json',
iconPath: 'https://path.to/tool-b/icon.ico',
iconIndex: 0
}]
}
];
app.setJumpList(jumpListConfig).then(() => console.log('JumpList applied')).catch(e => console.log(`JumpList failed to apply: ${e.toString()}`));
To handle deeplink args:
function handleUseLastConfiguration() {
// this handler is called when the app is being launched
app.on('run-requested', event => {
if(event.userAppConfigArgs['use-last-configuration']) {
// your logic here
}
});
// this handler is called when the app was already running when the launch was requested
fin.desktop.main(function(args) {
if(args && args['use-last-configuration']) {
// your logic here
}
});
}
Sets the query string in all shortcuts for this app. Requires RVM 5.5+.
The new query string for this app's shortcuts.
const newQueryArgs = 'arg=true&arg2=false';
const app = await fin.Application.getCurrent();
try {
await app.setShortcutQueryParams(newQueryArgs);
} catch(err) {
console.error(err)
}
Sets new application's shortcut configuration. Windows only.
New application's shortcut configuration.
Application has to be launched with a manifest and has to have shortcut configuration (icon url, name, etc.) in its manifest to be able to change shortcut states.
async function setShortcuts(config) {
const app = await fin.Application.getCurrent();
return app.setShortcuts(config);
}
setShortcuts({
desktop: true,
startMenu: false,
systemStartup: true
}).then(() => console.log('Shortcuts are set.')).catch(err => console.log(err));
Adds a customizable icon in the system tray. To listen for a click on the icon use the tray-icon-clicked
event.
Image URL or base64 encoded string to be used as the icon
const imageUrl = "http://cdn.openfin.co/assets/testing/icons/circled-digit-one.png";
const base64EncodedImage = "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX\
///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII";
const dataURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DH\
xgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
async function setTrayIcon(icon) {
const app = await fin.Application.getCurrent();
return await app.setTrayIcon(icon);
}
// use image url to set tray icon
setTrayIcon(imageUrl).then(() => console.log('Setting tray icon')).catch(err => console.log(err));
// use base64 encoded string to set tray icon
setTrayIcon(base64EncodedImage).then(() => console.log('Setting tray icon')).catch(err => console.log(err));
// use a dataURL to set tray icon
setTrayIcon(dataURL).then(() => console.log('Setting tray icon')).catch(err => console.log(err));
Sets the zoom level of the application. The original size is 0 and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of original size, respectively.
The zoom level
async function setZoomLevel(number) {
const app = await fin.Application.getCurrent();
return await app.setZoomLevel(number);
}
setZoomLevel(5).then(() => console.log('Setting a zoom level')).catch(err => console.log(err));
Shows a menu on the tray icon. Use with tray-icon-clicked event.
User-defined shape for data returned upon menu item click. Should be a union of all possible data shapes for the entire menu, and the click handler should process these with a "reducer" pattern.
if the application has no tray icon set
if the system tray is currently hidden
const iconUrl = 'http://cdn.openfin.co/assets/testing/icons/circled-digit-one.png';
const app = fin.Application.getCurrentSync();
await app.setTrayIcon(iconUrl);
const template = [
{
label: 'Menu Item 1',
data: 'hello from item 1'
},
{ type: 'separator' },
{
label: 'Menu Item 2',
type: 'checkbox',
checked: true,
data: 'The user clicked the checkbox'
},
{
label: 'see more',
enabled: false,
submenu: [
{ label: 'submenu 1', data: 'hello from submenu' }
]
}
];
app.addListener('tray-icon-clicked', (event) => {
// right-click
if (event.button === 2) {
app.showTrayIconPopupMenu({ template }).then(r => {
if (r.result === 'closed') {
console.log('nothing happened');
} else {
console.log(r.data);
}
});
}
});
Closes the application by terminating its process.
async function terminateApp() {
const app = await fin.Application.getCurrent();
return await app.terminate();
}
terminateApp().then(() => console.log('Application terminated')).catch(err => console.log(err));
An object representing an application. Allows the developer to create, execute, show/close an application as well as listen to application events.