@interopio/workspaces-api 3.2.2 → 3.2.3

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.
@@ -1,175 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { ClientOperations, IncomingMethodTypes, INCOMING_METHODS, OUTGOING_METHODS, webPlatformMethodName, webPlatformWspStreamName } from "./constants";
3
- import { promisePlus } from "../shared/promisePlus";
4
- import { WorkspaceEventType } from "../types/subscription";
5
- import { InteropAPI, Subscription, InvocationResult, Instance } from "../types/glue";
6
- import { CallbackRegistry } from "callback-registry";
7
-
8
- export class InteropTransport {
9
-
10
- private readonly defaultTransportTimeout: number = 30000;
11
- private coreEventMethodInitiated = false;
12
- private corePlatformSubPromise: Promise<Subscription>;
13
-
14
- constructor(private readonly agm: InteropAPI,
15
- private readonly registry: CallbackRegistry) { }
16
-
17
- public async initiate(actualWindowId: string): Promise<void> {
18
-
19
- const desktopGlobal = (window as any).glue42gd || (window as any).iodesktop;
20
-
21
- if (desktopGlobal) {
22
- await Promise.all(
23
- Object.values(OUTGOING_METHODS).map((method) => {
24
- return this.verifyMethodLive(method.name);
25
- })
26
- );
27
-
28
- await Promise.all(
29
- Object.keys(INCOMING_METHODS).map((method: IncomingMethodTypes) => {
30
- return this.registerMethod(method);
31
- })
32
- );
33
-
34
- return;
35
- }
36
-
37
- const browserGlobal = (window as any).glue42core || (window as any).iobrowser;
38
-
39
- const systemId = browserGlobal.communicationId;
40
-
41
- await Promise.all([
42
- this.verifyMethodLive(webPlatformMethodName, systemId),
43
- this.verifyMethodLive(webPlatformWspStreamName, systemId)
44
- ]);
45
-
46
- await this.transmitControl("frameHello", { windowId: actualWindowId });
47
- }
48
-
49
- public coreSubscriptionReady(eventCallback: (args?: any) => void): Promise<Subscription> {
50
- if (!this.coreEventMethodInitiated) {
51
- this.subscribePlatform(eventCallback);
52
- }
53
- return this.corePlatformSubPromise;
54
- }
55
-
56
- public subscribePlatform(eventCallback: (args?: any) => void): void {
57
- this.coreEventMethodInitiated = true;
58
-
59
- const browserGlobal = (window as any).glue42core || (window as any).iobrowser;
60
-
61
- const systemId = browserGlobal.communicationId;
62
-
63
- this.corePlatformSubPromise = this.agm.subscribe(webPlatformWspStreamName, systemId ? { target: { instance: systemId } } : undefined);
64
-
65
- this.corePlatformSubPromise
66
- .then((sub) => {
67
- sub.onData((data) => eventCallback(data.data));
68
- });
69
- }
70
-
71
- public async subscribe(streamName: string, streamBranch: string, streamType: WorkspaceEventType): Promise<Subscription> {
72
-
73
- const subscriptionArgs = {
74
- branch: streamBranch,
75
- type: streamType
76
- };
77
-
78
- let subscription: Subscription;
79
-
80
- try {
81
- subscription = await this.agm.subscribe(streamName, { arguments: subscriptionArgs });
82
- } catch (error) {
83
- const message = `Internal subscription error! Error details: stream - ${streamName}, branch: ${streamBranch}. Internal message: ${error.message}`;
84
- throw new Error(message);
85
- }
86
-
87
- return subscription;
88
- }
89
-
90
- public async transmitControl(operation: string, operationArguments: any): Promise<any> {
91
-
92
- const desktopGlobal = (window as any).glue42gd || (window as any).iodesktop;
93
- const browserGlobal = (window as any).glue42core || (window as any).iobrowser;
94
-
95
- const invocationArguments = desktopGlobal ? { operation, operationArguments } : { operation, domain: "workspaces", data: operationArguments };
96
- const methodName = desktopGlobal ? OUTGOING_METHODS.control.name : webPlatformMethodName;
97
-
98
- const platformTarget = desktopGlobal ? undefined : browserGlobal.communicationId;
99
-
100
- let invocationResult: InvocationResult<any>;
101
- const baseErrorMessage = `Internal Workspaces Communication Error. Attempted operation: ${JSON.stringify(invocationArguments)}. `;
102
-
103
- // using the 0 index of the errors and values collections, because we expect only one server and
104
- // this is to safeguard in case in future we decide to deprecate the default returned/message properties in favor of using only collections
105
- try {
106
- invocationResult = await this.agm.invoke(methodName, invocationArguments, platformTarget ? { instance: platformTarget } : "best", { methodResponseTimeoutMs: this.defaultTransportTimeout });
107
-
108
- if (!invocationResult) {
109
- throw new Error("Received unsupported result from GD - empty result");
110
- }
111
-
112
- if (!Array.isArray(invocationResult.all_return_values) || invocationResult.all_return_values.length === 0) {
113
- throw new Error("Received unsupported result from GD - empty values collection");
114
- }
115
-
116
- } catch (error) {
117
- if (error && error.all_errors && error.all_errors.length) {
118
- // IMPORTANT: Do NOT change the `Inner message:` string, because it is used by other programs to extract the inner message of a communication error
119
- const invocationErrorMessage = error.all_errors[0].message;
120
- throw new Error(`${baseErrorMessage} -> Inner message: ${invocationErrorMessage}`);
121
-
122
- }
123
- // IMPORTANT: Do NOT change the `Inner message:` string, because it is used by other programs to extract the inner message of a communication error
124
- throw new Error(`${baseErrorMessage} -> Inner message: ${error.message}`);
125
- }
126
-
127
- return invocationResult.all_return_values[0].returned;
128
- }
129
-
130
- public onInternalMethodInvoked(key: IncomingMethodTypes, callback: (operation: ClientOperations, caller: Instance) => void) {
131
- return this.registry.add(key, callback);
132
- }
133
-
134
- private verifyMethodLive(name: string, systemId?: string): Promise<void> {
135
- return promisePlus(() => {
136
- return new Promise((resolve) => {
137
- const hasMethod = this.agm.methods().some((method) => {
138
- const nameMatch = method.name === name;
139
-
140
- const serverMatch = systemId ?
141
- method.getServers().some((server) => server.instance === systemId) :
142
- true;
143
-
144
- return nameMatch && serverMatch;
145
- });
146
-
147
- if (hasMethod) {
148
- resolve();
149
- return;
150
- }
151
-
152
- const unSub = this.agm.serverMethodAdded((data) => {
153
- const method = data.method;
154
- const server = data.server;
155
-
156
- const serverMatch = systemId ?
157
- server.instance === systemId :
158
- true;
159
-
160
- if (method.name === name && serverMatch) {
161
- unSub();
162
- resolve();
163
- }
164
- });
165
- });
166
- }, 15000, "Timeout waiting for the Workspaces communication channels");
167
- }
168
-
169
- private registerMethod(key: IncomingMethodTypes) {
170
- const method = INCOMING_METHODS[key];
171
- return this.agm.register(method.name, (args, caller) => {
172
- this.registry.execute(key, args, caller);
173
- });
174
- }
175
- }
@@ -1,487 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Workspace } from "../models/workspace";
3
- import { WorkspaceSnapshotResult, WorkspaceCreateConfigProtocol, FrameSummaryResult, AddItemResult, WorkspaceSummariesResult, WorkspaceSummaryResult, SimpleWindowOperationSuccessResult, FrameSnapshotResult, WorkspaceStreamData, GetPlatformFrameIdResult, OperationCheckResult } from "../types/protocol";
4
- import { OPERATIONS } from "../communication/constants";
5
- import { FrameCreateConfig, WorkspaceIoCCreateConfig, WindowCreateConfig, ParentCreateConfig } from "../types/ioc";
6
- import { IoC } from "../shared/ioc";
7
- import { Bridge } from "../communication/bridge";
8
- import { GDWindow, WindowsAPI, ContextsAPI, LayoutsAPI } from "../types/glue";
9
- import { IOConnectWorkspaces } from "../../workspaces";
10
- import { Frame } from "../models/frame";
11
- import { RefreshChildrenConfig } from "../types/privateData";
12
- import { AllParentTypes, Child, ContainerLockConfig, SubParentTypes } from "../types/builders";
13
- import { PrivateDataManager } from "../shared/privateDataManager";
14
- import { Window } from "../models/window";
15
- import { UnsubscribeFunction } from "callback-registry";
16
-
17
- export class BaseController {
18
-
19
- constructor(
20
- private readonly ioc: IoC,
21
- private readonly windows: WindowsAPI,
22
- private readonly contexts: ContextsAPI,
23
- private readonly layouts: LayoutsAPI,
24
- ) { }
25
-
26
- private get bridge(): Bridge {
27
- return this.ioc.bridge;
28
- }
29
-
30
- private get privateDataManager(): PrivateDataManager {
31
- return this.ioc.privateDataManager;
32
- }
33
-
34
- public checkIsWindowLoaded(windowId: string): boolean {
35
- return (!!windowId) && this.windows.list().some((win) => win.id === windowId);
36
- }
37
-
38
- public async createWorkspace(createConfig: WorkspaceCreateConfigProtocol): Promise<Workspace> {
39
- const snapshot = await this.bridge.send<WorkspaceSnapshotResult>(OPERATIONS.createWorkspace.name, createConfig);
40
-
41
- const frameConfig: FrameCreateConfig = {
42
- summary: snapshot.frameSummary
43
- };
44
- const frame = this.ioc.getModel<"frame">("frame", frameConfig);
45
-
46
- const workspaceConfig: WorkspaceIoCCreateConfig = { frame, snapshot };
47
-
48
- return this.ioc.getModel<"workspace">("workspace", workspaceConfig);
49
- }
50
-
51
- public async createEmptyFrame(definition: IOConnectWorkspaces.EmptyFrameDefinition): Promise<Frame> {
52
- const frameSummary = await this.bridge.send<FrameSummaryResult>(OPERATIONS.createFrame.name, definition);
53
- const frameConfig: FrameCreateConfig = {
54
- summary: frameSummary
55
- };
56
-
57
- return this.ioc.getModel<"frame">("frame", frameConfig);
58
- }
59
-
60
- public async initFrame(frameId: string, config: IOConnectWorkspaces.FrameInitializationConfig): Promise<void> {
61
- await this.bridge.send<void>(OPERATIONS.initFrame.name, { frameId, ...config });
62
- }
63
-
64
- public async restoreWorkspace(name: string, options: IOConnectWorkspaces.RestoreWorkspaceConfig): Promise<Workspace> {
65
- const snapshot = await this.bridge.send<WorkspaceSnapshotResult>(OPERATIONS.openWorkspace.name, { name, restoreOptions: options });
66
-
67
- const frameSummary = await this.bridge.send<FrameSummaryResult>(OPERATIONS.getFrameSummary.name, { itemId: snapshot.config.frameId });
68
-
69
- const frameConfig: FrameCreateConfig = {
70
- summary: frameSummary
71
- };
72
- const frame = this.ioc.getModel<"frame">("frame", frameConfig);
73
-
74
- const workspaceConfig: WorkspaceIoCCreateConfig = { frame, snapshot };
75
-
76
- return this.ioc.getModel<"workspace">("workspace", workspaceConfig);
77
- }
78
-
79
- public async add(type: "container" | "window", parentId: string, parentType: "row" | "column" | "group" | "workspace", definition: IOConnectWorkspaces.WorkspaceWindowDefinition | IOConnectWorkspaces.BoxDefinition): Promise<AddItemResult> {
80
- let operationName: string;
81
- const operationArgs = { definition, parentId, parentType };
82
-
83
- if (type === "window") {
84
- operationName = OPERATIONS.addWindow.name;
85
- } else if (type === "container") {
86
- operationName = OPERATIONS.addContainer.name;
87
- } else {
88
- throw new Error(`Unrecognized add type: ${type}`);
89
- }
90
-
91
- return await this.bridge.send<AddItemResult>(operationName, operationArgs);
92
- }
93
-
94
- public async getFrame(windowId: string): Promise<Frame> {
95
- const frameSummary = await this.bridge.send<FrameSummaryResult>(OPERATIONS.getFrameSummary.name, { itemId: windowId });
96
-
97
- const frameConfig: FrameCreateConfig = {
98
- summary: frameSummary
99
- };
100
- return this.ioc.getModel<"frame">("frame", frameConfig);
101
-
102
- }
103
-
104
- public getFrames(allFrameSummaries: FrameSummaryResult[], predicate?: (frame: Frame) => boolean): Frame[] {
105
-
106
- return allFrameSummaries.reduce<Frame[]>((frames, frameSummary) => {
107
-
108
- const frameConfig: FrameCreateConfig = {
109
- summary: frameSummary
110
- };
111
- const frameToCheck = this.ioc.getModel<"frame">("frame", frameConfig);
112
-
113
- if (!predicate || predicate(frameToCheck)) {
114
- frames.push(frameToCheck);
115
- }
116
-
117
- return frames;
118
- }, []);
119
- }
120
-
121
- public getAllWorkspaceSummaries(...bridgeResults: WorkspaceSummariesResult[]): IOConnectWorkspaces.WorkspaceSummary[] {
122
-
123
- const allSummaries = bridgeResults.reduce<WorkspaceSummaryResult[]>((summaries, summaryResult) => {
124
- summaries.push(...summaryResult.summaries);
125
- return summaries;
126
- }, []);
127
-
128
- return allSummaries.map<IOConnectWorkspaces.WorkspaceSummary>((summary) => {
129
-
130
- return Object.assign(
131
- {},
132
- { id: summary.id, width: summary.config.widthInPx, height: summary.config.heightInPx },
133
- summary.config
134
- );
135
- });
136
- }
137
-
138
- public handleOnSaved(callback: (layout: IOConnectWorkspaces.WorkspaceLayout) => void): UnsubscribeFunction {
139
- const wrappedCallback = (layout: IOConnectWorkspaces.WorkspaceLayout): void => {
140
- if (layout.type !== "Workspace") {
141
- return;
142
- }
143
-
144
- callback(layout);
145
- };
146
-
147
- const addedUnSub: UnsubscribeFunction = this.layouts.onAdded(wrappedCallback);
148
- const changedUnSub: UnsubscribeFunction = this.layouts.onChanged(wrappedCallback);
149
-
150
- return (): void => {
151
- addedUnSub();
152
- changedUnSub();
153
- };
154
- }
155
-
156
- public handleOnRemoved(callback: (layout: IOConnectWorkspaces.WorkspaceLayout) => void): UnsubscribeFunction {
157
- const wrappedCallback = (layout: IOConnectWorkspaces.WorkspaceLayout): void => {
158
- if (layout.type !== "Workspace") {
159
- return;
160
- }
161
-
162
- callback(layout);
163
- };
164
-
165
- return this.layouts.onRemoved(wrappedCallback);
166
- }
167
-
168
- public async importLayouts(layouts: IOConnectWorkspaces.WorkspaceLayout[], mode: "replace" | "merge"): Promise<void> {
169
- await this.layouts.import(layouts, mode);
170
- }
171
-
172
- public async transformStreamPayloadToWorkspace(payload: WorkspaceStreamData): Promise<Workspace> {
173
- const frameConfig: FrameCreateConfig = {
174
- summary: payload.frameSummary
175
- };
176
- const frame = this.ioc.getModel<"frame">("frame", frameConfig);
177
-
178
- const snapshot = payload.workspaceSnapshot || (await this.bridge.send<WorkspaceSnapshotResult>(OPERATIONS.getWorkspaceSnapshot.name, { itemId: payload.workspaceSummary.id }));
179
-
180
- const workspaceConfig: WorkspaceIoCCreateConfig = { frame, snapshot };
181
-
182
- const workspace = this.ioc.getModel<"workspace">("workspace", workspaceConfig);
183
-
184
- return workspace;
185
- }
186
-
187
- public async fetchWorkspace(itemId: string): Promise<Workspace> {
188
-
189
- const snapshot = await this.bridge.send<WorkspaceSnapshotResult>(OPERATIONS.getWorkspaceSnapshot.name, { itemId });
190
-
191
- const frameConfig: FrameCreateConfig = {
192
- summary: snapshot.frameSummary
193
- };
194
-
195
- const frame = this.ioc.getModel<"frame">("frame", frameConfig);
196
-
197
- const workspaceConfig: WorkspaceIoCCreateConfig = { frame, snapshot };
198
-
199
- return this.ioc.getModel<"workspace">("workspace", workspaceConfig);
200
-
201
- }
202
-
203
- public async bundleWorkspaceTo(type: "row" | "column", workspaceId: string): Promise<void> {
204
- await this.bridge.send(OPERATIONS.bundleWorkspace.name, { type, workspaceId });
205
- }
206
-
207
- public async bundleItemTo(type: "row" | "column", itemId: string): Promise<void> {
208
- const isSupported = await this.isOperationSupported(OPERATIONS.bundleItem.name);
209
-
210
- if (!isSupported) {
211
- throw new Error(`Operation ${OPERATIONS.bundleItem.name} is not supported. Ensure that you are running the latest version of all packages`);
212
- }
213
-
214
- await this.bridge.send(OPERATIONS.bundleItem.name, { type, itemId });
215
- }
216
-
217
- public getWorkspaceContext(workspaceId: string): Promise<any> {
218
- const contextName = `___workspace___${workspaceId}`;
219
- return this.contexts.get(contextName);
220
- }
221
-
222
- public setWorkspaceContext(workspaceId: string, data: any): Promise<void> {
223
- const contextName = `___workspace___${workspaceId}`;
224
- return this.contexts.set(contextName, data);
225
- }
226
-
227
- public updateWorkspaceContext(workspaceId: string, data: any): Promise<void> {
228
- const contextName = `___workspace___${workspaceId}`;
229
- return this.contexts.update(contextName, data);
230
- }
231
-
232
- public subscribeWorkspaceContextUpdated(workspaceId: string, callback: (data: any) => void): Promise<UnsubscribeFunction> {
233
- const contextName = `___workspace___${workspaceId}`;
234
- return this.contexts.subscribe(contextName, callback);
235
- }
236
-
237
- public async restoreItem(itemId: string): Promise<void> {
238
- await this.bridge.send(OPERATIONS.restoreItem.name, { itemId });
239
- }
240
-
241
- public async maximizeItem(itemId: string): Promise<void> {
242
- await this.bridge.send(OPERATIONS.maximizeItem.name, { itemId });
243
- }
244
-
245
- public async focusItem(itemId: string): Promise<void> {
246
- await this.bridge.send(OPERATIONS.focusItem.name, { itemId });
247
- }
248
-
249
- public async closeItem(itemId: string): Promise<void> {
250
- await this.bridge.send(OPERATIONS.closeItem.name, { itemId });
251
- }
252
-
253
- public async resizeItem(itemId: string, config: IOConnectWorkspaces.ResizeConfig): Promise<void> {
254
- await this.bridge.send(OPERATIONS.resizeItem.name, Object.assign({}, { itemId }, config));
255
- }
256
-
257
- public async setMaximizationBoundary(itemId: string, config: IOConnectWorkspaces.SetMaximizationBoundaryConfig): Promise<void> {
258
- await this.bridge.send(OPERATIONS.setMaximizationBoundary.name, Object.assign({}, { itemId }, config));
259
- }
260
-
261
- public async showWorkspaceLoadingAnimation(workspaceId: string): Promise<void> {
262
- await this.bridge.send(OPERATIONS.showLoadingAnimation.name, { itemId: workspaceId, type: "workspace" });
263
- }
264
-
265
- public async hideWorkspaceLoadingAnimation(workspaceId: string): Promise<void> {
266
- await this.bridge.send(OPERATIONS.hideLoadingAnimation.name, { itemId: workspaceId, type: "workspace" });
267
- }
268
-
269
- public async moveFrame(itemId: string, config: IOConnectWorkspaces.MoveConfig): Promise<void> {
270
- await this.bridge.send(OPERATIONS.moveFrame.name, Object.assign({}, { itemId }, config));
271
- }
272
-
273
- public getGDWindow(itemId: string): GDWindow {
274
- return this.windows.list().find((gdWindow) => gdWindow.id === itemId);
275
- }
276
-
277
- public async forceLoadWindow(itemId: string): Promise<string> {
278
- const controlResult = await this.bridge.send<SimpleWindowOperationSuccessResult>(OPERATIONS.forceLoadWindow.name, { itemId });
279
-
280
- return controlResult.windowId;
281
- }
282
-
283
- public async ejectWindow(itemId: string): Promise<SimpleWindowOperationSuccessResult> {
284
- return await this.bridge.send<SimpleWindowOperationSuccessResult>(OPERATIONS.ejectWindow.name, { itemId });
285
- }
286
-
287
- public async moveWindowTo(itemId: string, newParentId: string): Promise<void> {
288
- await this.bridge.send(OPERATIONS.moveWindowTo.name, { itemId, containerId: newParentId });
289
- }
290
-
291
- public async getSnapshot(itemId: string, type: "workspace" | "frame"): Promise<WorkspaceSnapshotResult | FrameSnapshotResult> {
292
- let result: WorkspaceSnapshotResult | FrameSnapshotResult;
293
-
294
- if (type === "workspace") {
295
- result = await this.bridge.send<WorkspaceSnapshotResult>(OPERATIONS.getWorkspaceSnapshot.name, { itemId });
296
- } else if (type === "frame") {
297
- result = await this.bridge.send<FrameSnapshotResult>(OPERATIONS.getFrameSnapshot.name, { itemId });
298
- }
299
-
300
- return result;
301
- }
302
-
303
- public async setItemTitle(itemId: string, title: string): Promise<void> {
304
- await this.bridge.send(OPERATIONS.setItemTitle.name, { itemId, title });
305
- }
306
-
307
- public refreshChildren(config: RefreshChildrenConfig): Child[] {
308
- const { parent, children, existingChildren, workspace } = config;
309
- if (parent instanceof Window || (parent as IOConnectWorkspaces.WorkspaceWindow).type === "window") {
310
- return;
311
- }
312
-
313
- const newChildren = children.map((newChildSnapshot) => {
314
- let childToAdd = existingChildren.find((child) => {
315
- return child.type === "window" ? child.elementId === newChildSnapshot.id : child.id === newChildSnapshot.id;
316
- });
317
-
318
- if (childToAdd) {
319
- this.privateDataManager.remapChild(childToAdd, {
320
- parent: parent as AllParentTypes,
321
- children: [],
322
- config: newChildSnapshot.config
323
- });
324
- } else {
325
- let createConfig: WindowCreateConfig | ParentCreateConfig;
326
- if (newChildSnapshot.type === "window") {
327
- createConfig = {
328
- id: newChildSnapshot.id,
329
- parent: parent as AllParentTypes,
330
- frame: workspace.frame,
331
- workspace,
332
- config: newChildSnapshot.config,
333
- } as WindowCreateConfig;
334
- } else {
335
- createConfig = {
336
- id: newChildSnapshot.id,
337
- parent: parent as AllParentTypes,
338
- frame: workspace.frame,
339
- workspace,
340
- config: newChildSnapshot.config,
341
- children: []
342
- } as ParentCreateConfig;
343
- }
344
-
345
- childToAdd = this.ioc.getModel<"child">(newChildSnapshot.type, createConfig);
346
- }
347
-
348
- if (newChildSnapshot.type !== "window") {
349
- this.refreshChildren({
350
- workspace, existingChildren,
351
- children: newChildSnapshot.children,
352
- parent: childToAdd
353
- });
354
- }
355
-
356
- return childToAdd;
357
- });
358
-
359
- if (parent instanceof Workspace) {
360
- return newChildren;
361
- } else {
362
- this.privateDataManager.remapChild(parent as SubParentTypes, { children: newChildren });
363
- return newChildren;
364
- }
365
- }
366
-
367
- public iterateFindChild(children: Child[], predicate: (child: Child) => boolean): Child {
368
- let foundChild = children.find((child) => predicate(child));
369
-
370
- if (foundChild) {
371
- return foundChild;
372
- }
373
-
374
- children.some((child) => {
375
- if (child instanceof Window) {
376
- return false;
377
- }
378
-
379
- foundChild = this.iterateFindChild((child as SubParentTypes).children, predicate);
380
-
381
- if (foundChild) {
382
- return true;
383
- }
384
- });
385
-
386
- return foundChild;
387
- }
388
-
389
- public iterateFilterChildren(children: Child[], predicate: (child: Child) => boolean): Child[] {
390
- const foundChildren = children.filter((child) => predicate(child));
391
-
392
- const grandChildren = children.reduce<Child[]>((innerFound, child) => {
393
- if (child instanceof Window) {
394
- return innerFound;
395
- }
396
-
397
- innerFound.push(...this.iterateFilterChildren((child as SubParentTypes).children, predicate));
398
-
399
- return innerFound;
400
- }, []);
401
-
402
- foundChildren.push(...grandChildren);
403
-
404
- return foundChildren;
405
- }
406
-
407
- public notifyWindowAdded(windowId: string): Promise<void> {
408
- return new Promise((resolve) => {
409
-
410
- const alreadyPresent: boolean = this.windows.list().some((win) => win.id === windowId);
411
-
412
- if (alreadyPresent) {
413
- return resolve();
414
- }
415
-
416
- const unsubscribe: UnsubscribeFunction = this.windows.onWindowAdded((win) => {
417
-
418
- if (win.id !== windowId) {
419
- return;
420
- }
421
-
422
- if (unsubscribe) {
423
- unsubscribe();
424
- }
425
-
426
- resolve();
427
- });
428
- });
429
- }
430
-
431
- public async hibernateWorkspace(workspaceId: string): Promise<void> {
432
- await this.bridge.send<void>(OPERATIONS.hibernateWorkspace.name, { workspaceId });
433
- }
434
-
435
- public async resumeWorkspace(workspaceId: string): Promise<void> {
436
- await this.bridge.send<void>(OPERATIONS.resumeWorkspace.name, { workspaceId });
437
- }
438
-
439
- public async lockWorkspace(workspaceId: string, config?: IOConnectWorkspaces.WorkspaceLockConfig): Promise<void> {
440
- await this.bridge.send<void>(OPERATIONS.lockWorkspace.name, { workspaceId, config });
441
- }
442
-
443
- public async lockWindow(windowPlacementId: string, config?: IOConnectWorkspaces.WorkspaceWindowLockConfig): Promise<void> {
444
- await this.bridge.send<void>(OPERATIONS.lockWindow.name, { windowPlacementId, config });
445
- }
446
-
447
- public async lockContainer(itemId: string, type: SubParentTypes["type"], config?: ContainerLockConfig): Promise<void> {
448
- await this.bridge.send<void>(OPERATIONS.lockContainer.name, { itemId, type, config });
449
- }
450
-
451
- public async pinWorkspace(workspaceId: string, icon?: string): Promise<void> {
452
- await this.bridge.send<void>(OPERATIONS.pinWorkspace.name, { workspaceId, icon });
453
- }
454
-
455
- public async unpinWorkspace(workspaceId: string): Promise<void> {
456
- await this.bridge.send<void>(OPERATIONS.unpinWorkspace.name, { workspaceId });
457
- }
458
-
459
- public async getWorkspaceIcon(workspaceId: string): Promise<string> {
460
- const result = await this.bridge.send<{ icon: string }>(OPERATIONS.getWorkspaceIcon.name, { workspaceId });
461
- return result.icon;
462
- }
463
-
464
- public setWorkspaceIcon(workspaceId: string, icon: string): Promise<void> {
465
- return this.bridge.send<void>(OPERATIONS.setWorkspaceIcon.name, { workspaceId, icon });
466
- }
467
-
468
- public async getPlatformFrameId(): Promise<GetPlatformFrameIdResult> {
469
- try {
470
- const result = await this.bridge.send<GetPlatformFrameIdResult>(OPERATIONS.getPlatformFrameId.name, {});
471
-
472
- return result;
473
- } catch (error) {
474
- return {}
475
- }
476
- }
477
-
478
- public async isOperationSupported(operation: string): Promise<OperationCheckResult> {
479
- const desktopGlobal = (window as any).glue42gd || (window as any).iodesktop;
480
-
481
- if (desktopGlobal) {
482
- // operation check is not supported in Glue42Desktop
483
- return { isSupported: true };
484
- }
485
- return await this.bridge.send<OperationCheckResult>(OPERATIONS.operationCheck.name, { operation });
486
- }
487
- }