完善同步
parent
4cea16c326
commit
a7c2857808
|
@ -116,7 +116,7 @@ declare namespace LX {
|
|||
musicInfos: LX.Music.MusicInfo[]
|
||||
}
|
||||
|
||||
type ListActionMusicClear = string
|
||||
type ListActionMusicClear = string[]
|
||||
|
||||
interface MyDefaultListInfoFull extends MyDefaultListInfo {
|
||||
list: LX.Music.MusicInfo[]
|
||||
|
|
|
@ -141,12 +141,12 @@ export class Event extends EventEmitter {
|
|||
|
||||
/**
|
||||
* 清空列表内的歌曲
|
||||
* @param listId 列表Id
|
||||
* @param ids 列表Id
|
||||
* @param isRemote 是否属于远程操作
|
||||
*/
|
||||
async list_music_clear(listId: string, isRemote: boolean = false) {
|
||||
await global.lx.worker.dbService.musicsClear(listId)
|
||||
this.emit('list_music_clear', listId, isRemote)
|
||||
async list_music_clear(ids: string[], isRemote: boolean = false) {
|
||||
await global.lx.worker.dbService.musicsClear(ids)
|
||||
this.emit('list_music_clear', ids, isRemote)
|
||||
this.list_changed()
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ export const registerRendererEvents = (sendEvent: <T = any>(name: string, params
|
|||
const list_music_overwrite = async(listId: string, musicInfos: LX.Music.MusicInfo[]) => {
|
||||
sendEvent<LX.List.ListActionMusicOverwrite>(PLAYER_EVENT_NAME.list_music_overwrite, { listId, musicInfos })
|
||||
}
|
||||
const list_music_clear = async(listId: string) => {
|
||||
sendEvent<LX.List.ListActionMusicClear>(PLAYER_EVENT_NAME.list_data_overwire, listId)
|
||||
const list_music_clear = async(ids: string[]) => {
|
||||
sendEvent<LX.List.ListActionMusicClear>(PLAYER_EVENT_NAME.list_data_overwire, ids)
|
||||
}
|
||||
global.lx.event_list.on('list_data_overwrite', list_data_overwrite)
|
||||
global.lx.event_list.on('list_create', list_create)
|
||||
|
|
|
@ -56,51 +56,51 @@ const handleListAction = ({ action, data }: LX.Sync.ActionList) => {
|
|||
const registerListActionEvent = () => {
|
||||
const list_data_overwrite = async(listData: MakeOptional<LX.List.ListDataFull, 'tempList'>, isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_data_overwrite', listData)
|
||||
await sendListAction({ action: 'list_data_overwrite', data: listData })
|
||||
}
|
||||
const list_create = async(position: number, lists: LX.List.UserListInfo[], isRemote: boolean = false) => {
|
||||
const list_create = async(position: number, listInfos: LX.List.UserListInfo[], isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_create', { position, lists })
|
||||
await sendListAction({ action: 'list_create', data: { position, listInfos } })
|
||||
}
|
||||
const list_remove = async(ids: string[], isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_remove', ids)
|
||||
await sendListAction({ action: 'list_remove', data: ids })
|
||||
}
|
||||
const list_update = async(lists: LX.List.UserListInfo[], isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_update', lists)
|
||||
await sendListAction({ action: 'list_update', data: lists })
|
||||
}
|
||||
const list_update_position = async(position: number, ids: string[], isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_update_position', { position, ids })
|
||||
await sendListAction({ action: 'list_update_position', data: { position, ids } })
|
||||
}
|
||||
const list_music_overwrite = async(listId: string, musicInfos: LX.Music.MusicInfo[], isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_music_overwrite', { listId, musicInfos })
|
||||
await sendListAction({ action: 'list_music_overwrite', data: { listId, musicInfos } })
|
||||
}
|
||||
const list_music_add = async(listId: string, musicInfos: LX.Music.MusicInfo[], addMusicLocationType: LX.AddMusicLocationType, isRemote: boolean = false) => {
|
||||
const list_music_add = async(id: string, musicInfos: LX.Music.MusicInfo[], addMusicLocationType: LX.AddMusicLocationType, isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_music_add', { listId, musicInfos, addMusicLocationType })
|
||||
await sendListAction({ action: 'list_music_add', data: { id, musicInfos, addMusicLocationType } })
|
||||
}
|
||||
const list_music_move = async(fromId: string, toId: string, musicInfos: LX.Music.MusicInfo[], addMusicLocationType: LX.AddMusicLocationType, isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_music_move', { fromId, toId, musicInfos, addMusicLocationType })
|
||||
await sendListAction({ action: 'list_music_move', data: { fromId, toId, musicInfos, addMusicLocationType } })
|
||||
}
|
||||
const list_music_remove = async(listId: string, ids: string[], isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_music_remove', { listId, ids })
|
||||
await sendListAction({ action: 'list_music_remove', data: { listId, ids } })
|
||||
}
|
||||
const list_music_update = async(musicInfos: LX.List.ListActionMusicUpdate, isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_music_update', musicInfos)
|
||||
await sendListAction({ action: 'list_music_update', data: musicInfos })
|
||||
}
|
||||
const list_music_clear = async(listId: string, isRemote: boolean = false) => {
|
||||
const list_music_clear = async(ids: string[], isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_music_clear', listId)
|
||||
await sendListAction({ action: 'list_music_clear', data: ids })
|
||||
}
|
||||
const list_music_update_position = async(listId: string, position: number, ids: string[], isRemote: boolean = false) => {
|
||||
if (isRemote) return
|
||||
await sendListAction('list_music_update_position', { listId, position, ids })
|
||||
await sendListAction({ action: 'list_music_update_position', data: { listId, position, ids } })
|
||||
}
|
||||
global.lx.event_list.on('list_data_overwrite', list_data_overwrite)
|
||||
global.lx.event_list.on('list_create', list_create)
|
||||
|
@ -143,9 +143,9 @@ const broadcast = async(action: listAction, data: any, excludeIds: string[] = []
|
|||
}
|
||||
}
|
||||
|
||||
export const sendListAction = async(action: string, data: any) => {
|
||||
export const sendListAction = async(action: LX.Sync.ActionList) => {
|
||||
// io.sockets
|
||||
return await broadcast('list:action', JSON.stringify({ action, data }))
|
||||
return await broadcast('list:action', JSON.stringify(action))
|
||||
}
|
||||
|
||||
export const registerListHandler = (_io: Server, socket: LX.Sync.Socket) => {
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
} from './utils'
|
||||
|
||||
const authMsg = 'lx-music auth::'
|
||||
const helloMsg = 'Hello~::^-^::~v2'
|
||||
const helloMsg = 'Hello~::^-^::~v2~'
|
||||
|
||||
const requestIps = new Map<string, number>()
|
||||
|
||||
|
|
|
@ -108,9 +108,8 @@ const updateSnapshot = async(path: string, data: string) => {
|
|||
})
|
||||
}
|
||||
|
||||
interface UserDataObj {
|
||||
[listId: string]: LX.List.UserListInfoFull
|
||||
}
|
||||
type UserDataObj = Record<string, LX.List.UserListInfoFull>
|
||||
|
||||
const createUserListDataObj = (listData: LX.Sync.ListData): UserDataObj => {
|
||||
const userListDataObj: UserDataObj = {}
|
||||
for (const list of listData.userList) userListDataObj[list.id] = list
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { Socket as _Socket, RemoteSocket as _RemoteSocket } from 'socket.io'
|
||||
|
||||
interface DefaultEventsMap {
|
||||
[event: string]: (...args: any[]) => void
|
||||
}
|
||||
type DefaultEventsMap = Record<string, (...args: any[]) => void>
|
||||
|
||||
|
||||
declare global {
|
||||
|
|
|
@ -250,14 +250,16 @@ export const removeMusicInfos = (listId: string, ids: string[]) => {
|
|||
* 清空列表内歌曲
|
||||
* @param listId 列表id
|
||||
*/
|
||||
export const removeMusicInfoByListId = (listId: string) => {
|
||||
export const removeMusicInfoByListId = (ids: string[]) => {
|
||||
const db = getDB()
|
||||
const musicInfoDeleteByListIdStatement = createMusicInfoDeleteByListIdStatement()
|
||||
const musicInfoOrderDeleteByListIdStatement = createMusicInfoOrderDeleteByListIdStatement()
|
||||
db.transaction((listId: string) => {
|
||||
musicInfoDeleteByListIdStatement.run(listId)
|
||||
musicInfoOrderDeleteByListIdStatement.run(listId)
|
||||
})(listId)
|
||||
db.transaction((ids: string[]) => {
|
||||
for (const id of ids) {
|
||||
musicInfoDeleteByListIdStatement.run(id)
|
||||
musicInfoOrderDeleteByListIdStatement.run(id)
|
||||
}
|
||||
})(ids)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -305,11 +305,13 @@ export const musicsUpdate = (musicInfos: LX.List.ListActionMusicUpdate) => {
|
|||
* 清空列表内的歌曲
|
||||
* @param listId 列表Id
|
||||
*/
|
||||
export const musicsClear = (listId: string) => {
|
||||
removeMusicInfoByListId(listId)
|
||||
const targetList = getListMusics(listId)
|
||||
if (targetList == null) return
|
||||
targetList.slice(0, targetList.length)
|
||||
export const musicsClear = (ids: string[]) => {
|
||||
removeMusicInfoByListId(ids)
|
||||
for (const id of ids) {
|
||||
const targetList = musicLists.get(id)
|
||||
if (!targetList) continue
|
||||
targetList.splice(0, targetList.length)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -69,16 +69,16 @@ export const buildLyricInfo = async(lyricInfo: MakeOptional<LX.Player.LyricInfo,
|
|||
|
||||
if (appSetting['player.isS2t']) {
|
||||
const tasks = [
|
||||
lyricInfo.lyric ? window.lx.worker.main.langS2t(lyricInfo.lyric) : Promise.resolve(''),
|
||||
lyricInfo.lyric ? langS2T(lyricInfo.lyric) : Promise.resolve(''),
|
||||
lyricInfo.tlyric ? langS2T(lyricInfo.tlyric) : Promise.resolve(''),
|
||||
lyricInfo.rlyric ? langS2T(lyricInfo.rlyric) : Promise.resolve(''),
|
||||
lyricInfo.lxlyric ? langS2T(lyricInfo.lxlyric) : Promise.resolve(''),
|
||||
]
|
||||
if (lyricInfo.rawlrcInfo) {
|
||||
tasks.push(lyricInfo.lyric ? window.lx.worker.main.langS2t(lyricInfo.lyric) : Promise.resolve(''))
|
||||
tasks.push(lyricInfo.tlyric ? window.lx.worker.main.langS2t(lyricInfo.tlyric) : Promise.resolve(''))
|
||||
tasks.push(lyricInfo.rlyric ? window.lx.worker.main.langS2t(lyricInfo.rlyric) : Promise.resolve(''))
|
||||
tasks.push(lyricInfo.lxlyric ? window.lx.worker.main.langS2t(lyricInfo.lxlyric) : Promise.resolve(''))
|
||||
tasks.push(lyricInfo.lyric ? langS2T(lyricInfo.lyric) : Promise.resolve(''))
|
||||
tasks.push(lyricInfo.tlyric ? langS2T(lyricInfo.tlyric) : Promise.resolve(''))
|
||||
tasks.push(lyricInfo.rlyric ? langS2T(lyricInfo.rlyric) : Promise.resolve(''))
|
||||
tasks.push(lyricInfo.lxlyric ? langS2T(lyricInfo.lxlyric) : Promise.resolve(''))
|
||||
}
|
||||
return await Promise.all(tasks).then(([lyric, tlyric, rlyric, lxlyric, lyric_raw, tlyric_raw, rlyric_raw, lxlyric_raw]) => {
|
||||
const rawlrcInfo = lyric_raw ? {
|
||||
|
|
|
@ -202,6 +202,17 @@ export const listMusicOverwrite = (listId: string, musicInfos: LX.Music.MusicInf
|
|||
return isExist || listId == loveList.id ? [listId] : []
|
||||
}
|
||||
|
||||
export const listMusicClear = (ids: string[]): string[] => {
|
||||
const changedIds: string[] = []
|
||||
for (const id of ids) {
|
||||
const list = allMusicList.get(id)
|
||||
if (!list?.length) continue
|
||||
overwriteMusicList(id, [])
|
||||
changedIds.push(id)
|
||||
}
|
||||
return changedIds
|
||||
}
|
||||
|
||||
export const listMusicAdd = (id: string, musicInfos: LX.Music.MusicInfo[], addMusicLocationType: LX.AddMusicLocationType): string[] => {
|
||||
const targetList = allMusicList.get(id)
|
||||
if (!targetList) return id == loveList.id ? [id] : []
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
listMusicUpdatePosition,
|
||||
setMusicList,
|
||||
setUserLists,
|
||||
listMusicClear,
|
||||
} from './action'
|
||||
import { allMusicList } from './state'
|
||||
|
||||
|
@ -122,10 +123,10 @@ export const overwriteListMusics = async(data: LX.List.ListActionMusicOverwrite)
|
|||
|
||||
/**
|
||||
* 清空列表内的歌曲
|
||||
* @param listId
|
||||
* @param ids
|
||||
*/
|
||||
export const clearListMusics = async(listId: LX.List.ListActionMusicClear) => {
|
||||
await rendererInvoke<LX.List.ListActionMusicClear>(PLAYER_EVENT_NAME.list_music_clear, listId)
|
||||
export const clearListMusics = async(ids: LX.List.ListActionMusicClear) => {
|
||||
await rendererInvoke<LX.List.ListActionMusicClear>(PLAYER_EVENT_NAME.list_music_clear, ids)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -218,6 +219,10 @@ export const registerListAction = (appSetting: LX.AppSetting, onListChanged: (li
|
|||
const updatedListIds = listMusicOverwrite(listId, musicInfos)
|
||||
if (updatedListIds.length) onListChanged(updatedListIds)
|
||||
}
|
||||
const list_music_clear = ({ params: ids }: LX.IpcRendererEventParams<LX.List.ListActionMusicClear>) => {
|
||||
const updatedListIds = listMusicClear(ids)
|
||||
if (updatedListIds.length) onListChanged(updatedListIds)
|
||||
}
|
||||
|
||||
rendererOn(PLAYER_EVENT_NAME.list_data_overwire, list_data_overwrite)
|
||||
rendererOn(PLAYER_EVENT_NAME.list_add, list_create)
|
||||
|
@ -230,7 +235,7 @@ export const registerListAction = (appSetting: LX.AppSetting, onListChanged: (li
|
|||
rendererOn(PLAYER_EVENT_NAME.list_music_update, list_music_update)
|
||||
rendererOn(PLAYER_EVENT_NAME.list_music_update_position, list_music_update_position)
|
||||
rendererOn(PLAYER_EVENT_NAME.list_music_overwrite, list_music_overwrite)
|
||||
// rendererOn(PLAYER_EVENT_NAME.list_data_overwire, list_music_clear)
|
||||
rendererOn(PLAYER_EVENT_NAME.list_data_overwire, list_music_clear)
|
||||
|
||||
return () => {
|
||||
rendererOff(PLAYER_EVENT_NAME.list_data_overwire, list_data_overwrite)
|
||||
|
@ -244,6 +249,6 @@ export const registerListAction = (appSetting: LX.AppSetting, onListChanged: (li
|
|||
rendererOff(PLAYER_EVENT_NAME.list_music_update, list_music_update)
|
||||
rendererOff(PLAYER_EVENT_NAME.list_music_update_position, list_music_update_position)
|
||||
rendererOff(PLAYER_EVENT_NAME.list_music_overwrite, list_music_overwrite)
|
||||
// rendererOff(PLAYER_EVENT_NAME.list_data_overwire, list_music_clear)
|
||||
rendererOff(PLAYER_EVENT_NAME.list_data_overwire, list_music_clear)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue