@interopio/browser-platform 3.0.1

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 (97) hide show
  1. package/browser.platform.d.ts +455 -0
  2. package/changelog.md +69 -0
  3. package/dist/browser.platform.es.js +46074 -0
  4. package/dist/browser.platform.es.js.map +1 -0
  5. package/dist/browser.platform.umd.js +46082 -0
  6. package/dist/browser.platform.umd.js.map +1 -0
  7. package/license.md +21 -0
  8. package/package.json +78 -0
  9. package/readme.md +9 -0
  10. package/rollup.config.js +45 -0
  11. package/src/common/constants.ts +46 -0
  12. package/src/common/defaultConfig.ts +56 -0
  13. package/src/common/gateway.d.ts +32 -0
  14. package/src/common/types.ts +222 -0
  15. package/src/connection/gateway.ts +132 -0
  16. package/src/connection/no-gateway.ts +1 -0
  17. package/src/connection/portsBridge.ts +441 -0
  18. package/src/connection/preferred.ts +247 -0
  19. package/src/controllers/domains.ts +156 -0
  20. package/src/controllers/glue.ts +604 -0
  21. package/src/controllers/interception.ts +53 -0
  22. package/src/controllers/license.ts +50 -0
  23. package/src/controllers/main.ts +256 -0
  24. package/src/controllers/plugins.ts +121 -0
  25. package/src/controllers/serviceWorker.ts +193 -0
  26. package/src/controllers/state.ts +84 -0
  27. package/src/controllers/system.ts +99 -0
  28. package/src/controllers/transactions.ts +80 -0
  29. package/src/factory.ts +40 -0
  30. package/src/fallbacks/browser.ts +47 -0
  31. package/src/fallbacks/dekstop.ts +21 -0
  32. package/src/index.ts +18 -0
  33. package/src/libs/applications/appStore/directory.ts +235 -0
  34. package/src/libs/applications/appStore/remoteWatcher.ts +112 -0
  35. package/src/libs/applications/controller.ts +469 -0
  36. package/src/libs/applications/decoders.ts +98 -0
  37. package/src/libs/applications/defaults.ts +6 -0
  38. package/src/libs/applications/types.ts +98 -0
  39. package/src/libs/channels/controller.ts +109 -0
  40. package/src/libs/channels/decoders.ts +19 -0
  41. package/src/libs/extension/controller.ts +120 -0
  42. package/src/libs/extension/decoders.ts +18 -0
  43. package/src/libs/extension/types.ts +11 -0
  44. package/src/libs/intents/constants.ts +9 -0
  45. package/src/libs/intents/controller.ts +500 -0
  46. package/src/libs/intents/decoders.ts +96 -0
  47. package/src/libs/intents/resolverHelper.ts +264 -0
  48. package/src/libs/intents/types.ts +119 -0
  49. package/src/libs/layouts/constants.ts +3 -0
  50. package/src/libs/layouts/controller.ts +476 -0
  51. package/src/libs/layouts/decoders.ts +132 -0
  52. package/src/libs/layouts/global/builder.ts +400 -0
  53. package/src/libs/layouts/global/resetter.ts +116 -0
  54. package/src/libs/layouts/global/restorer.ts +217 -0
  55. package/src/libs/layouts/global/validator.ts +169 -0
  56. package/src/libs/layouts/idbStore.ts +63 -0
  57. package/src/libs/layouts/types.ts +133 -0
  58. package/src/libs/manager/controller.ts +175 -0
  59. package/src/libs/manager/decoders.ts +6 -0
  60. package/src/libs/manager/defaults.ts +5 -0
  61. package/src/libs/manager/identity.ts +92 -0
  62. package/src/libs/manager/session.ts +195 -0
  63. package/src/libs/manager/types.ts +51 -0
  64. package/src/libs/notifications/controller.ts +447 -0
  65. package/src/libs/notifications/decoders.ts +166 -0
  66. package/src/libs/notifications/types.ts +49 -0
  67. package/src/libs/notifications/utils.ts +7 -0
  68. package/src/libs/search/controller.ts +232 -0
  69. package/src/libs/search/decoders.ts +6 -0
  70. package/src/libs/search/repositories/applications.ts +62 -0
  71. package/src/libs/search/repositories/layouts.ts +48 -0
  72. package/src/libs/search/repositories/workspaces.ts +47 -0
  73. package/src/libs/search/types.ts +9 -0
  74. package/src/libs/themes/constants.ts +9 -0
  75. package/src/libs/themes/controller.ts +153 -0
  76. package/src/libs/themes/decoders.ts +28 -0
  77. package/src/libs/themes/types.ts +28 -0
  78. package/src/libs/windows/controller.ts +498 -0
  79. package/src/libs/windows/decoders.ts +64 -0
  80. package/src/libs/windows/types.ts +59 -0
  81. package/src/libs/workspaces/controller.ts +922 -0
  82. package/src/libs/workspaces/decoders.ts +868 -0
  83. package/src/libs/workspaces/defaultConfig.ts +11 -0
  84. package/src/libs/workspaces/frames.ts +239 -0
  85. package/src/libs/workspaces/hibernationWatcher.ts +231 -0
  86. package/src/libs/workspaces/types.ts +506 -0
  87. package/src/platform.ts +156 -0
  88. package/src/shared/decoders.ts +479 -0
  89. package/src/shared/fetchTimeout.ts +25 -0
  90. package/src/shared/ioc.ts +580 -0
  91. package/src/shared/logger.ts +19 -0
  92. package/src/shared/promisePlus.ts +62 -0
  93. package/src/shared/sequelizer.ts +48 -0
  94. package/src/shared/utils.ts +86 -0
  95. package/src/storage/local.ts +111 -0
  96. package/src/storage/session.ts +436 -0
  97. package/tsconfig.json +16 -0
@@ -0,0 +1,217 @@
1
+ import { IOConnectCore } from "@interopio/core";
2
+ import { IOConnectWorkspaces } from "@interopio/workspaces-api";
3
+ import logger from "../../../shared/logger";
4
+ import { RestoreLayoutConfig, ScreenDetailed } from "../types";
5
+ import { GlueController } from "../../../controllers/glue";
6
+ import { LayoutValidator } from "./validator";
7
+ import { Resetter } from "./resetter";
8
+ import { IOConnectBrowser } from "@interopio/browser";
9
+ import { defaultNoAppWindowComponentAppName } from "../constants";
10
+ import { GlueWorkspaceFrameClientControlName } from "../../../common/constants";
11
+ import { WorkspacesController } from "../../workspaces/controller";
12
+
13
+ export class Restorer {
14
+
15
+ constructor(
16
+ private readonly glueController: GlueController,
17
+ private readonly validator: LayoutValidator,
18
+ private readonly resetter: Resetter,
19
+ private readonly workspacesController: WorkspacesController
20
+ ) {}
21
+
22
+ private get logger(): IOConnectCore.Logger.API | undefined {
23
+ return logger.get("layouts.restorer");
24
+ }
25
+
26
+ public async restoreGlobalLayout(config: RestoreLayoutConfig, commandId: string, callerId?: string, callerType?: "plugin" | "client"): Promise<void> {
27
+
28
+ const layout = await this.glueController.getLayout(config.layout.name);
29
+
30
+ if (!layout) {
31
+ throw new Error(`Cannot restore layout: ${config.layout.name}, because it was not found in this platform`);
32
+ }
33
+
34
+ if (layout.type !== "Global") {
35
+ throw new Error(`Cannot restore layout: ${config.layout.name}, because it is not a Global Layout`);
36
+ }
37
+
38
+ if (!callerId || !callerType) {
39
+ throw new Error(`Cannot restore layout: ${config.layout.name}, because the callerId or callerType are missing`);
40
+ }
41
+
42
+ await this.validator.doInitialValidation(layout, commandId);
43
+
44
+ this.logger?.trace(`[${commandId}] the initial validation of the compliancy of the layout was completed`);
45
+
46
+ await this.closeInstances(callerType, callerId, commandId, config.layout.closeMe, config.layout.closeRunningInstances);
47
+
48
+ this.logger?.trace(`[${commandId}] closed all necessary running instances`);
49
+
50
+ await this.restore(layout, config, commandId);
51
+
52
+ this.logger?.trace(`[${commandId}] the layout ${layout.name} was restored`);
53
+ }
54
+
55
+ private async closeInstances(callerType: "plugin" | "client", callerId: string, commandId: string, closeCaller?: boolean, closeAll?: boolean): Promise<void> {
56
+
57
+ if (typeof closeAll === "undefined" || closeAll) {
58
+ await this.resetter.closeAllExceptCaller(callerId, commandId);
59
+ }
60
+
61
+ const shouldCloseCaller = closeCaller ||
62
+ (typeof closeCaller === "undefined" && typeof closeAll === "undefined") ||
63
+ (typeof closeCaller === "undefined" && closeAll);
64
+
65
+ if (shouldCloseCaller) {
66
+ await this.resetter.closeCaller(callerType, callerId, commandId);
67
+ }
68
+
69
+ }
70
+
71
+ private async restore(layout: IOConnectBrowser.Layouts.Layout, config: RestoreLayoutConfig, commandId: string): Promise<void> {
72
+ this.logger?.trace(`[${commandId}] starting the restore process of ${layout.name}`);
73
+
74
+ const iCanAcceptFrameComponent = await this.canPlatformFrameAcceptComponent(commandId);
75
+
76
+ const componentForPlatformFrame = iCanAcceptFrameComponent ?
77
+ this.pickComponentForPlatformFrame(layout.components.filter((component) => component.type === "workspaceFrame") as IOConnectBrowser.Layouts.WorkspaceFrameComponent[]) :
78
+ null;
79
+
80
+ const restorePromise = Promise.all(layout.components.map((component) => {
81
+
82
+ if (component.type === "window") {
83
+ return this.restoreWindowComponent(component, commandId, layout.context, config.layout.context);
84
+ }
85
+
86
+ if (component.type === "workspaceFrame") {
87
+ const placeInPlatform = componentForPlatformFrame === component;
88
+ return this.restoreWorkspaceFrameComponent(component, commandId, layout.context, config.layout.context, placeInPlatform);
89
+ }
90
+ }));
91
+
92
+ await restorePromise;
93
+ }
94
+
95
+ private async restoreWindowComponent(component: IOConnectBrowser.Layouts.WindowComponent, commandId: string, layoutContext?: any, restoreContext?: any): Promise<void> {
96
+ this.logger?.trace(`[${commandId}] restoring window component ${component.application} with id ${component.state.instanceId} and bounds: ${JSON.stringify(component.state.bounds)}`);
97
+
98
+ const windowContext = Object.assign({}, layoutContext, component.state.context, component.state.createArgs.context, restoreContext);
99
+
100
+ const targetBounds = component.state.bounds;
101
+
102
+ const boundsCheck = await this.checkTargetBoundsPossible(targetBounds);
103
+
104
+ if (!boundsCheck.isPossible) {
105
+ this.logger?.warn(`Restoring ${component.application} not possible with the saved bounds, falling back to default bounds`);
106
+ }
107
+
108
+ const boundsToUse = boundsCheck.isPossible ? targetBounds : undefined;
109
+
110
+ this.logger?.trace(`[${commandId}] calling the respective glue open/start method`);
111
+ // this assertion is safe, because of a prior validation
112
+ const startPromise = component.application === defaultNoAppWindowComponentAppName ?
113
+ this.glueController.openWindow({ name: (component.state.createArgs as { name: string }).name, url: (component.state.createArgs as { url: string }).url, layoutComponentId: component.state.instanceId, context: windowContext, bounds: boundsToUse }) :
114
+ this.glueController.startApp({ name: component.application, layoutComponentId: component.state.instanceId, context: windowContext, bounds: boundsToUse });
115
+
116
+ this.logger?.trace(`[${commandId}] the component was started`);
117
+ await startPromise;
118
+ }
119
+
120
+ private async restoreWorkspaceFrameComponent(component: IOConnectBrowser.Layouts.WorkspaceFrameComponent, commandId: string, layoutContext?: any, restoreContext?: any, placeInPlatform?: boolean): Promise<void> {
121
+ this.logger?.trace(`[${commandId}] restoring workspace frame component $with id ${component.state.instanceId} and bounds: ${JSON.stringify(component.state.bounds)}`);
122
+
123
+ const myFrameId = placeInPlatform ? (await this.getPlatformFrame(commandId))?.id : undefined;
124
+
125
+ const readyFrame = await this.createFrameWithWorkspaceComponents(component, myFrameId);
126
+
127
+ this.logger?.trace(`[${commandId}] the frame was restored, selecting the correct workspace`);
128
+
129
+ const frameWorkspaces = await readyFrame.workspaces();
130
+
131
+ await frameWorkspaces[component.state.selectedWorkspace]?.focus();
132
+
133
+ this.logger?.trace(`[${commandId}] the correct workspace was selected, restoring the workspaces context`);
134
+
135
+ const componentContext = Object.assign({}, layoutContext, restoreContext);
136
+
137
+ await Promise.all(frameWorkspaces.map((workspace) => workspace.updateContext(componentContext)));
138
+
139
+ this.logger?.trace(`[${commandId}] the frame component ${component.state.instanceId} is restored`);
140
+ }
141
+
142
+ private async canPlatformFrameAcceptComponent(commandId: string): Promise<boolean> {
143
+ // use myFrame if
144
+ // 1. myFrameId && I am empty && EVERY !component.state.context.isPlatform => for the 0 idx component
145
+ // 2. myFrameId && I am empty && component.state.context.isPlatform => for the 0 idx component
146
+ const myFrame = await this.getPlatformFrame(commandId);
147
+
148
+ if (!myFrame) {
149
+ return false;
150
+ }
151
+
152
+ const workspaces = await myFrame.workspaces();
153
+
154
+ return workspaces.length === 1 && workspaces[0].getAllWindows().length === 0;
155
+ }
156
+
157
+ private pickComponentForPlatformFrame(components: IOConnectBrowser.Layouts.WorkspaceFrameComponent[]): IOConnectBrowser.Layouts.WorkspaceFrameComponent | undefined {
158
+ if (components.length === 0) {
159
+ return;
160
+ }
161
+
162
+ const firstPlatformComponent = components.find((component) => component.state.context?.isPlatform);
163
+
164
+ return firstPlatformComponent || components[0];
165
+ }
166
+
167
+ private async checkTargetBoundsPossible(bounds: IOConnectBrowser.Windows.Bounds): Promise<{ isPossible: boolean }> {
168
+ if ((window as any).gtf) {
169
+ return { isPossible: true };
170
+ }
171
+
172
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
173
+ const totalScreenDetails = await (window as any).getScreenDetails();
174
+
175
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
176
+ const targetScreen: ScreenDetailed = totalScreenDetails.screens.find((screen: ScreenDetailed) => {
177
+ const leftFit = bounds.left >= screen.left && bounds.left <= screen.left + screen.width;
178
+
179
+ const topFit = bounds.top >= screen.top && bounds.top <= screen.top + screen.height;
180
+
181
+ return leftFit && topFit;
182
+ });
183
+
184
+ if (!targetScreen) {
185
+ return { isPossible: false };
186
+ }
187
+
188
+ return { isPossible: true };
189
+ }
190
+
191
+ private async getPlatformFrame(commandId: string): Promise<IOConnectWorkspaces.Frame | undefined> {
192
+ if (!this.glueController.isWorkspacesEnabled) {
193
+ return;
194
+ }
195
+
196
+ const workspaceControllerStarted = await this.workspacesController.handleCheckStarted(undefined, commandId);
197
+
198
+ if (!workspaceControllerStarted) {
199
+ return;
200
+ }
201
+
202
+ const platformFrameId = (await this.workspacesController.handleGetPlatformFrameId({}, commandId)).id;
203
+
204
+ if (platformFrameId) {
205
+ return this.glueController.getOrCreateWorkspaceFrame({ frameId: platformFrameId });
206
+ }
207
+ }
208
+
209
+ private async createFrameWithWorkspaceComponents(component: IOConnectBrowser.Layouts.WorkspaceFrameComponent, frameId?: string): Promise<IOConnectWorkspaces.Frame> {
210
+
211
+ const targetFrame = await this.glueController.getOrCreateWorkspaceFrame({ frameId, bounds: component.state.bounds, layoutComponentId: component.state.instanceId });
212
+
213
+ await this.glueController.invokeMethod(GlueWorkspaceFrameClientControlName, { operation: "initFrameFromSnapshot", operationArguments: { workspaces: component.state.workspaces, keepWorkspaces: [] } }, { windowId: targetFrame.id });
214
+
215
+ return targetFrame;
216
+ }
217
+ }
@@ -0,0 +1,169 @@
1
+ import { IOConnectBrowser } from "@interopio/browser";
2
+ import { IOConnectWorkspaces } from "@interopio/workspaces-api";
3
+ import { defaultNoAppWindowComponentAppName } from "../constants";
4
+ import { GlueController } from "../../../controllers/glue";
5
+ import { WorkspacesController } from "../../workspaces/controller";
6
+ import { WorkspaceSnapshotChildItem } from "../types";
7
+
8
+ export class LayoutValidator {
9
+
10
+ constructor(
11
+ private readonly glueController: GlueController,
12
+ private readonly workspacesController: WorkspacesController
13
+ ) {}
14
+
15
+ public async doInitialValidation(layout: IOConnectBrowser.Layouts.Layout, commandId: string): Promise<void> {
16
+ this.validateRequiredApplicationsExistence(layout);
17
+
18
+ await this.validateWorkspaceConfigurationInPlatform(layout, commandId);
19
+
20
+ this.validateNoAppNameAndUrl(layout);
21
+ }
22
+
23
+ public async doFinalValidation(layout: IOConnectBrowser.Layouts.Layout): Promise<void> {
24
+ this.validateWindowNamesCollision(layout);
25
+
26
+ this.validateInstanceIdCollision(layout);
27
+
28
+ await this.validateWorkspaceFramesIdCollisions(layout);
29
+ }
30
+
31
+ private validateWindowNamesCollision(layout: IOConnectBrowser.Layouts.Layout): void {
32
+ const requestedWindowNames = layout.components
33
+ .filter((component): component is IOConnectBrowser.Layouts.WindowComponent => component.type === "window" && component.application === defaultNoAppWindowComponentAppName && !!component.state.createArgs.name)
34
+ .map((component) => component.state.createArgs.name);
35
+
36
+ const allOpenedWindowNames = this.glueController.getAllWindowNames();
37
+
38
+ const nameCollisions = requestedWindowNames.filter((name) => allOpenedWindowNames.some((existingName) => name === existingName));
39
+
40
+ if (!nameCollisions.length) {
41
+ return;
42
+ }
43
+
44
+ throw new Error(`Cannot restore layout: ${layout.name}, because there are window names collisions: ${nameCollisions.join(", ")}`);
45
+ }
46
+
47
+ private validateInstanceIdCollision(layout: IOConnectBrowser.Layouts.Layout): void {
48
+ const requestedInstanceIds = layout.components
49
+ .filter((component): component is IOConnectBrowser.Layouts.WindowComponent => component.type === "window" && !!component.state.instanceId)
50
+ .map((component) => component.state.instanceId);
51
+
52
+ const allOpenedInstanceIds = this.glueController.getAllOpenedIds();
53
+
54
+ const idCollisions = requestedInstanceIds.filter((id) => allOpenedInstanceIds.some((existingInstanceId) => id === existingInstanceId));
55
+
56
+ if (!idCollisions.length) {
57
+ return;
58
+ }
59
+
60
+ throw new Error(`Cannot restore layout: ${layout.name}, because there are instances ids collisions: ${idCollisions.join(", ")}`);
61
+ }
62
+
63
+ private async validateWorkspaceFramesIdCollisions(layout: IOConnectBrowser.Layouts.Layout): Promise<void> {
64
+ if (layout.components.every((component) => component.type !== "workspaceFrame")) {
65
+ return;
66
+ }
67
+
68
+ const allOpenedFrameIds = await this.glueController.getAllOpenedFrameIds();
69
+
70
+ const requestedFrameIds = layout.components
71
+ .filter((component): component is IOConnectBrowser.Layouts.WorkspaceFrameComponent => component.type === "workspaceFrame")
72
+ .map((component) => component.state.instanceId);
73
+
74
+ const idCollisions = requestedFrameIds.filter((id) => allOpenedFrameIds.some((existingInstanceId) => id === existingInstanceId));
75
+
76
+ if (!idCollisions.length) {
77
+ return;
78
+ }
79
+
80
+ throw new Error(`Cannot restore layout: ${layout.name}, because there are frame ids collisions: ${idCollisions.join(", ")}`);
81
+ }
82
+
83
+ private validateNoAppNameAndUrl(layout: IOConnectBrowser.Layouts.Layout): void {
84
+ const corruptedWindowComponents = layout.components
85
+ .filter((component) => component.type === "window" && component.application === defaultNoAppWindowComponentAppName)
86
+ .filter<IOConnectBrowser.Layouts.WindowComponent>((noAppComponent): noAppComponent is IOConnectBrowser.Layouts.WindowComponent => noAppComponent.type === "window" && (!noAppComponent.state.createArgs.name || !noAppComponent.state.createArgs.url));
87
+
88
+ if (!corruptedWindowComponents.length) {
89
+ return;
90
+ }
91
+
92
+ const printableCorruptedComponents = corruptedWindowComponents.map((component) => JSON.stringify(component.state.createArgs)).join(", ");
93
+
94
+ throw new Error(`Cannot restore layout: ${layout.name}, because it has window components, which are not defined applications and are missing name or url, provided insufficient createArgs are: ${printableCorruptedComponents}`);
95
+ }
96
+
97
+ private validateRequiredApplicationsExistence(layout: IOConnectBrowser.Layouts.Layout): void {
98
+
99
+ const allAvailableAppNames = this.glueController.getAllApplicationNames();
100
+
101
+ const requiredAppsNames = layout.components
102
+ .filter((component) => component.type === "window" && component.application !== defaultNoAppWindowComponentAppName)
103
+ .map((windowComponent) => (windowComponent as IOConnectBrowser.Layouts.WindowComponent).application);
104
+
105
+ requiredAppsNames.push(...this.getRequiredAppNamesFromWorkspaceFrameComponents(layout));
106
+
107
+ if (!requiredAppsNames.length) {
108
+ return;
109
+ }
110
+
111
+ const missingAppNames = requiredAppsNames.filter((appName) => allAvailableAppNames.every((availableApp) => availableApp !== appName));
112
+
113
+ if (!missingAppNames.length) {
114
+ return;
115
+ }
116
+
117
+ throw new Error(`Cannot restore layout: ${layout.name}, because some required applications are not registered with this platform: ${missingAppNames.join(", ")}`);
118
+ }
119
+
120
+ private async validateWorkspaceConfigurationInPlatform(layout: IOConnectBrowser.Layouts.Layout, commandId: string): Promise<void> {
121
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
+ if (layout.components.every((component) => component.type !== "Workspace" || (component as any).type !== "workspaceFrame")) {
123
+ return;
124
+ }
125
+
126
+ const workspaceControllerStarted = (await this.workspacesController.handleCheckStarted({}, commandId))?.started;
127
+
128
+ if (!workspaceControllerStarted) {
129
+ throw new Error(`Cannot restore layout: ${layout.name}, because this platform does not have a valid Workspaces configuration`);
130
+ }
131
+ }
132
+
133
+ private getRequiredAppNamesFromWorkspaceFrameComponents(layout: IOConnectBrowser.Layouts.Layout): string[] {
134
+
135
+ const requiredApps: string[] = [];
136
+
137
+ for (const component of layout.components) {
138
+ if (component.type === "workspaceFrame") {
139
+
140
+ const workspaceAppNames = component.state.workspaces.reduce<string[]>((soFar, wsp) => {
141
+ soFar.push(...this.getAllAppNamesFromChildren(wsp.children));
142
+
143
+ return soFar;
144
+ }, []);
145
+
146
+ requiredApps.push(...workspaceAppNames);
147
+ }
148
+ }
149
+
150
+ return requiredApps;
151
+ }
152
+
153
+ private getAllAppNamesFromChildren(children: WorkspaceSnapshotChildItem[]): string[] {
154
+ const requiredAppNames = children
155
+ .filter((child): child is IOConnectWorkspaces.WindowLayoutItem => child.type === "window" && !!child.config.appName && child.config.appName !== defaultNoAppWindowComponentAppName)
156
+ .map((windowChild) => windowChild.config.appName);
157
+
158
+ for (const child of children) {
159
+ if (child.type === "window") {
160
+ continue;
161
+ }
162
+
163
+ requiredAppNames.push(...this.getAllAppNamesFromChildren(child.children));
164
+
165
+ }
166
+
167
+ return requiredAppNames;
168
+ }
169
+ }
@@ -0,0 +1,63 @@
1
+ /* eslint-disable indent */
2
+ import { IDBPDatabase } from "idb";
3
+ import { IOConnectBrowser } from "@interopio/browser";
4
+ import { IoC } from "../../shared/ioc";
5
+ import { Glue42CoreDB } from "../../common/types";
6
+ import { glueLayoutDecoder, layoutTypeDecoder } from "../../shared/decoders";
7
+
8
+ export class IdbLayoutsStore {
9
+
10
+ constructor(private readonly ioc: IoC) {
11
+ if (!("indexedDB" in window)) {
12
+ throw new Error("Cannot initialize the local storage, because IndexedDb is not supported");
13
+ }
14
+ }
15
+
16
+ private get database(): Promise<IDBPDatabase<Glue42CoreDB>> {
17
+ return this.ioc.getDatabase();
18
+ }
19
+
20
+ public async getAll(layoutType: IOConnectBrowser.Layouts.LayoutType): Promise<IOConnectBrowser.Layouts.Layout[]> {
21
+ switch (layoutType) {
22
+ case "Workspace": return (await this.database).getAll("workspaceLayouts" as never);
23
+ case "Global": return (await this.database).getAll("globalLayouts" as never);
24
+ default: throw new Error(`The provided layout type is not recognized: ${layoutType}`);
25
+ }
26
+ }
27
+
28
+ public async delete(name: string, layoutType: IOConnectBrowser.Layouts.LayoutType): Promise<void> {
29
+ switch (layoutType) {
30
+ case "Workspace": return (await this.database).delete("workspaceLayouts" as never, name);
31
+ case "Global": return (await this.database).delete("globalLayouts" as never, name);
32
+ default: throw new Error(`The provided layout type is not recognized: ${layoutType}`);
33
+ }
34
+ }
35
+
36
+ public async clear(layoutType: IOConnectBrowser.Layouts.LayoutType): Promise<void> {
37
+ switch (layoutType) {
38
+ case "Workspace": return (await this.database).clear("workspaceLayouts" as never);
39
+ case "Global": return (await this.database).clear("globalLayouts" as never);
40
+ default: throw new Error(`The provided layout type is not recognized: ${layoutType}`);
41
+ }
42
+ }
43
+
44
+ public async get(name: string, layoutType: IOConnectBrowser.Layouts.LayoutType): Promise<IOConnectBrowser.Layouts.Layout | undefined> {
45
+ switch (layoutType) {
46
+ case "Workspace": return (await this.database).get("workspaceLayouts" as never, name);
47
+ case "Global": return (await this.database).get("globalLayouts" as never, name);
48
+ default: throw new Error(`The provided layout type is not recognized: ${layoutType}`);
49
+ }
50
+ }
51
+
52
+ public async store(layout: IOConnectBrowser.Layouts.Layout, layoutType: IOConnectBrowser.Layouts.LayoutType): Promise<IDBValidKey> {
53
+ glueLayoutDecoder.runWithException(layout);
54
+ layoutTypeDecoder.runWithException(layoutType);
55
+
56
+ switch (layoutType) {
57
+ case "Workspace": return (await this.database).put("workspaceLayouts" as never, layout, layout.name);
58
+ case "Global": return (await this.database).put("globalLayouts" as never, layout, layout.name);
59
+ default: throw new Error(`The provided layout type is not recognized: ${layoutType}`);
60
+ }
61
+ }
62
+
63
+ }
@@ -0,0 +1,133 @@
1
+ import { IOConnectBrowser } from "@interopio/browser";
2
+ import { IOConnectWorkspaces } from "@interopio/workspaces-api";
3
+ import { UnsubscribeFunction } from "callback-registry";
4
+ import { InternalLayoutsConfig } from "../../common/types";
5
+
6
+ export type LayoutEvent = "layoutAdded" | "layoutChanged" | "layoutRemoved";
7
+
8
+ export type LayoutsOperationTypes = "get" | "getAll" | "export" | "import" | "remove" | "save" | "restore" |
9
+ "getGlobalPermissionState" | "requestGlobalPermission" | "checkGlobalActivated" | "operationCheck" | "getDefaultGlobal" | "setDefaultGlobal" | "clearDefaultGlobal";
10
+
11
+ export type WorkspaceSnapshotChildItem = IOConnectWorkspaces.WindowLayoutItem | IOConnectWorkspaces.RowLayoutItem | IOConnectWorkspaces.ColumnLayoutItem | IOConnectWorkspaces.GroupLayoutItem;
12
+
13
+ export interface LayoutModeExecutor {
14
+ setup(config: InternalLayoutsConfig): Promise<void>;
15
+ onLayoutEvent(callback: (payload: { operation: LayoutEvent; data: IOConnectBrowser.Layouts.Layout }) => void): UnsubscribeFunction;
16
+ getAll(type: IOConnectBrowser.Layouts.LayoutType): Promise<IOConnectBrowser.Layouts.Layout[]>;
17
+ save(layouts: IOConnectBrowser.Layouts.Layout[]): Promise<void>;
18
+ delete(name: string, type: IOConnectBrowser.Layouts.LayoutType): Promise<boolean>;
19
+ }
20
+
21
+ export interface SimpleLayoutConfig {
22
+ name: string;
23
+ type: IOConnectBrowser.Layouts.LayoutType;
24
+ }
25
+
26
+ export interface GetAllLayoutsConfig {
27
+ type: IOConnectBrowser.Layouts.LayoutType;
28
+ }
29
+
30
+ export interface AllLayoutsFullConfig {
31
+ layouts: IOConnectBrowser.Layouts.Layout[];
32
+ }
33
+
34
+ export interface LayoutsImportConfig {
35
+ layouts: IOConnectBrowser.Layouts.Layout[];
36
+ mode: "replace" | "merge";
37
+ isManagerOperation?: boolean;
38
+ }
39
+
40
+ export interface AllLayoutsSummariesResult {
41
+ summaries: IOConnectBrowser.Layouts.LayoutSummary[];
42
+ }
43
+
44
+ export interface SimpleLayoutResult {
45
+ layout: IOConnectBrowser.Layouts.Layout;
46
+ }
47
+
48
+ export interface OptionalSimpleLayoutResult {
49
+ layout?: IOConnectBrowser.Layouts.Layout;
50
+ }
51
+
52
+ export interface LayoutsSnapshot {
53
+ layouts: IOConnectBrowser.Layouts.Layout[];
54
+ }
55
+
56
+ export interface SaveLayoutConfig {
57
+ layout: IOConnectBrowser.Layouts.NewLayoutOptions
58
+ }
59
+
60
+ export interface RestoreLayoutConfig {
61
+ layout: IOConnectBrowser.Layouts.RestoreOptions
62
+ }
63
+
64
+ export interface DefaultGlobalLayoutData {
65
+ name: string;
66
+ }
67
+
68
+ export interface RawWindowsLayoutDataRequestConfig {
69
+ layoutType: "Global" | "Workspace";
70
+ layoutName: string;
71
+ context?: any;
72
+ instances?: string[];
73
+ ignoreInstances?: string[];
74
+ }
75
+
76
+ export interface SaveRequestClientResponse {
77
+ windowContext?: any;
78
+ }
79
+
80
+ export interface WindowRawLayoutData extends SaveRequestClientResponse {
81
+ bounds: IOConnectBrowser.Windows.Bounds;
82
+ url: string;
83
+ name: string;
84
+ application: string;
85
+ windowId: string;
86
+ initialContext?: any;
87
+ layoutComponentId?: string;
88
+ }
89
+
90
+ export interface WorkspaceWindowRawLayoutData extends SaveRequestClientResponse {
91
+ windowId: string;
92
+ frameId: string;
93
+ }
94
+
95
+ export interface WindowsRawLayoutData {
96
+ windows: WindowRawLayoutData[];
97
+ }
98
+
99
+ export interface PermissionStateResult {
100
+ state: "prompt" | "granted" | "denied";
101
+ }
102
+
103
+ export interface SimpleAvailabilityResult {
104
+ isAvailable: boolean;
105
+ }
106
+
107
+ export interface BaseSaveRequest {
108
+ layoutType: "Global" | "Workspace";
109
+ layoutName: string;
110
+ context?: any;
111
+ }
112
+
113
+ export interface FrameCompleteSnapshot {
114
+ snapshot: IOConnectWorkspaces.FrameSnapshot,
115
+ bounds: IOConnectWorkspaces.FrameBounds,
116
+ config: {
117
+ isPlatform?: boolean;
118
+ layoutComponentId?: string;
119
+ }
120
+ }
121
+
122
+ export interface ScreenDetailed {
123
+ availHeight: number;
124
+ availLeft: number;
125
+ availTop: number;
126
+ availWidth: number;
127
+ height: number;
128
+ left: number;
129
+ top: number;
130
+ width: number;
131
+ isPrimary: boolean;
132
+ isInternal: boolean;
133
+ }