Feature(custom): optimize theme download logic

This commit is contained in:
Kuingsmile
2026-01-15 11:18:40 +08:00
parent 5169f00254
commit f7667b5ff6
3 changed files with 9 additions and 5 deletions

View File

@@ -43,7 +43,7 @@ export async function resolveThemes(): Promise<{ key: string; label: string }[]>
}
}
export async function fetchThemes(): Promise<void> {
export async function fetchThemes(): Promise<boolean> {
try {
const zipUrl = 'https://github.com/Kuingsmile/piclist-themeHub/releases/download/latest/themes.zip'
const zipData = await axios.get(zipUrl, {
@@ -51,9 +51,10 @@ export async function fetchThemes(): Promise<void> {
headers: { 'Content-Type': 'application/octet-stream' },
})
const zip = new AdmZip(zipData.data as Buffer)
zip.extractAllTo(themesDir(), true)
zip.extractAllTo(path.join(themesDir()), true)
return true
} catch (_e) {
console.error('Failed to fetch themes from remote.')
return false
}
}

View File

@@ -62,7 +62,7 @@ export default [
{
action: IRPCActionType.THEME_FETCH_THEMES,
handler: async () => {
await fetchThemes()
return await fetchThemes()
},
type: IRPCType.INVOKE,
},

View File

@@ -2142,7 +2142,10 @@ async function loadThemes() {
async function handleDownloadThemes() {
try {
downloadingThemes.value = true
await window.electron.triggerRPC(IRPCActionType.THEME_FETCH_THEMES)
const result = await window.electron.triggerRPC(IRPCActionType.THEME_FETCH_THEMES)
if (!result) {
throw new Error('No themes were downloaded.')
}
message.success(t('pages.settings.system.downloadThemesSuccess'))
await loadThemes()
} catch (error) {