mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 12:42:06 +00:00
fix(music-together): fix queue index
This commit is contained in:
@ -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');
|
||||||
|
|
||||||
|
|||||||
@ -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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user