fix(music-together): fix queue index

This commit is contained in:
JellyBrick
2025-05-12 03:30:02 +09:00
parent 91a2eb9063
commit d10c6ec8fc
2 changed files with 24 additions and 7 deletions

View File

@ -668,7 +668,7 @@ export default createPlugin<
start({ ipc }) { start({ ipc }) {
this.ipc = ipc; this.ipc = ipc;
this.showPrompt = async (title: string, label: string) => this.showPrompt = (title: string, label: string) =>
ipc.invoke('music-together:prompt', title, label) as Promise<string>; ipc.invoke('music-together:prompt', title, label) as Promise<string>;
this.api = document.querySelector<AppElement>('ytmusic-app'); this.api = document.querySelector<AppElement>('ytmusic-app');

View File

@ -177,12 +177,23 @@ export class Queue {
if (!items) return false; if (!items) return false;
this.internalDispatch = true; this.internalDispatch = true;
this._videoList.push( this._videoList = mapQueueItem(
(it) =>
({
videoId: it!.videoId,
ownerId: this.owner!.id,
}) satisfies VideoData,
this.queue.queue.getItems(),
);
this._videoList.splice(
index ?? this._videoList.length,
0,
...videos.map((it) => ({ ...videos.map((it) => ({
...it, ...it,
ownerId: it.ownerId ?? this.owner?.id, ownerId: it.ownerId ?? this.owner?.id,
})), })),
); );
this.queue?.dispatch({ this.queue?.dispatch({
type: 'ADD_ITEMS', type: 'ADD_ITEMS',
payload: { payload: {
@ -291,7 +302,6 @@ export class Queue {
} }
if (!this.internalDispatch) { if (!this.internalDispatch) {
console.log('Music Together: Queue event', event);
if (event.type === 'CLEAR') { if (event.type === 'CLEAR') {
this.ignoreFlag = true; this.ignoreFlag = true;
} }
@ -310,15 +320,15 @@ export class Queue {
} }
).items, ).items,
); );
const index = this._videoList.length + videoList.length - 1; const index = this._videoList.length;
if (videoList.length > 0) { if (videoList.length > 0) {
this._videoList.push( this._videoList = [
...videoList.map((it) => ({ ...videoList.map((it) => ({
...it, ...it,
ownerId: it.ownerId ?? this.owner?.id, ownerId: it.ownerId ?? this.owner?.id,
})), })),
); ];
this.broadcast({ this.broadcast({
// play // play
type: 'ADD_SONGS', type: 'ADD_SONGS',
@ -364,7 +374,14 @@ export class Queue {
// add playlist // add playlist
type: 'ADD_SONGS', type: 'ADD_SONGS',
payload: { payload: {
// index: (event.payload as any).index, index:
event.payload && Object.hasOwn(event.payload, 'index')
? (
event.payload as {
index: number;
}
).index
: undefined,
videoList, videoList,
}, },
}); });