From 1b8efddd742e8c775efef87975cf4fa05c7e0732 Mon Sep 17 00:00:00 2001 From: Hampus Date: Sun, 8 Nov 2026 21:20:37 +0100 Subject: [PATCH] fix(desktop): keep the gateway on the native transport (#3982) --- fluxer_app/inline_scripts/preboot-gateway.js | 3 +++ .../gateway/transport/GatewayWireTransport.ts | 14 ++++++++------ .../platform/state/PrebootNetworkHandoff.ts | 17 +++++++++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/fluxer_app/inline_scripts/preboot-gateway.js b/fluxer_app/inline_scripts/preboot-gateway.js index 4fa28429d..ed630a106 100644 --- a/fluxer_app/inline_scripts/preboot-gateway.js +++ b/fluxer_app/inline_scripts/preboot-gateway.js @@ -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; diff --git a/fluxer_app/src/features/gateway/transport/GatewayWireTransport.ts b/fluxer_app/src/features/gateway/transport/GatewayWireTransport.ts index 4c1cb5f7d..b11b3eef0 100644 --- a/fluxer_app/src/features/gateway/transport/GatewayWireTransport.ts +++ b/fluxer_app/src/features/gateway/transport/GatewayWireTransport.ts @@ -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); } diff --git a/fluxer_app/src/features/platform/state/PrebootNetworkHandoff.ts b/fluxer_app/src/features/platform/state/PrebootNetworkHandoff.ts index 17f7d3fdd..6bb7952c5 100644 --- a/fluxer_app/src/features/platform/state/PrebootNetworkHandoff.ts +++ b/fluxer_app/src/features/platform/state/PrebootNetworkHandoff.ts @@ -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): 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:']), }), ); }