AboutSupportDeveloper GuideVersion 1.3.1

Represents a connection to an Snap Server instance that can be used to control interactions with the server.

Constructors

  • Constructs a new instance of the Snap client object ready to connect to the given instance id

    This should match the id of the server instance that is running which is the default case when using the Snap Server API, SnapServer.start

    Parameters

    • server_id: string

      The instance of the server that will be started or connected to

    Returns SnapServer

    const server = new Snap.SnapServer('test');
    

Properties

__extensions: SnapExtension[] = []
client?: ChannelClient
emitter: EventEmitter<DefaultEventMap> = ...
needToResetLayout?: boolean
server_id: string

The instance of the server that will be started or connected to

snap_identity?: Identity_4

Methods

  • Adds an event handler for the given event

    Type Parameters

    • TEventName extends
          | "all-events"
          | "client-registered"
          | "client-unregistered"
          | "move-size-completed"
          | "clients-attached"
          | "client-detached"
          | "groups-changed"
          | "client-activated"
          | "client-deactivated"

    Parameters

    Returns void

    void

    SnapServerEventTypes

  • Given a snapshot, extracts the Snap layout, if any, and applies it to the current Snap Server

    Parameters

    Returns Promise<void>

    This example shows how to implement a snapshot override that decorates a snapshot with the current Snap layout

      fin.Platform.init({
    overrideCallback: async (PlatformProvider, ...overrideArgs) => {
    try {
    class WithSnap extends PlatformProvider {
    async getSnapshot(...args: [undefined, OpenFin.ClientIdentity]): Promise<OpenFin.Snapshot> {
    const snapshot = await super.getSnapshot(...args);
    const snapSnapshot = await SnapServer.decorateSnapshot(snapshot);
    return snapSnapshot;
    }
    async applySnapshot(...args: [OpenFin.ApplySnapshotPayload, OpenFin.ClientIdentity]): Promise<void> {
    await SnapServer.prepareToApplySnapshot();
    await super.applySnapshot(...args);
    await SnapServer.applySnapshot(args[0].snapshot);
    }
    }
    return new WithSnap(...overrideArgs);
    } catch (error) {
    return new PlatformProvider();
    }
    },
    });
  • Attaches two windows together on a specified side and at a specified offset

    Parameters

    • targetClientId: string

      The client id of the window to attach to

    • toAttachClientId: string

      The client id of the window to attach

    • targetSide: AttachSide

      The side of the target window to attach to

    • offset: number

      The offset from the target window side to attach to

    Returns Promise<void>

    Promise

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there are two windows with the client ids 'my-client-id-1' and 'my-client-id-2'
    await server.attachWindows('my-client-id-1', 'my-client-id-2', 'left', 0);
  • Connects to an already running Snap Server instance

    Use this if the Snap server has been manually started or when wanting to interact with Snap from another part of an application. For example the Snap server was started as part of a platform provider and a view would like to also interact with Snap.

    Returns Promise<void>

    Promise

    Shows how to connect to an already running Snap Server instance with the id 'test'

    const server = new Snap.SnapServer('test');
    await server.connect();
  • Given a snapshot, decorates it with the current Snap layout and returns it

    Parameters

    • snapshot: Snapshot

      The OpenFin.Snapshot to decorate

    Returns Promise<SnapSnapshot>

    A Promise resolving to an instance of SnapSnapshot which contains both the original snapshot and the Snap layout

    This example shows how to implement a snapshot override that decorates a snapshot with the current Snap layout

      fin.Platform.init({
    overrideCallback: async (PlatformProvider, ...overrideArgs) => {
    try {
    class WithSnap extends PlatformProvider {
    async getSnapshot(...args: [undefined, OpenFin.ClientIdentity]): Promise<OpenFin.Snapshot> {
    const snapshot = await super.getSnapshot(...args);
    const snapSnapshot = await SnapServer.decorateSnapshot(snapshot);
    return snapSnapshot;
    }
    async applySnapshot(...args: [OpenFin.ApplySnapshotPayload, OpenFin.ClientIdentity]): Promise<void> {
    await SnapServer.prepareToApplySnapshot();
    await super.applySnapshot(...args);
    await SnapServer.applySnapshot(args[0].snapshot);
    }
    }
    return new WithSnap(...overrideArgs);
    } catch (error) {
    return new PlatformProvider();
    }
    },
    });
  • Detaches the given window from any other windows it is attached to

    Parameters

    • clientId: string

      The client id of the window to detach

    Returns Promise<void>

    Promise

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there is a window with the client id 'my-client-id'
    await server.detachFromGroup('my-client-id');
  • Listens for new windows being created within the platform automatically registers them with the Snap Server

    Returns Promise<(() => Promise<void>)>

    A function that can be called to stop listening for new windows

    Setup for automatic registration of new windows and creates a new window

    const server = new Snap.SnapServer('test');
    await server.connect();
    server.enableAutoWindowRegistration();

    // The following new Window will automatically be registered with Snap
    const newView = await fin.Platform.wrapSync(fin.Platform.getCurrentSync().identity).createView({
    name: 'new-view',
    url: 'https://my-own-content.com',
    });
  • Gets the IDs of all known groups

    Returns Promise<string[]>

    The group IDs of all groups

  • Gets a list of windows that are attached to the given window

    Parameters

    • clientId: string

      The client id of the window to get the attached windows for

    Returns Promise<string[]>

    string[] - A promise resolving to a list of client ids of the attached windows

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there is a window with the client id 'my-client-id'
    const attachedWindows = await server.getAttached('my-client-id');
  • Gets the group ID for the given window.

    Parameters

    • identifier: string | number

      Either the native window ID (as a number), or the client ID of the window (as a string)

    Returns Promise<string>

    The group ID

    An error if the ID provided is invalid.

  • Retrieves the current layout

    Returns Promise<SnapLayout>

    The layout object

  • Gets the resizable state for the given window.

    Parameters

    • identifier: string | number

      Either the native window ID (as a number), or the client ID of the window (as a string)

    Returns Promise<string>

    The resizable state

    An error if the ID provided is invalid.

  • Gets an array of windows in a given group

    Parameters

    • groupId: string

      The group ID

    Returns Promise<{
        clientId: string;
        nativeId: number;
    }[]>

    The windows in the group, or an empty array if the group does not exist.

  • Checks if the given window has any attachments

    Parameters

    • clientId: string

      The client id of the window to check

    Returns Promise<boolean>

    Promise - True if the window has attachments, false otherwise

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there is a window with the client id 'my-client-id'
    const hasAttachments = await server.hasAttachments('my-client-id');
  • Launches a new process and registers it with the Snap Server

    Parameters

    Returns Promise<LaunchResult>

    Promise

    const server = new Snap.SnapServer('test');
    await server.connect();
    await server.launch({
    path: 'C:\\Windows\\System32\\notepad.exe',
    client_id: 'my-notepad-client-id',
    });
  • Minimizes all windows in the given group

    Parameters

    • groupId: string

      The group ID

    Returns Promise<void>

  • Adds an event handler for the given event that will only be called once

    Type Parameters

    • TEventName extends
          | "all-events"
          | "client-registered"
          | "client-unregistered"
          | "move-size-completed"
          | "clients-attached"
          | "client-detached"
          | "groups-changed"
          | "client-activated"
          | "client-deactivated"

    Parameters

    Returns void

    void

    SnapServerEventTypes

  • Prepares the Snap server to apply a new snapshot, potentially modifying the given payload

    Parameters

    • OptionalsnapshotPayload: ApplySnapshotPayload

      The payload for applySnapshot

    • OptionalcustomClientIdMapper: ((id: string) => string)

      An optional mapper function for renaming any client IDs in the snapshot that are already in use in Snap. If not provided, then a default mapper function will be used when necessary, whose logic is as follows: For IDs containing three or more parts separated by a '/', the last part will be replaced with a new GUID. For other IDs, the the entire ID will be replaced with a new GUID. For example, <prefix>/<appId>/<instanceId> would be replaced with <prefix>/<appId>/<a new GUID>, and <another client ID> would be replaced with <a new GUID>. Client IDs referenced in the snapshot payload that are not already in use in Snap will be unchanged.

        • (id): string
        • Parameters

          • id: string

          Returns string

    Returns Promise<void>

    Promise

    This example shows how to implement a snapshot override that decorates a snapshot with the current Snap layout

      fin.Platform.init({
    overrideCallback: async (PlatformProvider, ...overrideArgs) => {
    try {
    class WithSnap extends PlatformProvider {
    async getSnapshot(...args: [undefined, OpenFin.ClientIdentity]): Promise<OpenFin.Snapshot> {
    const snapshot = await super.getSnapshot(...args);
    const snapSnapshot = await SnapServer.decorateSnapshot(snapshot);
    return snapSnapshot;
    }
    async applySnapshot(payload: OpenFin.ApplySnapshotPayload, identity?: OpenFin.Identity): Promise<void> {
    await snapServer.prepareToApplySnapshot(payload);
    await super.applySnapshot(payload, identity);
    await snapServer.applySnapshot(payload.snapshot);
    }
    }
    return new WithSnap(...overrideArgs);
    } catch (error) {
    return new PlatformProvider();
    }
    },
    });
  • Registers the given platform native window handle with the Snap Server

    Parameters

    • clientId: string

      The client id to register the window with

    • windowHandle: string

      The native window handle to register

    • OptionalresizingBehavior: ResizingBehavior

    Returns Promise<void>

    Promise

    const server = new Snap.SnapServer('test');
    await server.connect();

    // Assuming there is a window with the native id '0x0000000000001234'
    await server.registerWindow('my-client-id', '0x0000000000001234');
  • Removes an event handler for the given event

    Type Parameters

    • TEventName extends
          | "all-events"
          | "client-registered"
          | "client-unregistered"
          | "move-size-completed"
          | "clients-attached"
          | "client-detached"
          | "groups-changed"
          | "client-activated"
          | "client-deactivated"

    Parameters

    Returns void

    void

    SnapServerEventTypes

  • Restores and brings to front all windows in the given group

    Parameters

    • groupId: string

      The group ID

    Returns Promise<void>

  • Restores the given layout

    Parameters

    • layout: SnapLayout

      The layout object to restore

    • reset: boolean = true

      Whether existing snap connections should be reset

    Returns Promise<void>

    Promise

    const server = new Snap.SnapServer('test');
    await server.connect();

    const myLayout = { ... }
    await server.setLayout(myLayout);
  • Sets the resizable state for the given window.

    Parameters

    • identifier: string | number

      Either the native window ID (as a number), or the client ID of the window (as a string)

    • resizable: boolean

    Returns Promise<void>

  • Starts a new instance of Snap Server and connects to it passing an optional set of parameters

    Parameters

    Returns Promise<void>

    Promise

    const server = new Snap.SnapServer('test');
    await server.start();
  • Shuts down the connected Snap Server instance

    Returns Promise<void>

    Promise