fix(desktop): honour the system proxy in main-process requests (#3270)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-08 03:04:55 +02:00
1 parent 6de6be2358
commit 3071bc7525
16 files changed
+542 -19

No files matched your search

@@ -9,9 +9,10 @@ import {
isDesktopNativeGatewayTransportAvailable,
} from '@app/features/gateway/transport/GatewayWireTransport';
import {isDesktopLocalAppDocument} from '@app/features/platform/DesktopLocalAppRuntime';
import type {
NativeGatewayTransportAPI,
NativeGatewayTransportEvent,
import {
NATIVE_GATEWAY_TRANSPORT_PROXIED_MESSAGE,
type NativeGatewayTransportAPI,
type NativeGatewayTransportEvent,
} from '@fluxer/desktop_ipc/src/GatewayTransportContract';
import {afterEach, beforeEach, describe, expect, test, vi} from 'vitest';
@@ -431,7 +432,7 @@ describe('native transport fallback', () => {
test('native creates the shell refuses count toward the fallback', async () => {
const stub = createNativeGatewayTransportStub({
create: async () => {
throw new Error('The native gateway transport cannot reach a gateway that resolves through a proxy');
throw new Error('The native gateway transport addon is unavailable');
},
});
installElectronAPI(stub.api);
@@ -452,6 +453,28 @@ describe('native transport fallback', () => {
);
});
test('a gateway the shell routes through a proxy switches new transports to the browser at once', async () => {
const stub = createNativeGatewayTransportStub({
create: async () => {
throw new Error(
`Error invoking remote method 'native-gateway-transport:create': Error: ${NATIVE_GATEWAY_TRANSPORT_PROXIED_MESSAGE}`,
);
},
});
installElectronAPI(stub.api);
const transport = createGatewayWireTransport('wss://gateway.example/', {binaryType: 'arraybuffer'});
expect(transport.kind).toBe(GatewayWireTransportKind.DESKTOP_NATIVE);
transport.on('error', () => undefined);
transport.start();
await flush();
const next = createGatewayWireTransport('wss://gateway.example/', {binaryType: 'arraybuffer'});
expect(next.kind).toBe(GatewayWireTransportKind.BROWSER);
next.start();
expect(FakeWebSocket.instances.map((socket) => socket.url)).toEqual(['wss://gateway.example/']);
});
test('an open between failures resets the count', async () => {
const stub = createNativeGatewayTransportStub();
installElectronAPI(stub.api);
@@ -6,6 +6,7 @@ import {Logger} from '@app/features/platform/utils/AppLogger';
import {randomUuid} from '@app/features/platform/utils/RandomUuid';
import {getElectronAPI} from '@app/features/ui/utils/NativeUtils';
import {
NATIVE_GATEWAY_TRANSPORT_PROXIED_MESSAGE,
type NativeGatewayTransportAPI,
type NativeGatewayTransportCloseRequest,
type NativeGatewayTransportEvent,
@@ -433,7 +434,11 @@ class DesktopNativeGatewayWireTransport extends BaseGatewayWireTransport {
private failOpen(error: unknown): void {
if (this.disposed) return;
recordNativeGatewayFailureWithoutOpen();
if (describeError(error).includes(NATIVE_GATEWAY_TRANSPORT_PROXIED_MESSAGE)) {
switchProxiedGatewayToBrowserTransport();
} else {
recordNativeGatewayFailureWithoutOpen();
}
this.abandonNativeConnection();
this.emitTransportFailure(error);
}
@@ -600,6 +605,13 @@ function recordNativeGatewayFailureWithoutOpen(): void {
}
}
function switchProxiedGatewayToBrowserTransport(): void {
const state = getRouterState();
if (isNativeGatewayFallbackActive(state)) return;
state.nativeFailuresWithoutOpen = NATIVE_GATEWAY_FAILURES_BEFORE_BROWSER_FALLBACK;
log.warn('Desktop native gateway transport cannot use the configured proxy, using the browser transport');
}
function createDesktopConnectionId(): string {
return `${DESKTOP_CONNECTION_ID_PREFIX}${getRouterState().rendererRouterId}:${randomUuid()}`;
}