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
The instance of the server that will be started or connected to
const server = new Snap.SnapServer('test');
Optional
clientOptional
need_The instance of the server that will be started or connected to
Optional
snap_Adds an event handler for the given event
The name of the event to listen for SnapServerEventTypes
The handler to call when the event is fired
Rest
...eventArg: SnapServerEventTypes[TEventName]Rest
void
SnapServerEventTypes
Given a snapshot, extracts the Snap layout, if any, and applies it to the current Snap Server
The OpenFin.Snapshot to apply
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
The client id of the window to attach to
The client id of the window to attach
The side of the target window to attach to
The offset from the target window side to attach to
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);
Private
build_Optional
options: ServerOptionsOptional
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.
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
The OpenFin.Snapshot to decorate
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();
}
},
});
Private
defaultDetaches the given window from any other windows it is attached to
The client id of the window to detach
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');
Private
emit_Rest
...eventArg: SnapServerEventTypes[TEventName]Rest
Listens for new windows being created within the platform automatically registers them with the Snap Server
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',
});
Private
getGet the executable path for an app asset.
The app asset information.
The app asset alias information.
The app asset target information.
The app asset version information.
The native path for the asset.
Gets a list of windows that are attached to the given window
The client id of the window to get the attached windows for
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');
Retrieves the current layout
The layout object
Private
handlePrivate
handleChecks if the given window has any attachments
The client id of the window to check
Promise
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
a set of options specifying the process to launch LaunchOptions
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',
});
Adds an event handler for the given event that will only be called once
The name of the event to listen for
The handler to call when the event is fired
Rest
...eventArg: SnapServerEventTypes[TEventName]Rest
void
SnapServerEventTypes
Prepares the Snap server to apply a new snapshot, potentially modifying the given payload
Optional
snapshotPayload: ApplySnapshotPayloadThe payload for applySnapshot
Optional
Optional
customClientIdMapper: ((id) => 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.
Optional
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
The client id to register the window with
The native window handle to register
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
The name of the event to remove the handler for
The handler to remove
Rest
...eventArg: SnapServerEventTypes[TEventName]Rest
void
SnapServerEventTypes
Private
replaceRestores the given layout
The layout object to restore
Whether existing snap connections should be reset
Promise
const server = new Snap.SnapServer('test');
await server.connect();
const myLayout = { ... }
await server.setLayout(myLayout);
Starts a new instance of Snap Server and connects to it passing an optional set of parameters
Optional
options: ServerOptionsOptions for the started server ServerOptions
Optional
Promise
const server = new Snap.SnapServer('test');
await server.start();
Generated using TypeDoc
Represents a connection to an Snap Server instance that can be used to control interactions with the server.