From 94305ff96426311d230f0f09ec8833fd051148dc Mon Sep 17 00:00:00 2001 From: Xmader Date: Fri, 13 Nov 2020 01:27:15 -0500 Subject: [PATCH] v0.15.0 --- dist/main.js | 43 +++++++++++++++++++++++++++++++++---------- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/dist/main.js b/dist/main.js index 886c81f..0080480 100644 --- a/dist/main.js +++ b/dist/main.js @@ -5,7 +5,7 @@ // @supportURL https://github.com/Xmader/musescore-downloader/issues // @updateURL https://msdl.librescore.org/install.user.js // @downloadURL https://msdl.librescore.org/install.user.js -// @version 0.14.6 +// @version 0.15.0 // @description download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱 // @author Xmader // @match https://musescore.com/*/* @@ -220,6 +220,17 @@ const data = yield r.arrayBuffer(); return new Uint8Array(data); }); + const useTimeout = (promise, ms) => __awaiter(void 0, void 0, void 0, function* () { + if (!(promise instanceof Promise)) { + return promise; + } + return new Promise((resolve, reject) => { + const i = setTimeout(() => { + reject(new Error('timeout')); + }, ms); + promise.then(resolve, reject).finally(() => clearTimeout(i)); + }); + }); const waitForDocumentLoaded = () => { if (document.readyState !== 'complete') { return new Promise(resolve => { @@ -26876,13 +26887,13 @@ Please pipe the document into a Node stream.\ window.open(yield normalizeUrlInput(url)); })); }; - BtnAction.download = (url) => { + BtnAction.download = (url, fallback, timeout) => { return BtnAction.process(() => __awaiter(this, void 0, void 0, function* () { const _url = yield normalizeUrlInput(url); const a = document.createElement('a'); a.href = _url; a.dispatchEvent(new MouseEvent('click')); - })); + }), fallback, timeout); }; BtnAction.mscoreWindow = (fn) => { return (btnName, btn, setText) => __awaiter(this, void 0, void 0, function* () { @@ -26910,18 +26921,25 @@ Please pipe the document into a Node stream.\ fn(w, score, txt); }); }; - BtnAction.process = (fn) => { + BtnAction.process = (fn, fallback, timeout = Infinity) => { return (name, btn, setText) => __awaiter(this, void 0, void 0, function* () { const _onclick = btn.onclick; btn.onclick = null; setText(i18n('PROCESSING')()); try { - yield fn(); + yield useTimeout(fn(), timeout); setText(name); } catch (err) { - setText(i18n('BTN_ERROR')()); console.error(err); + if (fallback) { + // use fallback + yield fallback(); + setText(name); + } + else { + setText(i18n('BTN_ERROR')()); + } } btn.onclick = _onclick; }); @@ -26938,13 +26956,18 @@ Please pipe the document into a Node stream.\ const main = () => { const btnList = new BtnList(); const filename = scoreinfo.fileName; + let indvPartBtn = null; + const fallback = () => { + // btns fallback to load from MSCZ file (`Individual Parts`) + return indvPartBtn === null || indvPartBtn === void 0 ? void 0 : indvPartBtn.click(); + }; btnList.add({ name: i18n('DOWNLOAD')('MSCZ'), action: BtnAction.process(downloadMscz), }); btnList.add({ name: i18n('DOWNLOAD')('PDF'), - action: BtnAction.process(downloadPDF), + action: BtnAction.process(downloadPDF, fallback, 3 * 60 * 1000 /* 3min */), }); btnList.add({ name: i18n('DOWNLOAD')('MusicXML'), @@ -26957,13 +26980,13 @@ Please pipe the document into a Node stream.\ }); btnList.add({ name: i18n('DOWNLOAD')('MIDI'), - action: BtnAction.download(() => getFileUrl('midi')), + action: BtnAction.download(() => getFileUrl('midi'), fallback, 30 * 1000 /* 30s */), }); btnList.add({ name: i18n('DOWNLOAD')('MP3'), - action: BtnAction.download(() => getFileUrl('mp3')), + action: BtnAction.download(() => getFileUrl('mp3'), fallback, 30 * 1000 /* 30s */), }); - btnList.add({ + indvPartBtn = btnList.add({ name: i18n('IND_PARTS')(), tooltip: i18n('IND_PARTS_TOOLTIP')(), action: BtnAction.mscoreWindow((w, score, txt) => __awaiter(void 0, void 0, void 0, function* () { diff --git a/package-lock.json b/package-lock.json index a98833c..1ae9ff3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "musescore-downloader", - "version": "0.14.6", + "version": "0.15.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b1a4a76..4d4c1b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "musescore-downloader", - "version": "0.14.6", + "version": "0.15.0", "description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱", "main": "dist/main.js", "repository": {