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 {
|
try {
|
||||||
const zipUrl = 'https://github.com/Kuingsmile/piclist-themeHub/releases/download/latest/themes.zip'
|
const zipUrl = 'https://github.com/Kuingsmile/piclist-themeHub/releases/download/latest/themes.zip'
|
||||||
const zipData = await axios.get(zipUrl, {
|
const zipData = await axios.get(zipUrl, {
|
||||||
@@ -51,9 +51,10 @@ export async function fetchThemes(): Promise<void> {
|
|||||||
headers: { 'Content-Type': 'application/octet-stream' },
|
headers: { 'Content-Type': 'application/octet-stream' },
|
||||||
})
|
})
|
||||||
const zip = new AdmZip(zipData.data as Buffer)
|
const zip = new AdmZip(zipData.data as Buffer)
|
||||||
zip.extractAllTo(themesDir(), true)
|
zip.extractAllTo(path.join(themesDir()), true)
|
||||||
|
return true
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
console.error('Failed to fetch themes from remote.')
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export default [
|
|||||||
{
|
{
|
||||||
action: IRPCActionType.THEME_FETCH_THEMES,
|
action: IRPCActionType.THEME_FETCH_THEMES,
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
await fetchThemes()
|
return await fetchThemes()
|
||||||
},
|
},
|
||||||
type: IRPCType.INVOKE,
|
type: IRPCType.INVOKE,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2142,7 +2142,10 @@ async function loadThemes() {
|
|||||||
async function handleDownloadThemes() {
|
async function handleDownloadThemes() {
|
||||||
try {
|
try {
|
||||||
downloadingThemes.value = true
|
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'))
|
message.success(t('pages.settings.system.downloadThemesSuccess'))
|
||||||
await loadThemes()
|
await loadThemes()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user