修复潜在同步问题
parent
faff0edb4a
commit
58f016ca00
|
@ -153,8 +153,6 @@ exports.initSetting = isShowErrorAlert => {
|
||||||
// 迁移列表滚动位置设置 ~0.18.3
|
// 迁移列表滚动位置设置 ~0.18.3
|
||||||
if (setting.list.scroll) {
|
if (setting.list.scroll) {
|
||||||
let scroll = 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.delete('setting.list.scroll')
|
||||||
electronStore_config.set('setting.list.isSaveScrollLocation', scroll.enable)
|
electronStore_config.set('setting.list.isSaveScrollLocation', scroll.enable)
|
||||||
delete setting.list.scroll
|
delete setting.list.scroll
|
||||||
|
|
|
@ -11,6 +11,22 @@ let io
|
||||||
let syncingId = null
|
let syncingId = null
|
||||||
const wait = (time = 1000) => new Promise((resolve, reject) => setTimeout(resolve, time))
|
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) => {
|
const getRemoteListData = socket => new Promise((resolve, reject) => {
|
||||||
console.log('getRemoteListData')
|
console.log('getRemoteListData')
|
||||||
const handleError = reason => {
|
const handleError = reason => {
|
||||||
|
@ -23,7 +39,7 @@ const getRemoteListData = socket => new Promise((resolve, reject) => {
|
||||||
const data = JSON.parse(decryptMsg(socket.data.keyInfo, enData))
|
const data = JSON.parse(decryptMsg(socket.data.keyInfo, enData))
|
||||||
if (!data) return reject(new Error('Get remote list data failed'))
|
if (!data) return reject(new Error('Get remote list data failed'))
|
||||||
if (data.action != 'getData') return
|
if (data.action != 'getData') return
|
||||||
resolve(data.data)
|
resolve(patchListData(data.data))
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on('disconnect', handleError)
|
socket.on('disconnect', handleError)
|
||||||
|
@ -35,7 +51,7 @@ const getLocalListData = () => new Promise((resolve, reject) => {
|
||||||
const handleSuccess = ({ action, data }) => {
|
const handleSuccess = ({ action, data }) => {
|
||||||
if (action !== 'getData') return
|
if (action !== 'getData') return
|
||||||
global.lx_event.sync.off(SYNC_EVENT_NAMES.sync_handle_list, handleSuccess)
|
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.on(SYNC_EVENT_NAMES.sync_handle_list, handleSuccess)
|
||||||
global.lx_event.sync.sync_list({
|
global.lx_event.sync.sync_list({
|
||||||
|
@ -87,10 +103,10 @@ const updateSnapshot = (path, data) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const createListDataObj = listData => {
|
const createUserListDataObj = listData => {
|
||||||
const listDataObj = {}
|
const userListDataObj = {}
|
||||||
for (const list of listData.userList) listDataObj[list.id] = list
|
for (const list of listData.userList) userListDataObj[list.id] = list
|
||||||
return listDataObj
|
return userListDataObj
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleMergeList = (sourceList, targetList, addMusicLocationType) => {
|
const handleMergeList = (sourceList, targetList, addMusicLocationType) => {
|
||||||
|
@ -137,11 +153,11 @@ const mergeList = (sourceListData, targetListData) => {
|
||||||
newListData.defaultList = handleMergeList(sourceListData.defaultList, targetListData.defaultList, addMusicLocationType)
|
newListData.defaultList = handleMergeList(sourceListData.defaultList, targetListData.defaultList, addMusicLocationType)
|
||||||
newListData.loveList = handleMergeList(sourceListData.loveList, targetListData.loveList, addMusicLocationType)
|
newListData.loveList = handleMergeList(sourceListData.loveList, targetListData.loveList, addMusicLocationType)
|
||||||
|
|
||||||
const listDataObj = createListDataObj(sourceListData)
|
const userListDataObj = createUserListDataObj(sourceListData)
|
||||||
newListData.userList = [...sourceListData.userList]
|
newListData.userList = [...sourceListData.userList]
|
||||||
|
|
||||||
for (const list of targetListData.userList) {
|
for (const list of targetListData.userList) {
|
||||||
const targetList = listDataObj[list.id]
|
const targetList = userListDataObj[list.id]
|
||||||
if (targetList) {
|
if (targetList) {
|
||||||
targetList.list = handleMergeList(targetList, list, addMusicLocationType).list
|
targetList.list = handleMergeList(targetList, list, addMusicLocationType).list
|
||||||
} else {
|
} else {
|
||||||
|
@ -156,11 +172,11 @@ const overwriteList = (sourceListData, targetListData) => {
|
||||||
newListData.defaultList = sourceListData.defaultList
|
newListData.defaultList = sourceListData.defaultList
|
||||||
newListData.loveList = sourceListData.loveList
|
newListData.loveList = sourceListData.loveList
|
||||||
|
|
||||||
const listDataObj = createListDataObj(sourceListData)
|
const userListDataObj = createUserListDataObj(sourceListData)
|
||||||
newListData.userList = [...sourceListData.userList]
|
newListData.userList = [...sourceListData.userList]
|
||||||
|
|
||||||
for (const list of targetListData.userList) {
|
for (const list of targetListData.userList) {
|
||||||
const targetList = listDataObj[list.id]
|
const targetList = userListDataObj[list.id]
|
||||||
if (targetList) continue
|
if (targetList) continue
|
||||||
newListData.userList.push(list)
|
newListData.userList.push(list)
|
||||||
}
|
}
|
||||||
|
@ -299,9 +315,9 @@ const handleMergeListDataFromSnapshot = async(socket, snapshot) => {
|
||||||
const newListData = {}
|
const newListData = {}
|
||||||
newListData.defaultList = mergeListDataFromSnapshot(localListData.defaultList, remoteListData.defaultList, snapshot.defaultList, addMusicLocationType)
|
newListData.defaultList = mergeListDataFromSnapshot(localListData.defaultList, remoteListData.defaultList, snapshot.defaultList, addMusicLocationType)
|
||||||
newListData.loveList = mergeListDataFromSnapshot(localListData.loveList, remoteListData.loveList, snapshot.loveList, addMusicLocationType)
|
newListData.loveList = mergeListDataFromSnapshot(localListData.loveList, remoteListData.loveList, snapshot.loveList, addMusicLocationType)
|
||||||
const localUserListData = createListDataObj(localListData)
|
const localUserListData = createUserListDataObj(localListData)
|
||||||
const remoteUserListData = createListDataObj(remoteListData)
|
const remoteUserListData = createUserListDataObj(remoteListData)
|
||||||
const snapshotUserListData = createListDataObj(snapshot)
|
const snapshotUserListData = createUserListDataObj(snapshot)
|
||||||
const removedListIds = new Set()
|
const removedListIds = new Set()
|
||||||
const localUserListIds = new Set()
|
const localUserListIds = new Set()
|
||||||
const remoteUserListIds = new Set()
|
const remoteUserListIds = new Set()
|
||||||
|
@ -368,7 +384,7 @@ const syncList = async socket => {
|
||||||
}
|
}
|
||||||
console.log('isSyncRequired', isSyncRequired)
|
console.log('isSyncRequired', isSyncRequired)
|
||||||
if (isSyncRequired) return handleSyncList(socket)
|
if (isSyncRequired) return handleSyncList(socket)
|
||||||
return handleMergeListDataFromSnapshot(socket, fileData)
|
return handleMergeListDataFromSnapshot(socket, patchListData(fileData))
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkSyncQueue = async() => {
|
const checkSyncQueue = async() => {
|
||||||
|
|
|
@ -28,19 +28,16 @@ const state = {
|
||||||
id: 'default',
|
id: 'default',
|
||||||
name: '试听列表',
|
name: '试听列表',
|
||||||
list: [],
|
list: [],
|
||||||
location: 0,
|
|
||||||
},
|
},
|
||||||
loveList: {
|
loveList: {
|
||||||
id: 'love',
|
id: 'love',
|
||||||
name: '我的收藏',
|
name: '我的收藏',
|
||||||
list: [],
|
list: [],
|
||||||
location: 0,
|
|
||||||
},
|
},
|
||||||
tempList: {
|
tempList: {
|
||||||
id: 'temp',
|
id: 'temp',
|
||||||
name: '临时列表',
|
name: '临时列表',
|
||||||
list: [],
|
list: [],
|
||||||
location: 0,
|
|
||||||
},
|
},
|
||||||
userList: [],
|
userList: [],
|
||||||
}
|
}
|
||||||
|
@ -75,8 +72,8 @@ const actions = {
|
||||||
// mitations
|
// mitations
|
||||||
const mutations = {
|
const mutations = {
|
||||||
initList(state, { defaultList, loveList, userList }) {
|
initList(state, { defaultList, loveList, userList }) {
|
||||||
if (defaultList != null) Object.assign(state.defaultList, { list: defaultList.list, location: defaultList.location })
|
if (defaultList != null) Object.assign(state.defaultList, { list: defaultList.list })
|
||||||
if (loveList != null) Object.assign(state.loveList, { list: loveList.list, location: loveList.location })
|
if (loveList != null) Object.assign(state.loveList, { list: loveList.list })
|
||||||
if (userList != null) state.userList = userList
|
if (userList != null) state.userList = userList
|
||||||
allListInit(state.defaultList, state.loveList, state.userList)
|
allListInit(state.defaultList, state.loveList, state.userList)
|
||||||
state.isInitedList = true
|
state.isInitedList = true
|
||||||
|
@ -104,18 +101,17 @@ const mutations = {
|
||||||
state.userList = userList
|
state.userList = userList
|
||||||
allListInit(state.defaultList, state.loveList, state.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]
|
const targetList = allList[id]
|
||||||
if (targetList) {
|
if (targetList) {
|
||||||
if (name && targetList.name === name) {
|
if (name && targetList.name === name) {
|
||||||
if (!isSync) {
|
if (!isSync) {
|
||||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||||
action: 'set_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.list.splice(0, targetList.list.length, ...list)
|
||||||
targetList.location = location
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,14 +120,13 @@ const mutations = {
|
||||||
if (!isSync) {
|
if (!isSync) {
|
||||||
window.eventHub.$emit(eventSyncName.send_action_list, {
|
window.eventHub.$emit(eventSyncName.send_action_list, {
|
||||||
action: 'set_list',
|
action: 'set_list',
|
||||||
data: { id, list, name, location, source, sourceListId },
|
data: { id, list, name, source, sourceListId },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
let newList = {
|
let newList = {
|
||||||
name,
|
name,
|
||||||
id,
|
id,
|
||||||
list,
|
list,
|
||||||
location,
|
|
||||||
source,
|
source,
|
||||||
sourceListId,
|
sourceListId,
|
||||||
}
|
}
|
||||||
|
@ -316,7 +311,6 @@ const mutations = {
|
||||||
name,
|
name,
|
||||||
id,
|
id,
|
||||||
list: [],
|
list: [],
|
||||||
location: 0,
|
|
||||||
source,
|
source,
|
||||||
sourceListId,
|
sourceListId,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue