Skip to content

The agent that grows with you

refactor(desktop): gate lib and store host checks by capability

Tekniumede0b5384f8f
diff --git a/apps/desktop/src/api/plugins.ts b/apps/desktop/src/api/plugins.ts
index e781e663c93..86d4e8a6764 100644
--- a/apps/desktop/src/api/plugins.ts
+++ b/apps/desktop/src/api/plugins.ts
@@ -1,7 +1,7 @@
import { isStableOpen, reconnectBackoffDelayMs } from '@hermes/shared'
import type { HermesConnection } from '@/global'
-import { isBrowserHostedDesktop } from '@/lib/platform'
+import { hostHas } from '@/lib/host-capabilities'
import { RECONNECT_ATTEMPT_TIMEOUT_MS, withTimeout } from '@/lib/with-timeout'
import { $apiRequestScope, getApiRequestConnection, getApiRequestProfile, hermesApi, profileScoped } from './client'
@@ -192,7 +192,7 @@ export function pluginSocket(pluginId: string, path: string, onMessage: (data: u
// OAuth cookie auth (WS tickets are single-use, core-managed) and the browser-hosted
// Desktop (its session token never rides a URL): stay on the polling fallback rather than
// half-working.
- if (stale() || connection.authMode === 'oauth' || isBrowserHostedDesktop()) {
+ if (stale() || connection.authMode === 'oauth' || !hostHas('urlTokenAuth')) {
return
}
diff --git a/apps/desktop/src/lib/browser-profile-prefs.ts b/apps/desktop/src/lib/browser-profile-prefs.ts
index 2d6325dbd02..f21ef8b16f6 100644
--- a/apps/desktop/src/lib/browser-profile-prefs.ts
+++ b/apps/desktop/src/lib/browser-profile-prefs.ts
@@ -6,10 +6,10 @@ import {
migrateBrowserStartupProfile,
readBrowserStartupProfile
} from './browser-startup-profile'
-import { isBrowserHostedDesktop } from './platform'
+import { hostHas } from './host-capabilities'
function hostedBasePath(): string | null {
- return isBrowserHostedDesktop() ? browserPageBasePath() : null
+ return hostHas('originScopedPrefs') ? browserPageBasePath() : null
}
function namesProfile(profile: string | undefined, target: string): boolean {
diff --git a/apps/desktop/src/lib/clipboard.ts b/apps/desktop/src/lib/clipboard.ts
index bf2876b367a..3823b77c60c 100644
--- a/apps/desktop/src/lib/clipboard.ts
+++ b/apps/desktop/src/lib/clipboard.ts
@@ -1,4 +1,4 @@
-import { isBrowserHostedDesktop } from '@/lib/platform'
+import { hostHas } from '@/lib/host-capabilities'
// Primitives and CopyButton enter one policy, never nested fallback retries.
const nativeWrites = new WeakMap<Clipboard, Clipboard['writeText'] | undefined>()
@@ -58,7 +58,7 @@ export async function writeClipboardText(text: string) {
const native =
clipboard && (nativeWrites.has(clipboard) ? nativeWrites.get(clipboard) : clipboard.writeText?.bind(clipboard))
- const ipc = isBrowserHostedDesktop() ? undefined : window.hermesDesktop?.writeClipboard
+ const ipc = hostHas('clipboardIpc') ? window.hermesDesktop?.writeClipboard : undefined
if (ipc) {
try {
diff --git a/apps/desktop/src/lib/desktop-fs.ts b/apps/desktop/src/lib/desktop-fs.ts
index ac65dab2f05..9d107b2b524 100644
--- a/apps/desktop/src/lib/desktop-fs.ts
+++ b/apps/desktop/src/lib/desktop-fs.ts
@@ -7,7 +7,7 @@ import type {
HermesSelectPathsOptions
} from '@/global'
import { translateNow } from '@/i18n'
-import { isBrowserHostedDesktop } from '@/lib/platform'
+import { hostHas } from '@/lib/host-capabilities'
import { $connection } from '@/store/session'
export interface DesktopFsRemotePicker {
@@ -45,7 +45,7 @@ export function desktopFsCacheKey(connection: HermesConnection | null = $connect
}
export function isDesktopFsRemoteMode() {
- return $connection.get()?.mode === 'remote' || isBrowserHostedDesktop()
+ return $connection.get()?.mode === 'remote' || !hostHas('nativeHostFiles')
}
// Active profile for FS/git REST calls. Without it the Electron api bridge
diff --git a/apps/desktop/src/lib/external-link.tsx b/apps/desktop/src/lib/external-link.tsx
index c33687e0a41..83ede9456ea 100644
--- a/apps/desktop/src/lib/external-link.tsx
+++ b/apps/desktop/src/lib/external-link.tsx
@@ -1,9 +1,9 @@
import type { ComponentProps, ReactNode } from 'react'
import { useEffect, useMemo, useState } from 'react'
+import { hostHas } from '@/lib/host-capabilities'
import { ArrowUpRight } from '@/lib/icons'
import { IS_MAC } from '@/lib/keybinds/combo'
-import { isBrowserHostedDesktop } from '@/lib/platform'
import { $alwaysExternalLinks } from '@/store/external-links'
import { resolveBrandIcon } from './brand-icon'
@@ -269,7 +269,7 @@ export function openLink(href: string, options: { native?: boolean } = {}): void
if (
options.native ||
- isBrowserHostedDesktop() ||
+ !hostHas('inAppLinks') ||
$alwaysExternalLinks.get() ||
isConnectorAuthorizationLink(target) ||
hudForcesNativeLinks() ||
diff --git a/apps/desktop/src/lib/media.ts b/apps/desktop/src/lib/media.ts
index a72cd7c9121..a3ae81c69ee 100644
--- a/apps/desktop/src/lib/media.ts
+++ b/apps/desktop/src/lib/media.ts
@@ -4,8 +4,8 @@ import { capabilityScoped, hermesApi, type OwnerScope, sessionFileOwnerScope } f
import type { HermesConnection } from '@/global'
import { translateNow } from '@/i18n'
import { desktopFsCacheKey, isReadFileErrorResult, readDesktopFileDataUrl } from '@/lib/desktop-fs'
+import { hostHas } from '@/lib/host-capabilities'
import { LruCache } from '@/lib/lru-cache'
-import { isBrowserHostedDesktop } from '@/lib/platform'
import { capitalize } from '@/lib/text'
import { notify, notifyError } from '@/store/notifications'
import { $connection } from '@/store/session'
@@ -122,7 +122,7 @@ export async function resolveMediaDisplaySrc(path: string, owner?: OwnerScope):
// profile; it takes the owner-pinned read below.
if (
owner?.connectionId === LOCAL_CONNECTION_ID &&
- !isBrowserHostedDesktop() &&
+ hostHas('nativeHostFiles') &&
window.hermesDesktop?.readFileDataUrl
) {
const dataUrl = await window.hermesDesktop.readFileDataUrl(filePathFromMediaPath(path))
@@ -283,7 +283,7 @@ export function mediaExternalUrl(path: string): string {
if (isRemoteGateway()) {
const conn = $connection.get()
- if (conn?.baseUrl && conn.token && !isBrowserHostedDesktop()) {
+ if (conn?.baseUrl && conn.token && hostHas('urlTokenAuth')) {
const file = encodeURIComponent(filePathFromMediaPath(path))
return `${conn.baseUrl}/api/files/download?path=${file}&token=${encodeURIComponent(conn.token)}`
diff --git a/apps/desktop/src/store/browser-tab-title.ts b/apps/desktop/src/store/browser-tab-title.ts
index ddd6d5f7652..8feb5d9604c 100644
--- a/apps/desktop/src/store/browser-tab-title.ts
+++ b/apps/desktop/src/store/browser-tab-title.ts
@@ -19,7 +19,7 @@
import { computed } from 'nanostores'
import { $workspaceOwnerLabels, workspaceOwnerTitle } from '@/components/pane-shell/workspace-scope'
-import { isBrowserHostedDesktop } from '@/lib/platform'
+import { hostHas } from '@/lib/host-capabilities'
import { normalizeProfileKey } from './profile'
import { $sessions, sessionMatchesStoredId } from './session'
@@ -83,7 +83,7 @@ const $browserTabTitle = computed(
/** Keep the tab title in step with session status. A no-op outside a browser
* host; returns the unsubscribe. */
export function installBrowserTabTitle(): () => void {
- if (typeof document === 'undefined' || !isBrowserHostedDesktop()) {
+ if (typeof document === 'undefined' || !hostHas('tabTitleStatus')) {
return () => {}
}
diff --git a/apps/desktop/src/store/profile.ts b/apps/desktop/src/store/profile.ts
index 8fa499daebc..2462622a36e 100644
--- a/apps/desktop/src/store/profile.ts
+++ b/apps/desktop/src/store/profile.ts
@@ -3,8 +3,9 @@ import { atom, batch, computed } from 'nanostores'
import type { HermesConnection } from '@/global'
import { getProfiles, hermesApi, setApiRequestProfile, STARTUP_REQUEST_TIMEOUT_MS } from '@/hermes'
+import { hostHas } from '@/lib/host-capabilities'
import { persistStore } from '@/lib/persist-store'
-import { initialGatewayProfile, isBrowserHostedDesktop } from '@/lib/platform'
+import { initialGatewayProfile } from '@/lib/platform'
import { sortByProfileOrder as sortProfilesByOrder } from '@/lib/profile-order'
import { invalidateProfileScopedQueries } from '@/lib/query-client'
import { arraysEqual, persistBoolean, persistStringArray, persistStringRecord, storedBoolean, storedStringArray, storedStringRecord } from '@/lib/storage'
@@ -1021,7 +1022,7 @@ export function selectProfile(name: string): void {
// — and its startup profile is the tab's own `?profile=`, which `remember`
// rewrites in place. The per-origin default and other tabs are untouched.
function remembersProfilePick(target: string): Promise<boolean> {
- if (isBrowserHostedDesktop()) {
+ if (hostHas('tabStartupProfile')) {
return Promise.resolve(true)
}
diff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.ts
index dec417e1eda..ccaae7d3752 100644
--- a/apps/desktop/src/store/session.ts
+++ b/apps/desktop/src/store/session.ts
@@ -12,7 +12,7 @@ import {
connectionScopeSuffix,
rescopeConnectionScopedStores
} from '@/lib/connection-scoped'
-import { isBrowserHostedDesktop } from '@/lib/platform'
+import { hostHas } from '@/lib/host-capabilities'
import { isMessagingSource } from '@/lib/session-source'
import type { TileSessionFocusStamp } from '@/lib/session-timer-since'
import { persistBoolean, persistString, readJson, storedBoolean, storedString, writeJson } from '@/lib/storage'
@@ -1881,7 +1881,7 @@ export const workspaceCwdForNewSession = (profile?: string): string => {
// chat reads its own profile's key and stays detached when it never chose one.
const owner = profile?.trim()
- if (owner && isBrowserHostedDesktop()) {
+ if (owner && hostHas('originScopedPrefs')) {
return readBrowserDefaultProjectDir(browserPageBasePath(), owner)
}
diff --git a/apps/desktop/src/store/translucency.ts b/apps/desktop/src/store/translucency.ts
index a642d1b0d0e..cd2ca65bf01 100644
--- a/apps/desktop/src/store/translucency.ts
+++ b/apps/desktop/src/store/translucency.ts
@@ -45,7 +45,8 @@ import {
} from '@hermes/shared/translucency'
import { atom, computed } from 'nanostores'
-import { isBrowserHostedDesktop, isMacPlatform, isWindowsPlatform } from '@/lib/platform'
+import { hostHas } from '@/lib/host-capabilities'
+import { isMacPlatform, isWindowsPlatform } from '@/lib/platform'
import { readJson, readKey, writeJson, writeKey } from '@/lib/storage'
export {
@@ -70,7 +71,7 @@ export type { Appearance }
*/
/** Browser-hosted Desktop has no native window material or opacity surface. */
export const GLASS_SUPPORTED =
- !isBrowserHostedDesktop() &&
+ hostHas('windowMaterial') &&
(typeof window !== 'undefined' && typeof window.hermesDesktop?.glassSupported === 'boolean'
? window.hermesDesktop.glassSupported
: isMacPlatform() || isWindowsPlatform())
@@ -81,7 +82,7 @@ export const GLASS_SUPPORTED =
* (see `$translucency`): a hidden lever must not move the window.
*/
export const TRANSLUCENCY_SUPPORTED =
- !isBrowserHostedDesktop() &&
+ hostHas('windowMaterial') &&
(typeof window !== 'undefined' && typeof window.hermesDesktop?.translucencySupported === 'boolean'
? window.hermesDesktop.translucencySupported
: isMacPlatform() || isWindowsPlatform())