@theia/core 1.77.0 → 1.78.0-next.19
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/lib/browser/catalog.json +208 -32
- package/lib/browser/encoding-registry.js +1 -1
- package/lib/browser/encoding-registry.js.map +1 -1
- package/lib/browser/encoding-registry.spec.d.ts +2 -0
- package/lib/browser/encoding-registry.spec.d.ts.map +1 -0
- package/lib/browser/encoding-registry.spec.js +43 -0
- package/lib/browser/encoding-registry.spec.js.map +1 -0
- package/lib/browser/messaging/service-connection-provider.d.ts.map +1 -1
- package/lib/browser/messaging/service-connection-provider.js +9 -1
- package/lib/browser/messaging/service-connection-provider.js.map +1 -1
- package/lib/browser/messaging/service-connection-provider.spec.d.ts +2 -0
- package/lib/browser/messaging/service-connection-provider.spec.d.ts.map +1 -0
- package/lib/browser/messaging/service-connection-provider.spec.js +76 -0
- package/lib/browser/messaging/service-connection-provider.spec.js.map +1 -0
- package/lib/browser/shell/tab-bars.d.ts +7 -0
- package/lib/browser/shell/tab-bars.d.ts.map +1 -1
- package/lib/browser/shell/tab-bars.js +25 -11
- package/lib/browser/shell/tab-bars.js.map +1 -1
- package/lib/browser/shell/tab-bars.spec.js +20 -0
- package/lib/browser/shell/tab-bars.spec.js.map +1 -1
- package/lib/common/core-preferences.d.ts +1 -0
- package/lib/common/core-preferences.d.ts.map +1 -1
- package/lib/common/core-preferences.js +11 -1
- package/lib/common/core-preferences.js.map +1 -1
- package/lib/common/messaging/handler.d.ts +11 -0
- package/lib/common/messaging/handler.d.ts.map +1 -1
- package/lib/common/messaging/proxy-factory.d.ts +8 -1
- package/lib/common/messaging/proxy-factory.d.ts.map +1 -1
- package/lib/common/messaging/proxy-factory.js +4 -2
- package/lib/common/messaging/proxy-factory.js.map +1 -1
- package/lib/common/messaging/proxy-factory.spec.js +16 -1
- package/lib/common/messaging/proxy-factory.spec.js.map +1 -1
- package/lib/common/shell-environment.d.ts +61 -0
- package/lib/common/shell-environment.d.ts.map +1 -0
- package/lib/common/shell-environment.js +29 -0
- package/lib/common/shell-environment.js.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.d.ts +20 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.d.ts.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.js +72 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.js.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.spec.d.ts +2 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.spec.d.ts.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.spec.js +86 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.spec.js.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-module.d.ts +4 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-module.d.ts.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-module.js +26 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-module.js.map +1 -0
- package/lib/electron-main/electron-main-application.d.ts.map +1 -1
- package/lib/electron-main/electron-main-application.js +12 -4
- package/lib/electron-main/electron-main-application.js.map +1 -1
- package/lib/electron-node/keyboard/electron-backend-keyboard-module.d.ts.map +1 -1
- package/lib/electron-node/keyboard/electron-backend-keyboard-module.js +1 -1
- package/lib/electron-node/keyboard/electron-backend-keyboard-module.js.map +1 -1
- package/lib/electron-node/request/electron-backend-request-service.d.ts +4 -1
- package/lib/electron-node/request/electron-backend-request-service.d.ts.map +1 -1
- package/lib/electron-node/request/electron-backend-request-service.js +56 -13
- package/lib/electron-node/request/electron-backend-request-service.js.map +1 -1
- package/lib/node/backend-application-module.d.ts.map +1 -1
- package/lib/node/backend-application-module.js +13 -5
- package/lib/node/backend-application-module.js.map +1 -1
- package/lib/node/env-variables/env-variables-server.d.ts +13 -3
- package/lib/node/env-variables/env-variables-server.d.ts.map +1 -1
- package/lib/node/env-variables/env-variables-server.js +21 -14
- package/lib/node/env-variables/env-variables-server.js.map +1 -1
- package/lib/node/env-variables/env-variables-server.spec.d.ts +2 -0
- package/lib/node/env-variables/env-variables-server.spec.d.ts.map +1 -0
- package/lib/node/env-variables/env-variables-server.spec.js +83 -0
- package/lib/node/env-variables/env-variables-server.spec.js.map +1 -0
- package/lib/node/i18n/i18n-backend-module.js +2 -2
- package/lib/node/i18n/i18n-backend-module.js.map +1 -1
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/logger-backend-module.js +1 -1
- package/lib/node/logger-backend-module.js.map +1 -1
- package/lib/node/messaging/connection-container-module.d.ts +11 -2
- package/lib/node/messaging/connection-container-module.d.ts.map +1 -1
- package/lib/node/messaging/connection-container-module.js +13 -2
- package/lib/node/messaging/connection-container-module.js.map +1 -1
- package/lib/node/messaging/connection-container-module.spec.d.ts +2 -0
- package/lib/node/messaging/connection-container-module.spec.d.ts.map +1 -0
- package/lib/node/messaging/connection-container-module.spec.js +37 -0
- package/lib/node/messaging/connection-container-module.spec.js.map +1 -0
- package/lib/node/messaging/default-messaging-service.d.ts +33 -4
- package/lib/node/messaging/default-messaging-service.d.ts.map +1 -1
- package/lib/node/messaging/default-messaging-service.js +52 -10
- package/lib/node/messaging/default-messaging-service.js.map +1 -1
- package/lib/node/messaging/gated-channel-multiplexer.d.ts +20 -0
- package/lib/node/messaging/gated-channel-multiplexer.d.ts.map +1 -0
- package/lib/node/messaging/gated-channel-multiplexer.js +50 -0
- package/lib/node/messaging/gated-channel-multiplexer.js.map +1 -0
- package/lib/node/messaging/gated-channel-multiplexer.spec.d.ts +2 -0
- package/lib/node/messaging/gated-channel-multiplexer.spec.d.ts.map +1 -0
- package/lib/node/messaging/gated-channel-multiplexer.spec.js +74 -0
- package/lib/node/messaging/gated-channel-multiplexer.spec.js.map +1 -0
- package/lib/node/messaging/index.d.ts +1 -0
- package/lib/node/messaging/index.d.ts.map +1 -1
- package/lib/node/messaging/index.js +1 -0
- package/lib/node/messaging/index.js.map +1 -1
- package/lib/node/messaging/messaging-backend-module.js +1 -1
- package/lib/node/messaging/messaging-backend-module.js.map +1 -1
- package/lib/node/messaging/messaging-service.d.ts +5 -1
- package/lib/node/messaging/messaging-service.d.ts.map +1 -1
- package/lib/node/messaging/messaging-service.js.map +1 -1
- package/lib/node/messaging/test/default-messaging-service.spec.js +82 -2
- package/lib/node/messaging/test/default-messaging-service.spec.js.map +1 -1
- package/lib/node/messaging/websocket-frontend-connection-service.d.ts +1 -0
- package/lib/node/messaging/websocket-frontend-connection-service.d.ts.map +1 -1
- package/lib/node/messaging/websocket-frontend-connection-service.js +8 -0
- package/lib/node/messaging/websocket-frontend-connection-service.js.map +1 -1
- package/lib/node/messaging/websocket-frontend-connection-service.spec.d.ts +2 -0
- package/lib/node/messaging/websocket-frontend-connection-service.spec.d.ts.map +1 -0
- package/lib/node/messaging/websocket-frontend-connection-service.spec.js +141 -0
- package/lib/node/messaging/websocket-frontend-connection-service.spec.js.map +1 -0
- package/lib/node/performance/measurement-backend-bindings.js +1 -1
- package/lib/node/performance/measurement-backend-bindings.js.map +1 -1
- package/lib/node/process-utils.d.ts +125 -2
- package/lib/node/process-utils.d.ts.map +1 -1
- package/lib/node/process-utils.js +297 -25
- package/lib/node/process-utils.js.map +1 -1
- package/lib/node/process-utils.slow-spec.js +78 -3
- package/lib/node/process-utils.slow-spec.js.map +1 -1
- package/lib/node/process-utils.spec.js +237 -2
- package/lib/node/process-utils.spec.js.map +1 -1
- package/lib/node/shell-environment.d.ts +107 -0
- package/lib/node/shell-environment.d.ts.map +1 -0
- package/lib/node/shell-environment.js +396 -0
- package/lib/node/shell-environment.js.map +1 -0
- package/lib/node/shell-environment.spec.d.ts +2 -0
- package/lib/node/shell-environment.spec.d.ts.map +1 -0
- package/lib/node/shell-environment.spec.js +348 -0
- package/lib/node/shell-environment.spec.js.map +1 -0
- package/lib/node/test/exiting-backend.d.ts +5 -0
- package/lib/node/test/exiting-backend.d.ts.map +1 -1
- package/lib/node/test/exiting-backend.js +16 -3
- package/lib/node/test/exiting-backend.js.map +1 -1
- package/package.json +7 -4
- package/src/browser/encoding-registry.spec.ts +48 -0
- package/src/browser/encoding-registry.ts +1 -1
- package/src/browser/messaging/service-connection-provider.spec.ts +88 -0
- package/src/browser/messaging/service-connection-provider.ts +9 -2
- package/src/browser/shell/tab-bars.spec.ts +22 -0
- package/src/browser/shell/tab-bars.ts +25 -12
- package/src/common/core-preferences.ts +12 -1
- package/src/common/messaging/handler.ts +11 -0
- package/src/common/messaging/proxy-factory.spec.ts +17 -1
- package/src/common/messaging/proxy-factory.ts +16 -2
- package/src/common/shell-environment.ts +81 -0
- package/src/electron-browser/shell-environment/electron-shell-environment-contribution.spec.ts +95 -0
- package/src/electron-browser/shell-environment/electron-shell-environment-contribution.ts +72 -0
- package/src/electron-browser/shell-environment/electron-shell-environment-module.ts +29 -0
- package/src/electron-main/electron-main-application.ts +15 -4
- package/src/electron-node/keyboard/electron-backend-keyboard-module.ts +2 -1
- package/src/electron-node/request/electron-backend-request-service.ts +59 -11
- package/src/node/backend-application-module.ts +19 -5
- package/src/node/env-variables/env-variables-server.spec.ts +93 -0
- package/src/node/env-variables/env-variables-server.ts +22 -14
- package/src/node/i18n/i18n-backend-module.ts +2 -2
- package/src/node/index.ts +1 -0
- package/src/node/logger-backend-module.ts +1 -1
- package/src/node/messaging/connection-container-module.spec.ts +39 -0
- package/src/node/messaging/connection-container-module.ts +16 -4
- package/src/node/messaging/default-messaging-service.ts +64 -10
- package/src/node/messaging/gated-channel-multiplexer.spec.ts +80 -0
- package/src/node/messaging/gated-channel-multiplexer.ts +52 -0
- package/src/node/messaging/index.ts +1 -0
- package/src/node/messaging/messaging-backend-module.ts +1 -1
- package/src/node/messaging/messaging-service.ts +5 -1
- package/src/node/messaging/test/default-messaging-service.spec.ts +89 -2
- package/src/node/messaging/websocket-frontend-connection-service.spec.ts +158 -0
- package/src/node/messaging/websocket-frontend-connection-service.ts +9 -0
- package/src/node/performance/measurement-backend-bindings.ts +1 -1
- package/src/node/process-utils.slow-spec.ts +90 -3
- package/src/node/process-utils.spec.ts +268 -3
- package/src/node/process-utils.ts +342 -24
- package/src/node/shell-environment.spec.ts +388 -0
- package/src/node/shell-environment.ts +406 -0
- package/src/node/test/exiting-backend.ts +17 -3
|
@@ -24,7 +24,8 @@ export default new ContainerModule(bind => {
|
|
|
24
24
|
bind(KeyboardLayoutProvider).toService(ElectronKeyboardLayoutProvider);
|
|
25
25
|
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
26
26
|
new RpcConnectionHandler(keyboardPath, () =>
|
|
27
|
-
ctx.container.get(KeyboardLayoutProvider)
|
|
27
|
+
ctx.container.get(KeyboardLayoutProvider),
|
|
28
|
+
{ independentOfShellEnvironment: true }
|
|
28
29
|
)
|
|
29
30
|
).inSingletonScope();
|
|
30
31
|
});
|
|
@@ -21,12 +21,34 @@ import { ILogger } from '../../common/index.js';
|
|
|
21
21
|
|
|
22
22
|
decorate(injectable(), NodeRequestService);
|
|
23
23
|
|
|
24
|
+
type ProxyResponseHandler = (result: string | undefined) => void;
|
|
25
|
+
|
|
24
26
|
@injectable()
|
|
25
27
|
export class ElectronBackendRequestService extends NodeRequestService {
|
|
26
28
|
|
|
27
29
|
@inject(ILogger) @named('core:ElectronBackendRequestService')
|
|
28
30
|
protected readonly logger: ILogger;
|
|
29
31
|
|
|
32
|
+
private static readonly pendingProxyRequests = new Map<string, ProxyResponseHandler>();
|
|
33
|
+
private static proxyResponseListenerAttached = false;
|
|
34
|
+
|
|
35
|
+
private static attachProxyResponseListener(): void {
|
|
36
|
+
if (this.proxyResponseListenerAttached || !process.send) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.proxyResponseListenerAttached = true;
|
|
40
|
+
process.on('message', (msg: unknown) => {
|
|
41
|
+
const response = msg as { type: string, id: string, result: string };
|
|
42
|
+
if (response?.type === 'resolve-proxy-response' && response.id) {
|
|
43
|
+
const handler = this.pendingProxyRequests.get(response.id);
|
|
44
|
+
if (handler) {
|
|
45
|
+
this.pendingProxyRequests.delete(response.id);
|
|
46
|
+
handler(response.result);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
30
52
|
override async getProxyUrl(url: string): Promise<string | undefined> {
|
|
31
53
|
if (this.proxyUrl) {
|
|
32
54
|
return this.proxyUrl;
|
|
@@ -34,8 +56,15 @@ export class ElectronBackendRequestService extends NodeRequestService {
|
|
|
34
56
|
try {
|
|
35
57
|
const proxy = await this.resolveProxy(url);
|
|
36
58
|
if (proxy && proxy !== 'DIRECT') {
|
|
37
|
-
|
|
38
|
-
|
|
59
|
+
// Handle fallback proxies separated by semicolons, e.g., "PROXY proxy:8080; DIRECT"
|
|
60
|
+
const firstProxy = proxy.split(';')[0].trim();
|
|
61
|
+
const proxyType = firstProxy.split(' ')[0]; // e.g., "PROXY", "HTTPS"
|
|
62
|
+
const proxyHost = firstProxy.split(' ')[1];
|
|
63
|
+
if (!proxyHost) {
|
|
64
|
+
// Malformed proxy string, fall back
|
|
65
|
+
return super.getProxyUrl(url);
|
|
66
|
+
}
|
|
67
|
+
return this.buildProxyUrl(proxyHost, proxyType);
|
|
39
68
|
}
|
|
40
69
|
} catch (e) {
|
|
41
70
|
this.logger.error('Could not resolve electron proxy.', e);
|
|
@@ -44,20 +73,39 @@ export class ElectronBackendRequestService extends NodeRequestService {
|
|
|
44
73
|
}
|
|
45
74
|
|
|
46
75
|
override async resolveProxy(url: string): Promise<string | undefined> {
|
|
47
|
-
|
|
48
|
-
|
|
76
|
+
if (!process.send) {
|
|
77
|
+
// Running in --no-cluster mode (in the Electron main process): call session directly.
|
|
78
|
+
const { session } = await import('../../../electron-shared/electron/index.cjs');
|
|
79
|
+
return session.defaultSession.resolveProxy(url);
|
|
80
|
+
}
|
|
81
|
+
// Running as a forked child process: ask the main process via Node IPC.
|
|
82
|
+
return new Promise<string | undefined>(resolve => {
|
|
83
|
+
const id = Math.random().toString(36).slice(2);
|
|
84
|
+
ElectronBackendRequestService.attachProxyResponseListener();
|
|
85
|
+
const timer = setTimeout(() => {
|
|
86
|
+
ElectronBackendRequestService.pendingProxyRequests.delete(id);
|
|
87
|
+
resolve(undefined);
|
|
88
|
+
}, 5000);
|
|
89
|
+
ElectronBackendRequestService.pendingProxyRequests.set(id, (result: string | undefined) => {
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
resolve(result);
|
|
92
|
+
});
|
|
93
|
+
process.send!({ type: 'resolve-proxy', id, url });
|
|
94
|
+
});
|
|
49
95
|
}
|
|
50
96
|
|
|
51
|
-
protected buildProxyUrl(
|
|
97
|
+
protected buildProxyUrl(proxyHost: string, proxyType: string): string | undefined {
|
|
98
|
+
if (proxyType !== 'HTTPS' && proxyType !== 'PROXY') {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
52
102
|
if (proxyHost.startsWith('http://') || proxyHost.startsWith('https://')) {
|
|
53
103
|
return proxyHost;
|
|
54
104
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
return proxyHost;
|
|
105
|
+
|
|
106
|
+
return proxyType === 'HTTPS'
|
|
107
|
+
? 'https://' + proxyHost
|
|
108
|
+
: 'http://' + proxyHost;
|
|
61
109
|
}
|
|
62
110
|
|
|
63
111
|
protected override async processOptions(options: NodeRequestOptions): Promise<NodeRequestOptions> {
|
|
@@ -44,6 +44,8 @@ import { ApplicationServerImpl } from './application-server.js';
|
|
|
44
44
|
import { ApplicationServer, applicationPath } from '../common/application-protocol.js';
|
|
45
45
|
import { EnvVariablesServer, envVariablesPath } from './../common/env-variables/index.js';
|
|
46
46
|
import { EnvVariablesServerImpl } from './env-variables/index.js';
|
|
47
|
+
import { ShellEnvironmentServer, shellEnvironmentPath } from '../common/shell-environment.js';
|
|
48
|
+
import { ShellEnvironmentServerImpl } from './shell-environment.js';
|
|
47
49
|
import { ConnectionContainerModule } from './messaging/connection-container-module.js';
|
|
48
50
|
import { QuickInputService, quickInputServicePath, QuickPickService, quickPickServicePath } from '../common/quick-pick-service.js';
|
|
49
51
|
import { WsRequestValidator, WsRequestValidatorContribution } from './ws-request-validators.js';
|
|
@@ -115,9 +117,12 @@ export const backendApplicationModule = new ContainerModule(bind => {
|
|
|
115
117
|
|
|
116
118
|
bind(ApplicationServerImpl).toSelf().inSingletonScope();
|
|
117
119
|
bind(ApplicationServer).toService(ApplicationServerImpl);
|
|
120
|
+
// The services of this module start no processes and the frontend needs them to start up,
|
|
121
|
+
// so they are not held until the login shell environment is known (see ConnectionHandler.independentOfShellEnvironment).
|
|
118
122
|
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
119
123
|
new RpcConnectionHandler(applicationPath, () =>
|
|
120
|
-
ctx.container.get(ApplicationServer)
|
|
124
|
+
ctx.container.get(ApplicationServer),
|
|
125
|
+
{ independentOfShellEnvironment: true }
|
|
121
126
|
)
|
|
122
127
|
).inSingletonScope();
|
|
123
128
|
|
|
@@ -126,7 +131,15 @@ export const backendApplicationModule = new ContainerModule(bind => {
|
|
|
126
131
|
new RpcConnectionHandler(envVariablesPath, () => {
|
|
127
132
|
const envVariablesServer = ctx.container.get<EnvVariablesServer>(EnvVariablesServer);
|
|
128
133
|
return envVariablesServer;
|
|
129
|
-
})
|
|
134
|
+
}, { independentOfShellEnvironment: true })
|
|
135
|
+
).inSingletonScope();
|
|
136
|
+
|
|
137
|
+
bind(ShellEnvironmentServerImpl).toSelf().inSingletonScope();
|
|
138
|
+
bind(ShellEnvironmentServer).toService(ShellEnvironmentServerImpl);
|
|
139
|
+
bind(BackendApplicationContribution).toService(ShellEnvironmentServerImpl);
|
|
140
|
+
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
141
|
+
new RpcConnectionHandler(shellEnvironmentPath, () => ctx.container.get<ShellEnvironmentServer>(ShellEnvironmentServer),
|
|
142
|
+
{ independentOfShellEnvironment: true })
|
|
130
143
|
).inSingletonScope();
|
|
131
144
|
|
|
132
145
|
bind(ApplicationPackage).toConstantValue(new ApplicationPackage({ projectPath: BackendApplicationPath }));
|
|
@@ -135,7 +148,8 @@ export const backendApplicationModule = new ContainerModule(bind => {
|
|
|
135
148
|
bindRootContributionProvider(bind, WsRequestValidatorContribution);
|
|
136
149
|
bind(KeyStoreService).to(KeyStoreServiceImpl).inSingletonScope();
|
|
137
150
|
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
138
|
-
new RpcConnectionHandler(keyStoreServicePath, () => ctx.container.get<KeyStoreService>(KeyStoreService)
|
|
151
|
+
new RpcConnectionHandler(keyStoreServicePath, () => ctx.container.get<KeyStoreService>(KeyStoreService),
|
|
152
|
+
{ independentOfShellEnvironment: true })
|
|
139
153
|
).inSingletonScope();
|
|
140
154
|
|
|
141
155
|
bind(ContributionFilterRegistry).to(ContributionFilterRegistryImpl).inSingletonScope();
|
|
@@ -146,7 +160,7 @@ export const backendApplicationModule = new ContainerModule(bind => {
|
|
|
146
160
|
bind(OSBackendProviderImpl).toSelf().inSingletonScope();
|
|
147
161
|
bind(OSBackendProvider).toService(OSBackendProviderImpl);
|
|
148
162
|
bind(ConnectionHandler).toDynamicValue(
|
|
149
|
-
ctx => new RpcConnectionHandler(OSBackendProviderPath, () => ctx.container.get(OSBackendProvider))
|
|
163
|
+
ctx => new RpcConnectionHandler(OSBackendProviderPath, () => ctx.container.get(OSBackendProvider), { independentOfShellEnvironment: true })
|
|
150
164
|
).inSingletonScope();
|
|
151
165
|
|
|
152
166
|
bind(ProxyCliContribution).toSelf().inSingletonScope();
|
|
@@ -157,7 +171,7 @@ export const backendApplicationModule = new ContainerModule(bind => {
|
|
|
157
171
|
bindRootContributionProvider(bind, BackendRequestAllowedContribution);
|
|
158
172
|
bind(BackendRequestFacade).toSelf().inSingletonScope();
|
|
159
173
|
bind(ConnectionHandler).toDynamicValue(
|
|
160
|
-
ctx => new RpcConnectionHandler(REQUEST_SERVICE_PATH, () => ctx.container.get(BackendRequestFacade))
|
|
174
|
+
ctx => new RpcConnectionHandler(REQUEST_SERVICE_PATH, () => ctx.container.get(BackendRequestFacade), { independentOfShellEnvironment: true })
|
|
161
175
|
).inSingletonScope();
|
|
162
176
|
|
|
163
177
|
bindNodeStopwatch(bind);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import { Container } from 'inversify';
|
|
19
|
+
import { ILogger } from '../../common/logger.js';
|
|
20
|
+
import { isWindows } from '../../common/os.js';
|
|
21
|
+
import { MockLogger } from '../../common/test/mock-logger.js';
|
|
22
|
+
import { EnvVariable } from '../../common/env-variables/index.js';
|
|
23
|
+
import { EnvVariablesServerImpl } from './env-variables-server.js';
|
|
24
|
+
|
|
25
|
+
describe('EnvVariablesServerImpl', () => {
|
|
26
|
+
|
|
27
|
+
const variable = 'THEIA_ENV_VARIABLES_SERVER_SPEC';
|
|
28
|
+
// the server reports the names in lower case on Windows, where the environment is case-insensitive
|
|
29
|
+
const name = isWindows ? variable.toLowerCase() : variable;
|
|
30
|
+
let configDir: string | undefined;
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
configDir = process.env.THEIA_CONFIG_DIR;
|
|
34
|
+
// keeps the server from looking the configuration directory up in the application configuration
|
|
35
|
+
process.env.THEIA_CONFIG_DIR = '/tmp/theia-env-variables-server-spec';
|
|
36
|
+
delete process.env[variable];
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
if (configDir === undefined) {
|
|
41
|
+
delete process.env.THEIA_CONFIG_DIR;
|
|
42
|
+
} else {
|
|
43
|
+
process.env.THEIA_CONFIG_DIR = configDir;
|
|
44
|
+
}
|
|
45
|
+
delete process.env[variable];
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const create = (type: typeof EnvVariablesServerImpl = EnvVariablesServerImpl): EnvVariablesServerImpl => {
|
|
49
|
+
const container = new Container();
|
|
50
|
+
container.bind(ILogger).to(MockLogger);
|
|
51
|
+
container.bind(type).toSelf();
|
|
52
|
+
return container.get(type);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** A server that reports an environment of its own, as a subclass might to mask or add variables. */
|
|
56
|
+
class MaskedEnvVariablesServer extends EnvVariablesServerImpl {
|
|
57
|
+
protected override get envs(): { [key: string]: EnvVariable } {
|
|
58
|
+
return { [name]: { name, value: 'masked' } };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
it('reports the environment as it is at the time of the request', async () => {
|
|
63
|
+
const server = create();
|
|
64
|
+
expect(await server.getValue(variable)).to.be.undefined;
|
|
65
|
+
expect((await server.getVariables()).map(env => env.name)).not.to.include(name);
|
|
66
|
+
|
|
67
|
+
process.env[variable] = 'set after the server was created';
|
|
68
|
+
expect(await server.getValue(variable)).to.deep.equal({ name, value: 'set after the server was created' });
|
|
69
|
+
expect(await server.getVariables()).to.deep.include({ name, value: 'set after the server was created' });
|
|
70
|
+
|
|
71
|
+
process.env[variable] = 'changed';
|
|
72
|
+
expect(await server.getValue(variable)).to.deep.equal({ name, value: 'changed' });
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('answers a single variable from the environment that it reports as a whole', async () => {
|
|
76
|
+
const server = create(MaskedEnvVariablesServer);
|
|
77
|
+
process.env[variable] = 'in the process';
|
|
78
|
+
expect(await server.getVariables()).to.deep.equal([{ name, value: 'masked' }]);
|
|
79
|
+
expect(await server.getValue(variable)).to.deep.equal({ name, value: 'masked' });
|
|
80
|
+
expect(await server.getValue('PATH')).to.be.undefined;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('looks a variable up regardless of case on Windows only', async () => {
|
|
84
|
+
const server = create();
|
|
85
|
+
process.env[variable] = 'value';
|
|
86
|
+
const found = await server.getValue(variable.toLowerCase());
|
|
87
|
+
if (isWindows) {
|
|
88
|
+
expect(found).to.deep.equal({ name, value: 'value' });
|
|
89
|
+
} else {
|
|
90
|
+
expect(found).to.be.undefined;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -26,10 +26,15 @@ import { BackendApplicationPath } from '../backend-application.js';
|
|
|
26
26
|
import { BackendApplicationConfigProvider } from '../backend-application-config-provider.js';
|
|
27
27
|
import { ILogger } from '../../common/logger.js';
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Serves the environment variables of the backend process.
|
|
31
|
+
*
|
|
32
|
+
* The variables are read from `process.env` on every request rather than captured once, because the backend
|
|
33
|
+
* takes the `PATH` of the user's login shell after it has started, see `ShellEnvironmentServer`.
|
|
34
|
+
*/
|
|
29
35
|
@injectable()
|
|
30
36
|
export class EnvVariablesServerImpl implements EnvVariablesServer {
|
|
31
37
|
|
|
32
|
-
protected readonly envs: { [key: string]: EnvVariable } = {};
|
|
33
38
|
protected readonly homeDirUri = FileUri.create(homedir()).toString();
|
|
34
39
|
protected readonly configDirUri: Promise<string>;
|
|
35
40
|
protected readonly pathExistenceCache: { [key: string]: boolean } = {};
|
|
@@ -40,14 +45,19 @@ export class EnvVariablesServerImpl implements EnvVariablesServer {
|
|
|
40
45
|
constructor() {
|
|
41
46
|
this.configDirUri = this.createConfigDirUri();
|
|
42
47
|
this.configDirUri.then(configDirUri => this.logger.info(`Configuration directory URI: '${configDirUri}'`));
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The variables of `process.env` as of now, keyed by name, which is lower-cased on Windows.
|
|
52
|
+
* Both `getVariables` and `getValue` answer from it.
|
|
53
|
+
*/
|
|
54
|
+
protected get envs(): { [key: string]: EnvVariable } {
|
|
55
|
+
const envs: { [key: string]: EnvVariable } = {};
|
|
56
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
57
|
+
const name = isWindows ? key.toLowerCase() : key;
|
|
58
|
+
envs[name] = { name, value };
|
|
59
|
+
}
|
|
60
|
+
return envs;
|
|
51
61
|
}
|
|
52
62
|
|
|
53
63
|
protected async createConfigDirUri(): Promise<string> {
|
|
@@ -78,14 +88,12 @@ export class EnvVariablesServerImpl implements EnvVariablesServer {
|
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
async getVariables(): Promise<EnvVariable[]> {
|
|
81
|
-
return Object.
|
|
91
|
+
return Object.values(this.envs);
|
|
82
92
|
}
|
|
83
93
|
|
|
84
94
|
async getValue(key: string): Promise<EnvVariable | undefined> {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
return this.envs[key];
|
|
95
|
+
// `process.env` is case-insensitive on Windows, where the name is reported in lower case as in `getVariables`.
|
|
96
|
+
return this.envs[isWindows ? key.toLowerCase() : key];
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
getConfigDirUri(): Promise<string> {
|
|
@@ -27,7 +27,7 @@ import { BackendApplicationContribution } from '../backend-application.js';
|
|
|
27
27
|
export default new ContainerModule(bind => {
|
|
28
28
|
bind(LocalizationProvider).toSelf().inSingletonScope();
|
|
29
29
|
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
30
|
-
new RpcConnectionHandler(localizationPath, () => ctx.container.get(LocalizationProvider))
|
|
30
|
+
new RpcConnectionHandler(localizationPath, () => ctx.container.get(LocalizationProvider), { independentOfShellEnvironment: true })
|
|
31
31
|
).inSingletonScope();
|
|
32
32
|
bind(LocalizationRegistry).toSelf().inSingletonScope();
|
|
33
33
|
bindRootContributionProvider(bind, LocalizationContribution);
|
|
@@ -35,7 +35,7 @@ export default new ContainerModule(bind => {
|
|
|
35
35
|
bind(LocalizationServer).toService(LocalizationServerImpl);
|
|
36
36
|
bind(BackendApplicationContribution).toService(LocalizationServerImpl);
|
|
37
37
|
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
38
|
-
new RpcConnectionHandler(LocalizationServerPath, () => ctx.container.get(LocalizationServer))
|
|
38
|
+
new RpcConnectionHandler(LocalizationServerPath, () => ctx.container.get(LocalizationServer), { independentOfShellEnvironment: true })
|
|
39
39
|
).inSingletonScope();
|
|
40
40
|
bind(TheiaLocalizationContribution).toSelf().inSingletonScope();
|
|
41
41
|
bind(LocalizationContribution).toService(TheiaLocalizationContribution);
|
package/src/node/index.ts
CHANGED
|
@@ -23,5 +23,6 @@ export * from './cli.js';
|
|
|
23
23
|
export * from './setting-service.js';
|
|
24
24
|
export { FileSystemLocking } from './filesystem-locking.js';
|
|
25
25
|
export { BundledResourceProvider } from './bundled-resource-provider.js';
|
|
26
|
+
export { ShellEnvironmentServerImpl, ShellEnvironmentTimeoutError } from './shell-environment.js';
|
|
26
27
|
export { BackendRequestAllowedContribution } from './request/backend-request-facade.js';
|
|
27
28
|
export { HttpConnectionValidator } from './hosting/browser-connection-token.js';
|
|
@@ -82,6 +82,6 @@ export const loggerBackendModule = new ContainerModule(bind => {
|
|
|
82
82
|
dispatching.clients.add(client);
|
|
83
83
|
client.onDidCloseConnection(() => dispatching.clients.delete(client));
|
|
84
84
|
return container.get<ILoggerServer>(ILoggerServer);
|
|
85
|
-
})
|
|
85
|
+
}, { independentOfShellEnvironment: true })
|
|
86
86
|
).inSingletonScope();
|
|
87
87
|
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import { Container } from 'inversify';
|
|
19
|
+
import { ConnectionHandler } from '../../common/messaging/handler.js';
|
|
20
|
+
import { ConnectionContainerModule } from './connection-container-module.js';
|
|
21
|
+
|
|
22
|
+
describe('ConnectionContainerModule', () => {
|
|
23
|
+
|
|
24
|
+
it('declares frontend services independent of the shell environment, and backend services as told', () => {
|
|
25
|
+
const BackendService = Symbol('BackendService');
|
|
26
|
+
const module = ConnectionContainerModule.create(({ bind, bindFrontendService, bindBackendService }) => {
|
|
27
|
+
bindFrontendService('/services/frontend', Symbol('FrontendService'));
|
|
28
|
+
bind(BackendService).toConstantValue({});
|
|
29
|
+
bindBackendService('/services/held', BackendService);
|
|
30
|
+
bindBackendService('/services/independent', BackendService, undefined, { independentOfShellEnvironment: true });
|
|
31
|
+
});
|
|
32
|
+
const container = new Container();
|
|
33
|
+
container.load(module);
|
|
34
|
+
const independence = new Map(container.getAll<ConnectionHandler>(ConnectionHandler).map(handler => [handler.path, handler.independentOfShellEnvironment]));
|
|
35
|
+
expect(independence.get('/services/frontend')).to.be.true;
|
|
36
|
+
expect(independence.get('/services/held')).to.be.false;
|
|
37
|
+
expect(independence.get('/services/independent')).to.be.true;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
18
18
|
|
|
19
19
|
import { interfaces, ContainerModule } from 'inversify';
|
|
20
|
-
import { RpcProxyFactory, ConnectionHandler, RpcConnectionHandler, RpcProxy } from '../../common/index.js';
|
|
20
|
+
import { RpcProxyFactory, ConnectionHandler, RpcConnectionHandler, RpcConnectionHandlerOptions, RpcProxy } from '../../common/index.js';
|
|
21
21
|
|
|
22
22
|
export type BindFrontendService = <T extends object>(path: string, serviceIdentifier: interfaces.ServiceIdentifier<T>) => interfaces.BindingWhenOnSyntax<T>;
|
|
23
23
|
export type BindBackendService = <T extends object, C extends object = object>(
|
|
24
|
-
path: string, serviceIdentifier: interfaces.ServiceIdentifier<T>, onActivation?: (service: T, proxy: RpcProxy<C>) => T
|
|
24
|
+
path: string, serviceIdentifier: interfaces.ServiceIdentifier<T>, onActivation?: (service: T, proxy: RpcProxy<C>) => T,
|
|
25
|
+
options?: RpcConnectionHandlerOptions<T>
|
|
25
26
|
) => void;
|
|
26
27
|
export type ConnectionContainerModuleCallBack = (registry: {
|
|
27
28
|
bind: interfaces.Bind
|
|
@@ -61,6 +62,15 @@ export type ConnectionContainerModuleCallBack = (registry: {
|
|
|
61
62
|
* }
|
|
62
63
|
* ```
|
|
63
64
|
*
|
|
65
|
+
* A backend service is held until the environment of the user's login shell is known, unless it is declared independent of it,
|
|
66
|
+
* see `ConnectionHandler.independentOfShellEnvironment`:
|
|
67
|
+
* ```ts
|
|
68
|
+
* const myConnectionModule3 = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
|
|
69
|
+
* bind(MyStartupService).toSelf().inSingletonScope();
|
|
70
|
+
* bindBackendService(myStartupServicePath, MyStartupService, undefined, { independentOfShellEnvironment: true });
|
|
71
|
+
* });
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
64
74
|
* #### Injecting a frontend service
|
|
65
75
|
* ```ts
|
|
66
76
|
* @injectable()
|
|
@@ -78,16 +88,18 @@ export const ConnectionContainerModule: symbol & { create(callback: ConnectionCo
|
|
|
78
88
|
const service = serviceFactory.createProxy();
|
|
79
89
|
bind<ConnectionHandler>(ConnectionHandler).toConstantValue({
|
|
80
90
|
path,
|
|
91
|
+
// the backend only calls the frontend through this channel, so there is nothing to hold
|
|
92
|
+
independentOfShellEnvironment: true,
|
|
81
93
|
onConnection: connection => serviceFactory.listen(connection)
|
|
82
94
|
});
|
|
83
95
|
return bind(serviceIdentifier).toConstantValue(service as any);
|
|
84
96
|
};
|
|
85
|
-
const bindBackendService: BindBackendService = (path, serviceIdentifier, onActivation) => {
|
|
97
|
+
const bindBackendService: BindBackendService = (path, serviceIdentifier, onActivation, options) => {
|
|
86
98
|
bind(ConnectionHandler).toDynamicValue(context =>
|
|
87
99
|
new RpcConnectionHandler<any>(path, proxy => {
|
|
88
100
|
const service = context.container.get(serviceIdentifier);
|
|
89
101
|
return onActivation ? onActivation(service, proxy) : service;
|
|
90
|
-
})
|
|
102
|
+
}, options)
|
|
91
103
|
).inSingletonScope();
|
|
92
104
|
};
|
|
93
105
|
callback({ bind, unbind, isBound, rebind, bindFrontendService, bindBackendService });
|
|
@@ -23,6 +23,8 @@ import { Channel, ChannelMultiplexer } from '../../common/message-rpc/channel.js
|
|
|
23
23
|
import { FrontendConnectionService } from './frontend-connection-service.js';
|
|
24
24
|
import { BackendApplicationContribution } from '../backend-application.js';
|
|
25
25
|
import { ILogger } from '../../common/logger.js';
|
|
26
|
+
import { ShellEnvironmentServer } from '../../common/shell-environment.js';
|
|
27
|
+
import { GatedChannelMultiplexer } from './gated-channel-multiplexer.js';
|
|
26
28
|
|
|
27
29
|
export const MessagingContainer = Symbol('MessagingContainer');
|
|
28
30
|
export const MainChannel = Symbol('MainChannel');
|
|
@@ -44,6 +46,9 @@ export class DefaultMessagingService implements MessagingService, BackendApplica
|
|
|
44
46
|
@inject(ContributionProvider) @named(MessagingService.Contribution)
|
|
45
47
|
protected readonly contributions: ContributionProvider<MessagingService.Contribution>;
|
|
46
48
|
|
|
49
|
+
@inject(ShellEnvironmentServer)
|
|
50
|
+
protected readonly shellEnvironment: ShellEnvironmentServer;
|
|
51
|
+
|
|
47
52
|
protected readonly channelHandlers = new ConnectionHandlers<Channel>();
|
|
48
53
|
|
|
49
54
|
initialize(): void {
|
|
@@ -57,13 +62,13 @@ export class DefaultMessagingService implements MessagingService, BackendApplica
|
|
|
57
62
|
this.frontendConnectionService.registerConnectionHandler(path, callback);
|
|
58
63
|
}
|
|
59
64
|
|
|
60
|
-
registerChannelHandler(spec: string, callback: (params: MessagingService.PathParams, channel: Channel) => void): void {
|
|
61
|
-
this.channelHandlers.push(spec, (params, channel) => callback(params, channel));
|
|
65
|
+
registerChannelHandler(spec: string, callback: (params: MessagingService.PathParams, channel: Channel) => void, options?: MessagingService.ChannelHandlerOptions): void {
|
|
66
|
+
this.channelHandlers.push(spec, (params, channel) => callback(params, channel), options);
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
protected handleConnection(channel: Channel): void {
|
|
65
|
-
const multiplexer = new ChannelMultiplexer(channel);
|
|
66
70
|
const channelHandlers = this.getConnectionChannelHandlers(channel);
|
|
71
|
+
const multiplexer = this.createChannelMultiplexer(channel, channelHandlers);
|
|
67
72
|
multiplexer.onDidOpenChannel(event => {
|
|
68
73
|
if (channelHandlers.route(event.id, event.channel)) {
|
|
69
74
|
this.logger.debug(`Opening channel for service path '${event.id}'.`);
|
|
@@ -72,6 +77,35 @@ export class DefaultMessagingService implements MessagingService, BackendApplica
|
|
|
72
77
|
});
|
|
73
78
|
}
|
|
74
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Creates the multiplexer of the service channels on the main channel of a frontend. It holds the channels of the
|
|
82
|
+
* services that depend on the environment of the user's login shell until that environment is known, see {@link holdChannel}.
|
|
83
|
+
*/
|
|
84
|
+
protected createChannelMultiplexer(mainChannel: Channel, channelHandlers: ConnectionHandlers<Channel>): ChannelMultiplexer {
|
|
85
|
+
return new GatedChannelMultiplexer(mainChannel, id => this.holdChannel(id, channelHandlers));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Holds the opening of a service channel until the `PATH` of the user's login shell has been applied to `process.env`,
|
|
90
|
+
* unless the service is declared independent of it (see `ConnectionHandler.independentOfShellEnvironment`). Terminals, tasks,
|
|
91
|
+
* debug sessions, the plugin host and whatever else runs the user's tools are requested through these channels, so by the
|
|
92
|
+
* time a request arrives, they find those tools. In a browser deployment and on Windows, nothing is held.
|
|
93
|
+
*
|
|
94
|
+
* @returns the promise to wait for, or `undefined` if the channel is not to be held
|
|
95
|
+
*/
|
|
96
|
+
protected holdChannel(id: string, channelHandlers: ConnectionHandlers<Channel>): Promise<void> | undefined {
|
|
97
|
+
if (channelHandlers.isIndependentOfShellEnvironment(id)) {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
const start = performance.now();
|
|
101
|
+
return this.shellEnvironment.whenResolved().then(() => {
|
|
102
|
+
const held = performance.now() - start;
|
|
103
|
+
if (held >= 10) {
|
|
104
|
+
this.logger.debug(`Held the channel '${id}' for ${held.toFixed(0)} ms until the login shell environment was resolved.`);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
75
109
|
protected createMainChannelContainer(socket: Channel): Container {
|
|
76
110
|
const connectionContainer: Container = this.container.createChild() as Container;
|
|
77
111
|
connectionContainer.bind(MainChannel).toConstantValue(socket);
|
|
@@ -88,7 +122,7 @@ export class DefaultMessagingService implements MessagingService, BackendApplica
|
|
|
88
122
|
for (const connectionHandler of connectionHandlers.getContributions(true)) {
|
|
89
123
|
connectionChannelHandlers.push(connectionHandler.path, (_, channel) => {
|
|
90
124
|
connectionHandler.onConnection(channel);
|
|
91
|
-
});
|
|
125
|
+
}, { independentOfShellEnvironment: connectionHandler.independentOfShellEnvironment });
|
|
92
126
|
}
|
|
93
127
|
return connectionChannelHandlers;
|
|
94
128
|
}
|
|
@@ -96,15 +130,15 @@ export class DefaultMessagingService implements MessagingService, BackendApplica
|
|
|
96
130
|
}
|
|
97
131
|
|
|
98
132
|
export class ConnectionHandlers<T> {
|
|
99
|
-
protected readonly handlers:
|
|
133
|
+
protected readonly handlers: ConnectionHandlers.Entry<T>[] = [];
|
|
100
134
|
|
|
101
135
|
constructor(
|
|
102
136
|
protected readonly parent?: ConnectionHandlers<T>
|
|
103
137
|
) { }
|
|
104
138
|
|
|
105
|
-
push(spec: string, callback: (params: MessagingService.PathParams, connection: T) => void): void {
|
|
139
|
+
push(spec: string, callback: (params: MessagingService.PathParams, connection: T) => void, options: MessagingService.ChannelHandlerOptions = {}): void {
|
|
106
140
|
const route = new Route(spec);
|
|
107
|
-
const
|
|
141
|
+
const handle = (path: string, channel: T): string | false => {
|
|
108
142
|
const params = route.match(path);
|
|
109
143
|
if (!params) {
|
|
110
144
|
return false;
|
|
@@ -112,13 +146,13 @@ export class ConnectionHandlers<T> {
|
|
|
112
146
|
callback(params, channel);
|
|
113
147
|
return route.reverse(params);
|
|
114
148
|
};
|
|
115
|
-
this.handlers.push(
|
|
149
|
+
this.handlers.push({ route, handle, independentOfShellEnvironment: options.independentOfShellEnvironment ?? false });
|
|
116
150
|
}
|
|
117
151
|
|
|
118
152
|
route(path: string, connection: T): string | false {
|
|
119
|
-
for (const
|
|
153
|
+
for (const { handle } of this.handlers) {
|
|
120
154
|
try {
|
|
121
|
-
const result =
|
|
155
|
+
const result = handle(path, connection);
|
|
122
156
|
if (result) {
|
|
123
157
|
return result;
|
|
124
158
|
}
|
|
@@ -131,4 +165,24 @@ export class ConnectionHandlers<T> {
|
|
|
131
165
|
}
|
|
132
166
|
return false;
|
|
133
167
|
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Whether the handler of the given path is declared independent of the shell environment,
|
|
171
|
+
* see {@link ConnectionHandler.independentOfShellEnvironment}. A path without a handler is not.
|
|
172
|
+
*/
|
|
173
|
+
isIndependentOfShellEnvironment(path: string): boolean {
|
|
174
|
+
const entry = this.handlers.find(({ route }) => !!route.match(path));
|
|
175
|
+
if (entry) {
|
|
176
|
+
return entry.independentOfShellEnvironment;
|
|
177
|
+
}
|
|
178
|
+
return this.parent?.isIndependentOfShellEnvironment(path) ?? false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export namespace ConnectionHandlers {
|
|
183
|
+
export interface Entry<T> {
|
|
184
|
+
readonly route: Route;
|
|
185
|
+
readonly handle: (path: string, connection: T) => string | false;
|
|
186
|
+
readonly independentOfShellEnvironment: boolean;
|
|
187
|
+
}
|
|
134
188
|
}
|