Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* global fin */
- const phonebookUUID = 'phonebook-openfin';
- const phonebookManifestUrl = '';
- const phonebookChannel = '';
- function smartSend(message) {
- let appExists = false;
- let isAppRunning;
- fin.desktop.System.getAllApplications(applications => {
- applications.forEach(app => {
- if (app.uuid === phonebookUUID) {
- appExists = true;
- isAppRunning = app.isRunning;
- }
- });
- if (!appExists) {
- fin.desktop.Application.createFromManifest(phonebookManifestUrl, (app) => {
- app.run(() => waitThenPublishMessage(message));
- });
- } else {
- if (isAppRunning) {
- publishMessage(message);
- } else {
- const wrappedApp = fin.desktop.Application.wrap(phonebookUUID);
- wrappedApp.run(() => {
- waitThenPublishMessage(message);
- });
- }
- }
- })
- }
- function publishMessage(message) {
- fin.desktop.InterApplicationBus.send(phonebookUUID, phonebookChannel, message);
- }
- function waitThenPublishMessage(message) {
- function listener() {
- publishMessage(message);
- console.log(`Sent ${phonebookUUID} ${message} on channel ${phonebookUUID}`);
- fin.desktop.InterApplicationBus.unsubscribe(phonebookUUID, 'subscription-confirmed', listener);
- }
- fin.desktop.InterApplicationBus.subscribe(phonebookUUID, 'subscription-confirmed', listener);
- }
Add Comment
Please, Sign In to add comment