The best way to control Claude Code, Codex and more from any computer or phone

main
ts 62 lines 1.76 KB
Raw
1 import type { EnvironmentId } from "@t3tools/contracts";
2 import { splitFilePathPosition } from "@t3tools/shared/fileLinks";
3 import { msg } from "gt-react";
4
5 import { m } from "../../i18n/messages";
6
7 import type { MarkdownFileLinkMeta } from "../../markdown-links";
8 import type { RemoteOpenMode } from "../../remoteOpen";
9
10 export function canUseMarkdownFileShellActions(
11 environmentId: EnvironmentId | null,
12 remoteOpenMode: RemoteOpenMode,
13 isRemoteOpenResolved: boolean,
14 ): boolean {
15 return environmentId !== null && isRemoteOpenResolved && remoteOpenMode === "local-exec";
16 }
17
18 export function hasMarkdownFilePrimaryAction(input: {
19 canOpenInEditor: boolean;
20 canOpenInBrowser: boolean;
21 canOpenInPanel: boolean;
22 canOpenMedia?: boolean;
23 }): boolean {
24 return (
25 input.canOpenInEditor ||
26 input.canOpenInBrowser ||
27 input.canOpenInPanel ||
28 input.canOpenMedia === true
29 );
30 }
31
32 export function markdownFileCopyMenuItems({
33 targetPath,
34 workspaceRelativePath,
35 }: Pick<MarkdownFileLinkMeta, "targetPath" | "workspaceRelativePath">) {
36 const items = [
37 {
38 id: "copy-full",
39 label: m(msg("Copy full path")),
40 value: targetPath,
41 title: m(msg("Full path")),
42 },
43 ];
44 if (workspaceRelativePath !== null) {
45 const position = targetPath.slice(splitFilePathPosition(targetPath).path.length);
46 items.unshift({
47 id: "copy-relative",
48 label: m(msg("Copy relative path")),
49 value: `${workspaceRelativePath}${position}`,
50 title: m(msg("Relative path")),
51 });
52 }
53 return items;
54 }
55
56 export function shouldUseMarkdownFileBrowserPrimaryAction(input: {
57 canOpenInEditor: boolean;
58 canOpenInBrowser: boolean;
59 canOpenInPanel: boolean;
60 }): boolean {
61 return input.canOpenInBrowser && !input.canOpenInEditor && !input.canOpenInPanel;
62 }