diff --git a/src/main/rendererEvents/playList.js b/src/main/rendererEvents/playList.js index a22c5e4f..86a90d89 100644 --- a/src/main/rendererEvents/playList.js +++ b/src/main/rendererEvents/playList.js @@ -26,12 +26,18 @@ mainHandle(ipcMainWindowNames.get_playlist, async(event, isIgnoredError = false) } }) +const handleSaveList = ({ defaultList, loveList, userList }) => { + if (!electronStore_list) return + let data = {} + if (defaultList != null) data.defaultList = defaultList + if (loveList != null) data.loveList = loveList + if (userList != null) data.userList = userList + electronStore_list.set(data) +} mainOn(ipcMainWindowNames.save_playlist, (event, { type, data }) => { switch (type) { - case 'defaultList': - case 'loveList': - case 'userList': - electronStore_list && electronStore_list.set(type, data) + case 'myList': + handleSaveList(data) break case 'downloadList': electronStore_downloadList && electronStore_downloadList.set('list', data) diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 161531cb..3364102a 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -37,6 +37,20 @@ dnscache({ cachesize: 1000, }) +const listThrottle = (fn, delay = 100) => { + let timer = null + let _data = {} + return function(data) { + Object.assign(_data, data) + if (timer) return + timer = setTimeout(() => { + timer = null + fn.call(this, _data) + _data = {} + }, delay) + } +} + export default { data() { return { @@ -70,24 +84,12 @@ export default { }), }, created() { - this.saveDefaultList = throttle(n => { + this.saveMyList = listThrottle(data => { rendererSend(NAMES.mainWindow.save_playlist, { - type: 'defaultList', - data: n, + type: 'myList', + data, }) - }, 500) - this.saveLoveList = throttle(n => { - rendererSend(NAMES.mainWindow.save_playlist, { - type: 'loveList', - data: n, - }) - }, 500) - this.saveUserList = throttle(n => { - rendererSend(NAMES.mainWindow.save_playlist, { - type: 'userList', - data: n, - }) - }, 500) + }, 300) this.saveDownloadList = throttle(n => { rendererSend(NAMES.mainWindow.save_playlist, { type: 'downloadList', @@ -115,19 +117,19 @@ export default { }, defaultList: { handler(n) { - this.saveDefaultList(n) + this.saveMyList({ defaultList: n }) }, deep: true, }, loveList: { handler(n) { - this.saveLoveList(n) + this.saveMyList({ loveList: n }) }, deep: true, }, userList: { handler(n) { - this.saveUserList(n) + this.saveMyList({ userList: n }) }, deep: true, },