|
| 1 | +<template> |
| 2 | + <Dialog :open="open" @update:open="emit('update:open', $event)"> |
| 3 | + <DialogContent class="sm:max-w-2xl max-h-[85vh] flex flex-col"> |
| 4 | + <DialogHeader> |
| 5 | + <DialogTitle>{{ t('settings.acp.dependency.title') }}</DialogTitle> |
| 6 | + <DialogDescription> |
| 7 | + {{ t('settings.acp.dependency.description') }} |
| 8 | + </DialogDescription> |
| 9 | + </DialogHeader> |
| 10 | + |
| 11 | + <div class="flex-1 overflow-y-auto space-y-4 pr-2"> |
| 12 | + <div |
| 13 | + v-for="(dep, index) in dependencies" |
| 14 | + :key="index" |
| 15 | + class="border rounded-lg p-4 space-y-3 bg-zinc-50 dark:bg-zinc-900" |
| 16 | + > |
| 17 | + <div> |
| 18 | + <h3 class="font-semibold text-lg text-foreground">{{ dep.name }}</h3> |
| 19 | + <p class="text-sm text-muted-foreground mt-1">{{ dep.description }}</p> |
| 20 | + </div> |
| 21 | + |
| 22 | + <!-- Installation Commands --> |
| 23 | + <div |
| 24 | + v-if="dep.installCommands && hasInstallCommands(dep.installCommands)" |
| 25 | + class="space-y-2" |
| 26 | + > |
| 27 | + <Label class="text-sm font-medium">{{ |
| 28 | + t('settings.acp.dependency.installCommands') |
| 29 | + }}</Label> |
| 30 | + <div class="space-y-2"> |
| 31 | + <template v-for="(command, cmdType) in dep.installCommands" :key="cmdType"> |
| 32 | + <div v-if="command" class="flex items-center gap-2"> |
| 33 | + <div class="flex-1 flex items-center gap-2 bg-background border rounded-md p-2"> |
| 34 | + <code class="flex-1 text-sm font-mono text-foreground break-all">{{ |
| 35 | + command |
| 36 | + }}</code> |
| 37 | + <Button |
| 38 | + variant="ghost" |
| 39 | + size="icon" |
| 40 | + class="h-8 w-8 shrink-0" |
| 41 | + @click="copyToClipboard(command)" |
| 42 | + :title="t('settings.acp.dependency.copy')" |
| 43 | + > |
| 44 | + <Icon icon="lucide:copy" class="h-4 w-4" /> |
| 45 | + </Button> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + </template> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + |
| 52 | + <!-- Download URL --> |
| 53 | + <div v-if="dep.downloadUrl" class="space-y-2"> |
| 54 | + <Label class="text-sm font-medium">{{ |
| 55 | + t('settings.acp.dependency.downloadUrl') |
| 56 | + }}</Label> |
| 57 | + <div class="flex items-center gap-2 bg-background border rounded-md p-2"> |
| 58 | + <a |
| 59 | + :href="dep.downloadUrl" |
| 60 | + target="_blank" |
| 61 | + rel="noopener noreferrer" |
| 62 | + class="flex-1 text-sm text-primary hover:underline break-all" |
| 63 | + > |
| 64 | + {{ dep.downloadUrl }} |
| 65 | + </a> |
| 66 | + <Button |
| 67 | + variant="ghost" |
| 68 | + size="icon" |
| 69 | + class="h-8 w-8 shrink-0" |
| 70 | + @click="copyToClipboard(dep.downloadUrl)" |
| 71 | + :title="t('settings.acp.dependency.copy')" |
| 72 | + > |
| 73 | + <Icon icon="lucide:copy" class="h-4 w-4" /> |
| 74 | + </Button> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + |
| 80 | + <DialogFooter class="mt-4"> |
| 81 | + <Button @click="emit('update:open', false)"> |
| 82 | + {{ t('common.close') }} |
| 83 | + </Button> |
| 84 | + </DialogFooter> |
| 85 | + </DialogContent> |
| 86 | + </Dialog> |
| 87 | +</template> |
| 88 | + |
| 89 | +<script setup lang="ts"> |
| 90 | +import { useI18n } from 'vue-i18n' |
| 91 | +import { useToast } from '@/components/use-toast' |
| 92 | +import { |
| 93 | + Dialog, |
| 94 | + DialogContent, |
| 95 | + DialogDescription, |
| 96 | + DialogFooter, |
| 97 | + DialogHeader, |
| 98 | + DialogTitle |
| 99 | +} from '@shadcn/components/ui/dialog' |
| 100 | +import { Button } from '@shadcn/components/ui/button' |
| 101 | +import { Label } from '@shadcn/components/ui/label' |
| 102 | +import { Icon } from '@iconify/vue' |
| 103 | + |
| 104 | +interface ExternalDependency { |
| 105 | + name: string |
| 106 | + description: string |
| 107 | + platform?: string[] |
| 108 | + checkCommand?: string |
| 109 | + checkPaths?: string[] |
| 110 | + installCommands?: { |
| 111 | + winget?: string |
| 112 | + chocolatey?: string |
| 113 | + scoop?: string |
| 114 | + } |
| 115 | + downloadUrl?: string |
| 116 | + requiredFor?: string[] |
| 117 | +} |
| 118 | + |
| 119 | +defineProps<{ |
| 120 | + open: boolean |
| 121 | + dependencies: ExternalDependency[] |
| 122 | +}>() |
| 123 | + |
| 124 | +const emit = defineEmits<{ |
| 125 | + (e: 'update:open', value: boolean): void |
| 126 | +}>() |
| 127 | + |
| 128 | +const { t } = useI18n() |
| 129 | +const { toast } = useToast() |
| 130 | + |
| 131 | +const hasInstallCommands = (commands: ExternalDependency['installCommands']): boolean => { |
| 132 | + if (!commands) return false |
| 133 | + return Boolean(commands.winget || commands.chocolatey || commands.scoop) |
| 134 | +} |
| 135 | + |
| 136 | +const copyToClipboard = async (text: string) => { |
| 137 | + try { |
| 138 | + if (window.api?.copyText) { |
| 139 | + window.api.copyText(text) |
| 140 | + toast({ |
| 141 | + title: t('settings.acp.dependency.copied'), |
| 142 | + duration: 2000 |
| 143 | + }) |
| 144 | + } else if (navigator.clipboard) { |
| 145 | + await navigator.clipboard.writeText(text) |
| 146 | + toast({ |
| 147 | + title: t('settings.acp.dependency.copied'), |
| 148 | + duration: 2000 |
| 149 | + }) |
| 150 | + } else { |
| 151 | + console.warn('[AcpDependencyDialog] Clipboard API not available') |
| 152 | + } |
| 153 | + } catch (error) { |
| 154 | + console.error('[AcpDependencyDialog] Failed to copy to clipboard:', error) |
| 155 | + toast({ |
| 156 | + title: t('settings.acp.dependency.copyFailed'), |
| 157 | + variant: 'destructive' |
| 158 | + }) |
| 159 | + } |
| 160 | +} |
| 161 | +</script> |
0 commit comments