refactor: btns fallback

This commit is contained in:
Xmader 2020-11-13 01:00:45 -05:00
parent 9aa6c406c6
commit 837b960e88
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
2 changed files with 8 additions and 3 deletions

View File

@ -160,7 +160,7 @@ export namespace BtnAction {
})
}
export const download = (url: UrlInput, fallback?: () => Promisable<void>, timeout = 30 * 1000): BtnAction => {
export const download = (url: UrlInput, fallback?: () => Promisable<void>, timeout = Infinity): BtnAction => {
return process(async (): Promise<void> => {
try {
const _url = await useTimeout(normalizeUrlInput(url), timeout)

View File

@ -14,6 +14,11 @@ const main = (): void => {
const filename = scoreinfo.fileName
let indvPartBtn: HTMLButtonElement | null = null
const timeout = 30 * 1000 // 30s
const fallback = () => {
// btns fallback to load from MSCZ file (`Individual Parts`)
return indvPartBtn?.click()
}
btnList.add({
name: i18n('DOWNLOAD')('MSCZ'),
@ -37,12 +42,12 @@ const main = (): void => {
btnList.add({
name: i18n('DOWNLOAD')('MIDI'),
action: BtnAction.download(() => getFileUrl('midi'), () => indvPartBtn?.click()),
action: BtnAction.download(() => getFileUrl('midi'), fallback, timeout),
})
btnList.add({
name: i18n('DOWNLOAD')('MP3'),
action: BtnAction.download(() => getFileUrl('mp3'), () => indvPartBtn?.click()),
action: BtnAction.download(() => getFileUrl('mp3'), fallback, timeout),
})
indvPartBtn = btnList.add({