|
1 | 1 | import { threadPullRequestSearchTerms } from "@t3tools/shared/threadPullRequests"; |
2 | 2 | import type { CommandPaletteLinkedThreads } from "../commandPaletteBus"; |
| 3 | +import { |
| 4 | + addProjectRemoteSourceLabel, |
| 5 | + addProjectRemoteSourcePathHint, |
| 6 | + buildAddProjectRemoteSourceReadiness, |
| 7 | + type AddProjectRemoteSource, |
| 8 | + type AddProjectRemoteSourceReadiness, |
| 9 | +} from "@t3tools/client-runtime/operations/projects"; |
3 | 10 | import { |
4 | 11 | type EnvironmentId, |
| 12 | + type EnvironmentMachineKind, |
5 | 13 | type FilesystemBrowseEntry, |
6 | 14 | type KeybindingCommand, |
| 15 | + type SourceControlDiscoveryResult, |
| 16 | + type SourceControlRepositoryInfo, |
7 | 17 | THREAD_JUMP_KEYBINDING_COMMANDS, |
8 | 18 | } from "@t3tools/contracts"; |
9 | 19 | import { filterFilesystemBrowseEntries } from "@t3tools/client-runtime/state/filesystem"; |
@@ -657,3 +667,87 @@ export function getCommandPaletteInputPlaceholder(mode: CommandPaletteMode): str |
657 | 667 | return "Enter path (e.g. ~/projects/my-app)"; |
658 | 668 | } |
659 | 669 | } |
| 670 | + |
| 671 | +export function getEnvironmentBrowsePlatform(os: string | null | undefined): string { |
| 672 | + if (os === "windows") { |
| 673 | + return "Win32"; |
| 674 | + } |
| 675 | + if (os === "darwin") { |
| 676 | + return "MacIntel"; |
| 677 | + } |
| 678 | + if (os === "linux") { |
| 679 | + return "Linux"; |
| 680 | + } |
| 681 | + return typeof navigator === "undefined" ? "" : navigator.platform; |
| 682 | +} |
| 683 | + |
| 684 | +export interface AddProjectEnvironmentOption { |
| 685 | + readonly environmentId: EnvironmentId; |
| 686 | + readonly label: string; |
| 687 | + readonly machine: EnvironmentMachineKind; |
| 688 | + readonly isPrimary: boolean; |
| 689 | + readonly isConnected: boolean; |
| 690 | + readonly status: string; |
| 691 | +} |
| 692 | + |
| 693 | +export type AddProjectCloneFlow = |
| 694 | + | { |
| 695 | + readonly step: "repository"; |
| 696 | + readonly environmentId: EnvironmentId; |
| 697 | + readonly source: AddProjectRemoteSource; |
| 698 | + } |
| 699 | + | { |
| 700 | + readonly step: "confirm"; |
| 701 | + readonly environmentId: EnvironmentId; |
| 702 | + readonly source: AddProjectRemoteSource; |
| 703 | + readonly repositoryInput: string; |
| 704 | + readonly repository: SourceControlRepositoryInfo | null; |
| 705 | + readonly remoteUrl: string; |
| 706 | + }; |
| 707 | + |
| 708 | +export function remoteProjectInputPlaceholder(flow: AddProjectCloneFlow | null): string | null { |
| 709 | + if (!flow) return null; |
| 710 | + if (flow.step === "confirm") return null; |
| 711 | + if (flow.source === "url") { |
| 712 | + return "Enter Git clone URL"; |
| 713 | + } |
| 714 | + return `Enter ${addProjectRemoteSourceLabel(flow.source)} repository (${addProjectRemoteSourcePathHint(flow.source)})`; |
| 715 | +} |
| 716 | + |
| 717 | +export function buildPaletteRemoteSourceReadiness( |
| 718 | + discovery: SourceControlDiscoveryResult | null, |
| 719 | +): AddProjectRemoteSourceReadiness { |
| 720 | + const readiness = buildAddProjectRemoteSourceReadiness(discovery); |
| 721 | + return (source) => { |
| 722 | + const entry = readiness(source); |
| 723 | + return entry.hint === null |
| 724 | + ? entry |
| 725 | + : { |
| 726 | + ...entry, |
| 727 | + hint: entry.hint.replace( |
| 728 | + "Open Source Control settings", |
| 729 | + "Open Settings -> Source Control", |
| 730 | + ), |
| 731 | + }; |
| 732 | + }; |
| 733 | +} |
| 734 | + |
| 735 | +export function errorMessage(error: unknown): string { |
| 736 | + if (error instanceof Error && error.message.trim().length > 0) { |
| 737 | + return error.message; |
| 738 | + } |
| 739 | + return "An error occurred."; |
| 740 | +} |
| 741 | + |
| 742 | +const OVERLAY_MODE_BY_COMMAND = { |
| 743 | + "commandPalette.toggle": "command", |
| 744 | + "filePicker.toggle": "files", |
| 745 | + "projectSearch.toggle": "content", |
| 746 | +} as const satisfies Partial<Record<string, SearchOverlayMode>>; |
| 747 | + |
| 748 | +export function overlayModeForCommand(command: string | null): SearchOverlayMode | null { |
| 749 | + if (command === null) return null; |
| 750 | + return command in OVERLAY_MODE_BY_COMMAND |
| 751 | + ? OVERLAY_MODE_BY_COMMAND[command as keyof typeof OVERLAY_MODE_BY_COMMAND] |
| 752 | + : null; |
| 753 | +} |
0 commit comments