Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/services/desktop-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 6 additions & 2 deletions src/services/ui-api/server-operation-bridge.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
}));
}));
}
Expand Down