From 04c810e2921c3314012746bb12e8139efcbb11a7 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 30 Aug 2020 12:25:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B2=A1=E6=9C=89=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=9D=83=E9=99=90=E7=9A=84=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + src/renderer/store/modules/download.js | 23 ++++++++++++++--------- src/renderer/utils/download/Downloader.js | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 476e8a04..26c780e9 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -16,6 +16,7 @@ - 桌面歌词当前播放行改为上下居中 - 为区分静音状态,静音时音量条会变淡,调整音量条时将会取消静音 - 优化随机播放机制,现在通过`下一曲`切换歌曲时,直到播放完整个列表之前将不会再随机到之前播放过的歌曲,并且通过`上一曲`可以正确播放上一首歌曲 +- 当下载目录没有写入权限时将显示没有写入权限的提示 ### 移除 diff --git a/src/renderer/store/modules/download.js b/src/renderer/store/modules/download.js index 036a9f87..e62bbeac 100644 --- a/src/renderer/store/modules/download.js +++ b/src/renderer/store/modules/download.js @@ -218,13 +218,13 @@ const refreshUrl = function(commit, downloadInfo) { if (!dl) return dl.refreshUrl(result.url) dl.start().catch(err => { - commit('onError', downloadInfo) + commit('onError', { downloadInfo, errorMsg: err.message }) commit('setStatusText', { downloadInfo, text: err.message }) this.dispatch('download/startTask') }) }).catch(err => { // console.log(err) - commit('onError', downloadInfo) + commit('onError', { downloadInfo, errorMsg: err.message }) commit('setStatusText', { downloadInfo, text: err.message }) this.dispatch('download/startTask') }) @@ -299,7 +299,7 @@ const actions = { try { await checkPath(rootState.setting.download.savePath) } catch (error) { - commit('onError', downloadInfo) + commit('onError', { downloadInfo, errorMsg: error.message }) commit('setStatusText', '检查下载目录出错: ' + error.message) await dispatch('startTask') return @@ -324,9 +324,14 @@ const actions = { console.log('on complate') }, onError(err) { + // console.log(err) + if (err.code == 'EPERM') { + commit('onError', { downloadInfo, errorMsg: '歌曲下载目录没有写入权限,请尝试更改歌曲保存路径' }) + return + } // console.log(tryNum[downloadInfo.key]) if (++tryNum[downloadInfo.key] > 2) { - commit('onError', downloadInfo) + commit('onError', { downloadInfo, errorMsg: err.message }) dispatch('startTask') return } @@ -375,7 +380,7 @@ const actions = { dls[downloadInfo.key] = download(options) }).catch(err => { // console.log(err.message) - commit('onError', downloadInfo) + commit('onError', { downloadInfo, errorMsg: err.message }) commit('setStatusText', { downloadInfo, text: err.message }) dispatch('startTask') }) @@ -437,7 +442,7 @@ const actions = { try { await dl.start() } catch (error) { - commit('onError', downloadInfo) + commit('onError', { downloadInfo, errorMsg: error.message }) commit('setStatusText', error.message) await dispatch('startTask') } @@ -448,7 +453,7 @@ const actions = { startTasks(store, list) { if (isRuningActionTask) return isRuningActionTask = true - return startTasks(store, [...list]).finally(() => { + return startTasks(store, list.filter(item => !(item.isComplate || item.status == state.downloadStatus.RUN || item.status == state.downloadStatus.WAITING))).finally(() => { isRuningActionTask = false }) }, @@ -522,9 +527,9 @@ const mutations = { downloadInfo.status = state.downloadStatus.COMPLETED downloadInfo.statusText = '下载完成' }, - onError(state, downloadInfo) { + onError(state, { downloadInfo, errorMsg }) { downloadInfo.status = state.downloadStatus.ERROR - downloadInfo.statusText = '任务出错' + downloadInfo.statusText = errorMsg || '任务出错' }, onStart(state, downloadInfo) { downloadInfo.status = state.downloadStatus.RUN diff --git a/src/renderer/utils/download/Downloader.js b/src/renderer/utils/download/Downloader.js index bfe89ca2..1dc2e7fb 100644 --- a/src/renderer/utils/download/Downloader.js +++ b/src/renderer/utils/download/Downloader.js @@ -172,7 +172,7 @@ class Task extends EventEmitter { this.chunkInfo.startByte = 0 this.resumeLastChunk = null this.progress.downloaded = 0 - if (unlinkErr) this.__handleError(unlinkErr) + if (unlinkErr && unlinkErr.code !== 'ENOENT') this.__handleError(unlinkErr) }) }) }