Improve install path validation and i18n (#2042)

Co-authored-by: huchenlei <huchenlei@proton.me>
Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
filtered
2024-12-25 06:36:32 +11:00
committed by GitHub
parent 467b35f98d
commit 006d544ac5
8 changed files with 54 additions and 11 deletions

View File

@@ -26,9 +26,12 @@
<Button icon="pi pi-folder" @click="browsePath" class="w-12" />
</div>
<Message v-if="pathError" severity="error">
<Message v-if="pathError" severity="error" class="whitespace-pre-line">
{{ pathError }}
</Message>
<Message v-if="pathExists" severity="warn">
{{ $t('install.pathExists') }}
</Message>
</div>
<!-- System Paths Info -->
@@ -74,6 +77,7 @@ const { t } = useI18n()
const installPath = defineModel<string>('installPath', { required: true })
const pathError = defineModel<string>('pathError', { required: true })
const pathExists = ref(false)
const appData = ref('')
const appPath = ref('')
@@ -92,11 +96,25 @@ onMounted(async () => {
const validatePath = async (path: string) => {
try {
pathError.value = ''
pathExists.value = false
const validation = await electron.validateInstallPath(path)
// Create a pre-formatted list of errors
if (!validation.isValid) {
pathError.value = validation.error
const errors: string[] = []
if (validation.cannotWrite) errors.push(t('install.cannotWrite'))
if (validation.freeSpace < validation.requiredSpace) {
const requiredGB = validation.requiredSpace / 1024 / 1024 / 1024
errors.push(`${t('install.insufficientFreeSpace')}: ${requiredGB} GB`)
}
if (validation.parentMissing) errors.push(t('install.parentMissing'))
if (validation.error)
errors.push(`${t('install.unhandledError')}: ${validation.error}`)
pathError.value = errors.join('\n')
}
// Display the path exists warning
if (validation.exists) pathExists.value = true
} catch (error) {
pathError.value = t('install.pathValidationFailed')
}