From 58f016ca003c24ead4a1d406999ee389a4f44988 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 30 Oct 2021 10:06:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BD=9C=E5=9C=A8=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/utils.js | 2 -- src/main/modules/sync/server/syncList.js | 44 ++++++++++++++++-------- src/renderer/store/modules/list.js | 16 +++------ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index 08e8dc97..074e7f0c 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -153,8 +153,6 @@ exports.initSetting = isShowErrorAlert => { // 迁移列表滚动位置设置 ~0.18.3 if (setting.list.scroll) { let scroll = setting.list.scroll - // electronStore_list.set('defaultList.location', scroll.locations.default || 0) - // electronStore_list.set('loveList.location', scroll.locations.love || 0) electronStore_config.delete('setting.list.scroll') electronStore_config.set('setting.list.isSaveScrollLocation', scroll.enable) delete setting.list.scroll diff --git a/src/main/modules/sync/server/syncList.js b/src/main/modules/sync/server/syncList.js index 88c69c9e..6fa90328 100644 --- a/src/main/modules/sync/server/syncList.js +++ b/src/main/modules/sync/server/syncList.js @@ -11,6 +11,22 @@ let io let syncingId = null const wait = (time = 1000) => new Promise((resolve, reject) => setTimeout(resolve, time)) +const patchListData = listData => { + return Object.assign({}, { + defaultList: { + id: 'default', + name: '试听列表', + list: [], + }, + loveList: { + id: 'love', + name: '我的收藏', + list: [], + }, + userList: [], + }, listData) +} + const getRemoteListData = socket => new Promise((resolve, reject) => { console.log('getRemoteListData') const handleError = reason => { @@ -23,7 +39,7 @@ const getRemoteListData = socket => new Promise((resolve, reject) => { const data = JSON.parse(decryptMsg(socket.data.keyInfo, enData)) if (!data) return reject(new Error('Get remote list data failed')) if (data.action != 'getData') return - resolve(data.data) + resolve(patchListData(data.data)) } socket.on('disconnect', handleError) @@ -35,7 +51,7 @@ const getLocalListData = () => new Promise((resolve, reject) => { const handleSuccess = ({ action, data }) => { if (action !== 'getData') return global.lx_event.sync.off(SYNC_EVENT_NAMES.sync_handle_list, handleSuccess) - resolve(data) + resolve(patchListData(data)) } global.lx_event.sync.on(SYNC_EVENT_NAMES.sync_handle_list, handleSuccess) global.lx_event.sync.sync_list({ @@ -87,10 +103,10 @@ const updateSnapshot = (path, data) => { } -const createListDataObj = listData => { - const listDataObj = {} - for (const list of listData.userList) listDataObj[list.id] = list - return listDataObj +const createUserListDataObj = listData => { + const userListDataObj = {} + for (const list of listData.userList) userListDataObj[list.id] = list + return userListDataObj } const handleMergeList = (sourceList, targetList, addMusicLocationType) => { @@ -137,11 +153,11 @@ const mergeList = (sourceListData, targetListData) => { newListData.defaultList = handleMergeList(sourceListData.defaultList, targetListData.defaultList, addMusicLocationType) newListData.loveList = handleMergeList(sourceListData.loveList, targetListData.loveList, addMusicLocationType) - const listDataObj = createListDataObj(sourceListData) + const userListDataObj = createUserListDataObj(sourceListData) newListData.userList = [...sourceListData.userList] for (const list of targetListData.userList) { - const targetList = listDataObj[list.id] + const targetList = userListDataObj[list.id] if (targetList) { targetList.list = handleMergeList(targetList, list, addMusicLocationType).list } else { @@ -156,11 +172,11 @@ const overwriteList = (sourceListData, targetListData) => { newListData.defaultList = sourceListData.defaultList newListData.loveList = sourceListData.loveList - const listDataObj = createListDataObj(sourceListData) + const userListDataObj = createUserListDataObj(sourceListData) newListData.userList = [...sourceListData.userList] for (const list of targetListData.userList) { - const targetList = listDataObj[list.id] + const targetList = userListDataObj[list.id] if (targetList) continue newListData.userList.push(list) } @@ -299,9 +315,9 @@ const handleMergeListDataFromSnapshot = async(socket, snapshot) => { const newListData = {} newListData.defaultList = mergeListDataFromSnapshot(localListData.defaultList, remoteListData.defaultList, snapshot.defaultList, addMusicLocationType) newListData.loveList = mergeListDataFromSnapshot(localListData.loveList, remoteListData.loveList, snapshot.loveList, addMusicLocationType) - const localUserListData = createListDataObj(localListData) - const remoteUserListData = createListDataObj(remoteListData) - const snapshotUserListData = createListDataObj(snapshot) + const localUserListData = createUserListDataObj(localListData) + const remoteUserListData = createUserListDataObj(remoteListData) + const snapshotUserListData = createUserListDataObj(snapshot) const removedListIds = new Set() const localUserListIds = new Set() const remoteUserListIds = new Set() @@ -368,7 +384,7 @@ const syncList = async socket => { } console.log('isSyncRequired', isSyncRequired) if (isSyncRequired) return handleSyncList(socket) - return handleMergeListDataFromSnapshot(socket, fileData) + return handleMergeListDataFromSnapshot(socket, patchListData(fileData)) } const checkSyncQueue = async() => { diff --git a/src/renderer/store/modules/list.js b/src/renderer/store/modules/list.js index 0e570b76..afb6a4f2 100644 --- a/src/renderer/store/modules/list.js +++ b/src/renderer/store/modules/list.js @@ -28,19 +28,16 @@ const state = { id: 'default', name: '试听列表', list: [], - location: 0, }, loveList: { id: 'love', name: '我的收藏', list: [], - location: 0, }, tempList: { id: 'temp', name: '临时列表', list: [], - location: 0, }, userList: [], } @@ -75,8 +72,8 @@ const actions = { // mitations const mutations = { initList(state, { defaultList, loveList, userList }) { - if (defaultList != null) Object.assign(state.defaultList, { list: defaultList.list, location: defaultList.location }) - if (loveList != null) Object.assign(state.loveList, { list: loveList.list, location: loveList.location }) + if (defaultList != null) Object.assign(state.defaultList, { list: defaultList.list }) + if (loveList != null) Object.assign(state.loveList, { list: loveList.list }) if (userList != null) state.userList = userList allListInit(state.defaultList, state.loveList, state.userList) state.isInitedList = true @@ -104,18 +101,17 @@ const mutations = { state.userList = userList allListInit(state.defaultList, state.loveList, state.userList) }, - setList(state, { id, list, name, location, source, sourceListId, isSync }) { + setList(state, { id, list, name, source, sourceListId, isSync }) { const targetList = allList[id] if (targetList) { if (name && targetList.name === name) { if (!isSync) { window.eventHub.$emit(eventSyncName.send_action_list, { action: 'set_list', - data: { id, list, name, location, source, sourceListId }, + data: { id, list, name, source, sourceListId }, }) } targetList.list.splice(0, targetList.list.length, ...list) - targetList.location = location return } @@ -124,14 +120,13 @@ const mutations = { if (!isSync) { window.eventHub.$emit(eventSyncName.send_action_list, { action: 'set_list', - data: { id, list, name, location, source, sourceListId }, + data: { id, list, name, source, sourceListId }, }) } let newList = { name, id, list, - location, source, sourceListId, } @@ -316,7 +311,6 @@ const mutations = { name, id, list: [], - location: 0, source, sourceListId, }