fix(desktop): keep the gateway on the native transport (#3982)

This commit is contained in:
Hampus authored and GitHub committed 2026-11-08 21:20:37 +01:00
1 parent 3acaaa355b
commit 1b8efddd74
3 files changed
+24 -10

No files matched your search

@@ -3,6 +3,9 @@
if (typeof WebSocket !== 'function' || typeof fetch !== 'function') {
return;
}
if (location.protocol === 'fluxer-app:') {
return;
}
const path = location.pathname;
if (path === '/' || path.startsWith('/migrate/') || path.startsWith('/oauth2/')) {
return;
@@ -1,7 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {isDesktopLocalAppDocument} from '@app/features/platform/DesktopLocalAppRuntime';
import {type PrebootGatewaySocket, takePrebootGatewaySocket} from '@app/features/platform/state/PrebootNetworkHandoff';
import {
discardPrebootGatewaySocket,
type PrebootGatewaySocket,
takePrebootGatewaySocket,
} from '@app/features/platform/state/PrebootNetworkHandoff';
import {Logger} from '@app/features/platform/utils/AppLogger';
import {randomUuid} from '@app/features/platform/utils/RandomUuid';
import {getElectronAPI} from '@app/features/ui/utils/NativeUtils';
@@ -786,13 +790,11 @@ function getDesktopGatewayTransportRouter(api: NativeGatewayTransportAPI): Deskt
}
export function createGatewayWireTransport(url: string, options: GatewayWireTransportOptions): GatewayWireTransport {
const preboot = options.adoptPrebootSocket === true ? takePrebootGatewaySocket(url) : null;
if (preboot != null) {
return new BrowserGatewayWireTransport(url, options, preboot);
}
const api = resolveNativeGatewayTransportAPI(url);
if (api != null) {
discardPrebootGatewaySocket();
return new DesktopNativeGatewayWireTransport(url, getDesktopGatewayTransportRouter(api));
}
return new BrowserGatewayWireTransport(url, options, null);
const preboot = options.adoptPrebootSocket === true ? takePrebootGatewaySocket(url) : null;
return new BrowserGatewayWireTransport(url, options, preboot);
}
@@ -76,6 +76,11 @@ export function takePrebootDiscoveryResponse(url: string, signal?: AbortSignal |
return signal == null ? discovery.response : waitForAbortablePromise(discovery.response, signal);
}
export function discardPrebootGatewaySocket(): void {
const handoff = readHandoff();
if (handoff != null) discardGateway(handoff);
}
export function takePrebootGatewaySocket(url: string): PrebootGatewaySocket | null {
const handoff = readHandoff();
const gateway = handoff?.gateway;
@@ -102,9 +107,13 @@ function boundedUrl(value: string | null, protocols: ReadonlyArray<string>): str
export function writePrebootNetworkHint(hint: PrebootNetworkHint): void {
if (typeof window === 'undefined') return;
const desktop = isDesktopLocalAppDocument();
const gateway = boundedUrl(hint.gatewayEndpoint, desktop ? ['wss:'] : ['ws:', 'wss:']);
if (gateway == null || hint.accountKey.length === 0 || hint.accountKey.length > MAX_HINT_FIELD_LENGTH) {
const gateway = boundedUrl(hint.gatewayEndpoint, ['ws:', 'wss:']);
if (
isDesktopLocalAppDocument() ||
gateway == null ||
hint.accountKey.length === 0 ||
hint.accountKey.length > MAX_HINT_FIELD_LENGTH
) {
writeRawStorageItem(PREBOOT_NETWORK_HINT_STORAGE_KEY, null);
return;
}
@@ -114,7 +123,7 @@ export function writePrebootNetworkHint(hint: PrebootNetworkHint): void {
v: PREBOOT_NETWORK_HINT_VERSION,
a: hint.accountKey,
g: gateway,
d: desktop ? null : boundedUrl(hint.discoveryUrl, ['http:', 'https:']),
d: boundedUrl(hint.discoveryUrl, ['http:', 'https:']),
}),
);
}