@theia/core 1.78.0-next.0 → 1.78.0-next.23
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 +247 -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/application-shell.d.ts.map +1 -1
- package/lib/browser/shell/application-shell.js +13 -1
- package/lib/browser/shell/application-shell.js.map +1 -1
- package/lib/browser/shell/tab-bars.d.ts +78 -1
- package/lib/browser/shell/tab-bars.d.ts.map +1 -1
- package/lib/browser/shell/tab-bars.js +267 -18
- package/lib/browser/shell/tab-bars.js.map +1 -1
- package/lib/browser/shell/tab-bars.spec.js +401 -1
- package/lib/browser/shell/tab-bars.spec.js.map +1 -1
- package/lib/browser/widgets/widget.d.ts.map +1 -1
- package/lib/browser/widgets/widget.js +34 -1
- package/lib/browser/widgets/widget.js.map +1 -1
- package/lib/common/core-preferences.d.ts +2 -0
- package/lib/common/core-preferences.d.ts.map +1 -1
- package/lib/common/core-preferences.js +21 -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/messaging/socket-write-buffer.d.ts +8 -2
- package/lib/common/messaging/socket-write-buffer.d.ts.map +1 -1
- package/lib/common/messaging/socket-write-buffer.js +18 -12
- package/lib/common/messaging/socket-write-buffer.js.map +1 -1
- package/lib/common/messaging/socket-write-buffer.spec.d.ts +2 -0
- package/lib/common/messaging/socket-write-buffer.spec.d.ts.map +1 -0
- package/lib/common/messaging/socket-write-buffer.spec.js +72 -0
- package/lib/common/messaging/socket-write-buffer.spec.js.map +1 -0
- 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/application-shell.ts +14 -1
- package/src/browser/shell/tab-bars.spec.ts +452 -1
- package/src/browser/shell/tab-bars.ts +285 -20
- package/src/browser/style/tabs.css +58 -3
- package/src/browser/widgets/widget.ts +36 -1
- package/src/common/core-preferences.ts +23 -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/messaging/socket-write-buffer.spec.ts +90 -0
- package/src/common/messaging/socket-write-buffer.ts +18 -14
- 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
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
17
|
import * as chai from 'chai';
|
|
18
|
-
import { RpcProxyFactory, RpcProxy } from './proxy-factory.js';
|
|
18
|
+
import { RpcConnectionHandler, RpcProxyFactory, RpcProxy } from './proxy-factory.js';
|
|
19
19
|
import { ChannelPipe } from '../message-rpc/channel.spec.js';
|
|
20
20
|
|
|
21
21
|
const expect = chai.expect;
|
|
@@ -106,3 +106,19 @@ function getSetup(): {
|
|
|
106
106
|
serverProxy
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
+
|
|
110
|
+
describe('RpcConnectionHandler', () => {
|
|
111
|
+
it('is held until the shell environment is resolved unless declared independent of it', () => {
|
|
112
|
+
const held = new RpcConnectionHandler('/services/held', () => new TestServer());
|
|
113
|
+
expect(held.independentOfShellEnvironment).to.be.false;
|
|
114
|
+
const independent = new RpcConnectionHandler('/services/independent', () => new TestServer(), { independentOfShellEnvironment: true });
|
|
115
|
+
expect(independent.independentOfShellEnvironment).to.be.true;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('takes the proxy factory constructor from the options or, as before, as the third argument', () => {
|
|
119
|
+
class CustomFactory extends RpcProxyFactory<TestServer> { }
|
|
120
|
+
expect(new RpcConnectionHandler('/services/a', () => new TestServer()).factoryConstructor).to.equal(RpcProxyFactory);
|
|
121
|
+
expect(new RpcConnectionHandler('/services/b', () => new TestServer(), CustomFactory).factoryConstructor).to.equal(CustomFactory);
|
|
122
|
+
expect(new RpcConnectionHandler('/services/c', () => new TestServer(), { factoryConstructor: CustomFactory }).factoryConstructor).to.equal(CustomFactory);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -42,12 +42,26 @@ export interface RpcConnectionEventEmitter {
|
|
|
42
42
|
}
|
|
43
43
|
export type RpcProxy<T> = T & RpcConnectionEventEmitter;
|
|
44
44
|
|
|
45
|
+
export interface RpcConnectionHandlerOptions<T extends object> {
|
|
46
|
+
/** See {@link ConnectionHandler.independentOfShellEnvironment}. The default is `false`. */
|
|
47
|
+
independentOfShellEnvironment?: boolean;
|
|
48
|
+
/** Creates the proxy factory of each connection. The default is {@link RpcProxyFactory}. */
|
|
49
|
+
factoryConstructor?: new () => RpcProxyFactory<T>;
|
|
50
|
+
}
|
|
51
|
+
|
|
45
52
|
export class RpcConnectionHandler<T extends object> implements ConnectionHandler {
|
|
53
|
+
readonly factoryConstructor: new () => RpcProxyFactory<T>;
|
|
54
|
+
readonly independentOfShellEnvironment: boolean;
|
|
55
|
+
|
|
46
56
|
constructor(
|
|
47
57
|
readonly path: string,
|
|
48
58
|
readonly targetFactory: (proxy: RpcProxy<T>) => any,
|
|
49
|
-
|
|
50
|
-
) {
|
|
59
|
+
options: RpcConnectionHandlerOptions<T> | (new () => RpcProxyFactory<T>) = {}
|
|
60
|
+
) {
|
|
61
|
+
const { factoryConstructor, independentOfShellEnvironment } = typeof options === 'function' ? { factoryConstructor: options } : options;
|
|
62
|
+
this.factoryConstructor = factoryConstructor ?? RpcProxyFactory;
|
|
63
|
+
this.independentOfShellEnvironment = independentOfShellEnvironment ?? false;
|
|
64
|
+
}
|
|
51
65
|
|
|
52
66
|
onConnection(connection: Channel): void {
|
|
53
67
|
const factory = new this.factoryConstructor();
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 CodeSignal 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 { Uint8ArrayReadBuffer, Uint8ArrayWriteBuffer } from '../message-rpc/uint8-array-message-buffer.js';
|
|
19
|
+
import { SocketWriteBuffer } from './socket-write-buffer.js';
|
|
20
|
+
import { WebSocket } from './web-socket-channel.js';
|
|
21
|
+
|
|
22
|
+
function encode(text: string): Uint8Array {
|
|
23
|
+
const buffer = new Uint8ArrayWriteBuffer();
|
|
24
|
+
buffer.writeString(text);
|
|
25
|
+
return buffer.getCurrentContents();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function recordingSocket(): { socket: WebSocket, sent: string[] } {
|
|
29
|
+
const sent: string[] = [];
|
|
30
|
+
const socket = { send: (data: Uint8Array) => sent.push(new Uint8ArrayReadBuffer(data).readString()) } as unknown as WebSocket;
|
|
31
|
+
return { socket, sent };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe('SocketWriteBuffer', () => {
|
|
35
|
+
|
|
36
|
+
it('sends each buffered message as its own socket message', () => {
|
|
37
|
+
const buffer = new SocketWriteBuffer();
|
|
38
|
+
['one', 'two', 'three'].forEach(text => buffer.buffer(encode(text)));
|
|
39
|
+
const { socket, sent } = recordingSocket();
|
|
40
|
+
|
|
41
|
+
buffer.flush(socket);
|
|
42
|
+
|
|
43
|
+
expect(sent).to.deep.equal(['one', 'two', 'three']);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('sends nothing again on the next flush', () => {
|
|
47
|
+
const buffer = new SocketWriteBuffer();
|
|
48
|
+
buffer.buffer(encode('one'));
|
|
49
|
+
const { socket, sent } = recordingSocket();
|
|
50
|
+
|
|
51
|
+
buffer.flush(socket);
|
|
52
|
+
buffer.buffer(encode('two'));
|
|
53
|
+
buffer.flush(socket);
|
|
54
|
+
|
|
55
|
+
expect(sent).to.deep.equal(['one', 'two']);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('sends what was buffered even if the caller changes its buffer afterwards', () => {
|
|
59
|
+
const buffer = new SocketWriteBuffer();
|
|
60
|
+
const data = encode('one');
|
|
61
|
+
buffer.buffer(data);
|
|
62
|
+
data.set(encode('two'));
|
|
63
|
+
const { socket, sent } = recordingSocket();
|
|
64
|
+
|
|
65
|
+
buffer.flush(socket);
|
|
66
|
+
|
|
67
|
+
expect(sent).to.deep.equal(['one']);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('copies a Node Buffer too, whose slice() shares memory', () => {
|
|
71
|
+
const buffer = new SocketWriteBuffer();
|
|
72
|
+
const data = Buffer.from(encode('one'));
|
|
73
|
+
buffer.buffer(data);
|
|
74
|
+
data.set(encode('two'));
|
|
75
|
+
const { socket, sent } = recordingSocket();
|
|
76
|
+
|
|
77
|
+
buffer.flush(socket);
|
|
78
|
+
|
|
79
|
+
expect(sent).to.deep.equal(['one']);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('refuses a message that would take it past its size limit until drained', () => {
|
|
83
|
+
const buffer = new SocketWriteBuffer();
|
|
84
|
+
buffer.buffer(new Uint8Array(100 * 1024 - 1));
|
|
85
|
+
|
|
86
|
+
expect(() => buffer.buffer(new Uint8Array(2))).to.throw('Max disconnected buffer size exceeded');
|
|
87
|
+
buffer.drain();
|
|
88
|
+
expect(() => buffer.buffer(new Uint8Array(100 * 1024))).to.not.throw();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -21,38 +21,42 @@ import { WebSocket } from './web-socket-channel.js';
|
|
|
21
21
|
export class SocketWriteBuffer {
|
|
22
22
|
private static readonly DEFAULT_DISCONNECTED_BUFFER_SIZE = 100 * 1024;
|
|
23
23
|
|
|
24
|
-
protected
|
|
25
|
-
protected
|
|
24
|
+
protected bufferedMessages: Uint8Array[] = [];
|
|
25
|
+
protected bufferedBytes = 0;
|
|
26
26
|
|
|
27
27
|
protected get maxBufferSize(): number {
|
|
28
28
|
return SocketWriteBuffer.DEFAULT_DISCONNECTED_BUFFER_SIZE;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Stores a copy of `data`, so the caller can reuse its buffer before the next flush.
|
|
33
|
+
*/
|
|
31
34
|
buffer(data: Uint8Array): void {
|
|
32
35
|
this.ensureWriteBuffer(data.byteLength);
|
|
33
|
-
|
|
34
|
-
this.
|
|
36
|
+
// Not `data.slice()`: on a Node `Buffer` that returns a view of the same memory.
|
|
37
|
+
this.bufferedMessages.push(new Uint8Array(data));
|
|
38
|
+
this.bufferedBytes += data.byteLength;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
protected ensureWriteBuffer(byteLength: number): void {
|
|
38
|
-
if (
|
|
39
|
-
this.disconnectedBuffer = new Uint8Array(this.maxBufferSize);
|
|
40
|
-
this.bufferWritePosition = 0;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (this.bufferWritePosition + byteLength > this.disconnectedBuffer.byteLength) {
|
|
42
|
+
if (this.bufferedBytes + byteLength > this.maxBufferSize) {
|
|
44
43
|
throw new Error(`Max disconnected buffer size exceeded by adding ${byteLength} bytes`);
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
|
|
47
|
+
/**
|
|
48
|
+
* Sends each buffered message on its own: the receiving side reads one message per socket message.
|
|
49
|
+
*/
|
|
48
50
|
flush(socket: WebSocket): void {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
const messages = this.bufferedMessages;
|
|
52
|
+
this.drain();
|
|
53
|
+
for (const message of messages) {
|
|
54
|
+
socket.send(message);
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
drain(): void {
|
|
56
|
-
this.
|
|
59
|
+
this.bufferedMessages = [];
|
|
60
|
+
this.bufferedBytes = 0;
|
|
57
61
|
}
|
|
58
62
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
export const shellEnvironmentPath = '/services/shell-environment';
|
|
18
|
+
|
|
19
|
+
export const ShellEnvironmentServer = Symbol('ShellEnvironmentServer');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The environment of the user's login shell, resolved by the backend when it starts.
|
|
23
|
+
*
|
|
24
|
+
* A GUI application on macOS and Linux does not inherit the variables that the user's dotfiles
|
|
25
|
+
* (`.zshrc`, `.bash_profile`, ...) define, `PATH` among them, so the processes that the backend
|
|
26
|
+
* spawns for the user, such as terminals, tasks, debug adapters and the plugin host, would not find
|
|
27
|
+
* the user's tools. The backend of an Electron application therefore runs the login shell once at
|
|
28
|
+
* start-up and applies its `PATH` to its own `process.env`, from where every process spawned
|
|
29
|
+
* later inherits it. The other variables of the login shell are not applied. The channel of every
|
|
30
|
+
* service that a frontend opens is held until that has happened, unless the service is declared
|
|
31
|
+
* independent of the shell environment (see `ConnectionHandler.independentOfShellEnvironment`),
|
|
32
|
+
* so backend code that serves a request of a held
|
|
33
|
+
* service sees the resolved environment without waiting. Only code that spawns processes on its own,
|
|
34
|
+
* before any frontend connects, needs to await {@link whenResolved}.
|
|
35
|
+
*
|
|
36
|
+
* The resolution is skipped in browser deployments, on Windows, and when the backend itself was
|
|
37
|
+
* started from the login shell that is being resolved.
|
|
38
|
+
*/
|
|
39
|
+
export interface ShellEnvironmentServer {
|
|
40
|
+
/**
|
|
41
|
+
* Settles once the `PATH` of the login shell has been applied to the backend's `process.env`,
|
|
42
|
+
* or once the resolution has been skipped, has failed or has timed out, with the outcome.
|
|
43
|
+
* The returned promise never rejects.
|
|
44
|
+
*/
|
|
45
|
+
whenResolved(): Promise<ShellEnvironmentResolution>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Stores the time in seconds to wait for the login shell at the next start of the backend,
|
|
49
|
+
* `undefined` to restore the default.
|
|
50
|
+
*/
|
|
51
|
+
setResolutionTimeout(seconds: number | undefined): Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The outcome of the resolution of the login shell environment, see {@link ShellEnvironmentServer}.
|
|
56
|
+
*/
|
|
57
|
+
export interface ShellEnvironmentResolution {
|
|
58
|
+
/**
|
|
59
|
+
* - `applied`: the `PATH` of the login shell has been applied to `process.env`
|
|
60
|
+
* - `skipped`: there was nothing to resolve, see `reason`
|
|
61
|
+
* - `timeout`: the login shell did not answer within the resolution timeout; `process.env` is unchanged
|
|
62
|
+
* - `failed`: the login shell could not be run or its output could not be read or defines no `PATH`, see `reason`;
|
|
63
|
+
* `process.env` is unchanged
|
|
64
|
+
*/
|
|
65
|
+
readonly status: 'applied' | 'skipped' | 'timeout' | 'failed';
|
|
66
|
+
/**
|
|
67
|
+
* Why the resolution was skipped or what went wrong.
|
|
68
|
+
*/
|
|
69
|
+
readonly reason?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The preference that controls how long the backend waits for the login shell, in seconds, and the bounds
|
|
74
|
+
* within which its value is honoured.
|
|
75
|
+
*/
|
|
76
|
+
export namespace ShellEnvironmentResolutionTimeout {
|
|
77
|
+
export const PREFERENCE = 'application.shellEnvironmentResolutionTimeout';
|
|
78
|
+
export const DEFAULT = 10;
|
|
79
|
+
export const MIN = 1;
|
|
80
|
+
export const MAX = 120;
|
|
81
|
+
}
|
package/src/electron-browser/shell-environment/electron-shell-environment-contribution.spec.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
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 { Emitter } from '../../common/event.js';
|
|
20
|
+
import { ILogger } from '../../common/logger.js';
|
|
21
|
+
import { MessageService } from '../../common/message-service.js';
|
|
22
|
+
import { PreferenceService } from '../../common/preferences/preference-service.js';
|
|
23
|
+
import { Deferred, wait } from '../../common/promise-util.js';
|
|
24
|
+
import { ShellEnvironmentResolutionTimeout, ShellEnvironmentResolution, ShellEnvironmentServer } from '../../common/shell-environment.js';
|
|
25
|
+
import { MockLogger } from '../../common/test/mock-logger.js';
|
|
26
|
+
import { ElectronShellEnvironmentContribution } from './electron-shell-environment-contribution.js';
|
|
27
|
+
|
|
28
|
+
describe('ElectronShellEnvironmentContribution', () => {
|
|
29
|
+
|
|
30
|
+
let resolution: Deferred<ShellEnvironmentResolution>;
|
|
31
|
+
let warnings: string[];
|
|
32
|
+
let storedTimeouts: (number | undefined)[];
|
|
33
|
+
let configuredTimeout: number | undefined;
|
|
34
|
+
let preferenceChanged: Emitter<{ preferenceName: string }>;
|
|
35
|
+
|
|
36
|
+
const setup = (): ElectronShellEnvironmentContribution => {
|
|
37
|
+
resolution = new Deferred();
|
|
38
|
+
warnings = [];
|
|
39
|
+
storedTimeouts = [];
|
|
40
|
+
configuredTimeout = undefined;
|
|
41
|
+
preferenceChanged = new Emitter();
|
|
42
|
+
const container = new Container({ defaultScope: 'Singleton' });
|
|
43
|
+
container.bind(ILogger).to(MockLogger);
|
|
44
|
+
container.bind(MessageService).toConstantValue({
|
|
45
|
+
warn: async (message: string) => { warnings.push(message); return undefined; }
|
|
46
|
+
} as unknown as MessageService);
|
|
47
|
+
container.bind(PreferenceService).toConstantValue({
|
|
48
|
+
ready: Promise.resolve(),
|
|
49
|
+
inspect: () => ({ globalValue: configuredTimeout }),
|
|
50
|
+
onPreferenceChanged: preferenceChanged.event
|
|
51
|
+
} as unknown as PreferenceService);
|
|
52
|
+
container.bind(ShellEnvironmentServer).toConstantValue(<ShellEnvironmentServer>{
|
|
53
|
+
whenResolved: () => resolution.promise,
|
|
54
|
+
setResolutionTimeout: async seconds => { storedTimeouts.push(seconds); }
|
|
55
|
+
});
|
|
56
|
+
container.bind(ElectronShellEnvironmentContribution).toSelf();
|
|
57
|
+
return container.get(ElectronShellEnvironmentContribution);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const start = async (outcome: ShellEnvironmentResolution): Promise<void> => {
|
|
61
|
+
setup().onStart();
|
|
62
|
+
resolution.resolve(outcome);
|
|
63
|
+
await wait(0);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
it('warns when the login shell did not answer in time', async () => {
|
|
67
|
+
await start({ status: 'timeout' });
|
|
68
|
+
expect(warnings).to.have.lengthOf(1);
|
|
69
|
+
expect(warnings[0]).to.contain('reasonable time');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('warns with the reason when the login shell could not be resolved', async () => {
|
|
73
|
+
await start({ status: 'failed', reason: 'The login shell exited with code 3' });
|
|
74
|
+
expect(warnings).to.deep.equal(['Unable to resolve your shell environment: The login shell exited with code 3']);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('says nothing when the environment was applied or the resolution skipped', async () => {
|
|
78
|
+
await start({ status: 'applied' });
|
|
79
|
+
await start({ status: 'skipped', reason: 'the application runs on Windows' });
|
|
80
|
+
expect(warnings).to.be.empty;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('stores the configured timeout for the next start, and again when it changes', async () => {
|
|
84
|
+
const contribution = setup();
|
|
85
|
+
contribution.onStart();
|
|
86
|
+
await wait(0);
|
|
87
|
+
expect(storedTimeouts).to.deep.equal([undefined]);
|
|
88
|
+
|
|
89
|
+
configuredTimeout = 30;
|
|
90
|
+
preferenceChanged.fire({ preferenceName: 'application.confirmExit' });
|
|
91
|
+
expect(storedTimeouts).to.deep.equal([undefined]);
|
|
92
|
+
preferenceChanged.fire({ preferenceName: ShellEnvironmentResolutionTimeout.PREFERENCE });
|
|
93
|
+
expect(storedTimeouts).to.deep.equal([undefined, 30]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { inject, injectable, named } from 'inversify';
|
|
18
|
+
import { FrontendApplicationContribution } from '../../browser/frontend-application-contribution.js';
|
|
19
|
+
import { ILogger } from '../../common/logger.js';
|
|
20
|
+
import { MessageService } from '../../common/message-service.js';
|
|
21
|
+
import { nls } from '../../common/nls.js';
|
|
22
|
+
import { PreferenceService } from '../../common/preferences/preference-service.js';
|
|
23
|
+
import { ShellEnvironmentResolutionTimeout, ShellEnvironmentResolution, ShellEnvironmentServer } from '../../common/shell-environment.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Tells the user when the environment of the login shell could not be resolved, as the backend's child processes
|
|
27
|
+
* may then not find the user's tools, and stores the resolution timeout preference for the next start of the backend,
|
|
28
|
+
* which resolves the environment before the preferences are available.
|
|
29
|
+
*/
|
|
30
|
+
@injectable()
|
|
31
|
+
export class ElectronShellEnvironmentContribution implements FrontendApplicationContribution {
|
|
32
|
+
|
|
33
|
+
@inject(ShellEnvironmentServer)
|
|
34
|
+
protected readonly shellEnvironment: ShellEnvironmentServer;
|
|
35
|
+
|
|
36
|
+
@inject(MessageService)
|
|
37
|
+
protected readonly messageService: MessageService;
|
|
38
|
+
|
|
39
|
+
@inject(PreferenceService)
|
|
40
|
+
protected readonly preferences: PreferenceService;
|
|
41
|
+
|
|
42
|
+
@inject(ILogger) @named('core:ElectronShellEnvironmentContribution')
|
|
43
|
+
protected readonly logger: ILogger;
|
|
44
|
+
|
|
45
|
+
onStart(): void {
|
|
46
|
+
this.shellEnvironment.whenResolved().then(resolution => this.report(resolution))
|
|
47
|
+
.catch(error => this.logger.warn('Could not learn whether the shell environment was resolved:', error));
|
|
48
|
+
this.preferences.ready.then(() => {
|
|
49
|
+
this.storeResolutionTimeout();
|
|
50
|
+
this.preferences.onPreferenceChanged(event => {
|
|
51
|
+
if (event.preferenceName === ShellEnvironmentResolutionTimeout.PREFERENCE) {
|
|
52
|
+
this.storeResolutionTimeout();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected report(resolution: ShellEnvironmentResolution): void {
|
|
59
|
+
if (resolution.status === 'timeout') {
|
|
60
|
+
this.messageService.warn(nls.localizeByDefault(
|
|
61
|
+
'Unable to resolve your shell environment in a reasonable time. Please review your shell configuration and restart.'));
|
|
62
|
+
} else if (resolution.status === 'failed') {
|
|
63
|
+
this.messageService.warn(nls.localizeByDefault('Unable to resolve your shell environment: {0}', resolution.reason ?? ''));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected storeResolutionTimeout(): void {
|
|
68
|
+
const configured = this.preferences.inspect<number>(ShellEnvironmentResolutionTimeout.PREFERENCE)?.globalValue;
|
|
69
|
+
this.shellEnvironment.setResolutionTimeout(typeof configured === 'number' ? configured : undefined)
|
|
70
|
+
.catch(error => this.logger.warn('Could not store the shell environment resolution timeout:', error));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 { ContainerModule } from 'inversify';
|
|
18
|
+
import { FrontendApplicationContribution } from '../../browser/frontend-application-contribution.js';
|
|
19
|
+
import { WebSocketConnectionProvider } from '../../browser/messaging/ws-connection-provider.js';
|
|
20
|
+
import { ShellEnvironmentServer, shellEnvironmentPath } from '../../common/shell-environment.js';
|
|
21
|
+
import { ElectronShellEnvironmentContribution } from './electron-shell-environment-contribution.js';
|
|
22
|
+
|
|
23
|
+
export default new ContainerModule(bind => {
|
|
24
|
+
bind(ShellEnvironmentServer).toDynamicValue(ctx =>
|
|
25
|
+
WebSocketConnectionProvider.createProxy<ShellEnvironmentServer>(ctx.container, shellEnvironmentPath)
|
|
26
|
+
).inSingletonScope();
|
|
27
|
+
bind(ElectronShellEnvironmentContribution).toSelf().inSingletonScope();
|
|
28
|
+
bind(FrontendApplicationContribution).toService(ElectronShellEnvironmentContribution);
|
|
29
|
+
});
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { inject, injectable, named } from 'inversify';
|
|
18
18
|
import {
|
|
19
19
|
screen, app, BrowserWindow, WebContents, Event as ElectronEvent, BrowserWindowConstructorOptions, nativeImage,
|
|
20
|
-
nativeTheme, shell, dialog
|
|
20
|
+
nativeTheme, shell, dialog, session
|
|
21
21
|
} from '../../electron-shared/electron/index.cjs';
|
|
22
22
|
import * as path from 'path';
|
|
23
23
|
import { Argv } from '../../shared/yargs/index.cjs';
|
|
@@ -849,9 +849,20 @@ export class ElectronMainApplication {
|
|
|
849
849
|
await this.getForkOptions(),
|
|
850
850
|
);
|
|
851
851
|
return new Promise((resolve, reject) => {
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
852
|
+
backendProcess.on('message', (msg: AddressInfo | { type: string, id: string, url: string }) => {
|
|
853
|
+
// The backend server main file is supposed to send the resolved proxy via IPC.
|
|
854
|
+
if (msg && typeof msg === 'object' && 'type' in msg && msg.type === 'resolve-proxy') {
|
|
855
|
+
session.defaultSession.resolveProxy(msg.url).then(
|
|
856
|
+
result => backendProcess.send({ type: 'resolve-proxy-response', id: msg.id, result }),
|
|
857
|
+
error => {
|
|
858
|
+
console.warn(`Proxy resolution failed for ${msg.url}:`, error);
|
|
859
|
+
backendProcess.send({ type: 'resolve-proxy-response', id: msg.id, result: undefined });
|
|
860
|
+
}
|
|
861
|
+
);
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
// The backend server main file is also supposed to send the resolved http(s) server port via IPC.
|
|
865
|
+
resolve((msg as AddressInfo).port);
|
|
855
866
|
});
|
|
856
867
|
backendProcess.on('error', error => {
|
|
857
868
|
reject(error);
|
|
@@ -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> {
|