1+ import { clientHostEnvironmentAtom } from "../state/clientHostEnvironment" ;
12import { buildFileLinkParentSuffixByPath , fileLinkLabel } from "@t3tools/shared/fileLinks" ;
23import {
34 isWindowsDrivePathHref ,
@@ -411,6 +412,7 @@ type MarkdownServerConfigFields = ReturnType<typeof markdownServerConfigFields>;
411412function markdownServerConfigFields ( config : ServerConfig | null ) {
412413 return {
413414 pullRequestsEnabled : config !== null ,
415+ isMacOS : config ?. environment . platform . os === "darwin" ,
414416 availableEditors : config ?. availableEditors ?? NO_MARKDOWN_EDITORS ,
415417 revealInFileManagerLabel :
416418 config ?. shellRevealInFileManager === true && config . availableEditors . includes ( "file-manager" )
@@ -427,6 +429,7 @@ function markdownServerConfigFieldsEqual(
427429) : boolean {
428430 return (
429431 previous . pullRequestsEnabled === next . pullRequestsEnabled &&
432+ previous . isMacOS === next . isMacOS &&
430433 previous . revealInFileManagerLabel === next . revealInFileManagerLabel &&
431434 previous . availableEditors . length === next . availableEditors . length &&
432435 previous . availableEditors . every ( ( editor , index ) => editor === next . availableEditors [ index ] )
@@ -552,6 +555,7 @@ function useChatMarkdownState({
552555 const environmentId = threadRef ?. environmentId ?? explicitEnvironmentId ?? null ;
553556 const canOperateHost = useEnvironmentScope ( environmentId , AuthOrchestrationOperateScope ) ;
554557 const canOperatePreview = useEnvironmentScope ( environmentId , AuthPreviewOperateScope ) ;
558+ const isClientHost = useAtomValue ( clientHostEnvironmentAtom ( environmentId ) ) ;
555559 const remoteOpen = useRemoteOpenResolution ( environmentId ) ;
556560 const canUseShellActions =
557561 canOperateHost &&
@@ -621,7 +625,7 @@ function useChatMarkdownState({
621625 } ,
622626 ) ;
623627 } ;
624- const { pullRequestsEnabled, availableEditors, revealInFileManagerLabel } = useAtomValue (
628+ const { pullRequestsEnabled, availableEditors, revealInFileManagerLabel, isMacOS } = useAtomValue (
625629 markdownServerConfigFieldsAtom ( environmentId ) ,
626630 ) ;
627631 const projects = useProjects ( ) ;
@@ -822,6 +826,13 @@ function useChatMarkdownState({
822826 cwd,
823827 findWorkspaceMatch : ( ) => findWorkspaceFileMatch ( fileLinkMeta ) ,
824828 } ) ;
829+ const isAppBundle = isMacOS && fileLinkMeta . filePath . endsWith ( ".app" ) ;
830+ const canOpenApp =
831+ environmentId !== null &&
832+ isAppBundle &&
833+ isClientHost &&
834+ canOperateHost &&
835+ availableEditors . includes ( "file-manager" ) ;
825836 const mediaPath = mediaSource ?? fileLinkMeta . filePath ;
826837 const canPreviewMedia =
827838 mediaMimeTypeFromExtension (
@@ -836,9 +847,14 @@ function useChatMarkdownState({
836847 environmentId = { environmentId }
837848 href = { fileLinkMeta . targetPath }
838849 targetPath = { fileLinkMeta . targetPath }
839- iconPath = { fileLinkMeta . filePath }
850+ iconPath = {
851+ isAppBundle && cwd
852+ ? resolveWorkspaceFilePath ( fileLinkMeta . filePath , cwd )
853+ : fileLinkMeta . filePath
854+ }
855+ isAppBundle = { isAppBundle }
840856 workspaceRelativePath = { fileLinkMeta . workspaceRelativePath }
841- panelPath = { panelPath }
857+ panelPath = { isAppBundle ? null : panelPath }
842858 line = { fileLinkMeta . line }
843859 label = { fileLinkLabel (
844860 {
@@ -852,12 +868,18 @@ function useChatMarkdownState({
852868 theme = { resolvedTheme }
853869 threadRef = { threadRef }
854870 onOpen = {
855- canUseShellActions
871+ canOpenApp
856872 ? async ( ) =>
857- openInPreferredEditor (
858- markdownFileEditorTarget ( fileLinkMeta , await resolveHostPath ( ) ) ,
859- )
860- : undefined
873+ openInEditor ( {
874+ environmentId,
875+ input : { cwd : ( await resolveHostPath ( ) ) . absolutePath , editor : "file-manager" } ,
876+ } )
877+ : canUseShellActions
878+ ? async ( ) =>
879+ openInPreferredEditor (
880+ markdownFileEditorTarget ( fileLinkMeta , await resolveHostPath ( ) ) ,
881+ )
882+ : undefined
861883 }
862884 resolveCopyPaths = { async ( ) =>
863885 markdownFileCopyPaths ( fileLinkMeta , await resolveHostPath ( ) , cwd )
@@ -868,7 +890,7 @@ function useChatMarkdownState({
868890 ? ( ) => openMarkdownMedia ( mediaPath , fileLinkMeta . filePath )
869891 : undefined
870892 }
871- openInEditorMenuLabel = { preferredEditorMenuLabel }
893+ openInEditorMenuLabel = { canOpenApp ? "Open app" : preferredEditorMenuLabel }
872894 onReveal = {
873895 canUseShellActions && revealInFileManagerLabel !== undefined
874896 ? async ( ) => revealFileInFileManager ( ( await resolveHostPath ( ) ) . absolutePath )
0 commit comments