refactor: btns fallback
This commit is contained in:
parent
9aa6c406c6
commit
837b960e88
|
@ -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> => {
|
return process(async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const _url = await useTimeout(normalizeUrlInput(url), timeout)
|
const _url = await useTimeout(normalizeUrlInput(url), timeout)
|
||||||
|
|
|
@ -14,6 +14,11 @@ const main = (): void => {
|
||||||
const filename = scoreinfo.fileName
|
const filename = scoreinfo.fileName
|
||||||
|
|
||||||
let indvPartBtn: HTMLButtonElement | null = null
|
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({
|
btnList.add({
|
||||||
name: i18n('DOWNLOAD')('MSCZ'),
|
name: i18n('DOWNLOAD')('MSCZ'),
|
||||||
|
@ -37,12 +42,12 @@ const main = (): void => {
|
||||||
|
|
||||||
btnList.add({
|
btnList.add({
|
||||||
name: i18n('DOWNLOAD')('MIDI'),
|
name: i18n('DOWNLOAD')('MIDI'),
|
||||||
action: BtnAction.download(() => getFileUrl('midi'), () => indvPartBtn?.click()),
|
action: BtnAction.download(() => getFileUrl('midi'), fallback, timeout),
|
||||||
})
|
})
|
||||||
|
|
||||||
btnList.add({
|
btnList.add({
|
||||||
name: i18n('DOWNLOAD')('MP3'),
|
name: i18n('DOWNLOAD')('MP3'),
|
||||||
action: BtnAction.download(() => getFileUrl('mp3'), () => indvPartBtn?.click()),
|
action: BtnAction.download(() => getFileUrl('mp3'), fallback, timeout),
|
||||||
})
|
})
|
||||||
|
|
||||||
indvPartBtn = btnList.add({
|
indvPartBtn = btnList.add({
|
||||||
|
|
Loading…
Reference in New Issue