Skip to content

Commit 96b6f2f

Browse files
feat(electron): copy button of connection page (#154)
Co-authored-by: arlo <webfansplz@gmail.com>
1 parent 8cd47f8 commit 96b6f2f

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

packages/client/src/components/WaitForConnection.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { VueInput } from '@vue/devtools-ui'
2+
import { VueIcon, VueInput } from '@vue/devtools-ui'
33
import AppConnecting from '~/components/AppConnecting.vue'
44
55
const props = defineProps<{
@@ -16,6 +16,8 @@ const _network = scriptWrapper(props.network!)
1616
1717
const local = ref(_local)
1818
const network = ref(_network)
19+
20+
const { copy } = useCopy()
1921
</script>
2022

2123
<template>
@@ -28,11 +30,13 @@ const network = ref(_network)
2830
<p class="text-center text-sm op80 text-base">
2931
Add one of the following to the top of your page 👇:
3032
</p>
31-
<div class="mt-3 $ui-fcc flex-row">
32-
<VueInput v-model="local" left-icon="i-carbon-copy" class="w-400px!" />
33+
<div class="mt-3 $ui-fcc flex-row gap3">
34+
<VueInput v-model="local" class="w-380px!" />
35+
<VueIcon icon="i-carbon-copy" class="cursor-pointer text-primary-300 hover:text-primary-500" @click="copy(local)" />
3336
</div>
34-
<div class="mt-3 $ui-fcc flex-row">
35-
<VueInput v-model="network" left-icon="i-carbon-copy" class="w-400px!" />
37+
<div class="mt-3 $ui-fcc flex-row gap3">
38+
<VueInput v-model="network" class="w-380px!" />
39+
<VueIcon icon="i-carbon-copy" class="cursor-pointer text-primary-300 hover:text-primary-500" @click="copy(network)" />
3640
</div>
3741
</div>
3842
</AppConnecting>

packages/client/src/components/assets/AssetDetails.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const codeSnippets = computed(() => {
5757
return items
5858
})
5959
60-
const copy = useCopy()
60+
const { copy } = useCopy()
6161
const timeAgo = useTimeAgo(() => asset.value.mtime)
6262
const fileSize = computed(() => {
6363
const size = asset.value.size
@@ -159,7 +159,7 @@ const supportsPreview = computed(() => {
159159
icon="i-carbon-copy"
160160
action mr1 mt--2px flex-none
161161
:border="false"
162-
@click="copy(asset.publicPath, 'assets-public-path')"
162+
@click="copy(asset.publicPath, { silent: false, type: 'assets-public-path' })"
163163
/>
164164
<RouterLink
165165
:to="asset.publicPath"

packages/client/src/components/code/CodeSnippets.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const props = defineProps<{
99
}>()
1010
1111
const selected = shallowRef<CodeSnippet | undefined>(props.codeSnippets[0])
12-
const copy = useCopy()
12+
const { copy } = useCopy()
1313
1414
const selectedLang = computed(() => (selected.value?.lang || 'text') as BuiltinLanguage)
1515
@@ -45,7 +45,7 @@ watchEffect(() => {
4545
w-full of-auto p3
4646
/>
4747
<div flex="~ gap-2" px3 pb3>
48-
<VueButton @click="copy(selected!.code, eventType || `code-snippet-${selected.name}`)">
48+
<VueButton @click="copy(selected!.code, { silent: false, type: eventType || `code-snippet-${selected.name}` })">
4949
Copy
5050
<template #icon>
5151
<slot name="i-carbon-copy" />
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1+
import { showVueNotification } from '@vue/devtools-ui'
2+
3+
interface CopyOptions {
4+
silent?: boolean
5+
type?: string
6+
}
7+
18
export function useCopy() {
2-
const clipboard = useClipboard()
9+
const { copy: _copy, copied } = useClipboard()
10+
11+
const copy = (text: string, options: CopyOptions = {}) => {
12+
const {
13+
silent = false,
14+
type = '',
15+
} = options
16+
_copy(text).then(() => {
17+
if (!silent) {
18+
showVueNotification({
19+
message: 'Copied to clipboard',
20+
type: 'success',
21+
duration: 3000,
22+
})
23+
}
24+
}).catch(() => {
25+
if (!silent) {
26+
showVueNotification({
27+
message: 'Failed to copy to clipboard',
28+
type: 'error',
29+
duration: 3000,
30+
})
31+
}
32+
})
33+
}
334

4-
return (text: string, type?: string) => {
5-
clipboard.copy(text)
35+
return {
36+
copy,
37+
copied,
638
}
739
}

packages/ui/src/components/Input.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const props = withDefaults(defineProps<{
1515
loading?: boolean
1616
autoFocus?: boolean
1717
loadingDebounceTime?: number
18+
readonly?: boolean
1819
}>(), {
1920
placeholder: '',
2021
variant: 'normal',
@@ -26,6 +27,7 @@ const props = withDefaults(defineProps<{
2627
loading: false,
2728
autoFocus: false,
2829
loadingDebounceTime: 0,
30+
readonly: false,
2931
})
3032
3133
const emit = defineEmits<{
@@ -42,7 +44,7 @@ const focused = refWithControl(false, {
4244
emit('updateFocused', value)
4345
},
4446
})
45-
const noFocusAnimation = computed(() => props.variant === 'flat' || props.variant === 'warning')
47+
const noFocusAnimation = computed(() => props.variant === 'flat' || props.variant === 'warning' || props.disabled || props.readonly)
4648
4749
const disabled = computed(() => props.disabled || loading.value)
4850
@@ -100,7 +102,7 @@ watchEffect(() => {
100102
<input
101103
ref="inputRef" v-model="value"
102104
class="$ui-base w-full bg-transparent color-inherit outline-none placeholder-color-gray-500 dark:placeholder-gray-300" :type="props.password ? 'password' : 'text'"
103-
:placeholder="placeholder" :disabled="disabled"
105+
:placeholder="placeholder" :disabled="disabled || readonly"
104106
@blur="focused = false"
105107
>
106108
<div v-if="loading" :class="iconClasses">

0 commit comments

Comments
 (0)