@openfin/core 31.74.30 → 32.75.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/package.json +1 -1
  2. package/src/OpenFin.d.ts +46 -12
  3. package/src/api/application/Instance.js +23 -5
  4. package/src/api/base.d.ts +1 -2
  5. package/src/api/base.js +1 -2
  6. package/src/api/events/system.d.ts +6 -3
  7. package/src/api/fin.js +1 -2
  8. package/src/api/interappbus/channel/protocols/classic/strategy.js +24 -6
  9. package/src/api/interappbus/index.js +1 -1
  10. package/src/api/interop/InteropClient.d.ts +1 -1
  11. package/src/api/interop/InteropClient.js +1 -1
  12. package/src/api/interop/SessionContextGroupBroker.d.ts +1 -1
  13. package/src/api/interop/SessionContextGroupBroker.js +5 -4
  14. package/src/api/interop/SessionContextGroupClient.js +1 -1
  15. package/src/api/interop/fdc3/PrivateChannelProvider.d.ts +1 -1
  16. package/src/api/interop/fdc3/PrivateChannelProvider.js +1 -8
  17. package/src/api/interop/fdc3/fdc3-1.2.js +34 -1
  18. package/src/api/interop/fdc3/utils.js +24 -4
  19. package/src/api/platform/Factory.d.ts +2 -1
  20. package/src/api/platform/Instance.d.ts +5 -4
  21. package/src/api/platform/Instance.js +2 -1
  22. package/src/api/platform/layout/Factory.js +6 -4
  23. package/src/api/platform/layout/Instance.js +3 -0
  24. package/src/api/platform/layout/controllers/layout-entities-controller.d.ts +7 -4
  25. package/src/api/platform/layout/controllers/layout-entities-controller.js +42 -11
  26. package/src/api/platform/layout/controllers/tab-drag-controller.d.ts +2 -1
  27. package/src/api/platform/layout/entities/layout-entities.d.ts +12 -2
  28. package/src/api/platform/layout/entities/layout-entities.js +14 -2
  29. package/src/api/platform/layout/utils/layout-traversal.d.ts +1 -0
  30. package/src/api/platform/layout/utils/layout-traversal.js +11 -11
  31. package/src/api/platform/provider.d.ts +2 -1
  32. package/src/api/system/index.d.ts +9 -0
  33. package/src/api/system/index.js +31 -2
  34. package/src/api/view/Instance.d.ts +6 -3
  35. package/src/api/view/Instance.js +9 -7
  36. package/src/api/webcontents/main.d.ts +1 -22
  37. package/src/api/window/Instance.d.ts +3 -0
  38. package/src/api/window/Instance.js +3 -0
  39. package/src/shapes/protocol.d.ts +1 -0
  40. package/src/transport/transport-errors.d.ts +9 -1
  41. package/src/transport/transport-errors.js +45 -2
  42. package/src/transport/transport.d.ts +15 -5
  43. package/src/transport/transport.js +48 -20
  44. package/src/util/channel-api-relay.js +11 -1
  45. package/src/util/errors.d.ts +1 -0
  46. package/src/util/errors.js +1 -0
  47. package/src/util/ref-counter.d.ts +1 -1
  48. package/src/util/ref-counter.js +3 -2
  49. package/src/transport/fin_store.d.ts +0 -4
  50. package/src/transport/fin_store.js +0 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfin/core",
3
- "version": "31.74.30",
3
+ "version": "32.75.6",
4
4
  "license": "SEE LICENSE IN LICENSE.MD",
5
5
  "main": "./src/mock.js",
6
6
  "types": "./src/mock.d.ts",
package/src/OpenFin.d.ts CHANGED
@@ -1,20 +1,20 @@
1
- import type { Application } from './api/application';
1
+ import type { Application } from './api/application/index';
2
2
  import { AppVersionEvent } from './api/events/system';
3
3
  import { TypedEventEmitter } from './api/events/typedEventEmitter';
4
- import type { ExternalApplication } from './api/external-application';
4
+ import type { ExternalApplication } from './api/external-application/index';
5
5
  import { FinApi } from './api/fin';
6
- import type { _Frame } from './api/frame';
6
+ import type { _Frame } from './api/frame/index';
7
7
  import type ChannelClient from './api/interappbus/channel/client';
8
- import { MessagingProtocols } from './api/interappbus/channel/protocols';
8
+ import { MessagingProtocols } from './api/interappbus/channel/protocols/index';
9
9
  import type { ChannelProvider } from './api/interappbus/channel/provider';
10
- import type { InteropBroker, InteropClient } from './api/interop';
11
- import type { Platform } from './api/platform';
12
- import type { Layout } from './api/platform/layout';
13
- import type { ColumnOrRow, TabStack } from './api/platform/layout/entities/layout-entities';
10
+ import type { InteropBroker, InteropClient } from './api/interop/index';
11
+ import type { Platform } from './api/platform/index';
12
+ import type { Layout } from './api/platform/layout/index';
14
13
  import { PlatformProvider } from './api/platform/provider';
15
- import { SnapshotSource } from './api/snapshot-source';
16
- import type { View } from './api/view';
17
- import { _Window } from './api/window';
14
+ import { SnapshotSource } from './api/snapshot-source/index';
15
+ import type { View } from './api/view/index';
16
+ import { _Window } from './api/window/index';
17
+ import { ColumnOrRow, TabStack } from './api/platform/layout/entities/layout-entities';
18
18
  export type Fin<MeType extends EntityType = 'window' | 'view'> = FinApi<MeType>;
19
19
  export type { Application, ExternalApplication, _Frame as Frame, ChannelClient, ChannelProvider, Platform, Layout, View, ColumnOrRow, TabStack, _Window as Window, InteropClient, InteropBroker, SnapshotSource };
20
20
  export type { LayoutEntityDefinition, LayoutEntityTypes, LayoutPosition } from './api/platform/layout/entities/shapes';
@@ -246,7 +246,7 @@ export type DisplayMetadata = {
246
246
  */
247
247
  readonly glyph?: string;
248
248
  };
249
- export type LegacyWinOptionsInAppOptions = Pick<WindowCreationOptions, 'accelerator' | 'alwaysOnTop' | 'api' | 'aspectRatio' | 'autoplayPolicy' | 'autoShow' | 'backgroundColor' | 'contentNavigation' | 'contextMenu' | 'cornerRounding' | 'customData' | 'customRequestHeaders' | 'defaultCentered' | 'defaultHeight' | 'defaultLeft' | 'defaultTop' | 'defaultWidth' | 'frame' | 'hideOnClose' | 'icon' | 'maxHeight' | 'maximizable' | 'maxWidth' | 'minHeight' | 'minimizable' | 'minWidth' | 'opacity' | 'preloadScripts' | 'resizable' | 'resizeRegion' | 'saveWindowState' | 'ignoreSavedWindowState' | 'shadow' | 'showTaskbarIcon' | 'smallWindow' | 'state' | 'taskbarIconGroup' | 'waitForPageLoad'>;
249
+ export type LegacyWinOptionsInAppOptions = Pick<WindowCreationOptions, 'accelerator' | 'alwaysOnTop' | 'api' | 'aspectRatio' | 'autoplayPolicy' | 'autoShow' | 'backgroundColor' | 'contentNavigation' | 'contextMenu' | 'cornerRounding' | 'customData' | 'customRequestHeaders' | 'defaultCentered' | 'defaultHeight' | 'defaultLeft' | 'defaultTop' | 'defaultWidth' | 'frame' | 'hideOnClose' | 'icon' | 'maxHeight' | 'maximizable' | 'maxWidth' | 'minHeight' | 'minimizable' | 'minWidth' | 'opacity' | 'preloadScripts' | 'resizable' | 'resizeRegion' | 'saveWindowState' | 'ignoreSavedWindowState' | 'shadow' | 'showTaskbarIcon' | 'smallWindow' | 'state' | 'taskbarIconGroup' | 'waitForPageLoad' | '_internalWorkspaceData'>;
250
250
  export type Snapshot = {
251
251
  windows: WindowCreationOptions[];
252
252
  snapshotDetails?: {
@@ -794,6 +794,11 @@ export type MutableWindowOptions = {
794
794
  */
795
795
  showTaskbarIcon: boolean;
796
796
  interop: InteropConfig;
797
+ /**
798
+ * @internal
799
+ * Used by Workspace to store custom data. Overwriting or modifying this field may impact the functionality of Workspace
800
+ */
801
+ _internalWorkspaceData: any;
797
802
  workspacePlatform: WorkspacePlatformOptions;
798
803
  };
799
804
  export type WorkspacePlatformOptions = {
@@ -1193,6 +1198,11 @@ export type MutableViewOptions = {
1193
1198
  */
1194
1199
  preventDragOut: boolean;
1195
1200
  interop?: InteropConfig;
1201
+ /**
1202
+ * @internal
1203
+ * Used by Workspace to store custom data. Overwriting or modifying this field may impact the functionality of Workspace
1204
+ */
1205
+ _internalWorkspaceData: any;
1196
1206
  };
1197
1207
  /**
1198
1208
  * User-facing options for a view.
@@ -2909,6 +2919,9 @@ export interface PopupResult<T = any> {
2909
2919
  data?: T;
2910
2920
  lastDispatchResult?: PopupResult;
2911
2921
  }
2922
+ export type SystemShutdownHandler = (shutdownEvent: {
2923
+ proceed: () => void;
2924
+ }) => void;
2912
2925
  export type AppVersionProgressEvent = {
2913
2926
  type: 'app-version-progress';
2914
2927
  } & AppVersionProgress;
@@ -2971,3 +2984,24 @@ export interface InteropActionLoggingOption {
2971
2984
  export type InteropLoggingActions = 'beforeAction' | 'afterAction';
2972
2985
  export type InteropLoggingOptions = Record<InteropLoggingActions, InteropActionLoggingOption>;
2973
2986
  export type { Me } from './api/me';
2987
+ /**
2988
+ * Configuration for page capture.
2989
+ */
2990
+ export interface CapturePageOptions {
2991
+ /**
2992
+ * The area of the window to be captured.
2993
+ */
2994
+ area?: Rectangle;
2995
+ /**
2996
+ * @defaultValue 'png'
2997
+ *
2998
+ * The format of the captured image. Can be 'png', 'jpg', or 'bmp'.
2999
+ */
3000
+ format?: 'bmp' | 'jpg' | 'png';
3001
+ /**
3002
+ * @defaultValue 100
3003
+ *
3004
+ * Quality of JPEG image. Between 0 - 100.
3005
+ */
3006
+ quality?: number;
3007
+ }
@@ -141,11 +141,29 @@ class Application extends base_1.EmitterBase {
141
141
  * @tutorial Application.quit
142
142
  */
143
143
  async quit(force = false) {
144
- await this._close(force);
145
- await this.wire.sendAction('destroy-application', { force, ...this.identity });
146
- }
147
- _close(force = false) {
148
- return this.wire.sendAction('close-application', { force, ...this.identity }).then(() => undefined);
144
+ try {
145
+ await this._close(force);
146
+ await this.wire.sendAction('destroy-application', { force, ...this.identity });
147
+ }
148
+ catch (error) {
149
+ const acceptableErrors = [
150
+ 'Remote connection has closed',
151
+ 'Could not locate the requested application'
152
+ ];
153
+ if (!acceptableErrors.some(msg => error.message.includes(msg))) {
154
+ throw error;
155
+ }
156
+ }
157
+ }
158
+ async _close(force = false) {
159
+ try {
160
+ await this.wire.sendAction('close-application', { force, ...this.identity });
161
+ }
162
+ catch (error) {
163
+ if (!error.message.includes('Remote connection has closed')) {
164
+ throw error;
165
+ }
166
+ }
149
167
  }
150
168
  close(force = false) {
151
169
  console.warn('Deprecation Warning: Application.close is deprecated Please use Application.quit');
package/src/api/base.d.ts CHANGED
@@ -2,14 +2,13 @@
2
2
  import { EventEmitter } from 'events';
3
3
  import { Transport } from '../transport/transport';
4
4
  import type * as OpenFin from '../OpenFin';
5
- import Fin from './fin';
6
5
  import { BaseEvent, EventHandler } from './events/base';
7
6
  type ApplicationIdentity = OpenFin.ApplicationIdentity;
8
7
  type Identity = OpenFin.Identity;
9
8
  export declare class Base {
10
9
  wire: Transport;
11
10
  constructor(wire: Transport);
12
- protected get fin(): Fin;
11
+ protected get fin(): OpenFin.Fin<OpenFin.EntityType>;
13
12
  get me(): Identity;
14
13
  protected isNodeEnvironment: () => boolean;
15
14
  protected isOpenFinEnvironment: () => boolean;
package/src/api/base.js CHANGED
@@ -14,7 +14,6 @@ var _EmitterBase_emitterAccessor;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Reply = exports.EmitterBase = exports.Base = void 0;
16
16
  const promises_1 = require("../util/promises");
17
- const fin_store_1 = require("../transport/fin_store");
18
17
  class Base {
19
18
  constructor(wire) {
20
19
  this.isNodeEnvironment = () => {
@@ -29,7 +28,7 @@ class Base {
29
28
  this.wire = wire;
30
29
  }
31
30
  get fin() {
32
- return (0, fin_store_1.getFin)(this.wire);
31
+ return this.wire.getFin();
33
32
  }
34
33
  get me() {
35
34
  return this.wire.me;
@@ -1,6 +1,6 @@
1
1
  import type * as OpenFin from '../../OpenFin';
2
2
  import { PropagatedApplicationEvent } from './application';
3
- import { BaseEvent } from './base';
3
+ import { BaseEvent, IdentityEvent } from './base';
4
4
  import { PropagatedViewEvent } from './view';
5
5
  import { PropagatedWindowEvent } from './window';
6
6
  import { AppVersionCompleteEvent, AppVersionErrorEvent, AppVersionProgressEvent, AppVersionRuntimeStatusEvent } from '../../OpenFin';
@@ -38,13 +38,16 @@ export type EventWithId<Event extends AppVersionEvent> = Event extends infer E e
38
38
  appVersionId: string;
39
39
  } : never;
40
40
  export type AppVersionEventWithId = EventWithId<AppVersionEvent>;
41
- export type ApplicationCreatedEvent = BaseEvent & {
41
+ export type ApplicationCreatedEvent = IdentityEvent & {
42
42
  type: 'application-created';
43
43
  };
44
44
  export type DesktopIconClickedEvent = BaseEvent & {
45
45
  type: 'desktop-icon-clicked';
46
46
  };
47
+ export type SystemShutdownEvent = BaseEvent & {
48
+ type: 'system-shutdown';
49
+ };
47
50
  export type SystemEvent = {
48
51
  topic: 'system';
49
- } & (ExcludeRequested<PropagatedWindowEvent> | PropagatedViewEvent | PropagatedApplicationEvent | ApplicationCreatedEvent | DesktopIconClickedEvent | IdleEvent | MonitorEvent | SessionChangedEvent | AppVersionEventWithId);
52
+ } & (ExcludeRequested<PropagatedWindowEvent> | PropagatedViewEvent | PropagatedApplicationEvent | ApplicationCreatedEvent | DesktopIconClickedEvent | IdleEvent | MonitorEvent | SessionChangedEvent | AppVersionEventWithId | SystemShutdownEvent);
50
53
  export type SystemEventType = SystemEvent['type'];
package/src/api/fin.js CHANGED
@@ -13,13 +13,11 @@ const index_8 = require("./global-hotkey/index");
13
13
  const index_9 = require("./view/index");
14
14
  const index_10 = require("./platform/index");
15
15
  const me_1 = require("./me");
16
- const fin_store_1 = require("../transport/fin_store");
17
16
  const interop_1 = require("./interop");
18
17
  const snapshot_source_1 = require("./snapshot-source");
19
18
  class Fin extends events_1.EventEmitter {
20
19
  constructor(wire) {
21
20
  super();
22
- (0, fin_store_1.registerFin)(wire, this);
23
21
  this.wire = wire;
24
22
  this.System = new index_1.default(wire);
25
23
  this.Window = new index_2.default(wire);
@@ -33,6 +31,7 @@ class Fin extends events_1.EventEmitter {
33
31
  this.View = new index_9.default(wire);
34
32
  this.Interop = new interop_1.default(wire);
35
33
  this.SnapshotSource = new snapshot_source_1.default(wire);
34
+ wire.registerFin(this);
36
35
  this.me = (0, me_1.getMe)(wire);
37
36
  // Handle disconnect events
38
37
  wire.on('disconnected', () => {
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _ClassicStrategy_wire, _ClassicStrategy_endpointIdentityMap;
13
+ var _ClassicStrategy_wire, _ClassicStrategy_endpointIdentityMap, _ClassicStrategy_pendingMessagesByEndpointId;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ClassicInfo = exports.ClassicStrategy = void 0;
16
16
  /*
@@ -26,7 +26,11 @@ class ClassicStrategy {
26
26
  // Store full endpointIdentity by endpointId of all known endpoints for this strategy instance.
27
27
  // (clients will only have 1: the provider, the provider will have all clients)
28
28
  _ClassicStrategy_endpointIdentityMap.set(this, new Map());
29
+ // Store a set of cancellable promises to be able to reject them when client
30
+ // connection problems occur
31
+ _ClassicStrategy_pendingMessagesByEndpointId.set(this, new Map);
29
32
  this.send = async (endpointId, action, payload) => {
33
+ var _a;
30
34
  const to = __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
31
35
  if (!to) {
32
36
  throw new Error(`Could not locate routing info for endpoint ${endpointId}`);
@@ -38,20 +42,27 @@ class ClassicStrategy {
38
42
  delete cleanId.endpointId;
39
43
  }
40
44
  delete cleanId.isLocalEndpointId;
41
- const raw = await __classPrivateFieldGet(this, _ClassicStrategy_wire, "f")
45
+ // grab the promise before awaiting it to save in our pending messages map
46
+ const p = __classPrivateFieldGet(this, _ClassicStrategy_wire, "f")
42
47
  .sendAction('send-channel-message', {
43
48
  ...cleanId,
44
49
  providerIdentity: this.providerIdentity,
45
50
  action,
46
51
  payload
47
- })
48
- .catch((reason) => {
49
- throw new Error(reason.message);
52
+ });
53
+ (_a = __classPrivateFieldGet(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId)) === null || _a === void 0 ? void 0 : _a.add(p);
54
+ const raw = await p.catch((error) => {
55
+ throw new Error(error.message);
56
+ }).finally(() => {
57
+ var _a;
58
+ // clean up the pending promise
59
+ (_a = __classPrivateFieldGet(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId)) === null || _a === void 0 ? void 0 : _a.delete(p);
50
60
  });
51
61
  return raw.payload.data.result;
52
62
  };
53
63
  this.close = async () => {
54
64
  this.messageReceiver.removeEndpoint(this.providerIdentity.channelId, this.endpointId);
65
+ [...__classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").keys()].forEach((id) => this.closeEndpoint(id));
55
66
  __classPrivateFieldSet(this, _ClassicStrategy_endpointIdentityMap, new Map(), "f");
56
67
  };
57
68
  __classPrivateFieldSet(this, _ClassicStrategy_wire, wire, "f");
@@ -63,13 +74,20 @@ class ClassicStrategy {
63
74
  this.messageReceiver.addEndpoint(listener, this.providerIdentity.channelId, this.endpointId);
64
75
  }
65
76
  async closeEndpoint(endpointId) {
77
+ const id = __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").get(endpointId);
66
78
  __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").delete(endpointId);
79
+ const pendingSet = __classPrivateFieldGet(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").get(endpointId);
80
+ pendingSet === null || pendingSet === void 0 ? void 0 : pendingSet.forEach((p) => {
81
+ const errorMsg = `Channel connection with identity uuid: ${id === null || id === void 0 ? void 0 : id.uuid} / name: ${id === null || id === void 0 ? void 0 : id.name} / endpointId: ${endpointId} no longer connected.`;
82
+ p.cancel(new Error(errorMsg));
83
+ });
67
84
  }
68
85
  isEndpointConnected(endpointId) {
69
86
  return __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").has(endpointId);
70
87
  }
71
88
  addEndpoint(endpointId, payload) {
72
89
  __classPrivateFieldGet(this, _ClassicStrategy_endpointIdentityMap, "f").set(endpointId, payload.endpointIdentity);
90
+ __classPrivateFieldGet(this, _ClassicStrategy_pendingMessagesByEndpointId, "f").set(endpointId, new Set());
73
91
  }
74
92
  isValidEndpointPayload(payload) {
75
93
  var _a, _b;
@@ -78,6 +96,6 @@ class ClassicStrategy {
78
96
  }
79
97
  }
80
98
  exports.ClassicStrategy = ClassicStrategy;
81
- _ClassicStrategy_wire = new WeakMap(), _ClassicStrategy_endpointIdentityMap = new WeakMap();
99
+ _ClassicStrategy_wire = new WeakMap(), _ClassicStrategy_endpointIdentityMap = new WeakMap(), _ClassicStrategy_pendingMessagesByEndpointId = new WeakMap();
82
100
  // Arbitrarily starting at 5 to leave the door open to backfilling pre endpointId etc.
83
101
  exports.ClassicInfo = { version: 5, minimumVersion: 0, type: 'classic' };
@@ -17,7 +17,7 @@ class InterApplicationBus extends base_1.Base {
17
17
  subscriberAdded: 'subscriber-added',
18
18
  subscriberRemoved: 'subscriber-removed'
19
19
  };
20
- this.refCounter = new ref_counter_1.default();
20
+ this.refCounter = new ref_counter_1.RefCounter();
21
21
  this.Channel = new index_1.Channel(wire);
22
22
  this.emitter = new events_1.EventEmitter();
23
23
  wire.registerMessageHandler(this.onmessage.bind(this));
@@ -88,7 +88,7 @@ import { Base } from '../base';
88
88
  * @summary A SessionContextGroup instance method for adding a handler for context change.
89
89
  * @param {ContextHandler} contextHandler The callback to be invoked. Is invoked when (a) the context changes or (b) immediately after getting created if the context is already set.
90
90
  * @param {string} [contextType] The context type this handler should listen to. If not specified, a global handler for all context types will get created. Only one global handler is allowed per SessionContextGroup.
91
- * @return {Promise<void>}
91
+ * @return {Promise<Subscription>}
92
92
  */
93
93
  /**
94
94
  * {@link https://developers.openfin.co/of-docs/docs/enable-color-linking}
@@ -103,7 +103,7 @@ const utils_1 = require("./utils");
103
103
  * @summary A SessionContextGroup instance method for adding a handler for context change.
104
104
  * @param {ContextHandler} contextHandler The callback to be invoked. Is invoked when (a) the context changes or (b) immediately after getting created if the context is already set.
105
105
  * @param {string} [contextType] The context type this handler should listen to. If not specified, a global handler for all context types will get created. Only one global handler is allowed per SessionContextGroup.
106
- * @return {Promise<void>}
106
+ * @return {Promise<Subscription>}
107
107
  */
108
108
  /**
109
109
  * {@link https://developers.openfin.co/of-docs/docs/enable-color-linking}
@@ -18,7 +18,7 @@ export default class SessionContextGroupBroker {
18
18
  handlerAdded(payload: {
19
19
  handlerId: string;
20
20
  contextType?: string;
21
- }, clientIdentity: OpenFin.ClientIdentity): void;
21
+ }, clientIdentity: OpenFin.ClientIdentity): Promise<void>;
22
22
  handlerRemoved(payload: {
23
23
  handlerId: string;
24
24
  }, clientIdentity: OpenFin.ClientIdentity): void;
@@ -48,7 +48,7 @@ class SessionContextGroupBroker {
48
48
  getClientState(id) {
49
49
  return this.clients.get(id.endpointId);
50
50
  }
51
- handlerAdded(payload, clientIdentity) {
51
+ async handlerAdded(payload, clientIdentity) {
52
52
  const { handlerId, contextType } = payload;
53
53
  const clientSubscriptionState = this.getClientState(clientIdentity);
54
54
  if (!clientSubscriptionState) {
@@ -59,17 +59,18 @@ class SessionContextGroupBroker {
59
59
  clientSubscriptionState.contextHandlers.set(contextType, [...currentHandlerList, handlerId]);
60
60
  const currentContext = this.contextGroupMap.get(contextType);
61
61
  if (currentContext) {
62
- this.provider.dispatch(clientIdentity, handlerId, currentContext);
62
+ await this.provider.dispatch(clientIdentity, handlerId, currentContext);
63
63
  }
64
64
  }
65
65
  else {
66
66
  clientSubscriptionState.globalHandler = handlerId;
67
- [...this.contextGroupMap.keys()].forEach((currentContextType) => {
67
+ const globalDispatchPromises = [...this.contextGroupMap.keys()].map(async (currentContextType) => {
68
68
  const currentContext = this.contextGroupMap.get(currentContextType);
69
69
  if (currentContext) {
70
- this.provider.dispatch(clientIdentity, handlerId, currentContext);
70
+ await this.provider.dispatch(clientIdentity, handlerId, currentContext);
71
71
  }
72
72
  });
73
+ await Promise.all(globalDispatchPromises);
73
74
  }
74
75
  }
75
76
  handlerRemoved(payload, clientIdentity) {
@@ -63,7 +63,7 @@ class SessionContextGroupClient extends base_1.Base {
63
63
  handlerId = `sessionContextHandler:invoke-${this.id}`;
64
64
  }
65
65
  client.register(handlerId, (0, utils_1.wrapContextHandler)(contextHandler, handlerId));
66
- client.dispatch(`sessionContextGroup:handlerAdded-${this.id}`, { handlerId, contextType });
66
+ await client.dispatch(`sessionContextGroup:handlerAdded-${this.id}`, { handlerId, contextType });
67
67
  return { unsubscribe: await this.createUnsubscribeCb(handlerId) };
68
68
  }
69
69
  async createUnsubscribeCb(handlerId) {
@@ -1,5 +1,5 @@
1
1
  import type * as OpenFin from '../../../OpenFin';
2
- import { ChannelProvider } from '../../interappbus/channel/provider';
2
+ type ChannelProvider = OpenFin.ChannelProvider;
3
3
  type HandlerId = string;
4
4
  type ContextType = string;
5
5
  interface PrivateChannelClientState {
@@ -84,16 +84,9 @@ class PrivateChannelProvider {
84
84
  if (contextType) {
85
85
  const currentHandlersList = senderClientState.handlerIdsByContextTypes.get(contextType) || [];
86
86
  senderClientState.handlerIdsByContextTypes.set(contextType, [...currentHandlersList, handlerId]);
87
- const currContext = this.contextByContextType.get(contextType);
88
- if (currContext) {
89
- this.provider.dispatch(senderClientIdentity, handlerId, currContext);
90
- }
91
87
  }
92
88
  else {
93
89
  senderClientState.globalHandler = handlerId;
94
- if (this.lastContext) {
95
- this.provider.dispatch(senderClientIdentity, handlerId, this.lastContext);
96
- }
97
90
  }
98
91
  Array.from(this.clients.values()).forEach((currClientState) => {
99
92
  if (currClientState.clientIdentity.endpointId !== senderClientIdentity.endpointId &&
@@ -271,7 +264,7 @@ class PrivateChannelProvider {
271
264
  const allClientInfo = await this.provider.getAllClientInfo();
272
265
  return Array.from(this.clients.values()).filter((clientState) => {
273
266
  const { uuid, name } = clientState.clientIdentity;
274
- return allClientInfo.some(clientInfo => {
267
+ return allClientInfo.some((clientInfo) => {
275
268
  return name === clientInfo.name && uuid === clientInfo.uuid;
276
269
  });
277
270
  });
@@ -4,6 +4,7 @@ const base_1 = require("../../base");
4
4
  const utils_1 = require("./utils");
5
5
  const utils_2 = require("../utils");
6
6
  const InteropClient_1 = require("../InteropClient");
7
+ const lodash_1 = require("lodash");
7
8
  /**
8
9
  * @typedef { object } Listener
9
10
  * @summary Listener object returned by addContextListener and addIntentListener
@@ -393,7 +394,39 @@ class Fdc3Module extends base_1.Base {
393
394
  return {
394
395
  ...currentContextGroupInfo,
395
396
  type: 'system',
396
- addContextListener: this.addContextListener.bind(this),
397
+ addContextListener: (contextType, handler) => {
398
+ let realHandler;
399
+ let realType;
400
+ if (typeof contextType === 'function') {
401
+ console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
402
+ realHandler = contextType;
403
+ }
404
+ else {
405
+ realHandler = handler;
406
+ if (typeof contextType === 'string') {
407
+ realType = contextType;
408
+ }
409
+ }
410
+ const listener = (async () => {
411
+ let first = true;
412
+ const currentContext = await this.fin.me.interop.getCurrentContext(realType);
413
+ const wrappedHandler = (context, contextMetadata) => {
414
+ if (first) {
415
+ first = false;
416
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
417
+ return;
418
+ }
419
+ }
420
+ // eslint-disable-next-line consistent-return
421
+ return realHandler(context, contextMetadata);
422
+ };
423
+ return this.fin.me.interop.addContextHandler(wrappedHandler, realType);
424
+ })();
425
+ return {
426
+ ...listener,
427
+ unsubscribe: () => listener.then((l) => l.unsubscribe())
428
+ };
429
+ },
397
430
  broadcast: this.broadcast.bind(this),
398
431
  getCurrentContext: async (contextType) => {
399
432
  const context = await this.fin.me.interop.getCurrentContext(contextType);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getIntentResolution = exports.isChannel = exports.isContext = exports.connectPrivateChannel = exports.buildAppChannelObject = exports.buildPrivateChannelObject = exports.ChannelError = exports.ResultError = exports.UnsupportedChannelApiError = exports.getUnsupportedChannelApis = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const PrivateChannelClient_1 = require("./PrivateChannelClient");
6
+ const lodash_1 = require("lodash");
6
7
  const getUnsupportedChannelApis = (channelType) => {
7
8
  return {
8
9
  addContextListener: () => {
@@ -111,14 +112,33 @@ const buildAppChannelObject = (sessionContextGroup) => {
111
112
  return context === undefined ? null : context;
112
113
  },
113
114
  addContextListener: (contextType, handler) => {
114
- let listener;
115
+ let realHandler;
116
+ let realType;
115
117
  if (typeof contextType === 'function') {
116
118
  console.warn('addContextListener(handler) has been deprecated. Please use addContextListener(null, handler)');
117
- listener = sessionContextGroup.addContextHandler(contextType);
119
+ realHandler = contextType;
118
120
  }
119
121
  else {
120
- listener = sessionContextGroup.addContextHandler(handler, contextType === null ? undefined : contextType);
122
+ realHandler = handler;
123
+ if (typeof contextType === 'string') {
124
+ realType = contextType;
125
+ }
121
126
  }
127
+ const listener = (async () => {
128
+ let first = true;
129
+ const currentContext = await sessionContextGroup.getCurrentContext(realType);
130
+ const wrappedHandler = (context, contextMetadata) => {
131
+ if (first) {
132
+ first = false;
133
+ if ((0, lodash_1.isEqual)(currentContext, context)) {
134
+ return;
135
+ }
136
+ }
137
+ // eslint-disable-next-line consistent-return
138
+ return realHandler(context, contextMetadata);
139
+ };
140
+ return sessionContextGroup.addContextHandler(wrappedHandler, realType);
141
+ })();
122
142
  return {
123
143
  ...listener,
124
144
  unsubscribe: () => listener.then((l) => l.unsubscribe())
@@ -149,7 +169,7 @@ exports.isContext = isContext;
149
169
  const isChannel = (channel) => {
150
170
  if (channel && typeof channel === 'object' && 'type' in channel && 'id' in channel) {
151
171
  const { type, id } = channel;
152
- return (typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private'));
172
+ return typeof type === 'string' && typeof id === 'string' && (type === 'app' || type === 'private');
153
173
  }
154
174
  return false;
155
175
  };
@@ -1,8 +1,8 @@
1
1
  import type * as OpenFin from '../../OpenFin';
2
2
  import { Base } from '../base';
3
- import { Channel } from '../interappbus/channel/index';
4
3
  import { Transport } from '../../transport/transport';
5
4
  import { LayoutModule } from './layout/index';
5
+ type Channel = OpenFin.Fin['InterApplicationBus']['Channel'];
6
6
  /**
7
7
  * @PORTED
8
8
  * InitPlatformOptions interface
@@ -113,3 +113,4 @@ export default class PlatformModule extends Base {
113
113
  */
114
114
  startFromManifest(manifestUrl: string, opts?: OpenFin.RvmLaunchOptions): Promise<OpenFin.Platform>;
115
115
  }
116
+ export {};
@@ -1,9 +1,9 @@
1
1
  import type * as OpenFin from '../../OpenFin';
2
- import { View } from '../view';
3
2
  import { EmitterBase } from '../base';
4
- import { Channel } from '../interappbus/channel/index';
5
- import ChannelClient from '../interappbus/channel/client';
6
- import { LayoutModule } from './layout';
3
+ type View = OpenFin.View;
4
+ type Channel = OpenFin.Fin['InterApplicationBus']['Channel'];
5
+ type ChannelClient = OpenFin.ChannelClient;
6
+ type LayoutModule = OpenFin.Fin['Platform']['Layout'];
7
7
  /** Manages the life cycle of windows and views in the application.
8
8
  *
9
9
  * Enables taking snapshots of itself and applyi
@@ -147,3 +147,4 @@ export declare class Platform extends EmitterBase<OpenFin.PlatformEvent> {
147
147
  skipBeforeUnload: boolean;
148
148
  }): Promise<void>;
149
149
  }
150
+ export {};
@@ -7,6 +7,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
7
7
  var _Platform_connectToProvider;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Platform = void 0;
10
+ /* eslint-disable import/prefer-default-export, no-undef */
10
11
  const base_1 = require("../base");
11
12
  const validate_1 = require("../../util/validate");
12
13
  // Reuse clients to avoid overwriting already-registered client in provider
@@ -78,7 +79,7 @@ class Platform extends base_1.EmitterBase {
78
79
  const response = await client.dispatch('create-view', {
79
80
  target,
80
81
  opts: viewOptions,
81
- targetView,
82
+ targetView
82
83
  });
83
84
  if (!response || (0, validate_1.validateIdentity)(response.identity)) {
84
85
  throw new Error(`When overwriting the createView call, please return an object that has a valid 'identity' property: ${JSON.stringify(response)}`);
@@ -10,7 +10,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
11
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
12
  };
13
- var _LayoutModule_layoutManager;
13
+ var _LayoutModule_layoutManager, _LayoutModule_layoutInitializationAttempted;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.LayoutModule = void 0;
16
16
  /* eslint-disable no-undef, import/prefer-default-export */
@@ -91,6 +91,7 @@ class LayoutModule extends base_1.Base {
91
91
  constructor() {
92
92
  super(...arguments);
93
93
  _LayoutModule_layoutManager.set(this, void 0);
94
+ _LayoutModule_layoutInitializationAttempted.set(this, false);
94
95
  /**
95
96
  * Initialize the window's Layout. Must be called from a custom window that has a 'layout' option set upon creation of that window.
96
97
  * If a containerId is not provided, this method attempts to find an element with the id `layout-container`.
@@ -109,9 +110,10 @@ class LayoutModule extends base_1.Base {
109
110
  if (!this.fin.me.isWindow) {
110
111
  throw new Error('Layout.init can only be called from a Window context.');
111
112
  }
112
- else if (__classPrivateFieldGet(this, _LayoutModule_layoutManager, "f")) {
113
+ else if (__classPrivateFieldGet(this, _LayoutModule_layoutInitializationAttempted, "f")) {
113
114
  throw new Error('Layout for this window already initialized, please use Layout.replace call to replace the layout.');
114
115
  }
116
+ __classPrivateFieldSet(this, _LayoutModule_layoutInitializationAttempted, true, "f");
115
117
  // We need to go through environment to make sure it is only imported/bundled in OpenFin.
116
118
  const ManagerConstructor = await this.wire.environment.getManagerConstructor();
117
119
  const viewOverlay = new view_overlay_1.ViewOverlay(this.wire);
@@ -136,7 +138,7 @@ class LayoutModule extends base_1.Base {
136
138
  const { client, ofWindow } = ManagerConstructor.getClientAndWindow(__classPrivateFieldGet(this, _LayoutModule_layoutManager, "f"));
137
139
  // expose LayoutEntitiesController instance for API consumption
138
140
  const channelStrategy = new api_exposer_1.ChannelsExposer(client);
139
- await new api_exposer_1.ApiExposer(channelStrategy).exposeInstance(new layout_entities_controller_1.LayoutEntitiesController(__classPrivateFieldGet(this, _LayoutModule_layoutManager, "f"), ofWindow.identity.uuid, contentItemCache), { id: layout_constants_1.LAYOUT_CONTROLLER_ID });
141
+ await new api_exposer_1.ApiExposer(channelStrategy).exposeInstance(new layout_entities_controller_1.LayoutEntitiesController(__classPrivateFieldGet(this, _LayoutModule_layoutManager, "f"), contentItemCache), { id: layout_constants_1.LAYOUT_CONTROLLER_ID });
140
142
  // Adding this to the returned instance undocumented/typed for Browser.
141
143
  return Object.assign(this.getCurrentSync(), { layoutManager: __classPrivateFieldGet(this, _LayoutModule_layoutManager, "f") });
142
144
  };
@@ -203,4 +205,4 @@ class LayoutModule extends base_1.Base {
203
205
  }
204
206
  }
205
207
  exports.LayoutModule = LayoutModule;
206
- _LayoutModule_layoutManager = new WeakMap();
208
+ _LayoutModule_layoutManager = new WeakMap(), _LayoutModule_layoutInitializationAttempted = new WeakMap();