Skip to content

Commit

Permalink
fix: latency countup performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso committed Dec 13, 2024
1 parent f7896c5 commit 86ea651
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 52 deletions.
64 changes: 26 additions & 38 deletions src/components/proxies/LatencyTag.vue
Original file line number Diff line number Diff line change
@@ -1,61 +1,49 @@
<template>
<div class="badge flex w-8 items-center justify-center shadow-sm">
<template v-if="latencyRollingEffect">
<div
:class="twMerge('text-xs', color)"
ref="latencyRef"
v-show="latency > 0"
/>
<BoltIcon
v-show="latency === 0"
class="h-4 w-4"
/>
</template>
<template v-else>
<div
:class="twMerge('text-xs', color)"
v-if="latency > 0"
>
{{ latency }}
</div>
<BoltIcon
v-else
class="h-4 w-4"
/>
</template>
<div
:class="twMerge('text-xs', color)"
ref="latencyRef"
v-show="latency > 0"
/>
<BoltIcon
v-show="latency === 0"
class="h-4 w-4"
/>
</div>
</template>

<script setup lang="ts">
import { getLatencyByName } from '@/store/proxies'
import { latencyRollingEffect, lowLatency, mediumLatency } from '@/store/settings'
import { lowLatency, mediumLatency } from '@/store/settings'
import { BoltIcon } from '@heroicons/vue/24/outline'
import { CountUp } from 'countup.js'
import { twMerge } from 'tailwind-merge'
import { computed, onMounted, ref, watch } from 'vue'
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
const props = defineProps<{
name: string
}>()
const latencyRef = ref()
const latency = computed(() => getLatencyByName(props.name))
if (latencyRollingEffect.value) {
let countUp: CountUp | null = null
let countUp: CountUp | null = null
onMounted(() => {
countUp = new CountUp(latencyRef.value, latency.value, {
duration: 1,
separator: '',
enableScrollSpy: true,
})
countUp.start()
onMounted(() => {
countUp = new CountUp(latencyRef.value, latency.value, {
duration: 1,
separator: '',
enableScrollSpy: false,
startVal: latency.value,
})
watch(latency, () => {
countUp?.update(latency.value)
})
watch(latency, () => {
countUp?.update(latency.value)
})
}
})
onUnmounted(() => {
countUp = null
})
const color = computed(() => {
if (latency.value < lowLatency.value) {
Expand Down
1 change: 1 addition & 0 deletions src/components/proxies/ProxyProvider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<div class="flex items-center gap-2">
<div class="text-lg font-medium sm:text-xl">
{{ proxyProvider.name }}
<span class="text-sm"> ({{ proxyProvider.proxies.length }}) </span>
</div>
<div class="flex-1" />
<div class="flex gap-2">
Expand Down
4 changes: 2 additions & 2 deletions src/components/rules/RuleCard.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div class="card mb-1 block w-full gap-2 p-2 text-sm">
<span>{{ rule.type }}</span>
<span class="mx-2">{{ rule.payload }}</span>
<span class="min-w-32 text-primary">-> {{ rule.proxy }}</span>
<span class="mx-2">{{ rule.payload }} -></span>
<span class="min-w-32 text-primary">{{ rule.proxy }}</span>
</div>
</template>

Expand Down
1 change: 0 additions & 1 deletion src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ export default {
secondaryPathTip: 'If present, start with a "/", otherwise leave it empty.',
logRetentionLimit: 'Log Retention Limit',
DNSQuery: 'DNS Query',
latencyRollingEffect: 'Latency Rolling Effect',
}
1 change: 0 additions & 1 deletion src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,4 @@ export default {
secondaryPathTip: '如果有的话以/开头,没有则留空不填',
logRetentionLimit: '日志保留条数',
DNSQuery: 'DNS 查询',
latencyRollingEffect: '延迟滚动效果',
}
1 change: 0 additions & 1 deletion src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const proxyPreviewType = useStorage('config/proxy-preview-type', PROXY_PR
export const hideUnavailableProxies = useStorage('config/hide-unavailable-proxies', false)
export const lowLatency = useStorage('config/low-latency', 300)
export const mediumLatency = useStorage('config/medium-latency', 800)
export const latencyRollingEffect = useStorage('config/latency-rolling-effect', false)

// connections
export const useConnectionCard = useStorage('config/use-connecticon-card', false)
Expand Down
9 changes: 0 additions & 9 deletions src/views/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,6 @@
v-model="mediumLatency"
/>
</div>
<div class="flex items-center gap-2">
<span class="shrink-0"> {{ $t('latencyRollingEffect') }}: </span>
<input
type="checkbox"
class="toggle"
v-model="latencyRollingEffect"
/>
</div>
</div>
</div>

Expand Down Expand Up @@ -346,7 +338,6 @@ import {
autoUpgrade,
compactConnectionCard,
font,
latencyRollingEffect,
logRetentionLimit,
lowLatency,
mediumLatency,
Expand Down

0 comments on commit 86ea651

Please sign in to comment.