[Desktop] Fix torch mirror setting (#2475)

This commit is contained in:
Chenlei Hu
2025-02-08 21:08:23 -05:00
committed by GitHub
parent 4dd292252e
commit 3d59d478b6
2 changed files with 23 additions and 18 deletions

View File

@@ -80,11 +80,28 @@ const getTorchMirrorItem = (device: TorchDeviceType): UVMirror => {
}
}
const mirrors = computed<[UVMirror, ModelRef<string>][]>(() => [
[PYTHON_MIRROR, pythonMirror],
[PYPI_MIRROR, pypiMirror],
[getTorchMirrorItem(device), torchMirror]
])
const userIsInChina = ref(false)
onMounted(async () => {
userIsInChina.value = await isInChina()
})
const useFallbackMirror = (mirror: UVMirror) => ({
...mirror,
mirror: mirror.fallbackMirror
})
const mirrors = computed<[UVMirror, ModelRef<string>][]>(() =>
(
[
[PYTHON_MIRROR, pythonMirror],
[PYPI_MIRROR, pypiMirror],
[getTorchMirrorItem(device), torchMirror]
] as [UVMirror, ModelRef<string>][]
).map(([item, modelValue]) => [
userIsInChina.value ? useFallbackMirror(item) : item,
modelValue
])
)
const validationStates = ref<ValidationState[]>(
mirrors.value.map(() => ValidationState.IDLE)
@@ -102,13 +119,4 @@ const validationStateTooltip = computed(() => {
return t('install.settings.checkingMirrors')
}
})
onMounted(async () => {
// Check if user is in China and set fallback mirrors directly
if (await isInChina()) {
for (const [item, modelValue] of mirrors.value) {
modelValue.value = item.fallbackMirror
}
}
})
</script>

View File

@@ -44,10 +44,7 @@ const normalizedSettingId = computed(() => {
})
onMounted(() => {
// Set mirror value if not already set
if (!modelValue.value) {
modelValue.value = item.mirror
}
modelValue.value = item.mirror
})
watch(validationState, (newState) => {