mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-06 20:42:57 +08:00
✨ Feature(custom): optimize theme download logic
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ export default [
|
||||
{
|
||||
action: IRPCActionType.THEME_FETCH_THEMES,
|
||||
handler: async () => {
|
||||
await fetchThemes()
|
||||
return await fetchThemes()
|
||||
},
|
||||
type: IRPCType.INVOKE,
|
||||
},
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user