1+ import { clientHostEnvironmentAtom } from "../state/clientHostEnvironment" ;
12import { buildFileLinkParentSuffixByPath , fileLinkLabel } from "@t3tools/shared/fileLinks" ;
23import {
34 isWindowsDrivePathHref ,
@@ -410,6 +411,7 @@ type MarkdownServerConfigFields = ReturnType<typeof markdownServerConfigFields>;
410411function markdownServerConfigFields ( config : ServerConfig | null ) {
411412 return {
412413 pullRequestsEnabled : config !== null ,
414+ isMacOS : config ?. environment . platform . os === "darwin" ,
413415 availableEditors : config ?. availableEditors ?? NO_MARKDOWN_EDITORS ,
414416 revealInFileManagerLabel :
415417 config ?. shellRevealInFileManager === true && config . availableEditors . includes ( "file-manager" )
@@ -426,6 +428,7 @@ function markdownServerConfigFieldsEqual(
426428) : boolean {
427429 return (
428430 previous . pullRequestsEnabled === next . pullRequestsEnabled &&
431+ previous . isMacOS === next . isMacOS &&
429432 previous . revealInFileManagerLabel === next . revealInFileManagerLabel &&
430433 previous . availableEditors . length === next . availableEditors . length &&
431434 previous . availableEditors . every ( ( editor , index ) => editor === next . availableEditors [ index ] )
@@ -551,6 +554,7 @@ function useChatMarkdownState({
551554 const environmentId = threadRef ?. environmentId ?? explicitEnvironmentId ?? null ;
552555 const canOperateHost = useEnvironmentScope ( environmentId , AuthOrchestrationOperateScope ) ;
553556 const canOperatePreview = useEnvironmentScope ( environmentId , AuthPreviewOperateScope ) ;
557+ const isClientHost = useAtomValue ( clientHostEnvironmentAtom ( environmentId ) ) ;
554558 const remoteOpen = useRemoteOpenResolution ( environmentId ) ;
555559 const canUseShellActions =
556560 canOperateHost &&
@@ -620,7 +624,7 @@ function useChatMarkdownState({
620624 } ,
621625 ) ;
622626 } ;
623- const { pullRequestsEnabled, availableEditors, revealInFileManagerLabel } = useAtomValue (
627+ const { pullRequestsEnabled, availableEditors, revealInFileManagerLabel, isMacOS } = useAtomValue (
624628 markdownServerConfigFieldsAtom ( environmentId ) ,
625629 ) ;
626630 const projects = useProjects ( ) ;
@@ -811,6 +815,13 @@ function useChatMarkdownState({
811815 cwd,
812816 findWorkspaceMatch : ( ) => findWorkspaceFileMatch ( fileLinkMeta ) ,
813817 } ) ;
818+ const isAppBundle = isMacOS && fileLinkMeta . filePath . endsWith ( ".app" ) ;
819+ const canOpenApp =
820+ environmentId !== null &&
821+ isAppBundle &&
822+ isClientHost &&
823+ canOperateHost &&
824+ availableEditors . includes ( "file-manager" ) ;
814825 const mediaPath = mediaSource ?? fileLinkMeta . filePath ;
815826 const canPreviewMedia =
816827 mediaMimeTypeFromExtension (
@@ -825,9 +836,14 @@ function useChatMarkdownState({
825836 environmentId = { environmentId }
826837 href = { fileLinkMeta . targetPath }
827838 targetPath = { fileLinkMeta . targetPath }
828- iconPath = { fileLinkMeta . filePath }
839+ iconPath = {
840+ isAppBundle && cwd
841+ ? resolveWorkspaceFilePath ( fileLinkMeta . filePath , cwd )
842+ : fileLinkMeta . filePath
843+ }
844+ isAppBundle = { isAppBundle }
829845 workspaceRelativePath = { fileLinkMeta . workspaceRelativePath }
830- panelPath = { panelPath }
846+ panelPath = { isAppBundle ? null : panelPath }
831847 line = { fileLinkMeta . line }
832848 label = { fileLinkLabel (
833849 {
@@ -841,12 +857,18 @@ function useChatMarkdownState({
841857 theme = { resolvedTheme }
842858 threadRef = { threadRef }
843859 onOpen = {
844- canUseShellActions
860+ canOpenApp
845861 ? async ( ) =>
846- openInPreferredEditor (
847- markdownFileEditorTarget ( fileLinkMeta , await resolveHostPath ( ) ) ,
848- )
849- : undefined
862+ openInEditor ( {
863+ environmentId,
864+ input : { cwd : ( await resolveHostPath ( ) ) . absolutePath , editor : "file-manager" } ,
865+ } )
866+ : canUseShellActions
867+ ? async ( ) =>
868+ openInPreferredEditor (
869+ markdownFileEditorTarget ( fileLinkMeta , await resolveHostPath ( ) ) ,
870+ )
871+ : undefined
850872 }
851873 resolveCopyPaths = { async ( ) =>
852874 markdownFileCopyPaths ( fileLinkMeta , await resolveHostPath ( ) , cwd )
@@ -857,7 +879,7 @@ function useChatMarkdownState({
857879 ? ( ) => openMarkdownMedia ( mediaPath , fileLinkMeta . filePath )
858880 : undefined
859881 }
860- openInEditorMenuLabel = { preferredEditorMenuLabel }
882+ openInEditorMenuLabel = { canOpenApp ? "Open app" : preferredEditorMenuLabel }
861883 onReveal = {
862884 canUseShellActions && revealInFileManagerLabel !== undefined
863885 ? async ( ) => revealFileInFileManager ( ( await resolveHostPath ( ) ) . absolutePath )
0 commit comments