@openfin/native-window-integration-client
TypeScript icon, indicating that this package has built-in type declarations

0.0.17 • Public • Published

OpenFin NWI Library

This library exports the NativeWindowIntegrationClient class to connect to a native component and add native windows to snapshots.

This class has the following methods: static create(options) A factory method which launches the provider and creates a connection to it.

decorateSnapshot(snapshot) an instance method which adds native window information to a snapshot.

applySnapshot(snapshot) an instance which will look for native window information in a snapshot and attempt to restore it.

Prerequisites

Installation

npm i @openfin/native-window-integration-client

Usage

Import the native provider into your project, see hosting, and create a connection to it using the NativeWindowIntegrationClient.create method, the url to the hosted native provider/asset should be passed in as the url property in the client options.

import { NativeWindowIntegrationClient } from '@openfin/native-window-integration-client';
// native provider url loaded using webpack's file-loader
import assetUrl from '@openfin/native-window-integration-client/lib/provider.zip';


const configuration = [
    {
        'name': 'Notepad',
        'title': 'my_platform_notes',
        'launch': {
            'alias': 'my_platform_notes',
            'target': 'my_platform_notes.txt',
            'lifetime': 'application',
            'arguments': ''
        }
    },
    {
        'name': 'Symphony',
        'title': 'Symphony',
        'launch': {
            'path': 'C:\\Users\\openfin\\AppData\\Local\\Programs\\Symphony\\Symphony\\Symphony.exe',
            'lifetime': 'application'
        }
    }
]

fin.Platform.init({
    overrideCallback: async (PlatformProvider, ...args) => {
        try {
            console.log('Native Window Integration Client is connecting...');
            const myClient = await NativeWindowIntegrationClient.create({ url: assetUrl, configuration });
            console.log('Native Window Integration Client connected successfully!');

            class WithNative extends PlatformProvider {
                async getSnapshot(...args: [undefined, OpenFin.ClientIdentity]) {
                    const snapshot = await super.getSnapshot(...args);
                    try {
                        const snapshotWithNativeWindows = await myClient.decorateSnapshot(snapshot);
                        return snapshotWithNativeWindows;
                    } catch (error) {
                        console.log('Native Window Integration failed to get snapshotWithNativeWindows:');
                        console.error(error);
                        return snapshot;
                    }
                }
                async applySnapshot(...args: [OpenFin.ApplySnapshotPayload, OpenFin.ClientIdentity]) {
                    await super.applySnapshot(...args);
                    try {
                        await myClient.applySnapshot(args[0].snapshot);
                    } catch (error) {
                        console.log('Native Window Integration error applying native snapshot:');
                        console.error(error);
                    }
                }
            }
            console.log('Native Window Integration successfully enabled!');
            return new WithNative(...args);
        } catch (error) {
            console.log('Native Window Integration failed to initialize:');
            console.error(error);
            return new PlatformProvider(args);
        }
    }
});

API Permissions Requirements

Necessary OpenFin Secure APIs permissions:

  • System.downloadAsset
  • System.launchExternalProcess
  • System.enableNativeWindowIntegrationProvider

These will be called internally by the library.

Hosting

The native provider must be hosted. We highly reccomend using a tool such as webpack's file-loader to include the asset as part of your build to ensure versions stay in sync between the provider and library. Version mismatches will cause the NativeWindowClient.Create call to fail. Copying the provider.zip file to your project's root directory will cause version mismatches when the library is updated, which is why we recommend using a tool such as webpack to include the asset as part of your build.

####Example of hosting the native provider with webpack's file-loader:

module.exports = {
  module: {
    rules: [
      {
        test: /\.(zip)/,
        use: [
          {
            loader: 'file-loader',
             options: {
                            name: '[name].[ext]',
                            outputPath: 'static/',
                        }
          },
        ],
      },
    ],
  },
};

Readme

Keywords

none

Package Sidebar

Install

npm i @openfin/native-window-integration-client

Weekly Downloads

58

Version

0.0.17

License

SEE LICENSE IN LICENSE

Unpacked Size

74.1 MB

Total Files

21

Last publish

Collaborators

  • ameet-openfin
  • jmransegnola
  • marek_openfin
  • yoge-openfin
  • nil.ffej
  • gilesstevenson-openfin
  • eheyder
  • newaz.sharif
  • efraim-herstic
  • royhafin
  • openfincolinhu
  • openfin-johans
  • alan15008
  • openfin-ci-gh
  • hina-khalid
  • ife-dev1
  • mjosling
  • elliott.burr
  • vsaw3
  • gallak-openfin
  • galim.kaudinov
  • hzhi0209
  • andy.westacott
  • __tomasz__
  • cameronopenfin
  • jennrondeau
  • dhilan
  • benstubbington
  • davidcoxon-of
  • openfin-jeff
  • gouthamc
  • hannahmcmillen
  • xyopenfin
  • smocarski
  • eugeneross-openfin
  • imansuri
  • manamiueda
  • sakibahmad
  • shahossain
  • openfinbrandon
  • pierrebaize
  • noyangunday
  • michaelmcoates
  • johnmandia-openfin
  • rdepena
  • tgoc99
  • wenjunche
  • harsimran.openfin.singh
  • luiemilio
  • licui3936
  • connormccafferty
  • adam.saland
  • openfin-ci
  • chrishobsonexpero
  • richbrowne-openfin
  • azizyok
  • openfin-gavin
  • oblarg