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));
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.
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 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.
Retrieves current application's shortcut configuration.
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));
Adds a listener to the end of the listeners array for the specified event.
Optional
options: SubscriptionOptionsEvent payloads are documented in the OpenFin.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 OpenFin.Events namespace.
Adds a listener to the beginning of the listeners array for the specified event.
Optional
options: SubscriptionOptionsEvent payloads are documented in the OpenFin.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 OpenFin.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));
Removes all listeners, or those of the specified event.
Optional
eventType: Remove a listener from the listener array for the specified event.
Optional
options: SubscriptionOptionsSends a message to the RVM to upload the application's logs. On success, an object containing logId is returned.
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 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));
Set hover text for this application's system tray icon. Note: Application must first set a tray icon with Application.setTrayIcon.
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);
}
});
}
});
An object representing an application. Allows the developer to create, execute, show/close an application as well as listen to application events.