diff --git a/src/services/desktop-api.ts b/src/services/desktop-api.ts index 1d2dfd87..0bb4c572 100644 --- a/src/services/desktop-api.ts +++ b/src/services/desktop-api.ts @@ -94,6 +94,11 @@ const global = typeof globalThis !== 'undefined' export const DesktopApi: DesktopApi = global.desktopApi ?? {}; +// The desktop shell injects its API into the page before the UI loads. A browser +// tab pointed at the same server never has it, so this tells the two apart +// synchronously, unlike desktopVersion which never resolves in a browser. +export const isDesktopShell = (): boolean => !!global.desktopApi; + const DEFAULT_SERVER_PORT = 45457; const DEFAULT_MOCKTTP_PORT = 45456; diff --git a/src/services/ui-api/server-operation-bridge.ts b/src/services/ui-api/server-operation-bridge.ts index 920b65f1..81466a8a 100644 --- a/src/services/ui-api/server-operation-bridge.ts +++ b/src/services/ui-api/server-operation-bridge.ts @@ -1,6 +1,6 @@ import { autorun, IReactionDisposer } from 'mobx'; import { AccountStore } from '../../model/account/account-store'; -import { getServerPort } from '../desktop-api'; +import { getServerPort, isDesktopShell } from '../desktop-api'; import { OperationRegistry } from './api-registry'; const RECONNECT_BASE_MS = 1_000; @@ -83,7 +83,11 @@ export function startServerOperationBridge( disposers.push(autorun(() => { ws!.send(JSON.stringify({ type: 'operations', - operations: registry.getDefinitions() + operations: registry.getDefinitions(), + // The desktop app is the UI the user is actually driving, so it + // takes the bridge's primary role from any browser tab that + // happens to be pointed at the same server too. + priority: isDesktopShell() ? 1 : 0 })); })); }