@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.
- package/browser.platform.d.ts +455 -0
- package/changelog.md +69 -0
- package/dist/browser.platform.es.js +46074 -0
- package/dist/browser.platform.es.js.map +1 -0
- package/dist/browser.platform.umd.js +46082 -0
- package/dist/browser.platform.umd.js.map +1 -0
- package/license.md +21 -0
- package/package.json +78 -0
- package/readme.md +9 -0
- package/rollup.config.js +45 -0
- package/src/common/constants.ts +46 -0
- package/src/common/defaultConfig.ts +56 -0
- package/src/common/gateway.d.ts +32 -0
- package/src/common/types.ts +222 -0
- package/src/connection/gateway.ts +132 -0
- package/src/connection/no-gateway.ts +1 -0
- package/src/connection/portsBridge.ts +441 -0
- package/src/connection/preferred.ts +247 -0
- package/src/controllers/domains.ts +156 -0
- package/src/controllers/glue.ts +604 -0
- package/src/controllers/interception.ts +53 -0
- package/src/controllers/license.ts +50 -0
- package/src/controllers/main.ts +256 -0
- package/src/controllers/plugins.ts +121 -0
- package/src/controllers/serviceWorker.ts +193 -0
- package/src/controllers/state.ts +84 -0
- package/src/controllers/system.ts +99 -0
- package/src/controllers/transactions.ts +80 -0
- package/src/factory.ts +40 -0
- package/src/fallbacks/browser.ts +47 -0
- package/src/fallbacks/dekstop.ts +21 -0
- package/src/index.ts +18 -0
- package/src/libs/applications/appStore/directory.ts +235 -0
- package/src/libs/applications/appStore/remoteWatcher.ts +112 -0
- package/src/libs/applications/controller.ts +469 -0
- package/src/libs/applications/decoders.ts +98 -0
- package/src/libs/applications/defaults.ts +6 -0
- package/src/libs/applications/types.ts +98 -0
- package/src/libs/channels/controller.ts +109 -0
- package/src/libs/channels/decoders.ts +19 -0
- package/src/libs/extension/controller.ts +120 -0
- package/src/libs/extension/decoders.ts +18 -0
- package/src/libs/extension/types.ts +11 -0
- package/src/libs/intents/constants.ts +9 -0
- package/src/libs/intents/controller.ts +500 -0
- package/src/libs/intents/decoders.ts +96 -0
- package/src/libs/intents/resolverHelper.ts +264 -0
- package/src/libs/intents/types.ts +119 -0
- package/src/libs/layouts/constants.ts +3 -0
- package/src/libs/layouts/controller.ts +476 -0
- package/src/libs/layouts/decoders.ts +132 -0
- package/src/libs/layouts/global/builder.ts +400 -0
- package/src/libs/layouts/global/resetter.ts +116 -0
- package/src/libs/layouts/global/restorer.ts +217 -0
- package/src/libs/layouts/global/validator.ts +169 -0
- package/src/libs/layouts/idbStore.ts +63 -0
- package/src/libs/layouts/types.ts +133 -0
- package/src/libs/manager/controller.ts +175 -0
- package/src/libs/manager/decoders.ts +6 -0
- package/src/libs/manager/defaults.ts +5 -0
- package/src/libs/manager/identity.ts +92 -0
- package/src/libs/manager/session.ts +195 -0
- package/src/libs/manager/types.ts +51 -0
- package/src/libs/notifications/controller.ts +447 -0
- package/src/libs/notifications/decoders.ts +166 -0
- package/src/libs/notifications/types.ts +49 -0
- package/src/libs/notifications/utils.ts +7 -0
- package/src/libs/search/controller.ts +232 -0
- package/src/libs/search/decoders.ts +6 -0
- package/src/libs/search/repositories/applications.ts +62 -0
- package/src/libs/search/repositories/layouts.ts +48 -0
- package/src/libs/search/repositories/workspaces.ts +47 -0
- package/src/libs/search/types.ts +9 -0
- package/src/libs/themes/constants.ts +9 -0
- package/src/libs/themes/controller.ts +153 -0
- package/src/libs/themes/decoders.ts +28 -0
- package/src/libs/themes/types.ts +28 -0
- package/src/libs/windows/controller.ts +498 -0
- package/src/libs/windows/decoders.ts +64 -0
- package/src/libs/windows/types.ts +59 -0
- package/src/libs/workspaces/controller.ts +922 -0
- package/src/libs/workspaces/decoders.ts +868 -0
- package/src/libs/workspaces/defaultConfig.ts +11 -0
- package/src/libs/workspaces/frames.ts +239 -0
- package/src/libs/workspaces/hibernationWatcher.ts +231 -0
- package/src/libs/workspaces/types.ts +506 -0
- package/src/platform.ts +156 -0
- package/src/shared/decoders.ts +479 -0
- package/src/shared/fetchTimeout.ts +25 -0
- package/src/shared/ioc.ts +580 -0
- package/src/shared/logger.ts +19 -0
- package/src/shared/promisePlus.ts +62 -0
- package/src/shared/sequelizer.ts +48 -0
- package/src/shared/utils.ts +86 -0
- package/src/storage/local.ts +111 -0
- package/src/storage/session.ts +436 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
3
|
+
import deepEqual from "deep-equal";
|
|
4
|
+
import equal from "fast-deep-equal";
|
|
5
|
+
|
|
6
|
+
export const getRelativeBounds = (rect: IOConnectBrowser.Windows.Bounds, relativeTo: IOConnectBrowser.Windows.Bounds, relativeDirection: IOConnectBrowser.Windows.RelativeDirection): IOConnectBrowser.Windows.Bounds => {
|
|
7
|
+
const edgeDistance = 0;
|
|
8
|
+
|
|
9
|
+
if (relativeDirection === "bottom") {
|
|
10
|
+
return {
|
|
11
|
+
left: relativeTo.left,
|
|
12
|
+
top: relativeTo.top + relativeTo.height + edgeDistance,
|
|
13
|
+
width: relativeTo.width,
|
|
14
|
+
height: rect.height
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (relativeDirection === "top") {
|
|
19
|
+
return {
|
|
20
|
+
left: relativeTo.left,
|
|
21
|
+
top: relativeTo.top - rect.height - edgeDistance,
|
|
22
|
+
width: relativeTo.width,
|
|
23
|
+
height: rect.height
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (relativeDirection === "right") {
|
|
28
|
+
return {
|
|
29
|
+
left: relativeTo.left + relativeTo.width + edgeDistance,
|
|
30
|
+
top: relativeTo.top,
|
|
31
|
+
width: rect.width,
|
|
32
|
+
height: relativeTo.height
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (relativeDirection === "left") {
|
|
37
|
+
return {
|
|
38
|
+
left: relativeTo.left - rect.width - edgeDistance,
|
|
39
|
+
top: relativeTo.top,
|
|
40
|
+
width: rect.width,
|
|
41
|
+
height: relativeTo.height
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
throw new Error("invalid relativeDirection");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const objEqual = (objOne: object, objTwo: object): boolean => deepEqual(objOne, objTwo, { strict: true });
|
|
49
|
+
export const objEqualFast = (objOne: object, objTwo: object): boolean => equal(objOne, objTwo);
|
|
50
|
+
|
|
51
|
+
export const waitFor = (invocations: number, callback: () => any): () => void => {
|
|
52
|
+
let left = invocations;
|
|
53
|
+
return (): void => {
|
|
54
|
+
left--;
|
|
55
|
+
|
|
56
|
+
if (left === 0) {
|
|
57
|
+
callback();
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const wait = (ms: number): Promise<void> => new Promise<void>((resolve) => setTimeout(() => resolve(), ms));
|
|
63
|
+
|
|
64
|
+
export const extractErrorMsg = (error: any): string => {
|
|
65
|
+
const stringError = typeof error === "string" ?
|
|
66
|
+
error :
|
|
67
|
+
error.message ? JSON.stringify(error.message) :
|
|
68
|
+
JSON.stringify(error);
|
|
69
|
+
|
|
70
|
+
return stringError;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const checkMatch = (allowedResultsTracker: { count: number }, predicate: () => boolean): boolean => {
|
|
74
|
+
|
|
75
|
+
if (!allowedResultsTracker.count) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const isMatch = predicate();
|
|
80
|
+
|
|
81
|
+
if (isMatch) {
|
|
82
|
+
allowedResultsTracker.count = --allowedResultsTracker.count < 0 ? 0 : allowedResultsTracker.count;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return isMatch;
|
|
86
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { IOConnectBrowserPlatform } from "../../browser.platform";
|
|
2
|
+
import { DefaultGlobalLayoutData } from "../libs/layouts/types";
|
|
3
|
+
import { ThemesStoreData } from "../libs/themes/types";
|
|
4
|
+
|
|
5
|
+
export class LocalStoreController {
|
|
6
|
+
private readonly localStorage: Storage;
|
|
7
|
+
private readonly defaultGlobalLayoutNamespace = "g42_core_plus_default_global_layout";
|
|
8
|
+
private readonly themesNamespace = "g42_core_plus_themes";
|
|
9
|
+
private username = "g42_public";
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
this.localStorage = window.localStorage;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public start(user?: IOConnectBrowserPlatform.User.Config): void {
|
|
16
|
+
if (user?.username) {
|
|
17
|
+
this.username = user.username;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const userData = this.localStorage.getItem(this.username);
|
|
21
|
+
|
|
22
|
+
if (!userData) {
|
|
23
|
+
const initialValue = {
|
|
24
|
+
[this.defaultGlobalLayoutNamespace]: {},
|
|
25
|
+
[this.themesNamespace]: []
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
this.localStorage.setItem(this.username, JSON.stringify(initialValue));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public stop(): void {
|
|
33
|
+
this.username = "g42_public";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public saveThemeIfMissing(themeData: ThemesStoreData): void {
|
|
37
|
+
const allData: ThemesStoreData[] = this.getData<ThemesStoreData[]>(this.themesNamespace) || [];
|
|
38
|
+
|
|
39
|
+
if (allData.some((data) => data.theme.name === themeData.theme.name)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
allData.push(themeData);
|
|
44
|
+
|
|
45
|
+
this.saveData<ThemesStoreData[]>(this.themesNamespace, allData);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public getAllThemes(): ThemesStoreData[] {
|
|
49
|
+
const allData: ThemesStoreData[] = this.getData<ThemesStoreData[]>(this.themesNamespace) || [];
|
|
50
|
+
|
|
51
|
+
return allData;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public markThemeSelected(name: string, isUserSelected?: boolean): void {
|
|
55
|
+
const allData: ThemesStoreData[] = this.getData<ThemesStoreData[]>(this.themesNamespace) || [];
|
|
56
|
+
|
|
57
|
+
const foundTheme = allData.find((data) => data.theme.name === name);
|
|
58
|
+
|
|
59
|
+
if (!foundTheme) {
|
|
60
|
+
throw new Error(`Cannot mark theme: ${name} as selected, because it doesn't exist`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
allData.forEach((data) => {
|
|
64
|
+
data.selected = false;
|
|
65
|
+
data.isUserSelected = false;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
foundTheme.selected = true;
|
|
69
|
+
foundTheme.isUserSelected = !!isUserSelected;
|
|
70
|
+
|
|
71
|
+
this.saveData<ThemesStoreData[]>(this.themesNamespace, allData);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public getDefaultGlobalLayoutName(): string | undefined {
|
|
75
|
+
const data = this.getData<DefaultGlobalLayoutData>(this.defaultGlobalLayoutNamespace);
|
|
76
|
+
|
|
77
|
+
return data?.name;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public saveDefaultGlobalLayout(name: string): void {
|
|
81
|
+
this.saveData<DefaultGlobalLayoutData>(this.defaultGlobalLayoutNamespace, { name });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public clearDefaultGlobalLayout(): void {
|
|
85
|
+
this.saveData<object>(this.defaultGlobalLayoutNamespace, { });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private getData<T>(namespace: string): T | undefined {
|
|
89
|
+
const userData = this.localStorage.getItem(this.username);
|
|
90
|
+
|
|
91
|
+
if (!userData) {
|
|
92
|
+
throw new Error(`Cannot get data for namespace: ${namespace}, because the user data is missing`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return JSON.parse(userData)[namespace];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private saveData<T>(namespace: string, data: T): void {
|
|
99
|
+
const userData = this.localStorage.getItem(this.username);
|
|
100
|
+
|
|
101
|
+
if (!userData) {
|
|
102
|
+
throw new Error(`Cannot set data for namespace: ${namespace}, because the user data is missing`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const parsedUserData = JSON.parse(userData);
|
|
106
|
+
|
|
107
|
+
parsedUserData[namespace] = data;
|
|
108
|
+
|
|
109
|
+
this.localStorage.setItem(this.username, JSON.stringify(parsedUserData));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
import { IOConnectCore } from "@interopio/core";
|
|
2
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
3
|
+
import { SessionNonGlueData, SessionSystemSettings, SessionWindowData, WorkspaceWindowSession } from "../common/types";
|
|
4
|
+
import { BaseApplicationData, BridgeInstanceData, InstanceData } from "../libs/applications/types";
|
|
5
|
+
import { LayoutsSnapshot } from "../libs/layouts/types";
|
|
6
|
+
import { FrameSessionData } from "../libs/workspaces/types";
|
|
7
|
+
import logger from "../shared/logger";
|
|
8
|
+
|
|
9
|
+
export class SessionStorageController {
|
|
10
|
+
private sessionStorage!: Storage;
|
|
11
|
+
private readonly windowsNamespace = "g42_core_windows";
|
|
12
|
+
private readonly instancesNamespace = "g42_core_instances";
|
|
13
|
+
private readonly bridgeInstancesNamespace = "g42_core_bridge";
|
|
14
|
+
private readonly nonGlueNamespace = "g42_core_nonglue";
|
|
15
|
+
private readonly workspaceWindowsNamespace = "g42_core_workspace_clients";
|
|
16
|
+
private readonly workspaceFramesNamespace = "g42_core_workspace_frames";
|
|
17
|
+
private readonly workspaceHibernationNamespace = "g42_core_workspace_hibernation";
|
|
18
|
+
private readonly globalLayoutsNamespace = "g42_core_layouts_global";
|
|
19
|
+
private readonly workspaceLayoutsNamespace = "g42_core_layouts_workspace";
|
|
20
|
+
private readonly appDefsNamespace = "g42_core_app_definitions";
|
|
21
|
+
private readonly appDefsInmemoryNamespace = "g42_core_app_definitions_inmemory";
|
|
22
|
+
private readonly notificationsNamespace = "g42_core_notifications";
|
|
23
|
+
private readonly systemNamespace = "g42_system";
|
|
24
|
+
private readonly workspaceFrameCache = "g42_workspace_frame_cache";
|
|
25
|
+
private readonly allNamespaces = [
|
|
26
|
+
this.bridgeInstancesNamespace,
|
|
27
|
+
this.windowsNamespace,
|
|
28
|
+
this.instancesNamespace,
|
|
29
|
+
this.nonGlueNamespace,
|
|
30
|
+
this.workspaceWindowsNamespace,
|
|
31
|
+
this.workspaceFramesNamespace,
|
|
32
|
+
this.globalLayoutsNamespace,
|
|
33
|
+
this.workspaceLayoutsNamespace,
|
|
34
|
+
this.appDefsNamespace,
|
|
35
|
+
this.workspaceHibernationNamespace,
|
|
36
|
+
this.appDefsInmemoryNamespace,
|
|
37
|
+
this.notificationsNamespace,
|
|
38
|
+
this.workspaceFrameCache
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
private get logger(): IOConnectCore.Logger.API | undefined {
|
|
42
|
+
return logger.get("session.storage");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public start(): void {
|
|
46
|
+
this.sessionStorage = window.sessionStorage;
|
|
47
|
+
|
|
48
|
+
this.allNamespaces.forEach((namespace) => {
|
|
49
|
+
const data = this.sessionStorage.getItem(namespace);
|
|
50
|
+
|
|
51
|
+
if (!data) {
|
|
52
|
+
this.sessionStorage.setItem(namespace, JSON.stringify([]));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public shutdown(): void {
|
|
58
|
+
this.allNamespaces.forEach((namespace) => {
|
|
59
|
+
this.sessionStorage.setItem(namespace, JSON.stringify([]));
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
this.sessionStorage.removeItem(this.systemNamespace);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public getSystemSettings(): SessionSystemSettings | undefined {
|
|
66
|
+
const settingsAsString = this.sessionStorage.getItem(this.systemNamespace);
|
|
67
|
+
|
|
68
|
+
if (!settingsAsString) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return JSON.parse(settingsAsString);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public saveSystemSettings(settings: SessionSystemSettings): void {
|
|
76
|
+
this.sessionStorage.setItem(this.systemNamespace, JSON.stringify(settings));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public getTimeout(workspaceId: string): number | undefined {
|
|
80
|
+
const timers: Array<{ workspaceId: string; timeout: number }> = JSON.parse(this.sessionStorage.getItem(this.workspaceHibernationNamespace) as string);
|
|
81
|
+
|
|
82
|
+
return timers.find((timer) => timer.workspaceId === workspaceId)?.timeout;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public removeTimeout(workspaceId: string): void {
|
|
86
|
+
const timers: Array<{ workspaceId: string; timeout: number }> = JSON.parse(this.sessionStorage.getItem(this.workspaceHibernationNamespace) as string);
|
|
87
|
+
|
|
88
|
+
const timer = timers.find((timer) => timer.workspaceId === workspaceId);
|
|
89
|
+
|
|
90
|
+
if (timer) {
|
|
91
|
+
this.sessionStorage.setItem(this.workspaceHibernationNamespace, JSON.stringify(timers.filter((timer) => timer.workspaceId !== workspaceId)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public saveTimeout(workspaceId: string, timeout: number): void {
|
|
97
|
+
const allData: Array<{ workspaceId: string; timeout: number }> = JSON.parse(this.sessionStorage.getItem(this.workspaceHibernationNamespace) as string);
|
|
98
|
+
|
|
99
|
+
if (allData.some((data) => data.workspaceId === workspaceId)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
allData.push({ workspaceId, timeout });
|
|
104
|
+
|
|
105
|
+
this.sessionStorage.setItem(this.workspaceHibernationNamespace, JSON.stringify(allData));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public exportClearTimeouts(): Array<{ workspaceId: string; timeout: number }> {
|
|
109
|
+
const timers: Array<{ workspaceId: string; timeout: number }> = JSON.parse(this.sessionStorage.getItem(this.workspaceHibernationNamespace) as string);
|
|
110
|
+
|
|
111
|
+
this.sessionStorage.setItem(this.workspaceHibernationNamespace, JSON.stringify([]));
|
|
112
|
+
|
|
113
|
+
return timers;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public getAllApps(type: "remote" | "inmemory"): BaseApplicationData[] {
|
|
117
|
+
const namespace = type === "remote" ? this.appDefsNamespace : this.appDefsInmemoryNamespace;
|
|
118
|
+
|
|
119
|
+
const appsString = JSON.parse(this.sessionStorage.getItem(namespace) as string);
|
|
120
|
+
|
|
121
|
+
return appsString;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public overwriteApps(apps: BaseApplicationData[], type: "remote" | "inmemory"): void {
|
|
125
|
+
const namespace = type === "remote" ? this.appDefsNamespace : this.appDefsInmemoryNamespace;
|
|
126
|
+
|
|
127
|
+
this.sessionStorage.setItem(namespace, JSON.stringify(apps));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public removeApp(name: string, type: "remote" | "inmemory"): BaseApplicationData | undefined {
|
|
131
|
+
const namespace = type === "remote" ? this.appDefsNamespace : this.appDefsInmemoryNamespace;
|
|
132
|
+
|
|
133
|
+
const all = this.getAllApps(type);
|
|
134
|
+
|
|
135
|
+
const app = all.find((app) => app.name === name);
|
|
136
|
+
|
|
137
|
+
if (app) {
|
|
138
|
+
this.sessionStorage.setItem(namespace, JSON.stringify(all.filter((a) => a.name !== name)));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return app;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public getLayoutSnapshot(type: IOConnectBrowser.Layouts.LayoutType): LayoutsSnapshot {
|
|
145
|
+
const namespace = type === "Global" ? this.globalLayoutsNamespace : this.workspaceLayoutsNamespace;
|
|
146
|
+
|
|
147
|
+
const snapsString = JSON.parse(this.sessionStorage.getItem(namespace) as string);
|
|
148
|
+
|
|
149
|
+
return { layouts: snapsString };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public saveLayoutSnapshot(snapshot: LayoutsSnapshot, type: IOConnectBrowser.Layouts.LayoutType): void {
|
|
153
|
+
const namespace = type === "Global" ? this.globalLayoutsNamespace : this.workspaceLayoutsNamespace;
|
|
154
|
+
|
|
155
|
+
this.sessionStorage.setItem(namespace, JSON.stringify(snapshot.layouts));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public saveFrameData(frameData: FrameSessionData): void {
|
|
159
|
+
const allData: FrameSessionData[] = JSON.parse(this.sessionStorage.getItem(this.workspaceFramesNamespace) as string);
|
|
160
|
+
|
|
161
|
+
if (allData.some((data) => data.windowId === frameData.windowId)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
allData.push(frameData);
|
|
166
|
+
|
|
167
|
+
this.sessionStorage.setItem(this.workspaceFramesNamespace, JSON.stringify(allData));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public getPlatformFrame(): FrameSessionData | undefined {
|
|
171
|
+
return this.getAllFrames().find((frame) => frame.isPlatform);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public getAllFrames(): FrameSessionData[] {
|
|
175
|
+
const allData: FrameSessionData[] = JSON.parse(this.sessionStorage.getItem(this.workspaceFramesNamespace) as string);
|
|
176
|
+
return allData;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public getFrameData(windowId: string): FrameSessionData | undefined {
|
|
180
|
+
const allData: FrameSessionData[] = JSON.parse(this.sessionStorage.getItem(this.workspaceFramesNamespace) as string);
|
|
181
|
+
|
|
182
|
+
return allData.find((data) => data.windowId === windowId);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
public setFrameActive(windowId: string): void {
|
|
186
|
+
const allData: FrameSessionData[] = JSON.parse(this.sessionStorage.getItem(this.workspaceFramesNamespace) as string);
|
|
187
|
+
|
|
188
|
+
const frameData = allData.find((data) => data.windowId === windowId);
|
|
189
|
+
|
|
190
|
+
if (!frameData || frameData.active) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
frameData.active = true;
|
|
195
|
+
|
|
196
|
+
this.sessionStorage.setItem(this.workspaceFramesNamespace, JSON.stringify(allData));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public removeFrameData(windowId: string): boolean {
|
|
200
|
+
|
|
201
|
+
if (!windowId) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return this.doRemove<FrameSessionData>(windowId, this.workspaceFramesNamespace);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public saveWorkspaceClient(windowData: WorkspaceWindowSession): void {
|
|
209
|
+
const allData: WorkspaceWindowSession[] = JSON.parse(this.sessionStorage.getItem(this.workspaceWindowsNamespace) as string);
|
|
210
|
+
|
|
211
|
+
if (allData.some((data) => data.windowId === windowData.windowId)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
allData.push(windowData);
|
|
216
|
+
|
|
217
|
+
this.sessionStorage.setItem(this.workspaceWindowsNamespace, JSON.stringify(allData));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public getWorkspaceClientById(windowId: string): WorkspaceWindowSession | undefined {
|
|
221
|
+
const allData: WorkspaceWindowSession[] = JSON.parse(this.sessionStorage.getItem(this.workspaceWindowsNamespace) as string);
|
|
222
|
+
|
|
223
|
+
return allData.find((data) => data.windowId === windowId);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public pickWorkspaceClients(predicate: (client: WorkspaceWindowSession) => boolean): WorkspaceWindowSession[] {
|
|
227
|
+
const allData: WorkspaceWindowSession[] = JSON.parse(this.sessionStorage.getItem(this.workspaceWindowsNamespace) as string);
|
|
228
|
+
|
|
229
|
+
return allData.filter(predicate);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public removeWorkspaceClient(windowId: string): boolean {
|
|
233
|
+
if (!windowId) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return this.doRemove<WorkspaceWindowSession>(windowId, this.workspaceWindowsNamespace);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public getAllNonGlue(): SessionNonGlueData[] {
|
|
241
|
+
return JSON.parse(this.sessionStorage.getItem(this.nonGlueNamespace) as string);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public saveNonGlue(data: SessionNonGlueData): boolean {
|
|
245
|
+
const allData: SessionNonGlueData[] = JSON.parse(this.sessionStorage.getItem(this.nonGlueNamespace) as string);
|
|
246
|
+
|
|
247
|
+
if (allData.some((entry) => entry.windowId === data.windowId)) {
|
|
248
|
+
this.logger?.trace(`did not save this data: ${JSON.stringify(data)}, because an entry with this id already exists`);
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
this.logger?.trace(`saving non glue window with id: ${data.windowId}`);
|
|
253
|
+
|
|
254
|
+
allData.push(data);
|
|
255
|
+
|
|
256
|
+
this.sessionStorage.setItem(this.nonGlueNamespace, JSON.stringify(allData));
|
|
257
|
+
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public removeNonGlue(data: SessionNonGlueData): boolean {
|
|
262
|
+
if (!data || !data.windowId) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
this.logger?.trace(`removing non glue window with id: ${data.windowId}`);
|
|
267
|
+
|
|
268
|
+
return this.doRemove<SessionNonGlueData>(data.windowId, this.nonGlueNamespace);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
public saveBridgeInstanceData(data: BridgeInstanceData): void {
|
|
272
|
+
const allData: BridgeInstanceData[] = JSON.parse(this.sessionStorage.getItem(this.bridgeInstancesNamespace) as string);
|
|
273
|
+
|
|
274
|
+
if (allData.some((entry) => entry.windowId === data.windowId)) {
|
|
275
|
+
this.logger?.trace(`did not save this data: ${JSON.stringify(data)}, because an entry with this id already exists`);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
this.logger?.trace(`saving new instance with id: ${data.windowId} and app name: ${data.appName}`);
|
|
280
|
+
|
|
281
|
+
allData.push(data);
|
|
282
|
+
|
|
283
|
+
this.sessionStorage.setItem(this.bridgeInstancesNamespace, JSON.stringify(allData));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
public getBridgeInstanceData(windowId: string): BridgeInstanceData | undefined {
|
|
287
|
+
const all: BridgeInstanceData[] = JSON.parse(this.sessionStorage.getItem(this.bridgeInstancesNamespace) as string);
|
|
288
|
+
|
|
289
|
+
return all.find((e) => e.windowId === windowId);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public removeBridgeInstanceData(windowId: string): void {
|
|
293
|
+
const all: BridgeInstanceData[] = JSON.parse(this.sessionStorage.getItem(this.bridgeInstancesNamespace) as string);
|
|
294
|
+
|
|
295
|
+
this.sessionStorage.setItem(this.bridgeInstancesNamespace, JSON.stringify(all.filter((e) => e.windowId !== windowId)));
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
public saveInstanceData(data: InstanceData): void {
|
|
299
|
+
const allData: InstanceData[] = JSON.parse(this.sessionStorage.getItem(this.instancesNamespace) as string);
|
|
300
|
+
|
|
301
|
+
if (allData.some((entry) => entry.id === data.id)) {
|
|
302
|
+
this.logger?.trace(`did not save this data: ${JSON.stringify(data)}, because an entry with this id already exists`);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
this.logger?.trace(`saving new instance with id: ${data.id} and app name: ${data.applicationName}`);
|
|
307
|
+
|
|
308
|
+
allData.push(data);
|
|
309
|
+
|
|
310
|
+
this.sessionStorage.setItem(this.instancesNamespace, JSON.stringify(allData));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
public removeInstance(id: string): void {
|
|
314
|
+
this.logger?.trace(`removing instance with id: ${id}`);
|
|
315
|
+
|
|
316
|
+
const all = this.getAllInstancesData();
|
|
317
|
+
|
|
318
|
+
this.sessionStorage.setItem(this.instancesNamespace, JSON.stringify(all.filter((e) => e.id !== id)));
|
|
319
|
+
this.removeBridgeInstanceData(id);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
public getInstanceData(id: string): InstanceData | undefined {
|
|
323
|
+
const all = this.getAllInstancesData();
|
|
324
|
+
|
|
325
|
+
return all.find((e) => e.id === id);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
public getAllInstancesData(): InstanceData[] {
|
|
329
|
+
return JSON.parse(this.sessionStorage.getItem(this.instancesNamespace) as string);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
public removeNotification(id: string): void {
|
|
333
|
+
const allNotifications: IOConnectBrowser.Notifications.NotificationData[] = JSON.parse(this.sessionStorage.getItem(this.notificationsNamespace) as string);
|
|
334
|
+
|
|
335
|
+
const notification = allNotifications.find((notification) => notification.id === id);
|
|
336
|
+
|
|
337
|
+
if (notification) {
|
|
338
|
+
this.sessionStorage.setItem(this.notificationsNamespace, JSON.stringify(allNotifications.filter((notification) => notification.id !== id)));
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
public saveNotification(notification: IOConnectBrowser.Notifications.NotificationData): void {
|
|
343
|
+
const allNotifications: IOConnectBrowser.Notifications.NotificationData[] = JSON.parse(this.sessionStorage.getItem(this.notificationsNamespace) as string);
|
|
344
|
+
|
|
345
|
+
if (allNotifications.some((entry) => entry.id === notification.id)) {
|
|
346
|
+
this.logger?.trace(`did not save this data: ${JSON.stringify(notification)}, because an entry with this id already exists`);
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
this.logger?.trace(`saving notification with id: ${notification.id}`);
|
|
351
|
+
|
|
352
|
+
allNotifications.push(notification);
|
|
353
|
+
|
|
354
|
+
this.sessionStorage.setItem(this.notificationsNamespace, JSON.stringify(allNotifications));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
public getNotification(id: string): IOConnectBrowser.Notifications.NotificationData | undefined {
|
|
358
|
+
const allNotifications = this.getAllNotifications();
|
|
359
|
+
|
|
360
|
+
return allNotifications.find((notification) => notification.id === id);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
public getAllNotifications(): IOConnectBrowser.Notifications.NotificationData[] {
|
|
364
|
+
const allNotifications: IOConnectBrowser.Notifications.NotificationData[] = JSON.parse(this.sessionStorage.getItem(this.notificationsNamespace) as string);
|
|
365
|
+
|
|
366
|
+
return allNotifications;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
public saveWindowData(data: SessionWindowData): void {
|
|
370
|
+
const allData: SessionWindowData[] = JSON.parse(this.sessionStorage.getItem(this.windowsNamespace) as string);
|
|
371
|
+
|
|
372
|
+
if (allData.some((entry) => entry.name === data.name)) {
|
|
373
|
+
this.logger?.trace(`did not save this data: ${JSON.stringify(data)}, because an entry with this name already exists`);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
this.logger?.trace(`saving window with id: ${data.windowId} and name: ${data.name}`);
|
|
378
|
+
|
|
379
|
+
allData.push(data);
|
|
380
|
+
|
|
381
|
+
this.sessionStorage.setItem(this.windowsNamespace, JSON.stringify(allData));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
public getAllWindowsData(): SessionWindowData[] {
|
|
385
|
+
return JSON.parse(this.sessionStorage.getItem(this.windowsNamespace) as string);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
public getWindowDataById(windowId: string): SessionWindowData | undefined {
|
|
389
|
+
const all = this.getAllWindowsData();
|
|
390
|
+
|
|
391
|
+
return all.find((entry) => entry.windowId === windowId);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
public getWindowDataByName(name: string): SessionWindowData | undefined {
|
|
395
|
+
const all = this.getAllWindowsData();
|
|
396
|
+
|
|
397
|
+
return all.find((entry) => entry.name === name);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
public removeWindowData(windowId: string): boolean {
|
|
401
|
+
if (!windowId) {
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
this.logger?.trace(`removing window with id: ${windowId}`);
|
|
406
|
+
|
|
407
|
+
return this.doRemove<SessionWindowData>(windowId, this.windowsNamespace);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
public fullWindowClean(windowId: string): boolean {
|
|
411
|
+
const windowRemoved = this.removeWindowData(windowId);
|
|
412
|
+
const nonGlueRemoved = this.removeNonGlue({ windowId });
|
|
413
|
+
const workspaceClientRemoved = this.removeWorkspaceClient(windowId);
|
|
414
|
+
|
|
415
|
+
return windowRemoved || nonGlueRemoved || workspaceClientRemoved;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private doRemove<T extends { windowId: string }>(id: string, namespace: string): boolean {
|
|
419
|
+
const data: T[] = JSON.parse(this.sessionStorage.getItem(namespace) as string);
|
|
420
|
+
|
|
421
|
+
const result = data.reduce<{ removed: boolean; newData: T[] }>((soFar, entry) => {
|
|
422
|
+
|
|
423
|
+
if (entry.windowId === id) {
|
|
424
|
+
soFar.removed = true;
|
|
425
|
+
} else {
|
|
426
|
+
soFar.newData.push(entry);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return soFar;
|
|
430
|
+
}, { removed: false, newData: [] });
|
|
431
|
+
|
|
432
|
+
this.sessionStorage.setItem(namespace, JSON.stringify(result.newData));
|
|
433
|
+
|
|
434
|
+
return result.removed;
|
|
435
|
+
}
|
|
436
|
+
}
|