@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,232 @@
|
|
|
1
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
2
|
+
import { BridgeOperation, LibController, OperationCheckConfig, OperationCheckResult } from "../../common/types";
|
|
3
|
+
import logger from "../../shared/logger";
|
|
4
|
+
import { operationCheckConfigDecoder, operationCheckResultDecoder } from "../../shared/decoders";
|
|
5
|
+
import { SearchOperationsTypes, SearchRepository } from "./types";
|
|
6
|
+
import { searchOperationDecoder } from "./decoders";
|
|
7
|
+
import { IOConnectBrowserPlatform } from "../../../browser.platform";
|
|
8
|
+
import { ApplicationsRepository } from "./repositories/applications";
|
|
9
|
+
import { LayoutsRepository } from "./repositories/layouts";
|
|
10
|
+
import { WorkspacesRepository } from "./repositories/workspaces";
|
|
11
|
+
import { GlueController } from "../../controllers/glue";
|
|
12
|
+
import { IOConnectSearch } from "@interopio/search-api";
|
|
13
|
+
import { extractErrorMsg } from "../../shared/utils";
|
|
14
|
+
|
|
15
|
+
export class SearchController implements LibController {
|
|
16
|
+
|
|
17
|
+
private started = false;
|
|
18
|
+
private repos: SearchRepository[] = [];
|
|
19
|
+
private providerName = "Glue42 Core Plus Platform";
|
|
20
|
+
private provider: IOConnectSearch.Provider | undefined;
|
|
21
|
+
private activeQueries: { [key in string]: { allowedResultsCount: number } } = {};
|
|
22
|
+
private unsubFuncs: IOConnectSearch.UnsubscribeFunction[] = [];
|
|
23
|
+
|
|
24
|
+
private operations: { [key in SearchOperationsTypes]: BridgeOperation } = {
|
|
25
|
+
operationCheck: { name: "operationCheck", dataDecoder: operationCheckConfigDecoder, resultDecoder: operationCheckResultDecoder, execute: this.handleOperationCheck.bind(this) }
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
private readonly glueController: GlueController,
|
|
30
|
+
private readonly appsRepo: ApplicationsRepository,
|
|
31
|
+
private readonly layoutsRepo: LayoutsRepository,
|
|
32
|
+
private readonly workspacesRepo: WorkspacesRepository,
|
|
33
|
+
) { }
|
|
34
|
+
|
|
35
|
+
private get logger(): IOConnectBrowser.Logger.API | undefined {
|
|
36
|
+
return logger.get("notifications.controller");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public handlePlatformShutdown(): void {
|
|
40
|
+
this.started = false;
|
|
41
|
+
|
|
42
|
+
this.unsubFuncs.forEach((unsub) => unsub());
|
|
43
|
+
|
|
44
|
+
this.unsubFuncs = [];
|
|
45
|
+
|
|
46
|
+
this.repos = [];
|
|
47
|
+
|
|
48
|
+
this.activeQueries = {};
|
|
49
|
+
|
|
50
|
+
this.provider?.unregister();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public async configurePostStart(): Promise<void> {
|
|
54
|
+
this.repos.push(this.appsRepo);
|
|
55
|
+
this.repos.push(this.layoutsRepo);
|
|
56
|
+
|
|
57
|
+
if (!this.glueController.isWorkspacesEnabled) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
this.repos.push(this.workspacesRepo);
|
|
62
|
+
|
|
63
|
+
const myTypes = this.repos.map((repo) => ({ name: repo.type, displayName: repo.displayType }));
|
|
64
|
+
|
|
65
|
+
const myProviderRegistrationConfig: IOConnectSearch.ProviderRegistrationConfig = {
|
|
66
|
+
name: this.providerName,
|
|
67
|
+
types: myTypes
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
this.logger?.trace(`Registering the plus platform as a provider with name: ${myProviderRegistrationConfig.name} and types: ${JSON.stringify(myProviderRegistrationConfig.types?.join(", "))}.`);
|
|
71
|
+
|
|
72
|
+
this.provider = await this.glueController.registerProvider(myProviderRegistrationConfig);
|
|
73
|
+
|
|
74
|
+
if (!this.provider) {
|
|
75
|
+
throw new Error("The platform was not registered successfully as a provider.");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
this.logger?.trace("The platform plus was registered successfully as a provider.");
|
|
79
|
+
|
|
80
|
+
const unsubOnQuery = this.provider.onQuery((query) => {
|
|
81
|
+
this.processQuery(query).then(() => this.markQueryDone(query)).catch((error) => this.markQueryError(query, error));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const unsubOnQueryCancel = this.provider.onQueryCancel(this.processQueryCancel.bind(this));
|
|
85
|
+
|
|
86
|
+
this.unsubFuncs.push(unsubOnQuery);
|
|
87
|
+
this.unsubFuncs.push(unsubOnQueryCancel);
|
|
88
|
+
|
|
89
|
+
this.logger?.info("The module started successfully.");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public async start(): Promise<void> {
|
|
93
|
+
this.logger?.info("Starting the Global Search provider.");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public async handleControl(controlMessage: IOConnectBrowserPlatform.ControlMessage): Promise<any> {
|
|
97
|
+
if (!this.started) {
|
|
98
|
+
new Error("Cannot handle this search control message, because the controller has not been started");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const notificationsData = controlMessage.data;
|
|
102
|
+
|
|
103
|
+
const commandId = controlMessage.commandId;
|
|
104
|
+
|
|
105
|
+
const operationValidation = searchOperationDecoder.run(controlMessage.operation);
|
|
106
|
+
|
|
107
|
+
if (!operationValidation.ok) {
|
|
108
|
+
throw new Error(`This search request cannot be completed, because the operation name did not pass validation: ${JSON.stringify(operationValidation.error)}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const operationName: SearchOperationsTypes = operationValidation.result;
|
|
112
|
+
|
|
113
|
+
const incomingValidation = this.operations[operationName].dataDecoder?.run(notificationsData);
|
|
114
|
+
|
|
115
|
+
if (incomingValidation && !incomingValidation.ok) {
|
|
116
|
+
throw new Error(`Search request for ${operationName} rejected, because the provided arguments did not pass the validation: ${JSON.stringify(incomingValidation.error)}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
this.logger?.debug(`[${commandId}] ${operationName} command is valid with data: ${JSON.stringify(notificationsData)}`);
|
|
120
|
+
|
|
121
|
+
const result = await this.operations[operationName].execute(notificationsData, commandId);
|
|
122
|
+
|
|
123
|
+
const resultValidation = this.operations[operationName].resultDecoder?.run(result);
|
|
124
|
+
|
|
125
|
+
if (resultValidation && !resultValidation.ok) {
|
|
126
|
+
throw new Error(`Search request for ${operationName} could not be completed, because the operation result did not pass the validation: ${JSON.stringify(resultValidation.error)}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
this.logger?.trace(`[${commandId}] ${operationName} command was executed successfully`);
|
|
130
|
+
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private async handleOperationCheck(config: OperationCheckConfig): Promise<OperationCheckResult> {
|
|
135
|
+
const operations = Object.keys(this.operations);
|
|
136
|
+
|
|
137
|
+
const isSupported = operations.some((operation) => operation.toLowerCase() === config.operation.toLowerCase());
|
|
138
|
+
|
|
139
|
+
return { isSupported };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async processQuery(query: IOConnectSearch.ProviderQuery): Promise<void> {
|
|
143
|
+
|
|
144
|
+
this.logger?.info(`Processing a new query for: ${query.search}`);
|
|
145
|
+
|
|
146
|
+
this.activeQueries[query.id] = {
|
|
147
|
+
allowedResultsCount: query.providerLimits?.maxResults || Number.MAX_SAFE_INTEGER
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const reposToCall = query.types ?
|
|
151
|
+
this.repos.filter((repo) => query.types?.some((queryType) => queryType.name === repo.type)) :
|
|
152
|
+
this.repos;
|
|
153
|
+
|
|
154
|
+
await Promise.all(reposToCall.map((repo) => this.callRepo(repo, query)));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private async callRepo(repo: SearchRepository, query: IOConnectSearch.ProviderQuery): Promise<void> {
|
|
158
|
+
|
|
159
|
+
const repoResults = await this.getRepoResults(repo, query);
|
|
160
|
+
|
|
161
|
+
if (!this.activeQueries[query.id] || !repoResults) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
this.sendResults(repoResults, query);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private async getRepoResults(repo: SearchRepository, query: IOConnectSearch.ProviderQuery): Promise<IOConnectSearch.QueryResult[] | undefined> {
|
|
169
|
+
try {
|
|
170
|
+
const results = await repo.getResults(query);
|
|
171
|
+
|
|
172
|
+
return results;
|
|
173
|
+
} catch (error) {
|
|
174
|
+
this.markQueryError(query, error);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private sendResults(repoResults: IOConnectSearch.QueryResult[], query: IOConnectSearch.ProviderQuery): void {
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
repoResults.forEach((result) => {
|
|
183
|
+
|
|
184
|
+
if (!this.activeQueries[query.id]) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!this.activeQueries[query.id].allowedResultsCount) {
|
|
189
|
+
this.markQueryDone(query);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
--this.activeQueries[query.id].allowedResultsCount;
|
|
194
|
+
|
|
195
|
+
query.sendResult(result);
|
|
196
|
+
});
|
|
197
|
+
} catch (error) {
|
|
198
|
+
this.logger?.warn(`Failed sending results for query: ${query.search} with an error: ${extractErrorMsg(error)}`);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private markQueryDone(query: IOConnectSearch.ProviderQuery): void {
|
|
204
|
+
|
|
205
|
+
if (!this.activeQueries[query.id]) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
this.logger?.info(`The query for: ${query.search} is completed`);
|
|
210
|
+
|
|
211
|
+
delete this.activeQueries[query.id];
|
|
212
|
+
|
|
213
|
+
query.done();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private markQueryError(query: IOConnectSearch.ProviderQuery, error: any): void {
|
|
217
|
+
|
|
218
|
+
if (!this.activeQueries[query.id]) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this.logger?.warn(`The query for: ${query.search} ended with an error: ${extractErrorMsg(error)}`);
|
|
223
|
+
|
|
224
|
+
delete this.activeQueries[query.id];
|
|
225
|
+
|
|
226
|
+
query.error(extractErrorMsg(error));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private processQueryCancel(query: { id: string }): void {
|
|
230
|
+
delete this.activeQueries[query.id];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { IOConnectSearch } from "@interopio/search-api";
|
|
2
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
3
|
+
import { GlueController } from "../../../controllers/glue";
|
|
4
|
+
import { checkMatch } from "../../../shared/utils";
|
|
5
|
+
import { SearchRepository } from "../types";
|
|
6
|
+
|
|
7
|
+
export class ApplicationsRepository implements SearchRepository {
|
|
8
|
+
public type = "application";
|
|
9
|
+
public displayType = "Applications";
|
|
10
|
+
|
|
11
|
+
constructor(private readonly glueController: GlueController) {}
|
|
12
|
+
|
|
13
|
+
public getResults(query: IOConnectSearch.QueryConfig): Promise<IOConnectSearch.QueryResult[]> {
|
|
14
|
+
const eligibleApps: Set<IOConnectBrowser.AppManager.Application> = new Set<IOConnectBrowser.AppManager.Application>();
|
|
15
|
+
|
|
16
|
+
const allowedResultsTracker = {
|
|
17
|
+
count: Math.min(query.providerLimits?.maxResultsPerType || Number.MAX_SAFE_INTEGER, query.providerLimits?.maxResults || Number.MAX_SAFE_INTEGER)
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const allApps = this.glueController.getAllApplications();
|
|
21
|
+
|
|
22
|
+
const filteredByDisplayName = allApps.filter((app) => checkMatch(allowedResultsTracker, () => !!app.title?.toLowerCase().includes(query.search.toLowerCase())));
|
|
23
|
+
filteredByDisplayName.forEach((app) => eligibleApps.add(app));
|
|
24
|
+
|
|
25
|
+
if (!allowedResultsTracker.count) {
|
|
26
|
+
return Promise.resolve(this.transformApps(eligibleApps));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const filteredByCaption = allApps.filter((app) => checkMatch(allowedResultsTracker, () => !!app.caption?.toLowerCase().includes(query.search.toLowerCase())));
|
|
30
|
+
filteredByCaption.forEach((app) => eligibleApps.add(app));
|
|
31
|
+
|
|
32
|
+
if (!allowedResultsTracker.count) {
|
|
33
|
+
return Promise.resolve(this.transformApps(eligibleApps));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const filteredByName = allApps.filter((app) => checkMatch(allowedResultsTracker, () => app.name.toLowerCase().includes(query.search.toLowerCase())));
|
|
37
|
+
filteredByName.forEach((app) => eligibleApps.add(app));
|
|
38
|
+
|
|
39
|
+
return Promise.resolve(this.transformApps(eligibleApps));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private transformApps(eligibleApps: Set<IOConnectBrowser.AppManager.Application>): IOConnectSearch.QueryResult[] {
|
|
43
|
+
|
|
44
|
+
const results: IOConnectSearch.QueryResult[] = [];
|
|
45
|
+
|
|
46
|
+
for (const app of eligibleApps.values()) {
|
|
47
|
+
results.push({
|
|
48
|
+
type: {
|
|
49
|
+
name: this.type,
|
|
50
|
+
displayName: this.displayType
|
|
51
|
+
},
|
|
52
|
+
id: app.name,
|
|
53
|
+
displayName: app.title,
|
|
54
|
+
description: app.caption,
|
|
55
|
+
iconURL: app.icon
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return results;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IOConnectSearch } from "@interopio/search-api";
|
|
2
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
3
|
+
import { GlueController } from "../../../controllers/glue";
|
|
4
|
+
import { checkMatch } from "../../../shared/utils";
|
|
5
|
+
import { SearchRepository } from "../types";
|
|
6
|
+
|
|
7
|
+
export class LayoutsRepository implements SearchRepository {
|
|
8
|
+
public type = "layout";
|
|
9
|
+
public displayType = "Layouts";
|
|
10
|
+
|
|
11
|
+
constructor(private readonly glueController: GlueController) {}
|
|
12
|
+
|
|
13
|
+
public async getResults(query: IOConnectSearch.QueryConfig): Promise<IOConnectSearch.QueryResult[]> {
|
|
14
|
+
|
|
15
|
+
const eligibleLayouts: Set<IOConnectBrowser.Layouts.LayoutSummary> = new Set<IOConnectBrowser.Layouts.LayoutSummary>();
|
|
16
|
+
|
|
17
|
+
const allowedResultsTracker = {
|
|
18
|
+
count: Math.min(query.providerLimits?.maxResultsPerType || Number.MAX_SAFE_INTEGER, query.providerLimits?.maxResults || Number.MAX_SAFE_INTEGER)
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const allLayouts = await this.glueController.getAllLayoutsSummaries();
|
|
22
|
+
|
|
23
|
+
const filteredByName = allLayouts.filter((layout) => checkMatch(allowedResultsTracker, () => layout.name.toLowerCase().includes(query.search.toLowerCase())));
|
|
24
|
+
filteredByName.forEach((layout) => eligibleLayouts.add(layout));
|
|
25
|
+
|
|
26
|
+
return this.transformLayouts(eligibleLayouts);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private transformLayouts(eligibleLayouts: Set<IOConnectBrowser.Layouts.LayoutSummary>): IOConnectSearch.QueryResult[] {
|
|
30
|
+
|
|
31
|
+
const results: IOConnectSearch.QueryResult[] = [];
|
|
32
|
+
|
|
33
|
+
for (const layout of eligibleLayouts.values()) {
|
|
34
|
+
results.push({
|
|
35
|
+
type: {
|
|
36
|
+
name: this.type,
|
|
37
|
+
displayName: this.displayType
|
|
38
|
+
},
|
|
39
|
+
id: layout.name,
|
|
40
|
+
displayName: layout.name
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return results;
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IOConnectSearch } from "@interopio/search-api";
|
|
2
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
3
|
+
import { GlueController } from "../../../controllers/glue";
|
|
4
|
+
import { checkMatch } from "../../../shared/utils";
|
|
5
|
+
import { SearchRepository } from "../types";
|
|
6
|
+
|
|
7
|
+
export class WorkspacesRepository implements SearchRepository {
|
|
8
|
+
public type = "workspace";
|
|
9
|
+
public displayType = "Workspaces";
|
|
10
|
+
|
|
11
|
+
constructor(private readonly glueController: GlueController) {}
|
|
12
|
+
|
|
13
|
+
public async getResults(query: IOConnectSearch.QueryConfig): Promise<IOConnectSearch.QueryResult[]> {
|
|
14
|
+
|
|
15
|
+
const eligibleWorkspaces: Set<IOConnectBrowser.Layouts.LayoutSummary> = new Set<IOConnectBrowser.Layouts.LayoutSummary>();
|
|
16
|
+
|
|
17
|
+
const allowedResultsTracker = {
|
|
18
|
+
count: Math.min(query.providerLimits?.maxResultsPerType || Number.MAX_SAFE_INTEGER, query.providerLimits?.maxResults || Number.MAX_SAFE_INTEGER)
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const allWorkspaces = await this.glueController.getAllWorkspacesSummaries();
|
|
22
|
+
|
|
23
|
+
const filteredByName = allWorkspaces.filter((workspace) => checkMatch(allowedResultsTracker, () => workspace.name.toLowerCase().includes(query.search.toLowerCase())));
|
|
24
|
+
filteredByName.forEach((workspace) => eligibleWorkspaces.add(workspace));
|
|
25
|
+
|
|
26
|
+
return this.transformWorkspaces(eligibleWorkspaces);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private transformWorkspaces(eligibleWorkspaces: Set<IOConnectBrowser.Layouts.LayoutSummary>): IOConnectSearch.QueryResult[] {
|
|
30
|
+
|
|
31
|
+
const results: IOConnectSearch.QueryResult[] = [];
|
|
32
|
+
|
|
33
|
+
for (const workspace of eligibleWorkspaces.values()) {
|
|
34
|
+
results.push({
|
|
35
|
+
type: {
|
|
36
|
+
name: this.type,
|
|
37
|
+
displayName: this.displayType
|
|
38
|
+
},
|
|
39
|
+
id: workspace.name,
|
|
40
|
+
displayName: workspace.name
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return results;
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IOConnectSearch } from "@interopio/search-api";
|
|
2
|
+
|
|
3
|
+
export type SearchOperationsTypes = "operationCheck";
|
|
4
|
+
|
|
5
|
+
export interface SearchRepository {
|
|
6
|
+
type: string;
|
|
7
|
+
displayType: string;
|
|
8
|
+
getResults(query: IOConnectSearch.QueryConfig): Promise<IOConnectSearch.QueryResult[]>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
2
|
+
import { BridgeOperation, InternalPlatformConfig, LibController, OperationCheckConfig, OperationCheckResult } from "../../common/types";
|
|
3
|
+
import logger from "../../shared/logger";
|
|
4
|
+
import { IOConnectBrowserPlatform } from "../../../browser.platform";
|
|
5
|
+
import { AllThemesResponse, SelectThemeConfig, SimpleThemeResponse, ThemesOperationTypes } from "./types";
|
|
6
|
+
import { allThemesResponseDecoder, selectThemeConfigDecoder, simpleThemeResponseDecoder, themesOperationDecoder } from "./decoders";
|
|
7
|
+
import { operationCheckConfigDecoder, operationCheckResultDecoder } from "../../shared/decoders";
|
|
8
|
+
import { LocalStoreController } from "../../storage/local";
|
|
9
|
+
import { GlueController } from "../../controllers/glue";
|
|
10
|
+
import { GlueCorePlusThemesStream, darkTheme, lightTheme } from "./constants";
|
|
11
|
+
|
|
12
|
+
export class ThemesController implements LibController {
|
|
13
|
+
|
|
14
|
+
private started = false;
|
|
15
|
+
private themesStream!: IOConnectBrowser.Interop.Stream;
|
|
16
|
+
|
|
17
|
+
private operations: { [key in ThemesOperationTypes]: BridgeOperation } = {
|
|
18
|
+
getCurrent: { name: "getCurrent", resultDecoder: simpleThemeResponseDecoder, execute: this.handleGetCurrent.bind(this) },
|
|
19
|
+
list: { name: "list", resultDecoder: allThemesResponseDecoder, execute: this.handleList.bind(this) },
|
|
20
|
+
select: { name: "select", dataDecoder: selectThemeConfigDecoder, execute: this.handleSelect.bind(this) },
|
|
21
|
+
operationCheck: { name: "operationCheck", dataDecoder: operationCheckConfigDecoder, resultDecoder: operationCheckResultDecoder, execute: this.handleOperationCheck.bind(this) }
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
private readonly glueController: GlueController,
|
|
26
|
+
private readonly localStore: LocalStoreController
|
|
27
|
+
) { }
|
|
28
|
+
|
|
29
|
+
private get logger(): IOConnectBrowser.Logger.API | undefined {
|
|
30
|
+
return logger.get("themes.controller");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async start(config: InternalPlatformConfig): Promise<void> {
|
|
34
|
+
this.started = true;
|
|
35
|
+
|
|
36
|
+
this.localStore.saveThemeIfMissing({ theme: lightTheme, selected: false, isUserSelected: false });
|
|
37
|
+
this.localStore.saveThemeIfMissing({ theme: darkTheme, selected: false, isUserSelected: false });
|
|
38
|
+
|
|
39
|
+
this.themesStream = await this.glueController.createSystemStream(GlueCorePlusThemesStream);
|
|
40
|
+
|
|
41
|
+
const hasUserSelection = this.localStore.getAllThemes().some((themeData) => themeData.isUserSelected);
|
|
42
|
+
|
|
43
|
+
if (hasUserSelection) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const themeName = config.themes?.defaultTheme === "os" ? this.getOsTheme() :
|
|
48
|
+
config.themes?.defaultTheme === "light" ? "light" :
|
|
49
|
+
"dark";
|
|
50
|
+
|
|
51
|
+
this.localStore.markThemeSelected(themeName, false);
|
|
52
|
+
|
|
53
|
+
const theme = this.localStore.getAllThemes().find((data) => data.selected)?.theme;
|
|
54
|
+
|
|
55
|
+
this.themesStream.push({ theme });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public handlePlatformShutdown(): void {
|
|
59
|
+
this.started = false;
|
|
60
|
+
this.themesStream.close();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async handleControl(args: IOConnectBrowserPlatform.ControlMessage): Promise<void> {
|
|
64
|
+
if (!this.started) {
|
|
65
|
+
new Error("Cannot handle this themes control message, because the controller has not been started");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const notificationsData = args.data;
|
|
69
|
+
|
|
70
|
+
const commandId = args.commandId;
|
|
71
|
+
|
|
72
|
+
const operationValidation = themesOperationDecoder.run(args.operation);
|
|
73
|
+
|
|
74
|
+
if (!operationValidation.ok) {
|
|
75
|
+
throw new Error(`This themes request cannot be completed, because the operation name did not pass validation: ${JSON.stringify(operationValidation.error)}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const operationName: ThemesOperationTypes = operationValidation.result;
|
|
79
|
+
|
|
80
|
+
const incomingValidation = this.operations[operationName].dataDecoder?.run(notificationsData);
|
|
81
|
+
|
|
82
|
+
if (incomingValidation && !incomingValidation.ok) {
|
|
83
|
+
throw new Error(`Themes request for ${operationName} rejected, because the provided arguments did not pass the validation: ${JSON.stringify(incomingValidation.error)}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.logger?.debug(`[${commandId}] ${operationName} command is valid with data: ${JSON.stringify(notificationsData)}`);
|
|
87
|
+
|
|
88
|
+
const result = await this.operations[operationName].execute(notificationsData, commandId);
|
|
89
|
+
|
|
90
|
+
const resultValidation = this.operations[operationName].resultDecoder?.run(result);
|
|
91
|
+
|
|
92
|
+
if (resultValidation && !resultValidation.ok) {
|
|
93
|
+
throw new Error(`Themes request for ${operationName} could not be completed, because the operation result did not pass the validation: ${JSON.stringify(resultValidation.error)}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
this.logger?.trace(`[${commandId}] ${operationName} command was executed successfully`);
|
|
97
|
+
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public handleClientUnloaded(): void {
|
|
103
|
+
//noop
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private async handleGetCurrent(_: unknown, commandId: string): Promise<SimpleThemeResponse> {
|
|
107
|
+
this.logger?.trace(`[${commandId}] handling a getCurrent message`);
|
|
108
|
+
|
|
109
|
+
const allThemesData = this.localStore.getAllThemes();
|
|
110
|
+
|
|
111
|
+
const selectedTheme = allThemesData.find((themeData) => themeData.selected);
|
|
112
|
+
|
|
113
|
+
if (!selectedTheme) {
|
|
114
|
+
throw new Error("No selected theme found!");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return { theme: selectedTheme.theme };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private async handleList(_: unknown, commandId: string): Promise<AllThemesResponse> {
|
|
121
|
+
this.logger?.trace(`[${commandId}] handling a list message`);
|
|
122
|
+
|
|
123
|
+
const allThemesData = this.localStore.getAllThemes();
|
|
124
|
+
|
|
125
|
+
return { themes: allThemesData.map((data) => data.theme) };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private async handleSelect(config: SelectThemeConfig, commandId: string): Promise<void> {
|
|
129
|
+
this.logger?.trace(`[${commandId}] handling a select message`);
|
|
130
|
+
|
|
131
|
+
this.localStore.markThemeSelected(config.name, true);
|
|
132
|
+
|
|
133
|
+
const theme = this.localStore.getAllThemes().find((data) => data.selected)?.theme;
|
|
134
|
+
|
|
135
|
+
if (!theme) {
|
|
136
|
+
throw new Error("No selected theme found!");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.themesStream.push({ theme });
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private async handleOperationCheck(config: OperationCheckConfig): Promise<OperationCheckResult> {
|
|
143
|
+
const operations = Object.keys(this.operations);
|
|
144
|
+
|
|
145
|
+
const isSupported = operations.some((operation) => operation.toLowerCase() === config.operation.toLowerCase());
|
|
146
|
+
|
|
147
|
+
return { isSupported };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private getOsTheme(): "light" | "dark" {
|
|
151
|
+
return window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { constant, Decoder, oneOf, object, array } from "decoder-validate";
|
|
2
|
+
import { AllThemesResponse, SelectThemeConfig, SimpleThemeResponse, ThemesOperationTypes } from "./types";
|
|
3
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
4
|
+
import { nonEmptyStringDecoder } from "../../shared/decoders";
|
|
5
|
+
|
|
6
|
+
export const themesOperationDecoder: Decoder<ThemesOperationTypes> = oneOf<"getCurrent" | "list" | "select" | "operationCheck">(
|
|
7
|
+
constant("getCurrent"),
|
|
8
|
+
constant("list"),
|
|
9
|
+
constant("select"),
|
|
10
|
+
constant("operationCheck")
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const themeDecoder: Decoder<IOConnectBrowser.Themes.Theme> = object({
|
|
14
|
+
displayName: nonEmptyStringDecoder,
|
|
15
|
+
name: nonEmptyStringDecoder
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const simpleThemeResponseDecoder: Decoder<SimpleThemeResponse> = object({
|
|
19
|
+
theme: themeDecoder
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const allThemesResponseDecoder: Decoder<AllThemesResponse> = object({
|
|
23
|
+
themes: array(themeDecoder)
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const selectThemeConfigDecoder: Decoder<SelectThemeConfig> = object({
|
|
27
|
+
name: nonEmptyStringDecoder
|
|
28
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IOConnectBrowser } from "@interopio/browser";
|
|
2
|
+
|
|
3
|
+
export type ThemesOperationTypes = "getCurrent" | "list" | "select" | "operationCheck";
|
|
4
|
+
|
|
5
|
+
export interface SimpleThemeResponse {
|
|
6
|
+
theme: IOConnectBrowser.Themes.Theme;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface AllThemesResponse {
|
|
10
|
+
themes: IOConnectBrowser.Themes.Theme[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface SelectThemeConfig {
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ThemesStoreData {
|
|
18
|
+
theme: IOConnectBrowser.Themes.Theme;
|
|
19
|
+
selected: boolean;
|
|
20
|
+
isUserSelected: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export interface ThemesStoreData {
|
|
25
|
+
theme: IOConnectBrowser.Themes.Theme;
|
|
26
|
+
selected: boolean;
|
|
27
|
+
isUserSelected: boolean;
|
|
28
|
+
}
|