feat(desktop): wire remote filesystem browsing

This commit is contained in:
yoniebans
2026-06-11 09:41:35 -07:00
committed by Teknium
parent db79e90130
commit 8878484f85
12 changed files with 258 additions and 35 deletions
+6 -6
View File
@@ -23,7 +23,7 @@ export function desktopFsCacheKey() {
return connectionCacheKey($connection.get())
}
function isRemoteMode() {
export function isDesktopFsRemoteMode() {
return $connection.get()?.mode === 'remote'
}
@@ -41,7 +41,7 @@ function bridge() {
export async function readDesktopDir(path: string): Promise<HermesReadDirResult> {
const desktop = bridge()
if (!isRemoteMode()) {
if (!isDesktopFsRemoteMode()) {
return desktop.readDir(path)
}
return desktop.api<HermesReadDirResult>({ path: fsPath('list', path) })
@@ -49,7 +49,7 @@ export async function readDesktopDir(path: string): Promise<HermesReadDirResult>
export async function readDesktopFileText(path: string): Promise<HermesReadFileTextResult> {
const desktop = bridge()
if (!isRemoteMode()) {
if (!isDesktopFsRemoteMode()) {
return desktop.readFileText(path)
}
return desktop.api<HermesReadFileTextResult>({ path: fsPath('read-text', path) })
@@ -57,7 +57,7 @@ export async function readDesktopFileText(path: string): Promise<HermesReadFileT
export async function readDesktopFileDataUrl(path: string): Promise<string> {
const desktop = bridge()
if (!isRemoteMode()) {
if (!isDesktopFsRemoteMode()) {
return desktop.readFileDataUrl(path)
}
@@ -67,7 +67,7 @@ export async function readDesktopFileDataUrl(path: string): Promise<string> {
export async function desktopGitRoot(path: string): Promise<string | null> {
const desktop = bridge()
if (!isRemoteMode()) {
if (!isDesktopFsRemoteMode()) {
return desktop.gitRoot ? desktop.gitRoot(path) : null
}
@@ -77,7 +77,7 @@ export async function desktopGitRoot(path: string): Promise<string | null> {
export async function selectDesktopPaths(options?: HermesSelectPathsOptions): Promise<string[]> {
const desktop = bridge()
if (!isRemoteMode()) {
if (!isDesktopFsRemoteMode()) {
return desktop.selectPaths(options)
}
return remotePicker ? remotePicker.selectPaths(options) : []
+23 -2
View File
@@ -1,3 +1,4 @@
import { isDesktopFsRemoteMode, readDesktopFileText } from '@/lib/desktop-fs'
import type { PreviewTarget } from '@/store/preview'
const HTML_EXTENSIONS = new Set(['.htm', '.html'])
@@ -107,6 +108,26 @@ export function localPreviewTarget(rawTarget: string, cwd?: string | null): Prev
}
}
async function enrichPreviewTarget(target: PreviewTarget | null): Promise<PreviewTarget | null> {
if (!isDesktopFsRemoteMode() || !target || target.kind !== 'file' || target.previewKind === 'image') {
return target
}
try {
const result = await readDesktopFileText(target.path || target.source)
return {
...target,
binary: result.binary,
byteSize: result.byteSize,
language: result.language || target.language,
large: (result.byteSize ?? 0) > 512 * 1024,
mimeType: result.mimeType
}
} catch {
return target
}
}
export async function normalizeOrLocalPreviewTarget(
rawTarget: string,
cwd?: string | null
@@ -115,12 +136,12 @@ export async function normalizeOrLocalPreviewTarget(
const normalized = await window.hermesDesktop?.normalizePreviewTarget?.(rawTarget, cwd || undefined)
if (normalized) {
return normalized
return enrichPreviewTarget(normalized)
}
} catch {
// Running Electron may still have the old HTML-only preview IPC. Fall
// through to renderer-side local classification so text/images still open.
}
return localPreviewTarget(rawTarget, cwd)
return enrichPreviewTarget(localPreviewTarget(rawTarget, cwd))
}